diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3ae78cc5..7d9f6d5b 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -17,6 +17,7 @@ UNRELEASED * FIXED: Samples transferred to ADAT tx too frequently in TDM mode * FIXED: S/MUX not initialised to a value based on DEFAULT_FREQ in clockgen * FIXED: Trap when moving to DSD mode on XS3A based devices + * ADDED: CT_END token based handshake in MIDI channels transactions 4.0.0 ----- diff --git a/lib_xua/api/xua_midi.h b/lib_xua/api/xua_midi.h index 81a03eed..4098f8e0 100644 --- a/lib_xua/api/xua_midi.h +++ b/lib_xua/api/xua_midi.h @@ -1,4 +1,4 @@ -// Copyright 2011-2022 XMOS LIMITED. +// Copyright 2011-2024 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _XUA_MIDI_H_ #define _XUA_MIDI_H_ @@ -57,24 +57,25 @@ void midi_get_ack_or_data(chanend c, int &is_ack, unsigned int &datum); INLINE void midi_get_ack_or_data(chanend c, int &is_ack, unsigned int &datum) { if (testct(c)) { is_ack = 1; - (void) inct(c); // read 1-bytes control token - (void) inuchar(c); - (void) inuchar(c); - (void) inuchar(c); + chkct(c, XS1_CT_END); } else { is_ack = 0; datum = inuint(c); + chkct(c, XS1_CT_END); } } #endif INLINE void midi_send_ack(chanend c) { - outct(c, MIDI_ACK); - outuchar(c, 0); - outuchar(c, 0); - outuchar(c, 0); + outct(c, XS1_CT_END); } + +INLINE void midi_send_data(chanend c, unsigned int datum) { + outuint(c, datum); + outct(c, XS1_CT_END); +} + #define MIDI_RATE (31250) #define MIDI_BITTIME (XS1_TIMER_MHZ * 1000000 / MIDI_RATE) #define MIDI_BITTIME_2 (MIDI_BITTIME>>1) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 8ed2ba01..537210a0 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -839,7 +839,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, if (midi_data_remaining_to_device) { read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); + midi_send_data(c_midi, datum); midi_from_host_rdptr += 4; midi_data_remaining_to_device -= 4; } @@ -992,7 +992,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, { /* Read another word from the fifo and output it to MIDI thread */ read_via_xc_ptr(datum, midi_from_host_rdptr); - outuint(c_midi, datum); + midi_send_data(c_midi, datum); midi_from_host_rdptr += 4; midi_data_remaining_to_device -= 4; } diff --git a/lib_xua/src/midi/usb_midi.xc b/lib_xua/src/midi/usb_midi.xc index a81b235f..34c9c6f4 100644 --- a/lib_xua/src/midi/usb_midi.xc +++ b/lib_xua/src/midi/usb_midi.xc @@ -197,7 +197,7 @@ void usb_midi( { // send data // printstr("uart->decouple: "); - outuint(c_midi, event); + midi_send_data(c_midi, event); waiting_for_ack = 1; th_count++; } @@ -272,7 +272,7 @@ void usb_midi( // have we got more data to send if (!queue_is_empty(midi_to_host_fifo)) { - outuint(c_midi, queue_pop_word(midi_to_host_fifo, midi_to_host_fifo_arr)); + midi_send_data(c_midi, queue_pop_word(midi_to_host_fifo, midi_to_host_fifo_arr)); th_count++; } else @@ -296,7 +296,7 @@ void usb_midi( { // send data event = byterev(event); - outuint(c_midi, event); + midi_send_data(c_midi, event); th_count++; waiting_for_ack = 1; } diff --git a/tests/test_midi/src/app_midi_simple.xc b/tests/test_midi/src/app_midi_simple.xc index 94e71079..17fd4443 100644 --- a/tests/test_midi/src/app_midi_simple.xc +++ b/tests/test_midi/src/app_midi_simple.xc @@ -148,7 +148,7 @@ void test(chanend c_midi){ unsigned midi[] = {commands[tx_cmd_count][0], commands[tx_cmd_count][1], commands[tx_cmd_count][2]}; // Even though this is a Tx to MIDI we use midi_in_parse_helper to form the packet from bytes unsigned tx_packet = midi_in_parse_helper(midi, m_state); - outuint(c_midi, byterev(tx_packet)); + midi_send_data(c_midi, byterev(tx_packet)); dprintf("Sent packet to midi: %u %u %u (0x%8x)\n", commands[tx_cmd_count][0], commands[tx_cmd_count][1], commands[tx_cmd_count][2], tx_packet); t_tx += tx_interval; tx_end += max_tx_time; @@ -172,7 +172,7 @@ int main(void) on tile[0]: test(c_midi); on tile[1]: usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0); - // Setup HW so we can run this on the MC board + // Setup HW so we can run this on the MC board on tile[0]: board_setup(); }