[En-Nut-Discussion] Bug Fix

Damian Slee damian at commtech.com.au
Tue May 11 12:52:34 CEST 2004


this was reported a few months ago, and a couple of weeks ago.  it should be in CVS by now.

________________________________

From: en-nut-discussion-bounces at egnite.de on behalf of Vasil Atanasov
Sent: Sat 8/05/2004 3:42 PM
To: en-nut-discussion at egnite.de
Subject: [En-Nut-Discussion] Bug Fix


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 --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 6072 bytes
Desc: not available
URL: <http://lists.egnite.de/pipermail/en-nut-discussion/attachments/20040511/bc43bce8/attachment-0001.bin>


More information about the En-Nut-Discussion mailing list