diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-03-03 20:07:27 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-03-05 18:38:04 +0100 |
| commit | e32281cf6b01800f95d7640a127811c79234fe6f (patch) | |
| tree | f34d870bfdfa425600aead8cbf9aadcbc71d4fbc /src/Serial.c | |
| parent | 792e22676786a577b2edc0ed0ed78e51c5b38245 (diff) | |
| download | opensend-e32281cf6b01800f95d7640a127811c79234fe6f.tar.gz | |
Work on SIO IRQ
Diffstat (limited to 'src/Serial.c')
| -rw-r--r-- | src/Serial.c | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/src/Serial.c b/src/Serial.c index 4bfb45c..f0c092e 100644 --- a/src/Serial.c +++ b/src/Serial.c @@ -1,38 +1,57 @@ -/* ************************************* - * Includes - * *************************************/ - #include "Serial.h" #include "Interrupts.h" #include <psxsio.h> #include <stdarg.h> #include <stdio.h> +#include <psxbios.h> +#include <psx.h> +#include <stddef.h> + +static volatile size_t isr_calls; + +void sio_handler_callback(void) +{ + printf("%s\n", __func__); + isr_calls++; +} -/* ************************************* - * Defines - * *************************************/ +void SerialInit(void) +{ + int *sio_handler(void); -#define SERIAL_BAUDRATE 115200 -#define SERIAL_TX_RX_TIMEOUT 20000 -#define SERIAL_RX_FIFO_EMPTY 0 -#define SERIAL_TX_NOT_READY 0 -#define SERIAL_PRINTF_INTERNAL_BUFFER_SIZE 256 + enum + { + SIO_CLASS = 0xF000000B + }; -/* ************************************** - * Structs and enums * - * *************************************/ + EnterCriticalSection(); -/* ************************************* - * Local Variables - * *************************************/ + IMASK |= 1 << 8; -/* ************************************* - * Local Prototypes - * *************************************/ + const int sio_handle = OpenEvent(SIO_CLASS, 0x1000, 0x1000, sio_handler); -void SerialInit(void) -{ - SIOStart(115200); + if (sio_handle != 0xFFFFFFFF) + { + enum + { + BAUD_RATE = 115200 + }; + + EnableEvent(sio_handle); + SIOStart(BAUD_RATE); + redirect_stdio_to_sio(); + printf("sio_handle = 0x%08X", sio_handle); + } + + ExitCriticalSection(); + + SIOSendByte('y'); + + printf("%u\n", isr_calls); + + while (!(IPENDING & (1 << 8))); + + printf("SIO ISR triggered\n"); } void SerialRead(uint8_t *ptrArray, size_t nBytes) @@ -43,7 +62,8 @@ void SerialRead(uint8_t *ptrArray, size_t nBytes) do { - while ( (SIOCheckInBuffer() == SERIAL_RX_FIFO_EMPTY)); // Wait for RX FIFO not empty + /* Wait for RX FIFO not empty. */ + while (!SIOCheckInBuffer()); *(ptrArray++) = SIOReadByte(); } while (--nBytes); @@ -59,7 +79,8 @@ void SerialWrite(const void* ptrArray, size_t nBytes) InterruptsDisableInt(INT_SOURCE_VBLANK); do { - while ( (SIOCheckOutBuffer() == SERIAL_TX_NOT_READY)); // Wait for TX FIFO empty. + /* Wait for TX FIFO empty. */ + while (!SIOCheckOutBuffer()); SIOSendByte(*(uint8_t*)ptrArray++); |
