[En-Nut-Discussion] Problem writing interrupt handler
Pete Allinson
pete at peteallinson.plus.com
Tue Nov 16 12:12:28 CET 2004
Hi,
Can anyone help me with a problem I'm having writing code to start Timer 2
running and then deal with overflow interrupts.
This is the code I'm using to start timer 2:
#define TIMER_COUNT 0xF0
#define TIMER_CTRL 0x01
static volatile u_short ticks_lo = 0;
static volatile u_short ticks_hi = 0;
void InitTicker(void)
{
NutEnterCritical();
/*
* Initialize timer 2 and enable overflow interrupts.
*/
outb(TCNT2, TIMER_COUNT);
outb(TCCR2, TIMER_CTRL);
sbi(TIMSK, 6);
NutExitCritical();
}
And this is my interrupt handler:
SIGNAL(SIG_OVERFLOW2)
{
/* Reset the timer value. */
outb(TCNT2, TIMER_COUNT);
if (++ticks_lo == 1000) {
ticks_lo = 0;
#if 0
/* If this code is in, NutSleep() in main() never returns */
if (++ticks_hi == 1000) {
ticks_hi = 0;
}
#endif
}
}
(The code is cribbed from irsony.c)
Things go wrong if the code between the #if ... #endif is included. For
examples, a call to NutSleep() in my main() never returns, NutGetSeconds()
and NutGetMillis() don't seem to advance.
I've noticed that things also go wrong if 'ticks_lo' is a 'u_long' instead
of a 'u_short'.
I'm using WinAVR and Nut/OS 3.9.2 to program an Ethernut 2.1 rev.B.
Regards,
Pete Allinson
More information about the En-Nut-Discussion
mailing list