EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Handler syntax with high level languages

Started by bruce varley April 29, 2004
What sort of syntax do C and similar 'high level' platforms have for dealing
with asynchronous structures like custom interrupt handlers? Could anyone
show me a code sample of, say, setting up an ISR that triggers on a timer?


bruce varley wrote:
> What sort of syntax do C and similar 'high level' platforms have for dealing > with asynchronous structures like custom interrupt handlers? Could anyone > show me a code sample of, say, setting up an ISR that triggers on a timer? > >
Highly compiler dependent- there's no official support for it at all in C. Most embedded compilers (and BC++ and stuff like that) have some kind of support, but it's notat all portable. Here's a (stripped down) timer A CCR2 interrupt from mspgcc (for the MSP430) : interrupt(TIMERA1_VECTOR) CCR12ISR (void) { // Timebase interrupt - 1ms if( CCTL2 & CCIFG) { CCR2 += 6000; // Set time for next IRQ CCTL2 &= ~CCIFG; // Clear the interrupt ticks++; // Do time interrupt stuff here.... // ....... } } Paul Burke
bruce varley <bxvarley@weqstnet.com.au> wrote:
> What sort of syntax do C and similar 'high level' platforms have for dealing > with asynchronous structures like custom interrupt handlers?
C itself has no such syntax at all. Individual compilers do it in their own, individual ways. Some add an "interrupt" keyword, others use a #pragma that flags a given routine as an interrupt handler. The only "native" way C supports interrupts would by the <signal.h> mechanisms. But the runtime would have to be tailored to map interrupts to signal names, and provide interrupt handles written in ASM that call the signal handlers, if any are registered. Not exactly impossible, but for some reason, nobody seems to be doing it that way. -- Hans-Bernhard Broeker (broeker@physik.rwth-aachen.de) Even if all the snow were burnt, ashes would remain.

Memfault Beyond the Launch