[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/timer VirtualizeTimerC.nc, 1.5, 1.6

David Gay idgay at users.sourceforge.net
Wed Aug 9 17:11:43 PDT 2006


Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/timer
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv24082

Modified Files:
	VirtualizeTimerC.nc 
Log Message:
some virtualise timer changes/fixes:
- we shouldn't worry about t0 in the future (a value of t0 > now represents
  a value in the past)
- we need to worry about the underlying timer having fired (but not reached)
  us yet when we try and set the timer (if we don't, we can handle a past
  event as representing a future event); see the revised version of 
  executeTimersTask for details
- we track when timers are changed during execution of executeTimers


Index: VirtualizeTimerC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/timer/VirtualizeTimerC.nc,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** VirtualizeTimerC.nc	8 Aug 2006 23:14:34 -0000	1.5
--- VirtualizeTimerC.nc	10 Aug 2006 00:11:41 -0000	1.6
***************
*** 57,60 ****
--- 57,67 ----
    Timer_t m_timers[NUM_TIMERS];
  
+   enum {
+     /* bitmask */
+     S_TIMER_RUNNING = 1,
+     S_TIMER_CHANGED = 2
+   };
+   bool state;
+ 
    task void executeTimersNow();
  
***************
*** 65,68 ****
--- 72,78 ----
      int num;
  
+     /* We always come here with the timer stopped */
+     state = 0;
+ 
      for(num=0; num<NUM_TIMERS; num++)
      {
***************
*** 77,89 ****
  	// recomputed later, anyway.
  
! 	int32_t elapsed = then - timer->t0;
  	int32_t remaining = timer->dt - elapsed;
  
! 	// If the elapsed time is negative, then t0 is in the future, so
! 	// don't process it.  This implies:
! 	//   1) t0 in the future is okay
! 	//   2) dt can be at most maxval(uint32_t)/2
! 
! 	if ((elapsed >= 0) && (timer->dt <= (uint32_t)elapsed))
  	{
  	  if (timer->isoneshot)
--- 87,94 ----
  	// recomputed later, anyway.
  
! 	uint32_t elapsed = then - timer->t0;
  	int32_t remaining = timer->dt - elapsed;
  
! 	if (remaining <= 0)
  	{
  	  if (timer->isoneshot)
***************
*** 105,110 ****
  	// event or this was a one shot timer; note that a one shot
  	// timer that was restarted in its fired event will push us
! 	// through here with remaining < 0, but we've already scheduled
! 	// an executeTimers in that case
  	if (timer->isrunning)
  	{
--- 110,116 ----
  	// event or this was a one shot timer; note that a one shot
  	// timer that was restarted in its fired event will push us
! 	// through here with remaining <= 0, but we're already scheduled
! 	// an executeTimersTask in that case (and suppressed setting
! 	// TimerFrom)
  	if (timer->isrunning)
  	{
***************
*** 116,127 ****
      }
  
!     if (min_remaining_isset)
      {
!       uint32_t now = call TimerFrom.getNow();
!       uint32_t elapsed = now - then;
!       if (min_remaining < 0 || (uint32_t)min_remaining <= elapsed)
  	post executeTimersNow();
        else
! 	call TimerFrom.startOneShotAt(now, min_remaining - elapsed);
      }
    }
--- 122,134 ----
      }
  
!     if (!(state & S_TIMER_CHANGED) && min_remaining_isset)
      {
!       if (min_remaining <= 0)
  	post executeTimersNow();
        else
! 	{
! 	  call TimerFrom.startOneShotAt(then, min_remaining);
! 	  state |= S_TIMER_RUNNING;
! 	}
      }
    }
***************
*** 135,139 ****
    task void executeTimersNow()
    {
!     call TimerFrom.stop();
      executeTimers(call TimerFrom.getNow());
    }
--- 142,164 ----
    task void executeTimersNow()
    {
!     /* If we set a timer, try and stop it. But if it believes it's
!        not running, that means that the execution of its fired event
!        is pending, so we:
!        - don't need to call executeTimers (it will happen soon)
!        - we must not call executeTimers, because that would change the
!          timer's setting, confusing the pending call to TimerFrom.fired
! 	 (it would call executeTimers with an incorrect "then"
! 	 parameter)
!        We need to use an atomic section even though it's a "timer",
!        because it's based on an underlying alarm, whose transitions
!        are asynchronous (yuck?)
!     */
!     if (state & S_TIMER_RUNNING)
!       atomic
! 	{
! 	  if (!call TimerFrom.isRunning())
! 	    return;
! 	  call TimerFrom.stop();
! 	}
      executeTimers(call TimerFrom.getNow());
    }
***************
*** 146,149 ****
--- 171,175 ----
      timer->isoneshot = isoneshot;
      timer->isrunning = TRUE;
+     state |= S_TIMER_CHANGED;
      post executeTimersNow();
    }



More information about the Tinyos-2-commits mailing list