[En-Nut-Discussion] NutGetMillis in Uart ISR

Alain M. alainm at pobox.com
Wed Nov 7 00:43:22 CET 2007


Hi Hugo,

I believe that this is the way to use NutGetMillis(), and it absulutely 
doesn't matter if it oferflows after a few days.

And it will not be 48 days, but 24, a long overflows with 2^31. And if 
it is not signed, it gets very nasty to calculate and compare differences.

I am new to Nut/OS, but this is a very old trick: don't waste time 
counting 64 bits if 32 are more than enough to do the job. We are 
running in microcontrolers, not dualcore-64bit-manyGHz-pentiums.

just my 2c,
Alain

Hugo Simon escreveu:
> 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();
> 
>     }
> }
> 
> 
> 
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion
> 
> 



More information about the En-Nut-Discussion mailing list