[En-Nut-Discussion] Bug Fix

Vasil Atanasov vdat at engineer.bg
Sat May 8 09:42:02 CEST 2004


Hello,
I made Nut compatibable board but my Xtal is on 12MHz
I use #define NUT_CPU_FREQ 12000000, but system did'nt work.
After some test I found bug in module timer.c

Original source:

void NutTimerInit(void)
{
#ifdef NUT_CPU_FREQ
    /*
     * - Program prescaler to output PCK0/32 and clear Timer0 on compare match.
     * - Clear timer counter register to get the first tick right.
     * - Write (CPU frequency / (prescaler * 1KHz)) in the output compare.
     *   register, so we'll get a compare match interrupt every millisecond.
     */
#ifdef __AVR_ATmega128__
    outp(BV(CS00) | BV(CS20) | BV(WGM01), TCCR0);
#else
    outp(BV(CS00) | BV(CS02) | BV(CTC0), TCCR0);
#endif
    outp(0, TCNT0);
    outp(NUT_CPU_FREQ / (128L * 1000), OCR0);
    NutRegisterIrqHandler(&sig_OUTPUT_COMPARE0, NutTimer0Intr, 0);
    sbi(TIMSK, OCIE0);
#else
    NutComputeCpuClock();
    sbi(TIMSK, TOIE0);
#endif
}

New souce:
void NutTimerInit(void)
{
#ifdef NUT_CPU_FREQ
    /*
     * - Program prescaler to output PCK0/32 and clear Timer0 on compare match.
     * - Clear timer counter register to get the first tick right.
     * - Write (CPU frequency / (prescaler * 1KHz)) in the output compare.
     *   register, so we'll get a compare match interrupt every millisecond.
     */
#ifdef __AVR_ATmega128__
    outp(BV(CS00) | BV(CS02) | BV(WGM01), TCCR0);
#else
    outp(BV(CS00) | BV(CS02) | BV(CTC0), TCCR0);
#endif
    outp(0, TCNT0);
    outp(NUT_CPU_FREQ / (128L * 1000), OCR0);
    NutRegisterIrqHandler(&sig_OUTPUT_COMPARE0, NutTimer0Intr, 0);
    sbi(TIMSK, OCIE0);
#else
    NutComputeCpuClock();
    sbi(TIMSK, TOIE0);
#endif
}

When compiled original source system is busy to respond to intterupt request and have no time for other.

Vasil Atanasov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20040508/73580744/attachment-0001.html>


More information about the En-Nut-Discussion mailing list