summaryrefslogtreecommitdiff
path: root/src/Serial.c
diff options
context:
space:
mode:
authorXavi Del Campo <xavi.dcr@tutanota.com>2020-03-08 17:23:03 +0100
committerXavi Del Campo <xavi.dcr@tutanota.com>2020-03-08 22:33:58 +0100
commit68e21103e09c7a59292485ab805683760b86e6ba (patch)
tree92c33d6211eeae35600525e2520a138503e8281d /src/Serial.c
parent96b0c9d692fd4b41d41e13cdcd8fc773b3976dde (diff)
downloadopensend-68e21103e09c7a59292485ab805683760b86e6ba.tar.gz
Implemented message protocol, not tested yet
Diffstat (limited to 'src/Serial.c')
-rw-r--r--src/Serial.c42
1 files changed, 19 insertions, 23 deletions
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 <psxbios.h>
#include <psx.h>
#include <stddef.h>
+#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);
}