With IOTester it is very easy to use interrupt service functions. For instance to service
interrupt from an external keyboard-controller or touch-screen-controller device, or from
internal IOTester devices.
The interrupt function can be debugged with PC tools as usual.
The program example configures then internal IOTester-USB timer device and interrupt controller device
so periodic interrupts are generated. Timer interrupt from IOTester is serviced by an application specific interrupt function on the PC.
#include <iotester.h> // Define IOTester functions and symbolic names for internal registers
#include <stdio.h> // printf
unsigned int intrcnt;
// Timer interrupt function.
// The function is called periodically via IOT_TIMER generated interrupts
void timerint_func(void)
{
// Service interrupt
intrcnt++; // Here we just count number of interrupt events
// IOTester automatically do End-Of-Interrupt (EOI) handling for internal sources.
// so no special actions needed here
}
int main(void)
{
unsigned int old_intrcnt = 0;
intrcnt = 0;
// Init IOTESTER driver, search for any IOTester-USB connected to the PC
if (iot_init(0))
return 1; // Could not connect
// IOTester connection OK
iot_wr(IOT_PIN_MODE_REG, 0); // All pins is I/O pins (= hardware reset default)
//*** Init interrupt system ***
// Assign our interrupt funcion to the IOTester timer vector
iot_set_callback(IOTV_TIMER, &timerint_func);
// Configure IOTester timer for: 20*10ms = 0.2 sec, periodic interrupt (started at once)
iot_wr(IOT_TIMER_CTRL, IOT_TIMER_PERIODIC | 20);
// Configure IOTester interrupt controller.
// Enable timer terminal count to generate interrupt on PC
iot_wr(IOT_INTENA_SET, IOTIE_GLOBAL | IOTIE_TIMER);
//*** The interrupt system is now running ***
// Monitor interrupt generation from the "embedded target" system
printf("\n Test IOTester Timer interrupt (Console should show count down)\n");
// Let the timer interrupt hardware generate 100 timer ticks
while(intrcnt < 100)
{
// Monitor timer count down and report number of interrupt events
printf("\r%u %u", iot_rd(IOT_TIMER), old_intrcnt );
if (intrcnt != old_intrcnt)
{
// Next line
old_intrcnt = intrcnt;
printf("\n");
}
}
// Disable all IOTester timer and interrupt activity and disconnect.
// This is actually not nessesary here, but just to illustrate how close down is done "the pretty way"
iot_wr(IOT_INTENA_CLR, ~IOTIE_TIMER); // Disable timer generated interrupt
iot_wr(IOT_TIMER_CTRL, 0); // Disable timer counting
iot_set_callback(IOTV_TIMER, 0); // Remove interupt vector hook
iot_exit(); // Disconnect IOTester
return 0;
}
Links to:
IOTester tool description
Example 1: Start using IOTester I/O port pins - "Single chip mode"
Example 2: Enabling the External bus
Example 3: Using Internal Devices and External bus.
Example 4: Using Target Interrupt.
Example 5: Writing portable I/O driver source code with <iohw.h>
Example 6: <iohw.h> implementation methods and definition of I/O registers
Example 7: Swapping source code between PC and target platforms