From 68e21103e09c7a59292485ab805683760b86e6ba Mon Sep 17 00:00:00 2001 From: Xavi Del Campo Date: Sun, 8 Mar 2020 17:23:03 +0100 Subject: Implemented message protocol, not tested yet --- src/Serial.c | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'src/Serial.c') diff --git a/src/Serial.c b/src/Serial.c index f91f168..10bb90f 100644 --- a/src/Serial.c +++ b/src/Serial.c @@ -6,38 +6,29 @@ #include #include #include +#include "reception.h" -enum -{ - FIFO_SZ = 128 -}; - -typedef volatile struct -{ - unsigned char buf[FIFO_SZ]; - size_t pending, processed; - bool full; -} fifo; - -static fifo rx; +fifo rx; -void sio_handler_callback(void) +static void sio_handler_callback(void) { while (SIOCheckInBuffer()) { const unsigned char in = SIOReadByte(); size_t aux = rx.pending; - if (++aux >= (sizeof rx.buf / sizeof *rx.buf)) + if (++aux >= sizeof rx.buf / sizeof *rx.buf) aux = 0; if (aux != rx.processed) { rx.buf[aux] = in; - rx.pending = rx.processed; + rx.pending = aux; + reception_ev(); } else { + printf("fifo full\n"); rx.full = true; } } @@ -78,22 +69,27 @@ void SerialInit(void) }; const int not_crit = EnterCriticalSection(); - void sio_handler(void); + + EnterCriticalSection(); SIOReset(); SIOStart(BAUD_RATE); - const int sio_handle = OpenEvent(SIO_CLASS, SPEC_GENERAL_INTERRUPT, TRIGGER_CALLBACK, sio_handler); + IMASK |= 1 << INT_SIO; - if (sio_handle != 0xFFFFFFFF) - EnableEvent(sio_handle); + void sio_handler(void); + const int sio_handle = OpenEvent(SIO_CLASS, SPEC_GENERAL_INTERRUPT, TRIGGER_CALLBACK, sio_handler_callback); - IMASK |= 1 << INT_SIO; + if (sio_handle != -1) + EnableEvent(sio_handle); SIOEnableRXInterrupt(); if (not_crit) - { ExitCriticalSection(); - } +} + +void SerialWrite(const unsigned char byte) +{ + SIOSendByte(byte); } -- cgit v1.2.3