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 interrupt service routine for a timer, which increments a tick variable. The main function sets the necessary status registers. The application exits when 100 interrupts have been generated.
#pragma language = extended #include <stdio.h> #include "iorh850.h" #include <intrinsics.h> volatile int ticks = 0; void main (void) { /* Add your timer setup code here */ __enable_interrupt(); /* Enable interrupts */ while (ticks < 100); /* Endless loop */ printf("Done\n"); } /* Timer interrupt service routine */ #pragma vector = TIMER_VECTOR __interrupt void basic_timer(void) { ticks += 1; }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
TIMER_VECTOR
First activation
4000
Repeat interval
2000
Hold time
10
Probability (%)
100
Variance (%)
0
Table 23. 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.