INTC configuration (Software mode)
2.1.
Enabling interrupt requests
There are two stages for enabling interrupts; first, at a general level, the interrupt handling in
the microcontroller has to be enabled, then, at the peripheral level, for an ISR to be raised, the
registers in charge of that interrupt has to be configured.
Here’s the code for enabling interrupts at a general level:
Peripheral-level enabling of an ISR will be mentioned on that peripheral’s chapter.
Configuring hardware ISRs
INTC is implemented in following files in a project: INTCInterrupts.h, IntcInterrupts.c,
Exceptions.h, Expcetions.c. These files possess required routines to execute the previously
explained ISR handling procedure. The following function is used to configure an ISR’s handler
and priority:
vectorNum is the ISR’s vector number (see Interrupt Vector Table), handlerFn is a
void function
written by the user, and psrPriority is the priority between 0 and 15 (0 priority is not served).
Example: Blinking a LED when PIT1 (a timer, see following chapters) interrupt is generated.
INTC.CPR.B.PRI = 0; /* Single Core: Lower INTC's current priority */
asm( "wrteei 1"); /* Enable external interrupts */
void INTC_InstallINTCInterruptHandler (INTCInterruptFn handlerFn, unsigned short
vectorNum, unsigned char psrPriority);
void PIT1_Interrupt();
int main (void) {
initModesAndClock(); /* Initialisation of the device */
config_PORT_E(); /* Configuration of GPIO */
initPIT(); /* Init the timer PIT1 to trigger ISR every 0.5sec */
INTC_InstallINTCInterruptHandler(PIT1_Interrupt,60,2); /* 6
number, we choose to give a priority of 2 */
enableIrq(); /* Enable interrupts, after interrupt configs */
for (; ;){} /* Main loop */
}
void PIT1_Interrupt(){
//Finite State Machine for the LED 1
if(LED_state == 0) {
LED_state = 1;
SIU.GPDO[68].B.PDO = 0; /* Set LED */}
else {
LED_state = 0;
SIU.GPDO[68].B.PDO = 1; /* Clear LED */}
//Clear PIT1 interrupt
PIT.CH[1].TFLG.B.TIF = 1;