[En-Nut-Discussion] NutGetMillis in Uart ISR

Hugo Simon hugo.simon at gmx.de
Tue Nov 6 23:08:34 CET 2007


Hi.

May I use the NutGetMillis() function in the Uart interrupt service routine?
I want to use it to detect a timeout. Therefore I have defined a global
variable RcvTime which is set to NutGetMillis everytime the uart receive ISR
is called.

In a timer thread I read that value and compare it with the current
NutGetMillis. If the difference is more than 100ms I detect a timeout.

It mostly works, but sometimes there is a detection of a timeout, but there
is none.

Thanks Thorsten




volatile u_long RS485RcvTime;
/*
 * serial receive isr
 */
SIGNAL(SIG_UART1_RECV)
{
 char ch;
 char *RS485Buffer=(char *)RS485PacketBuffer;

 RS485RcvTime=NutGetMillis();

 // ... receive the character ...
}

THREAD(RS485Receiver, arg)
{
 u_long timeout;

 // now wait endlessly for packets
    for (;;)
    {
        NutThreadSetPriority(64);

         timeout=NutGetMillis()-RS485RcvTime;
         if (timeout>100)
         {
            // ... do some stuff with the received data
         }
        NutThreadSetPriority(128);
        NutThreadYield();

    }
}






More information about the En-Nut-Discussion mailing list