Hi all,

Is there a bug in tos/chips/MSP430/timer/MSP430AlarmC.nc? I would really
appreciate it if anyone could help me about this.

async command void Alarm.startAt( uint16_t t0, uint16_t dt )
 {
   atomic
   {
     uint16_t now = call Msp430Timer.get();
     uint16_t elapsed = now - t0;//if t0 = 65400, now = 340. bug???
     if( elapsed >= dt )
     {
       call Msp430Compare.setEventFromNow(2);
     }
     else
     {
       uint16_t remaining = dt - elapsed; //if elapsed = 65400, dt = 340.
bug???
       if( remaining <= 2 )
         call Msp430Compare.setEventFromNow(2);
       else
         call Msp430Compare.setEvent( now+remaining );
     }
     call Msp430TimerControl.clearPendingInterrupt();
     call Msp430TimerControl.enableEvents();
   }
 }


async command void Alarm.startAt( uint16_t t0, uint16_t dt)
 {
   atomic
   {
     uint16_t now = call Msp430Timer.get();
     uint16_t elapsed;
     //uint16_t elapsed = now - t0;//if t0 = 65400, now = 340. bug???
weishen.MODIFY
     // t0 -----------  now.   t0 <= now
     if(now>t0)
       elapsed = now - t0;
     else
       elapsed = 0xffff-t0 + now;
     if( elapsed >= dt )
     {
       call Msp430Compare.setEventFromNow(2);
     }
     else
     {
       //uint16_t remaining = dt - elapsed; //if elapsed = 65400, dt = 340.
bug??? weishen.
       uint16_t remaining;
       if(dt>elapsed)
          remaining = dt - elapsed;
       else
          remaining = 0xffff - elapsed + dt.
       if( remaining <= 2 )
         call Msp430Compare.setEventFromNow(2);
       else
         call Msp430Compare.setEvent( now+remaining );
     }
     call Msp430TimerControl.clearPendingInterrupt();
     call Msp430TimerControl.enableEvents();
   }
 }

-- 
Wei Shen
PhD Student in Mid Sweden University, Sweden
[email protected]
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to