diff --git a/include/pxi.h b/include/pxi.h index c878761..73bd396 100644 --- a/include/pxi.h +++ b/include/pxi.h @@ -3,8 +3,6 @@ #include "types.h" #include "io.h" - - // Defines for PX_SYNC regs #define PXI_DATA_RECEIVED(reg) (reg & 0xFF) #define PXI_DATA_SENT(reg) (reg>>8 & 0xFF) @@ -23,7 +21,15 @@ #define PXI_EMPTY_FULL_ERROR (1u<<14) #define PXI_ENABLE_SEND_RECV_FIFO (1u<<15) +// Custom PXI Command/Reply Definitions +#define PXI_CMD_FIRM_LAUNCH 0x544F4F42 +#define PXI_RPL_FIRM_LAUNCH_READY 0x4F4B6666 +#define PXI_RPL_OK 0x4F4B4F4B +#define PXI_RPL_HOME_PRESSED 0x4F4B4F4B + void PXI_init(void); void PXI_sendWord(u32 val); +bool PXI_trySendWord(u32 val); u32 PXI_recvWord(void); +u32 PXI_tryRecvWord(bool *success); diff --git a/source/arm11/pxi.c b/source/arm11/pxi.c index 357d31a..554b7ef 100644 --- a/source/arm11/pxi.c +++ b/source/arm11/pxi.c @@ -17,10 +17,29 @@ REG_PXI_SYNC11 |= PXI_NOTIFY_9; } +bool PXI_trySendWord(u32 val) +{ + if(REG_PXI_CNT11 & PXI_SEND_FIFO_FULL) + return false; + REG_PXI_SEND11 = val; + REG_PXI_SYNC11 |= PXI_NOTIFY_9; + return true; +} + u32 PXI_recvWord(void) { - // Returns 0 for now if there is no data. - // Will be fixed after implementing interrupts - if(REG_PXI_CNT11 & PXI_RECV_FIFO_EMPTY) return 0; + while(REG_PXI_CNT11 & PXI_RECV_FIFO_EMPTY); + return REG_PXI_RECV11; +} + +u32 PXI_tryRecvWord(bool *success) +{ + if(REG_PXI_CNT11 & PXI_RECV_FIFO_EMPTY); + { + *success = false; + return 0; + } + + *success = true; return REG_PXI_RECV11; } diff --git a/source/arm9/pxi.c b/source/arm9/pxi.c index 10f5fa4..cdce95b 100644 --- a/source/arm9/pxi.c +++ b/source/arm9/pxi.c @@ -17,8 +17,29 @@ REG_PXI_SYNC9 |= PXI_NOTIFY_11; } +bool PXI_trySendWord(u32 val) +{ + if(REG_PXI_CNT9 & PXI_SEND_FIFO_FULL) + return false; + REG_PXI_SEND9 = val; + REG_PXI_SYNC9 |= PXI_NOTIFY_11; + return true; +} + u32 PXI_recvWord(void) { while(REG_PXI_CNT9 & PXI_RECV_FIFO_EMPTY); return REG_PXI_RECV9; } + +u32 PXI_tryRecvWord(bool *success) +{ + if(REG_PXI_CNT9 & PXI_RECV_FIFO_EMPTY); + { + *success = false; + return 0; + } + + *success = true; + return REG_PXI_RECV9; +}