This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: About Interrupt Handler
- To: HuangQiang <jameshq at liverpool dot ac dot uk>
- Subject: Re: [ECOS] About Interrupt Handler
- From: Jonathan Larmour <jlarmour at redhat dot com>
- Date: Tue, 02 Oct 2001 18:28:37 +0100
- Cc: eCos <ecos-discuss at sources dot redhat dot com>
- Organization: Red Hat UK Ltd.
- References: <KIEBICHBADHFCLGCKOPDIEOHCHAA.jameshq@liv.ac.uk>
HuangQiang wrote:
>
> Is there any sample code available?
Any interrupt-driven device driver will use the driver API.
Or alternatively, here's something simple which should probably work (note
it will override the existing kernel clock interrupt that drives
timeslicing).
#include <cyg/kernel/kapi.h>
#include <stdio.h>
static volatile unsigned long n_timer_0_interrupts = 0;
/* this is the ISR for timer interrupts */
cyg_uint32 timer_0_handler(cyg_vector_t vector, cyg_addrword_t data)
{
/* keep track of how many times that timer has interrupted us; this
is basically all we do in this "driver" */
++n_timer_0_interrupts;
/* ISRs must acknowledge the interrupt, or they might be invoked
again */
cyg_interrupt_acknowledge(vector);
return CYG_ISR_HANDLED;
}
/* the main program here sits in an infinite loop seeing if
n_timer_0_interrupts has changed, and printing the new values if it
has changed */
int main( int argc, char *argv[] )
{
cyg_handle_t timer_0_ISR_H;
cyg_interrupt intr;
unsigned long previous_timer_0_count = 0;
/* create an interrupt handler with timer_0_handler() as the ISR
and no DSR. A DSR is not needed here because the ISR simply
increments a global variable and does not take much time or use
any operating system services */
cyg_interrupt_create(CYGNUM_HAL_INTERRUPT_RTC, 0, 0, &timer_0_handler,
NULL, &timer_0_ISR_H, &intr);
cyg_interrupt_attach(timer_0_ISR_H);
for (;;) {
if (n_timer_0_interrupts != previous_timer_0_count) {
printf("new value of n_timer_0_interrupts: %lu\n",
n_timer_0_interrupts);
previous_timer_0_count = n_timer_0_interrupts;
}
}
}
Jifl
--
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine