Merge pull request #396 from shuchitak/midi_ct_pause

Use CT_END tokens in MIDI to terminate connection
This commit is contained in:
danielpieczko
2024-05-29 16:21:49 +01:00
committed by GitHub
5 changed files with 18 additions and 16 deletions

View File

@@ -17,6 +17,7 @@ UNRELEASED
* FIXED: Samples transferred to ADAT tx too frequently in TDM mode * 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: S/MUX not initialised to a value based on DEFAULT_FREQ in clockgen
* FIXED: Trap when moving to DSD mode on XS3A based devices * FIXED: Trap when moving to DSD mode on XS3A based devices
* ADDED: CT_END token based handshake in MIDI channels transactions
4.0.0 4.0.0
----- -----

View File

@@ -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. // This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef _XUA_MIDI_H_ #ifndef _XUA_MIDI_H_
#define _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) { INLINE void midi_get_ack_or_data(chanend c, int &is_ack, unsigned int &datum) {
if (testct(c)) { if (testct(c)) {
is_ack = 1; is_ack = 1;
(void) inct(c); // read 1-bytes control token chkct(c, XS1_CT_END);
(void) inuchar(c);
(void) inuchar(c);
(void) inuchar(c);
} }
else { else {
is_ack = 0; is_ack = 0;
datum = inuint(c); datum = inuint(c);
chkct(c, XS1_CT_END);
} }
} }
#endif #endif
INLINE void midi_send_ack(chanend c) { INLINE void midi_send_ack(chanend c) {
outct(c, MIDI_ACK); outct(c, XS1_CT_END);
outuchar(c, 0);
outuchar(c, 0);
outuchar(c, 0);
} }
INLINE void midi_send_data(chanend c, unsigned int datum) {
outuint(c, datum);
outct(c, XS1_CT_END);
}
#define MIDI_RATE (31250) #define MIDI_RATE (31250)
#define MIDI_BITTIME (XS1_TIMER_MHZ * 1000000 / MIDI_RATE) #define MIDI_BITTIME (XS1_TIMER_MHZ * 1000000 / MIDI_RATE)
#define MIDI_BITTIME_2 (MIDI_BITTIME>>1) #define MIDI_BITTIME_2 (MIDI_BITTIME>>1)

View File

@@ -839,7 +839,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out,
if (midi_data_remaining_to_device) if (midi_data_remaining_to_device)
{ {
read_via_xc_ptr(datum, midi_from_host_rdptr); 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_from_host_rdptr += 4;
midi_data_remaining_to_device -= 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 another word from the fifo and output it to MIDI thread */
read_via_xc_ptr(datum, midi_from_host_rdptr); 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_from_host_rdptr += 4;
midi_data_remaining_to_device -= 4; midi_data_remaining_to_device -= 4;
} }

View File

@@ -197,7 +197,7 @@ void usb_midi(
{ {
// send data // send data
// printstr("uart->decouple: "); // printstr("uart->decouple: ");
outuint(c_midi, event); midi_send_data(c_midi, event);
waiting_for_ack = 1; waiting_for_ack = 1;
th_count++; th_count++;
} }
@@ -272,7 +272,7 @@ void usb_midi(
// have we got more data to send // have we got more data to send
if (!queue_is_empty(midi_to_host_fifo)) 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++; th_count++;
} }
else else
@@ -296,7 +296,7 @@ void usb_midi(
{ {
// send data // send data
event = byterev(event); event = byterev(event);
outuint(c_midi, event); midi_send_data(c_midi, event);
th_count++; th_count++;
waiting_for_ack = 1; waiting_for_ack = 1;
} }

View File

@@ -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]}; 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 // 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); 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); 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; t_tx += tx_interval;
tx_end += max_tx_time; tx_end += max_tx_time;
@@ -172,7 +172,7 @@ int main(void)
on tile[0]: test(c_midi); on tile[0]: test(c_midi);
on tile[1]: usb_midi(p_midi_rx, p_midi_tx, clk_midi, c_midi, 0); 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(); on tile[0]: board_setup();
} }