From a96a1375330bc0da47d0da1b089264d710edcd1d Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 29 May 2024 13:31:54 +0100 Subject: [PATCH 1/5] Send pause control token to release midi channel from ep_buffer --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index 8ed2ba01..b2d2cbb1 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -993,6 +993,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); + outct(c_midi, XS1_CT_PAUSE); midi_from_host_rdptr += 4; midi_data_remaining_to_device -= 4; } @@ -1001,6 +1002,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, { /* The midi/uart thread has sent us some data - handshake back */ midi_send_ack(c_midi); + outct(c_midi, XS1_CT_PAUSE); if (midi_data_collected_from_device < MIDI_USB_BUFFER_TO_HOST_SIZE) { /* There is room in the collecting buffer for the data */ From 5daee760affc358479c121adff466ba915b1b05c Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 29 May 2024 14:54:17 +0100 Subject: [PATCH 2/5] Use CT_END instead of CT_PAUSE for MIDI handshake --- lib_xua/api/xua_midi.h | 15 +++++++++------ lib_xua/src/core/buffer/ep/ep_buffer.xc | 6 ++---- lib_xua/src/midi/usb_midi.xc | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib_xua/api/xua_midi.h b/lib_xua/api/xua_midi.h index 81a03eed..d7697fbb 100644 --- a/lib_xua/api/xua_midi.h +++ b/lib_xua/api/xua_midi.h @@ -58,23 +58,26 @@ 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 b2d2cbb1..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,8 +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); - outct(c_midi, XS1_CT_PAUSE); + midi_send_data(c_midi, datum); midi_from_host_rdptr += 4; midi_data_remaining_to_device -= 4; } @@ -1002,7 +1001,6 @@ void XUA_Buffer_Ep(register chanend c_aud_out, { /* The midi/uart thread has sent us some data - handshake back */ midi_send_ack(c_midi); - outct(c_midi, XS1_CT_PAUSE); if (midi_data_collected_from_device < MIDI_USB_BUFFER_TO_HOST_SIZE) { /* There is room in the collecting buffer for the data */ 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; } From aa769dabb46fb3b4578aa6a4fbe5afae9bf153da Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 29 May 2024 15:28:06 +0100 Subject: [PATCH 3/5] fix tests --- tests/test_midi/src/app_midi_simple.xc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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(); } From e92665174d0f14368b24c5c4ce19da844d578425 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 29 May 2024 15:51:14 +0100 Subject: [PATCH 4/5] use CT_END as ack --- lib_xua/api/xua_midi.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib_xua/api/xua_midi.h b/lib_xua/api/xua_midi.h index d7697fbb..b5107bf5 100644 --- a/lib_xua/api/xua_midi.h +++ b/lib_xua/api/xua_midi.h @@ -57,7 +57,6 @@ 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 chkct(c, XS1_CT_END); } else { @@ -69,7 +68,6 @@ INLINE void midi_get_ack_or_data(chanend c, int &is_ack, unsigned int &datum) { #endif INLINE void midi_send_ack(chanend c) { - outct(c, MIDI_ACK); outct(c, XS1_CT_END); } From 5caee234e53b7b0a518b8fe2fe785be27cd90f85 Mon Sep 17 00:00:00 2001 From: Shuchita Khare Date: Wed, 29 May 2024 15:54:34 +0100 Subject: [PATCH 5/5] copyright + changelog --- CHANGELOG.rst | 1 + lib_xua/api/xua_midi.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 b5107bf5..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_