Interrupts

Since BitMasher uses many of the MCU's peripherals, interrupts are extensively used. To avoid scattering ISRs directly called by the CPU in different source files, they are consolidated in BM_ISR. However, the actual user-defined routines can be defined in separate source files. As a result, there is a registration process when creating an ISR for a particular peripheral.

For example, TIMER1 is used as the frame update (or VSYNC) timer for the render engine. The user-defined ISR is written in BM_RenderEngine.c:

void BM_RE_VSYNCISR()
{
  TIMER_IntClear(TIMER1, TIMER_IFC_OF);
  BM_ServiceQueue_addItemToServiceQueue(BM_SERVICE_UI, NULL);
}

However, when the TIMER1 interrupt is triggered, the function, TIMER1_IRQHandler() in BM_ISR.c is executed. To ensure that BM_RE_VSYNCISR is executed, the function must be registered with BM_ISR:

BM_ISR_Timer_registerTIMER1ISR(BM_RE_VSYNCISR);

This ensures that when TIMER1_IRQHandler is executed, BM_RE_VSYNCISR is also executed.