diff options
Diffstat (limited to 'libpsn00b/psxetc/interrupts.c')
| -rw-r--r-- | libpsn00b/psxetc/interrupts.c | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/libpsn00b/psxetc/interrupts.c b/libpsn00b/psxetc/interrupts.c index f2a273c..8bd11fc 100644 --- a/libpsn00b/psxetc/interrupts.c +++ b/libpsn00b/psxetc/interrupts.c @@ -4,6 +4,7 @@ */ #include <stdint.h> +#include <assert.h> #include <psxapi.h> #include <psxetc.h> #include <hwregs_c.h> @@ -99,8 +100,7 @@ static void _global_dma_handler(void) { /* IRQ and DMA handler API */ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { - if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) - return 0; + _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0); void *old_callback = _irq_handlers[irq]; _irq_handlers[irq] = func; @@ -116,15 +116,13 @@ void *InterruptCallback(IRQ_Channel irq, void (*func)(void)) { } void *GetInterruptCallback(IRQ_Channel irq) { - if ((irq < 0) || (irq >= NUM_IRQ_CHANNELS)) - return 0; + _sdk_validate_args((irq >= 0) && (irq < NUM_IRQ_CHANNELS), 0); return _irq_handlers[irq]; } void *DMACallback(DMA_Channel dma, void (*func)(void)) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return 0; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0); void *old_callback = _dma_handlers[dma]; _dma_handlers[dma] = func; @@ -151,12 +149,34 @@ void *DMACallback(DMA_Channel dma, void (*func)(void)) { } void *GetDMACallback(DMA_Channel dma) { - if ((dma < 0) || (dma >= NUM_DMA_CHANNELS)) - return 0; + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), 0); return _dma_handlers[dma]; } +/* DMA channel priority API */ + +int SetDMAPriority(DMA_Channel dma, int priority) { + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1); + + uint32_t dpcr = DMA_DPCR; + uint32_t channel = dpcr >> (dma * 4); + + dpcr &= ~(0xf << (dma * 4)); + if (priority >= 0) + dpcr |= ((priority & 7) | 8) << (dma * 4); + + DMA_DPCR = dpcr; + return (channel & 8) ? (channel & 7) : -1; +} + +int GetDMAPriority(DMA_Channel dma) { + _sdk_validate_args((dma >= 0) && (dma < NUM_DMA_CHANNELS), -1); + + uint32_t channel = DMA_DPCR >> (dma * 4); + return (channel & 8) ? (channel & 7) : -1; +} + /* Hook installation/removal API */ int ResetCallback(void) { @@ -190,7 +210,7 @@ void RestartCallback(void) { // Install the ISR hook and prevent the kernel's internal handlers from // automatically acknowledging SPI and timer IRQs. - SetCustomExitFromException(&_isr_jmp_buf); + HookEntryInt(&_isr_jmp_buf); ChangeClearPAD(0); ChangeClearRCnt(0, 0); ChangeClearRCnt(1, 0); @@ -217,7 +237,7 @@ void StopCallback(void) { DMA_DPCR = _saved_dma_dpcr & 0x07777777; DMA_DICR = 0; - SetDefaultExitFromException(); + ResetEntryInt(); ChangeClearPAD(1); ChangeClearRCnt(0, 1); ChangeClearRCnt(1, 1); |
