forked from PAWPAW-Mirror/lib_xua
Replace one place buffer going to host with queue
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
static unsigned makeSymbol(unsigned data) {
|
static unsigned makeSymbol(unsigned data) {
|
||||||
// Start and stop bits to the data packet
|
// Start and stop bits to the data packet
|
||||||
|
// like 10'b1dddddddd0
|
||||||
return (data << 1) | 0x200;
|
return (data << 1) | 0x200;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,9 +72,10 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
timer t;
|
timer t;
|
||||||
timer t2;
|
timer t2;
|
||||||
|
|
||||||
// these two vars make a one place buffer for data going out to host
|
// One place buffer for data going out to host
|
||||||
int got_next_event = 0;
|
queue to_host_fifo;
|
||||||
int next_event;
|
unsigned to_host_fifo_arr[1];
|
||||||
|
|
||||||
unsigned outputting_symbol, outputted_symbol;
|
unsigned outputting_symbol, outputted_symbol;
|
||||||
|
|
||||||
struct midi_in_parse_state mips;
|
struct midi_in_parse_state mips;
|
||||||
@@ -87,6 +89,7 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
|
|
||||||
//configure_clock_rate(clk_midi, 100, 1);
|
//configure_clock_rate(clk_midi, 100, 1);
|
||||||
init_queue(symbol_fifo, symbol_fifo_arr, USB_MIDI_DEVICE_OUT_FIFO_SIZE);
|
init_queue(symbol_fifo, symbol_fifo_arr, USB_MIDI_DEVICE_OUT_FIFO_SIZE);
|
||||||
|
init_queue(to_host_fifo, to_host_fifo_arr, 1);
|
||||||
|
|
||||||
configure_out_port_no_ready(p_midi_out, clk_midi, 1);
|
configure_out_port_no_ready(p_midi_out, clk_midi, 1);
|
||||||
configure_in_port(p_midi_in, clk_midi);
|
configure_in_port(p_midi_in, clk_midi);
|
||||||
@@ -154,7 +157,7 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
{valid, event} = midi_in_parse(mips, cable_number, rxByte);
|
{valid, event} = midi_in_parse(mips, cable_number, rxByte);
|
||||||
if (valid && !got_next_event) {
|
if (valid && isempty(to_host_fifo)) {
|
||||||
event = byterev(event);
|
event = byterev(event);
|
||||||
// data to send to host - add to fifo
|
// data to send to host - add to fifo
|
||||||
if (!waiting_for_ack) {
|
if (!waiting_for_ack) {
|
||||||
@@ -163,10 +166,8 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
outuint(c_midi, event);
|
outuint(c_midi, event);
|
||||||
waiting_for_ack = 1;
|
waiting_for_ack = 1;
|
||||||
th_count++;
|
th_count++;
|
||||||
}
|
} else {
|
||||||
else {
|
enqueue(to_host_fifo, event);
|
||||||
next_event = event;
|
|
||||||
got_next_event = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (valid) {
|
else if (valid) {
|
||||||
@@ -222,11 +223,10 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
if (is_ack) {
|
if (is_ack) {
|
||||||
// have we got more data to send
|
// have we got more data to send
|
||||||
//printstr("ack\n");
|
//printstr("ack\n");
|
||||||
if (got_next_event) {
|
if (!isempty(to_host_fifo)) {
|
||||||
//printstr("uart->decouple\n");
|
//printstr("uart->decouple\n");
|
||||||
outuint(c_midi, next_event);
|
outuint(c_midi, dequeue(to_host_fifo));
|
||||||
th_count++;
|
th_count++;
|
||||||
got_next_event = 0;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
waiting_for_ack = 0;
|
waiting_for_ack = 0;
|
||||||
@@ -240,7 +240,7 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
event = byterev(datum);
|
event = byterev(datum);
|
||||||
mr_count++;
|
mr_count++;
|
||||||
#ifdef MIDI_LOOPBACK
|
#ifdef MIDI_LOOPBACK
|
||||||
if (!got_next_event) {
|
if (isempty(to_host_fifo)) {
|
||||||
// data to send to host
|
// data to send to host
|
||||||
if (!waiting_for_ack) {
|
if (!waiting_for_ack) {
|
||||||
// send data
|
// send data
|
||||||
@@ -251,8 +251,7 @@ void usb_midi(in port ?p_midi_in, out port ?p_midi_out,
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
event = byterev(event);
|
event = byterev(event);
|
||||||
next_event = event;
|
enqueue(to_host_fifo, event);
|
||||||
got_next_event = 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user