Merge commit '1ec2c28deda76ce392849805fedd435cea103624' into feature/midi_docs

This commit is contained in:
Ed
2024-04-30 10:58:06 +01:00
10 changed files with 63 additions and 50 deletions

View File

@@ -1,8 +1,14 @@
// Copyright 2011-2021 XMOS LIMITED.
// Copyright 2011-2024 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#ifndef MIDIOUTPARSE_XH
#define MIDIOUTPARSE_XH
// If for any reason we pop a message when not needed (should never happen) this will cause midiparse out to send a size of 0 (drops packet)
#define MIDI_OUT_NULL_MESSAGE 0x00000000
#ifdef __XC__
// Takes a MIDI packet and decomoses it into up to 3 data bytes followed by a byte count.
{unsigned, unsigned, unsigned, unsigned} midi_out_parse(unsigned event);
#endif
#endif

View File

@@ -3,7 +3,9 @@
#ifndef QUEUE_H_
#define QUEUE_H_
#define assert(x) asm("ecallf %0"::"r"(x));
#include "midioutparse.h"
#include "xassert.h"
typedef struct queue_t {
/// Read index.
@@ -21,7 +23,7 @@ inline int is_power_of_2(unsigned x) {
}
inline void queue_init(queue_t &q, unsigned size) {
assert(is_power_of_2(size));
xassert(is_power_of_2(size) && "MIDI FIFO size must be a power of 2"); // Keep this enabled as will be discovered duirng dev time
q.rdptr = 0;
q.wrptr = 0;
q.size = size;
@@ -38,25 +40,26 @@ inline int queue_is_full(const queue_t &q) {
inline void queue_push_word(queue_t &q, unsigned array[], unsigned data)
{
assert(!queue_is_full(q));
if(queue_is_full(q)) {
xassert(0 && "Unexpected push to MIDI queue when full");
// Silently drop message if asserts not enabled
return;
}
array[q.wrptr++ & q.mask] = data;
}
inline unsigned queue_pop_word(queue_t &q, unsigned array[]) {
assert(!queue_is_empty(q));
if(queue_is_empty(q)){
xassert(0 && "Unexpected pop from MIDI queue when empty");
// Return NULL messaqe if asserts not enabled
return MIDI_OUT_NULL_MESSAGE;
}
return array[q.rdptr++ & q.mask];
}
inline void queue_push_byte(queue_t &q, unsigned char array[], unsigned data)
{
assert(!queue_is_full(q));
array[q.wrptr++ & q.mask] = data;
}
inline unsigned queue_pop_byte(queue_t &q, unsigned char array[]) {
assert(!queue_is_empty(q));
return array[q.rdptr++ & q.mask];
}
inline unsigned queue_items(const queue_t &q) {
return q.wrptr - q.rdptr;

View File

@@ -1,4 +1,4 @@
// Copyright 2013-2021 XMOS LIMITED.
// Copyright 2013-2024 XMOS LIMITED.
// This Software is subject to the terms of the XMOS Public Licence: Version 1.
#include "queue.h"
@@ -9,7 +9,5 @@ extern inline int queue_is_empty(const queue_t &q);
extern inline int queue_is_full(const queue_t &q);
extern inline void queue_push_word(queue_t &q, unsigned array[], unsigned data);
extern inline unsigned queue_pop_word(queue_t &q, unsigned array[]);
extern inline void queue_push_byte(queue_t &q, unsigned char array[], unsigned data);
extern inline unsigned queue_pop_byte(queue_t &q, unsigned char array[]);
extern inline unsigned queue_space(const queue_t &q);
extern inline unsigned queue_items(const queue_t &q);

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.
#include <xs1.h>
#include <xclib.h>
@@ -13,7 +13,7 @@
#include "iap_user.h"
#include "coprocessor_user.h"
#endif
//#define MIDI_LOOPBACK 1
int icount = 0;
static unsigned makeSymbol(unsigned data)
{
@@ -89,9 +89,9 @@ void usb_midi(
struct midi_in_parse_state mips;
// the symbol fifo (to go out of uart)
// the symbol fifo (to go out of uart).
queue_t symbol_fifo;
unsigned symbol_fifo_arr[USB_MIDI_DEVICE_OUT_FIFO_SIZE]; // Used for 32bit USB MIDI events
unsigned symbol_fifo_arr[USB_MIDI_DEVICE_OUT_FIFO_SIZE]; // Used for outgoing UART symbols (which include the start and stop bit)
unsigned rxPT, txPT;
int midi_from_host_overflow = 0;
@@ -264,7 +264,7 @@ void usb_midi(
}
break;
#endif
// Received as packet from USB
case !authenticating => midi_get_ack_or_data(c_midi, is_ack, datum):
if (is_ack)
@@ -281,6 +281,7 @@ void usb_midi(
}
}
else
// A midi packet from the host
{
unsigned midi[3];
unsigned size;
@@ -327,7 +328,7 @@ void usb_midi(
midi_from_host_overflow = 1;
}
// Drop through to the isTX guarded case
if (!isTX)
if (!isTX && size > 0) // do not start tx'ing if this packet has no size
{
t :> txT; // Should be enough to trigger the other case
isTX = 1;