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 "iorl78.h" #include <intrinsics.h> volatile int ticks = 0; void main (void) { /* Timer setup code */ __disable_interrupt(); /* Disable all interrupts */ TMIF00 = 0; /* Reset interrupt request flag */ TMMK00 = 0; /* Enable timer interrupts */ TS0 |= 0; /* Start the timer */ __enable_interrupt(); /* Enable all interrupts */ { ticks += 1; } while (ticks < 100); /* Endless loop */ printf("Done\n"); } /* Timer interrupt service routine */ #pragma vector = INTTM00_vect { ticks += 1; }Add your interrupt service routine to your application source code and add the file to your project.
Choose Project>Options>Debugger>Setup and select a device description file. The device description file contains information about the interrupt that C-SPY needs to be able to simulate it. Use the Use device description file browse button to locate the
ddffile.Build your project and start the simulator.
Choose Simulator>Interrupt Setup to open the Interrupt Setup dialog box. Select the Enable interrupt simulation option to enable interrupt simulation. Click New to open the Edit Interrupt dialog box. For the timer example, verify these settings:
Option
Settings
Interrupt
INTTM00
First activation
1000
Repeat interval
500
Hold time
10
Probability (%)
100
Variance (%)
0
Table 25. 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 1000
Continuously repeat the interrupt after approximately 500 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.