[En-Nut-Discussion] AT91SAM7X-EK, UART messing up the NutSleep

Albert Andras alandras at linetron.ro
Mon Jul 24 15:22:20 CEST 2006


Hi,

As I can see the problem is that when you create a new timer for NutSleep()
NutTimerProcessElapsed is not up to date with nut_ticks_resume holding a 
value 3-4 timer tick smaller than actual time.
That's why when doing first NutTimerProcessElapsed SleepTimer is decremented 
with time elapsed from last processing, and not time from creation.
Probably there are simple work around, but maybe the timer creating should 
take care of the difference between nut_ticks_resume and NutGetTickCount().
Should be nut_ticks_resume global for this?

For example:

NUTTIMERINFO * NutTimerCreate(u_long ticks, void (*callback) (HANDLE, void 
*), void *arg, u_char flags)
{
    NUTTIMERINFO *tn;

    tn = NutHeapAlloc(sizeof(NUTTIMERINFO));
    if (tn) {
        tn->tn_ticks_left = ticks+NutGetTickCount()-nut_ticks_resume;



Andras

----- Original Message ----- 
From: "Jix Electronics" <jix.electronics at mbnet.fi>
To: <en-nut-discussion at egnite.de>
Sent: Saturday, July 22, 2006 2:33 PM
Subject: [En-Nut-Discussion] AT91SAM7X-EK, UART messing up the NutSleep


> Hi,
>
> I run to problems with uart, seems that devices DEV_UART and DEV_DEBUG
> does not
> work properly, tested with version 4.1.9-rc5.
>
> When example code (below) is compiled with DEV_UART device. The first
> NutSleep
> call works correctly before registering the device. Second NutSleep waits
> just
> zero ticks, after that seems to work correctly.
>
> example code print output:
>
> (10)start=0, stop=10  --> 10
> (10)start=41, stop=41 --> 0
> (5)start=41, stop=46  --> 5
> (1)start=46, stop=47  --> 1
>
>
> When example code is compiled with DEV_DEBUG device, the first NutSleep 
> works
> correctly. All NutSleep calls after registering the device waits less than
> asked for.
>
> example code print output:
>
> (10)start=0, stop=10  --> 10
> (10)start=12, stop=20 --> 8
> (5)start=22, stop=25  --> 3
> (1)start=27, stop=27  --> 0
>
>
> Modified threads example code
> -----------------------------
> int main(void)
> {
>    u_long baud = 115200;
>    u_long start;
>    u_long stop;
>
>    start = NutGetTickCount();
>    NutSleep(10);
>    stop = NutGetTickCount();
>
>    /*
>     * Register the UART device, open it, assign stdout to it and set
>     * the baudrate.
>     */
>    NutRegisterDevice(&DEV_DEBUG, 0, 0);
>    freopen(DEV_DEBUG_NAME, "w", stdout);
>    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
>
>    printf("\n(10)start=%lu, stop=%lu\t--> %lu", start, stop, stop-start);
>
>    start = NutGetTickCount();
>    NutSleep(10);
>    stop = NutGetTickCount();
>    printf("\n(10)start=%lu, stop=%lu\t--> %lu", start, stop, stop-start);
>
>    start = NutGetTickCount();
>    NutSleep(5);
>    stop = NutGetTickCount();
>    printf("\n(5)start=%lu, stop=%lu\t--> %lu", start, stop, stop-start);
>
>    start = NutGetTickCount();
>    NutSleep(1);
>    stop = NutGetTickCount();
>    printf("\n(1)start=%lu, stop=%lu\t--> %lu", start, stop, stop-start);
>
>    /*
>     * Start two additional threads. All threads are started with
>     * priority 64.
>     */
>    NutThreadCreate("t1", Thread1, 0, 512);
>    NutThreadCreate("t2", Thread2, 0, 512);
>
>    putchar('\n');
>    putchar('\n');
>    putchar('\r');
>
>    /*
>     * Endless loop in main thread.
>     */
>    for (;;) {
>        putchar('M');
>        NutSleep(125);
>    }
> }
>
> Jix
>
> _______________________________________________
> En-Nut-Discussion mailing list
> En-Nut-Discussion at egnite.de
> http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion
>
> !DSPAM:44c20d2b174418176186612!
>
> 




More information about the En-Nut-Discussion mailing list