![]() |
This tutorial assumes that you are familiar with basic use of IAR Embedded Workbench, see the tutorials Getting Started using IAR Embedded Workbench.Contains an interrupt service routine for a timer which increments a counter. The main function sets the necessary status registers. The application exits when 100 interrupts have been generated.
1 In the IDE and if Information Center is not open, choose Help>Information Center.
2 Click the Product explorer symbol.
3 Under the heading Advanced Debugging, click Open tutorial workspace. Choose a destination for your project in the browse dialog box that appears. We recommend that you create a specific directory (with a subdirectory) where you store all your tutorial files, if not already done. In this tutorial we call the directory MyTutorials and the subdirectory AdvancedDebugging. The AdvancedDebugging workspace is opened in the IDE.
4 In the Workspace window, select the SimulatingATimerInterrupt project, right-click and choose Set as Active.
1 Open the file TimerInterrupt.c, which here is demonstrated by a few snippets which show how you can use some keywords and pragma directives for writing an interrupt service routine in C:The #pragma language directive enables the language extensions used in the file:
![]()
_ _enable_interrupt enables interrupts.
![]()
#pragma vector specifies the interrupt vector—in this case the interrupt vector for the timer interrupt.
![]()
_ _interrupt directs the compiler to use the calling convention needed for an interrupt function.
2 Use the TimerInterrupt.c file as is; you do not have to modify it in any way for this tutorial.The SimulatingATimerInterrupt project is preconfigured with appropriate option settings for this tutorial. Still, this procedure guides you through the option settings required for this tutorial.
1 Choose Project>Options>General Options>Target and select a device. You can find information about which device to use for this tutorial in the header of TimerInterrupt.c.A suitable device description file will automatically be used later on when you start the C-SPY debugger. This file contains device-specific information required by the C-SPY debugger to simulate, for example the interrupt used in this tutorial.
2
1
2
3
Select the interrupt vector from the drop-down list that matches the interrupt vector that is specified in the header of TimerInterrupt.c. The interrupt definition (retrieved from the ddf file) that the simulator uses to simulate the interrupt correctly. During execution, after each completed simulation of a single assembler instruction, the C-SPY simulator will check whether the activation time has been reached. If so, the interrupt will be triggered and set to pending provided that Probability is set to 100% (which it is in this example).
4 When you have made your settings, click OK to close the Edit Interrupt dialog box, and then click OK to close the Interrupt Setup dialog box.
1
![]()
Choose Simulator>Interrupt Log to open the Interrupt Log window, which logs various information about the interrupts, such as entrances to and exits from interrupt service routines, and whether the interrupt is triggered or has expired (reached the hold time).
![]()
Choose Simulator>Timeline to open the Timeline window which provides a graphical view of the interrupt events during the execution of your application.Right-click in the window and choose Select Graphs>Interrupts.Click in the Interrupts graph, right-click and choose Enable from the context menu to enable the Interrupt Log graph.
![]()
Choose Simulator>Interrupt Status to open the Interrupt Status window which shows the status of all the currently active interrupts, in other words, interrupts that are either being serviced or waiting to be serviced.
![]()
Choose Simulator>Forced Interrupt to open the Forced Interrupt window where you can force an interrupt instantly. Typically, this is useful when you are setting up an interrupt and you want to determine whether the interrupt is setup correct, and whether the interrupt service routine is invoked as expected.
5 Click the Reset button () and then click the Go button(
) to restart execution. Execution stops at the breakpoint. You can now view the information about the interrupt in the various windows:
![]()
In the Interrupt Log window you can see at which time and at which program counter value the interrupt was triggered.
![]()
In the Timeline window you can see that the Interrupt Log graph (illustrated with a black line) has appeared. The execution start of the interrupt service routine is illustrated with a black vertical line.
![]()
In the Interrupt Status window you can see that the interrupt is currently being serviced.
6 Click Go again.In the Interrupt Log window you can now see that a new interrupt has been generated. Double-click the Leave cell for the first interrupt; focus switches to the editor window and in the Interrupt Log graph in the Timeline window where the first interrupt is now illustrated by a green box.
7 Remove the breakpoint and then click Go again. The application reaches its end.