forked from PAWPAW-Mirror/lib_xua
Initial passing tx test using pyxsim
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
#include <platform.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <xclib.h>
|
||||
|
||||
#include "xua.h"
|
||||
@@ -31,59 +32,92 @@ on tile[MIDI_TILE] : buffered in port:1 p_midi_rx = XS1_PORT_1F;
|
||||
#define CLKBLK_MIDI XS1_CLKBLK_2
|
||||
on tile[MIDI_TILE] : clock clk_midi = CLKBLK_MIDI;
|
||||
|
||||
|
||||
/* Port declarations for I2C to config ADC's */
|
||||
on tile[0]: port p_scl = XS1_PORT_1L;
|
||||
on tile[0]: port p_sda = XS1_PORT_1M;
|
||||
#define MAX_TEST_COMMANDS 10
|
||||
#define TEST_COMMAND_FILE "midi_tx_cmds.txt"
|
||||
|
||||
/* See hwsupport.xc */
|
||||
void ctrlPort();
|
||||
|
||||
#define CABLE_NUM 0
|
||||
|
||||
#define NOTE_ON 0x90
|
||||
#define PITCH 60
|
||||
#define VELOCITY 80
|
||||
|
||||
void test(chanend c_midi){
|
||||
struct midi_in_parse_state mips;
|
||||
reset_midi_state(mips);
|
||||
unsigned mini_in_parse_helper(unsigned midi[3]){
|
||||
// printf("Composing data: 0x%x 0x%x 0x%x\n", midi[0], midi[1], midi[2]);
|
||||
|
||||
struct midi_in_parse_state m_state;
|
||||
reset_midi_state(m_state);
|
||||
|
||||
unsigned valid = 0;
|
||||
unsigned tx_data = 0;
|
||||
{valid, tx_data} = midi_in_parse(mips,CABLE_NUM, NOTE_ON);
|
||||
printf("Valid: %d data: %u\n", valid, tx_data);
|
||||
{valid, tx_data} = midi_in_parse(mips, CABLE_NUM, PITCH);
|
||||
printf("Valid: %d data: %u\n", valid, tx_data);
|
||||
{valid, tx_data} = midi_in_parse(mips, CABLE_NUM, VELOCITY);
|
||||
printf("Valid: %d data: %u\n", valid, tx_data);
|
||||
unsigned packed = 0;
|
||||
|
||||
for(int i = 0; i < 3; i++){
|
||||
{valid, packed} = midi_in_parse(m_state, CABLE_NUM, midi[i]);
|
||||
if(valid){
|
||||
return packed;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
char midi[3];
|
||||
unsigned size = 0;
|
||||
{midi[0], midi[1], midi[2], size} = midi_out_parse(tx_data);
|
||||
printf("size: %d data: 0x%x 0x%x 0x%x\n", size, midi[0], midi[1], midi[2]);
|
||||
unsigned parse_cmd_line(uint8_t commands[MAX_TEST_COMMANDS][3])
|
||||
{
|
||||
FILE * movable fptr_tx = fopen(TEST_COMMAND_FILE,"rt");
|
||||
if (fptr_tx == NULL) {
|
||||
printf("ERROR: TX command file %s not found or unable to open.\n", TEST_COMMAND_FILE);
|
||||
fclose(move(fptr_tx));
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned line = 0;
|
||||
|
||||
unsigned a,b,c;
|
||||
while (fscanf(fptr_tx, "%u %u %u\n", &a, &b, &c) == 3) {
|
||||
commands[line][0] = a;
|
||||
commands[line][1] = b;
|
||||
commands[line][2] = c;
|
||||
// printf("Line %u params: 0x%x 0x%x 0x%x\n", line, commands[line][0], commands[line][1], commands[line][2]);
|
||||
line++;
|
||||
if(line > MAX_TEST_COMMANDS){
|
||||
printf("ERROR: Too many lines in TX command file\n");
|
||||
|
||||
fclose(move(fptr_tx));
|
||||
return MAX_TEST_COMMANDS;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(move(fptr_tx));
|
||||
return line;
|
||||
}
|
||||
|
||||
void test(chanend c_midi){
|
||||
uint8_t commands[MAX_TEST_COMMANDS][3] = {{0}};
|
||||
unsigned num_tx = parse_cmd_line(commands);
|
||||
|
||||
int is_ack;
|
||||
unsigned int datum;
|
||||
unsigned datum;
|
||||
|
||||
unsigned count = 0;
|
||||
unsigned line = 0;
|
||||
while(1){
|
||||
select{
|
||||
case midi_get_ack_or_data(c_midi, is_ack, datum):
|
||||
printf("ACK: %d Datum: 0x%x\n", is_ack, datum);
|
||||
count++;
|
||||
if(count == 3){
|
||||
// printf("ACK: %d Datum: 0x%x\n", is_ack, datum);
|
||||
line++;
|
||||
if(line == num_tx){
|
||||
delay_microseconds(200); // Allow frame to complete
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
outuint(c_midi, byterev(tx_data));
|
||||
printf("SEND TO MIDI\n");
|
||||
delay_milliseconds(2); // 30 bits at 31.25 kbps is 0.96ms
|
||||
if(num_tx){
|
||||
unsigned midi[] = {commands[line][0], commands[line][1], commands[line][2]};
|
||||
unsigned tx_packet = mini_in_parse_helper(midi);
|
||||
outuint(c_midi, byterev(tx_packet));
|
||||
// printf("SEND TO MIDI: 0x%x\n", tx_packet);
|
||||
delay_milliseconds(2); // 30 bits at 31.25 kbps is 0.96ms
|
||||
} else {
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -91,11 +125,10 @@ void test(chanend c_midi){
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
int main(void)
|
||||
{
|
||||
chan c_midi;
|
||||
|
||||
|
||||
par
|
||||
{
|
||||
on tile[0]: test(c_midi);
|
||||
|
||||
Reference in New Issue
Block a user