diff --git a/include/arm9/crypto.h b/include/arm9/crypto.h index 17f261d..151f866 100644 --- a/include/arm9/crypto.h +++ b/include/arm9/crypto.h @@ -60,6 +60,8 @@ } AES_ctx; +void AES_init(void); + /** * @brief Selects keyslot and sets the key for the specified key type. * diff --git a/include/arm9/timer.h b/include/arm9/timer.h index 85e7bcc..d6f6607 100644 --- a/include/arm9/timer.h +++ b/include/arm9/timer.h @@ -42,13 +42,13 @@ /** * @brief Starts a timer. * - * @param[in] timer The timer to start. - * @param[in] prescaler The prescaler to use. - * @param[in] ticks The initial number of ticks. This is also the reload - * value on overflow. - * @param[in] irqHandler The IRQ handler function for this timer. NULL to disable IRQ. + * @param[in] timer The timer to start. + * @param[in] prescaler The prescaler to use. + * @param[in] ticks The initial number of ticks. This is also the reload + * value on overflow. + * @param[in] enableIrq Timer fires IRQs if true. */ -void TIMER_start(Timer timer, TimerPrescaler prescaler, u16 ticks, void (*irqHandler)(void)); +void TIMER_start(Timer timer, TimerPrescaler prescaler, u16 ticks, bool enableIrq); /** * @brief Stops a timer. diff --git a/source/arm9/crypto.c b/source/arm9/crypto.c index 0e2507e..345b84f 100644 --- a/source/arm9/crypto.c +++ b/source/arm9/crypto.c @@ -50,6 +50,26 @@ #define REG_AESKEYYFIFO ((vu32*)(AES_REGS_BASE + 0x108)) +void AES_init(void) +{ + REG_AESCNT = AES_MAC_SIZE(4) | AES_FLUSH_WRITE_FIFO | AES_FLUSH_READ_FIFO; + *((vu8*)0x10000008) |= 0xCu; // ?? + + //REG_NDMA0_CNT = 0; + REG_NDMA0_DST_ADDR = (u32)REG_AESWRFIFO; + REG_NDMA0_BLOCK_CNT = NDMA_BLOCK_SYS_FREQ; + REG_NDMA0_CNT = NDMA_REPEATING_MODE | NDMA_STARTUP_AES_IN | + NDMA_SRC_UPDATE_INC | NDMA_DST_UPDATE_FIXED; + + //REG_NDMA1_CNT = 0; + REG_NDMA1_SRC_ADDR = (u32)REG_AESRDFIFO; + REG_NDMA1_BLOCK_CNT = NDMA_BLOCK_SYS_FREQ; + REG_NDMA1_CNT = NDMA_REPEATING_MODE | NDMA_STARTUP_AES_OUT | + NDMA_SRC_UPDATE_FIXED | NDMA_DST_UPDATE_INC; + + REG_IRQ_IE |= 1u<>1; + REG_NDMA1_CNT = (REG_NDMA1_CNT<<1)>>1; // Throw possibly cached lines out of the window invalidateDCacheRange(savedOut, size); diff --git a/source/arm9/interrupt.c b/source/arm9/interrupt.c index a5a7dbd..0928899 100644 --- a/source/arm9/interrupt.c +++ b/source/arm9/interrupt.c @@ -8,8 +8,8 @@ void IRQ_init(void) { - // Atomic IRQ disable and aknowledge - __asm__ __volatile__("stm %0, {%1, %2}" : : "r" (®_IRQ_IE), "r" (0u), "r" (0xFFFFFFFFu) : "memory"); + REG_IRQ_IE = 0; + REG_IRQ_IF = 0xFFFFFFFFu; for(u32 i = 0; i < 32; i++) { @@ -22,7 +22,7 @@ void IRQ_registerHandler(Interrupt num, void (*irqHandler)(void)) { irqHandlerTable[num] = irqHandler; - REG_IRQ_IE |= (1u<