Interrupts are easily added to targets. All you need to do is write a void(void) function to be called by the interrupt source.
Continuing from the “Hello World” example, open the Visual Studio solution by finding the HelloWorld.sln file on the file system, like a normal Visual Studio solution.
Open the SIM_HW.c file in the C Target project, and create a parameterless TimerISR callback as shown below.
Build the solution by pressing F6 in Visual Studio. Remember that after adding a variable or function, you must be sure to build the target project so that the Target Model Builder can see the updates. Now open the Target Model Builder and click on the Interrupts tab. Right click the Interrupts table area and click ‘New’ to create a new interrupt. In the Callback ISR textbox, begin typing “Ti…” and you will see the “TimerISR” function displayed in the filtered results. Select it and click Done.
Close the Target Model Builder, and you will now see the target component updated with a TimerISR input port.
On the schematic, this port can be wired to any event source to fire the ISR. We need a timer, so we will now drag and drop a Timer component onto the schematic from the Virtuoso Components component group.
Left click the Timer component on the schematic and then in the Timer’s Properties window, change the timer interval from 1000000 microseconds to 1000 microseconds, as we want a tick every 1ms.
Wire the timer’s TimeElapsed event to the TimerISR port, as shown below.
Save the schematic and then click the “Update To IDE” button, and everything is ready to go. Set a breakpoint at the closing brace of the TimerISR function and then press F5 to run the solution. You will see the breakpoint in the TimerISR function get hit, showing the timer ISR being invoked by the timer component.