Simulating a simple interrupt
This example demonstrates the method for simulating a timer interrupt. However, the procedure can also be used for other types of interrupts.
Assume this simple application which contains an IRQ handler routine that handles system timer interrupts. It increments a tick variable. The main function sets the necessary status registers. The application exits when 100 interrupts have been generated.
/* Enables use of extended keywords */ #pragma language=extended #include <intrinsics.h> #include <stdio.h> unsigned int ticks = 0; /* IRQ handler */ #if __ARM_PROFILE_M__ /* Defines an interrupt handler for the Cortex-M UART interrupt. */ void UART_Handler() #else /* Defines an interrupt handler for other cores. */ __irq __arm void IRQ_Handler(void) #endif { /* We use only system timer interrupts, so we do not need to check the interrupt source. */ ticks += 1; TMOVFR_bit.OVF = 1; /* Clear system timer overflow flag */ } int main( void ) { __enable_interrupt(); /* Timer setup code */ ILC0_bit.ILR0 = 4; /* System timer interrupt priority */ TMRLR_bit.TMRLR = 1E5; /* System timer reload value */ TMEN_bit.TCEN = 1; /* Enable system timer */ while (ticks < 100); printf("Done\n"); }Add your interrupt service routine to your application source code and add the file to your project.
Build your project and start the simulator.
Choose Simulator>Interrupt Configuration to open the Interrupt Configuration window. Right-click in the window and select Enable Interrupt Simulation on the context menu. For the timer example, verify these settings:
Option
Settings
Interrupt
IRQ
First activation
4000
Repeat interval
2000
Hold time
10
Probability (%)
100
Variance (%)
0
Table 26. Timer interrupt settingsClick OK.
Execute your application. If you have enabled the interrupt properly in your application source code, C-SPY will:
Generate an interrupt when the cycle counter has passed 4000
Continuously repeat the interrupt after approximately 2000 cycles.
To watch the interrupt in action, choose Simulator>Interrupt Log to open the Interrupt Log window.
From the context menu, available in the Interrupt Log window, choose Enable to enable the logging. If you restart program execution, status information about entrances and exits to and from interrupts will now appear in the Interrupt Log window.
For information about how to get a graphical representation of the interrupts correlated with a time axis, see Timeline window—Interrupt Log graph.