[En-Nut-Discussion] NutGetCpuClock() sometimes does not work.

Louis B louisjbarman at hotmail.com
Fri Nov 5 16:07:25 CET 2004


Hi,

I found that NutGetCpuClock()  report backs the wrong clock frequency 
12285280 instead of 14742560. As a result uart0 stops working as it is set 
to the wrong baud rate.

I have two programs, one works and the other does not. However both programs 
are executing EXACTLY the same source code. The ONLY difference between the 
two is that I have linked in my full application (even though it is NOT 
being executed) for the program that does not work. However the cut down 
program with out my full application does work.

I fixed the problem by patching NutComputeCpuClock() so that it does NOT 
compile the asm method of calculating the clock speed.

Yes, I have checked that the large program is not overwriting any memory 
locations.

For those of you that are interested here is the output from the two 
different programs.

**** FAULTY OUTPUT ******
D..iW..Y.xY. at f+..c..]P.;]c...b.-.KVe(.
Now the baud is correct
NutGetCpuClock() = 12285280

**** CORRECT OUTPUT ******
Nut/OS 3.4.3.1 NUT TEST - WRONG BAUD RATE...

Now the baud is correct
NutGetCpuClock() = 14742560


And here is the IDENTICAL source code
**** IDENTICAL SOURCE CODE FOR BOTH CASES ******
int main(void)
{
    u_long baud = 38400L;

    /*
     * Initialize the uart device.
     */
    NutRegisterDevice(&devDebug0, 0, 0);
    freopen("uart0", "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    NutSleep(200);

    printf("\nNut/OS %s NUT TEST - WRONG BAUD RATE...\n", 
NutVersionString());

    fflush(stdout);

    NutSleep(2000);

    // A quick fix to correct the baud rate;
    UBRR0L = (u_char) 23;

    printf("\nNow the baud is correct\n");
    printf("NutGetCpuClock() = %ld\n", NutGetCpuClock());

    fflush(stdout);
    NutSleep(2000);

    // Halt here
    while (TRUE)
        ;
    return 0;
}

Any ideas as to the problem?

May be NutComputeCpuClock() should be changed so that in future it does not 
try to calculate the clock frequency dynamically.

Your Louis B.

_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today! 
http://www.msn.co.uk/messenger




More information about the En-Nut-Discussion mailing list