diff options
| author | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-03-08 14:09:11 +0100 |
|---|---|---|
| committer | Xavi Del Campo <xavi.dcr@tutanota.com> | 2020-03-08 17:10:59 +0100 |
| commit | 96b0c9d692fd4b41d41e13cdcd8fc773b3976dde (patch) | |
| tree | 8acee0c8d8c4a412f330e41214ec75e7702c8df7 | |
| parent | e32281cf6b01800f95d7640a127811c79234fe6f (diff) | |
First working RX ISR
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | cdimg/data/FONTS/FONT_2.FNT (renamed from cdimg/DATA/FONTS/FONT_2.FNT) | bin | 3136 -> 3136 bytes | |||
| -rw-r--r-- | include/reception.h | 7 | ||||
| -rw-r--r-- | src/Serial.c | 145 | ||||
| -rw-r--r-- | src/System.c | 1 | ||||
| -rw-r--r-- | src/main.c | 8 | ||||
| -rw-r--r-- | src/reception.c | 26 | ||||
| -rw-r--r-- | src/sio.s | 94 |
8 files changed, 107 insertions, 175 deletions
@@ -1,6 +1,7 @@ PSXSDK_DIR = /usr/local/psxsdk AS = mipsel-unknown-elf-as +AS_FLAGS = -msoft-float CC = mipsel-unknown-elf-gcc DEFINE = -DVIDEO_MODE=VMODE_PAL -D__PSXSDK__ -fno-strict-overflow -fsigned-char -msoft-float -mno-gpopt -fno-builtin -g LIBS = -lfixmath diff --git a/cdimg/DATA/FONTS/FONT_2.FNT b/cdimg/data/FONTS/FONT_2.FNT Binary files differindex 36361b2..36361b2 100644 --- a/cdimg/DATA/FONTS/FONT_2.FNT +++ b/cdimg/data/FONTS/FONT_2.FNT diff --git a/include/reception.h b/include/reception.h new file mode 100644 index 0000000..80a6acb --- /dev/null +++ b/include/reception.h @@ -0,0 +1,7 @@ +#ifndef RECEPTION_H +#define RECEPTION_H + +void reception_ev(void); +void reception_loop(void); + +#endif /* RECEPTION_H */ diff --git a/src/Serial.c b/src/Serial.c index f0c092e..f91f168 100644 --- a/src/Serial.c +++ b/src/Serial.c @@ -7,106 +7,93 @@ #include <psx.h> #include <stddef.h> -static volatile size_t isr_calls; - -void sio_handler_callback(void) +enum { - printf("%s\n", __func__); - isr_calls++; -} + FIFO_SZ = 128 +}; -void SerialInit(void) +typedef volatile struct { - int *sio_handler(void); + unsigned char buf[FIFO_SZ]; + size_t pending, processed; + bool full; +} fifo; - enum - { - SIO_CLASS = 0xF000000B - }; - - EnterCriticalSection(); +static fifo rx; - IMASK |= 1 << 8; +void sio_handler_callback(void) +{ + while (SIOCheckInBuffer()) + { + const unsigned char in = SIOReadByte(); + size_t aux = rx.pending; - const int sio_handle = OpenEvent(SIO_CLASS, 0x1000, 0x1000, sio_handler); + if (++aux >= (sizeof rx.buf / sizeof *rx.buf)) + aux = 0; - if (sio_handle != 0xFFFFFFFF) - { - enum + if (aux != rx.processed) { - BAUD_RATE = 115200 - }; - - EnableEvent(sio_handle); - SIOStart(BAUD_RATE); - redirect_stdio_to_sio(); - printf("sio_handle = 0x%08X", sio_handle); + rx.buf[aux] = in; + rx.pending = rx.processed; + } + else + { + rx.full = true; + } } - ExitCriticalSection(); - - SIOSendByte('y'); - - printf("%u\n", isr_calls); - - while (!(IPENDING & (1 << 8))); - - printf("SIO ISR triggered\n"); + SIOAcknowledgeInterrupt(); } -void SerialRead(uint8_t *ptrArray, size_t nBytes) +void SerialInit(void) { - if (nBytes) + enum { - InterruptsDisableInt(INT_SOURCE_VBLANK); - - do - { - /* Wait for RX FIFO not empty. */ - while (!SIOCheckInBuffer()); - - *(ptrArray++) = SIOReadByte(); - } while (--nBytes); - - InterruptsEnableInt(INT_SOURCE_VBLANK); - } -} + SPEC_COUNTER_BECOMES_ZERO = 0x0001, + SPEC_INTERRUPTED = 0x0002, + SPEC_EOF = 0x0004, + SPEC_FILE_WAS_CLOSED = 0x0008, + SPEC_CMD_ACK = 0x0010, + SPEC_CMD_COMPLETED = 0x0020, + SPEC_DATA_READY = 0x0040, + SPEC_DATA_END = 0x0080, + SPEC_TIMEOUT = 0x0100, + SPEC_UNKNOWN_CMD = 0x0200, + SPEC_END_READ_BUFFER = 0x0400, + SPEC_END_WRITE_BUFFER = 0x0800, + SPEC_GENERAL_INTERRUPT = 0x1000, + SPEC_NEW_DEVICE = 0x2000, + SPEC_SYS_CALL_INSTR = 0x4000, + SPEC_ERROR = 0x8000, + SPEC_PREV_WRITE_ERROR = 0x8001, + SPEC_DOMAIN_ERROR_LIBMATH = 0x0301, + SPEC_RANGE_ERROR_LIBMATH = 0x0302 + }; -void SerialWrite(const void* ptrArray, size_t nBytes) -{ - if (nBytes) + enum { - InterruptsDisableInt(INT_SOURCE_VBLANK); - do - { - /* Wait for TX FIFO empty. */ - while (!SIOCheckOutBuffer()); + SIO_CLASS = 0xF000000B, + TRIGGER_CALLBACK = 0x1000, + BAUD_RATE = 115200 + }; - SIOSendByte(*(uint8_t*)ptrArray++); + const int not_crit = EnterCriticalSection(); + void sio_handler(void); - } while (--nBytes); + SIOReset(); + SIOStart(BAUD_RATE); - InterruptsEnableInt(INT_SOURCE_VBLANK); - } - else - { - } -} + const int sio_handle = OpenEvent(SIO_CLASS, SPEC_GENERAL_INTERRUPT, TRIGGER_CALLBACK, sio_handler); -#ifdef SERIAL_INTERFACE -void Serial_printf(const char* const str, ...) -{ - va_list ap; - int result; - static char internal_buffer[SERIAL_PRINTF_INTERNAL_BUFFER_SIZE]; + if (sio_handle != 0xFFFFFFFF) + EnableEvent(sio_handle); - va_start(ap, str); + IMASK |= 1 << INT_SIO; - result = vsnprintf( internal_buffer, - SERIAL_PRINTF_INTERNAL_BUFFER_SIZE, - str, - ap ); + SIOEnableRXInterrupt(); - SerialWrite(internal_buffer, result); + if (not_crit) + { + ExitCriticalSection(); + } } -#endif // SERIAL_INTERFACE diff --git a/src/System.c b/src/System.c index 9a48d30..05a9b9b 100644 --- a/src/System.c +++ b/src/System.c @@ -6,6 +6,7 @@ void SystemInit(void) { + redirect_stdio_to_sio(); #if 0 PSX_InitEx(PSX_INIT_SAVESTATE | PSX_INIT_CD); #else @@ -1,5 +1,5 @@ #include "System.h" -#include <stdio.h> +#include "reception.h" #define PSX_EXE_HEADER_SIZE 2048 #define EXE_DATA_PACKET_SIZE 8 @@ -8,7 +8,10 @@ int main(void) { SystemInit(); - for (;;); + reception_loop(); + + for (;;) + ; #if 0 { @@ -122,5 +125,6 @@ int main(void) exeAddress(); } #endif + return 0; } diff --git a/src/reception.c b/src/reception.c new file mode 100644 index 0000000..12c1866 --- /dev/null +++ b/src/reception.c @@ -0,0 +1,26 @@ +#include "reception.h" +#include "Serial.h" +#include <stdbool.h> + +static volatile bool rx; + +static enum +{ + +} state; + +void reception_ev(void) +{ + rx = true; +} + +void reception_loop(void) +{ + for (;;) + { + if (rx) + { + + } + } +} diff --git a/src/sio.s b/src/sio.s deleted file mode 100644 index 7e4d887..0000000 --- a/src/sio.s +++ /dev/null @@ -1,94 +0,0 @@ -.extern sio_handler_callback -.extern sio_handler - -sio_handler: - addi $sp, -120 -.set noat - sw $at, 0($sp) - mfhi $at - sw $at, 112($sp) - mflo $at - sw $at, 116($sp) -.set at - sw $v0, 4($sp) - sw $v1, 8($sp) - sw $a0, 12($sp) - sw $a1, 16($sp) - sw $a2, 20($sp) - sw $a3, 24($sp) - sw $t0, 28($sp) - sw $t1, 32($sp) - sw $t2, 36($sp) - sw $t3, 40($sp) - sw $t4, 44($sp) - sw $t5, 48($sp) - sw $t6, 52($sp) - sw $t7, 56($sp) - sw $s0, 60($sp) - sw $s1, 64($sp) - sw $s2, 68($sp) - sw $s3, 72($sp) - sw $s4, 76($sp) - sw $s5, 80($sp) - sw $s6, 84($sp) - sw $s7, 88($sp) - sw $t8, 92($sp) - sw $t9, 96($sp) - sw $gp, 100($sp) - sw $s8, 104($sp) - - la $t0, sio_handler_callback - lw $t1, 0($t0) - - addiu $sp, $sp, -24 - jalr $t1 - nop - addiu $sp, $sp, 24 - - li $t0, 0x1f801070 # IPENDING - - lw $t1, 0($t0) - nop - nop - xori $t1, $t1, 0x100 # Acknowledge SIO IRQ - sw $t1, 0($t0) - -.set noat - lw $at, 112($sp) - nop - mthi $at - lw $at, 116($sp) - nop - mtlo $at - lw $at, 0($sp) -.set at - lw $v0, 4($sp) - lw $v1, 8($sp) - lw $a0, 12($sp) - lw $a1, 16($sp) - lw $a2, 20($sp) - lw $a3, 24($sp) - lw $t0, 28($sp) - lw $t1, 32($sp) - lw $t2, 36($sp) - lw $t3, 40($sp) - lw $t4, 44($sp) - lw $t5, 48($sp) - lw $t6, 52($sp) - lw $t7, 56($sp) - lw $s0, 60($sp) - lw $s1, 64($sp) - lw $s2, 68($sp) - lw $s3, 72($sp) - lw $s4, 76($sp) - lw $s5, 80($sp) - lw $s6, 84($sp) - lw $s7, 88($sp) - lw $t8, 92($sp) - lw $t9, 96($sp) - lw $gp, 100($sp) - lw $s8, 104($sp) - lw $ra, 108($sp) - addi $sp, 120 - jr $ra - nop |
