User guide

6.7 A semihosted application with interrupt handling
This section illustrates an Reference Peripheral Specification (RPS) based interrupt-driven timer, suitable for
embedded applications. The main() function initializes and starts two RPS timers.
When a timer expires, an interrupt is generated. The interrupt is handled in int_handler.c. The code simply sets
a flag and clears the interrupt. The interrupt flags are checked below in a endless loop. If a flag is set, a message is
displayed and the flag is then cleared.
6.7.1 Memory map
There are no memory specification options in the linker command options and the default values are used. The code
region starts at 0x08000. The RW data region and the ZI data region are placed sequentially after the code region.
The stack top is 0x80000.
6.7.2 Building the example
To build the example, either:
load the supplied rps_irq.mcp project into the CodeWarrior IDE
use a batch file (build_a.bat) or makefile containing the following:
armcc -c -g -O1 main.c -I..\include
armcc -c -g -O1 int_handler.c -I..\include
armlink main.o int_handler.o -o rps_irq.axf -info totals
6.7.3 Sample code
The code in Example 6-9 is compiled and linked on its own and executed in the semihosting environment and
Install_Handler is called to install the interrupt vector. The code in Example 6-10 demonstrates an interrupt
handler. The example can also be built as an embedded application with no semihosting (see An embeddable
application with interrupt handling).
Example 6-9 Sample main.c code for rps_irq
/*
** Copyright (C) ARM Limited, 2000. All rights reserved.
*/
#include <stdio.h>
#include <stdlib.h>
#include "stand_i.h"
#include "rpsarmul.h" /* EITHER: to use with the ARMulator */
/* #include "intgrt.h" */ /* OR: to use with the Integrator board */
int IntCT1 = 0;
int IntCT2 = 0;
int Count = 0;
#ifndef EMBEDDED
extern IRQ_Handler(void);
unsigned *irqvec = (unsigned *)0x18;
unsigned Install_Handler (unsigned routine, unsigned *vector)
/* Updates contents of 'vector' to contain branch instruction */
/* to reach 'routine' from 'vector'. Function return value is */
/* original contents of 'vector'. */
/* NB: 'Routine' must be within range of 32MB from 'vector'. */
{ unsigned vec, oldvec;
vec = ((routine - (unsigned)vector - 0x8)>>2);
if (vec & 0xff000000)
{
printf ("Installation of Handler failed");
exit(1);
}
vec = 0xea000000 | vec;
oldvec = *vector;
*vector = vec;
Writing Code for ROM
Copyright ?1999 2001 ARM Limited 6-18