First working RX ISR
This commit is contained in:
parent
e32281cf6b
commit
96b0c9d692
1
Makefile
1
Makefile
|
@ -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
|
||||
|
|
7
include/reception.h
Normal file
7
include/reception.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#ifndef RECEPTION_H
|
||||
#define RECEPTION_H
|
||||
|
||||
void reception_ev(void);
|
||||
void reception_loop(void);
|
||||
|
||||
#endif /* RECEPTION_H */
|
147
src/Serial.c
147
src/Serial.c
|
@ -7,106 +7,93 @@
|
|||
#include <psx.h>
|
||||
#include <stddef.h>
|
||||
|
||||
static volatile size_t isr_calls;
|
||||
enum
|
||||
{
|
||||
FIFO_SZ = 128
|
||||
};
|
||||
|
||||
typedef volatile struct
|
||||
{
|
||||
unsigned char buf[FIFO_SZ];
|
||||
size_t pending, processed;
|
||||
bool full;
|
||||
} fifo;
|
||||
|
||||
static fifo rx;
|
||||
|
||||
void sio_handler_callback(void)
|
||||
{
|
||||
printf("%s\n", __func__);
|
||||
isr_calls++;
|
||||
while (SIOCheckInBuffer())
|
||||
{
|
||||
const unsigned char in = SIOReadByte();
|
||||
size_t aux = rx.pending;
|
||||
|
||||
if (++aux >= (sizeof rx.buf / sizeof *rx.buf))
|
||||
aux = 0;
|
||||
|
||||
if (aux != rx.processed)
|
||||
{
|
||||
rx.buf[aux] = in;
|
||||
rx.pending = rx.processed;
|
||||
}
|
||||
else
|
||||
{
|
||||
rx.full = true;
|
||||
}
|
||||
}
|
||||
|
||||
SIOAcknowledgeInterrupt();
|
||||
}
|
||||
|
||||
void SerialInit(void)
|
||||
{
|
||||
int *sio_handler(void);
|
||||
enum
|
||||
{
|
||||
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
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
SIO_CLASS = 0xF000000B
|
||||
SIO_CLASS = 0xF000000B,
|
||||
TRIGGER_CALLBACK = 0x1000,
|
||||
BAUD_RATE = 115200
|
||||
};
|
||||
|
||||
EnterCriticalSection();
|
||||
const int not_crit = EnterCriticalSection();
|
||||
void sio_handler(void);
|
||||
|
||||
IMASK |= 1 << 8;
|
||||
SIOReset();
|
||||
SIOStart(BAUD_RATE);
|
||||
|
||||
const int sio_handle = OpenEvent(SIO_CLASS, 0x1000, 0x1000, sio_handler);
|
||||
const int sio_handle = OpenEvent(SIO_CLASS, SPEC_GENERAL_INTERRUPT, TRIGGER_CALLBACK, sio_handler);
|
||||
|
||||
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();
|
||||
IMASK |= 1 << INT_SIO;
|
||||
|
||||
SIOSendByte('y');
|
||||
SIOEnableRXInterrupt();
|
||||
|
||||
printf("%u\n", isr_calls);
|
||||
|
||||
while (!(IPENDING & (1 << 8)));
|
||||
|
||||
printf("SIO ISR triggered\n");
|
||||
}
|
||||
|
||||
void SerialRead(uint8_t *ptrArray, size_t nBytes)
|
||||
{
|
||||
if (nBytes)
|
||||
if (not_crit)
|
||||
{
|
||||
InterruptsDisableInt(INT_SOURCE_VBLANK);
|
||||
|
||||
do
|
||||
{
|
||||
/* Wait for RX FIFO not empty. */
|
||||
while (!SIOCheckInBuffer());
|
||||
|
||||
*(ptrArray++) = SIOReadByte();
|
||||
} while (--nBytes);
|
||||
|
||||
InterruptsEnableInt(INT_SOURCE_VBLANK);
|
||||
ExitCriticalSection();
|
||||
}
|
||||
}
|
||||
|
||||
void SerialWrite(const void* ptrArray, size_t nBytes)
|
||||
{
|
||||
if (nBytes)
|
||||
{
|
||||
InterruptsDisableInt(INT_SOURCE_VBLANK);
|
||||
do
|
||||
{
|
||||
/* Wait for TX FIFO empty. */
|
||||
while (!SIOCheckOutBuffer());
|
||||
|
||||
SIOSendByte(*(uint8_t*)ptrArray++);
|
||||
|
||||
} while (--nBytes);
|
||||
|
||||
InterruptsEnableInt(INT_SOURCE_VBLANK);
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef SERIAL_INTERFACE
|
||||
void Serial_printf(const char* const str, ...)
|
||||
{
|
||||
va_list ap;
|
||||
int result;
|
||||
static char internal_buffer[SERIAL_PRINTF_INTERNAL_BUFFER_SIZE];
|
||||
|
||||
va_start(ap, str);
|
||||
|
||||
result = vsnprintf( internal_buffer,
|
||||
SERIAL_PRINTF_INTERNAL_BUFFER_SIZE,
|
||||
str,
|
||||
ap );
|
||||
|
||||
SerialWrite(internal_buffer, result);
|
||||
}
|
||||
#endif // SERIAL_INTERFACE
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
26
src/reception.c
Normal file
26
src/reception.c
Normal file
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
94
src/sio.s
94
src/sio.s
|
@ -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
|
Loading…
Reference in New Issue
Block a user