From 2a3940d8a36433485a6ef489d5123cd491618b50 Mon Sep 17 00:00:00 2001 From: Duncan Wilkie Date: Mon, 7 Aug 2023 17:29:29 -0500 Subject: slave progress and WCET --- controller/libs/base_midi.c | 47 +++++++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'controller/libs/base_midi.c') diff --git a/controller/libs/base_midi.c b/controller/libs/base_midi.c index 6efd2f3..0394406 100644 --- a/controller/libs/base_midi.c +++ b/controller/libs/base_midi.c @@ -1,14 +1,18 @@ - // This file is written to be read side-along with the MIDI 1.0 spec. +// This file is written to be read side-along with the MIDI 1.0 spec. // Note the tables at its very end, with /absolutely no direct allusion in the text/. #include "base_midi.h" #include #include -// TODO: startup function to initialize ParseMemory buffer. + #ifdef RUNNING_STATUS uint8_t last_status = 0x00; #endif +ConsumerBehavior pfns; +ParserMemory memory; + + // Helper functions #define MAX_DATA_BYTE 0b01111111 static inline void MIDI_bare_send(uint8_t status) { @@ -539,24 +543,21 @@ void single_note_tuning_change(uint8_t device_id, uint8_t program, uint8_t *note // Parsing. // Stream parsing. -typedef struct { - uint8_t status; - bool first_byte; - uint8_t byte0; - bool send_eox; - uint8_t *stack; - size_t top; - size_t size; -} ParserMemory; #define WAITING_FOR_STATUS 0x00 -ParserMemory memory = {.status = WAITING_FOR_STATUS, - .first_byte = false, - .byte0 = 0x00, - .send_eox = false, - .stack = NULL, // TODO: initialize from main. - .top = 0, - .size = 128}; + + +void midi_init(ConsumerBehavior new_pfns) { + memory.status = WAITING_FOR_STATUS; + memory.first_byte = false; + memory.send_eox = false; + memory.stack = malloc(128); + memory.top = 0; + memory.size = 128; + + pfns = new_pfns; +} + static inline void push_fn(uint8_t val) { if (memory.top == memory.size - 1) { @@ -571,14 +572,6 @@ static inline void push_fn(uint8_t val) { push_fn(byte); \ } while(0) -static inline uint8_t pop() { - if (memory.size - memory.top > 128) { - memory.stack = realloc(memory.stack, memory.size - 128); - } - - --memory.top; - return memory.stack[memory.top + 1]; -} static inline void reset() { memory.stack = realloc(memory.stack, 128); @@ -594,7 +587,7 @@ static inline void reset() { #define channel (memory.status & 0x0f) - +#define MIDI_CI_SUBID 0x0d // Memory should be large enough to handle the largest message that's expected to be processed automatically here. void parse_midi_stream(uint8_t byte) { -- cgit v1.2.3