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

David Gay idgay at users.sourceforge.net
Fri Aug 11 14:28:02 PDT 2006


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

Modified Files:
	VirtualizeTimerC.nc 
Log Message:
separate firing and from-timer update logic (similar to VirtualizeAlarmC,
though doesn't have to worry about concurrent changes)


Index: VirtualizeTimerC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/timer/VirtualizeTimerC.nc,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** VirtualizeTimerC.nc	11 Aug 2006 21:07:37 -0000	1.7
--- VirtualizeTimerC.nc	11 Aug 2006 21:27:59 -0000	1.8
***************
*** 41,48 ****
  {
    enum
!   {
!     NUM_TIMERS = max_timers,
!     END_OF_LIST = 255,
!   };
  
    typedef struct
--- 41,48 ----
  {
    enum
!     {
!       NUM_TIMERS = max_timers,
!       END_OF_LIST = 255,
!     };
  
    typedef struct
***************
*** 58,64 ****
    bool m_timers_changed;
  
!   task void executeTimersNow();
  
!   void executeTimers()
    {
      /* This code supports a maximum dt of MAXINT. If min_remaining and
--- 58,90 ----
    bool m_timers_changed;
  
!   task void updateFromTimer();
  
!   void fireTimers(uint32_t now)
!   {
!     uint8_t num;
! 
!     for (num=0; num<NUM_TIMERS; num++)
!       {
! 	Timer_t* timer = &m_timers[num];
! 
! 	if (timer->isrunning)
! 	  {
! 	    uint32_t elapsed = now - timer->t0;
! 
! 	    if (elapsed >= timer->dt)
! 	      {
! 		if (timer->isoneshot)
! 		  timer->isrunning = FALSE;
! 		else // Update timer for next event
! 		  timer->t0 += timer->dt;
! 
! 		signal Timer.fired[num]();
! 	      }
! 	  }
!       }
!     post updateFromTimer();
!   }
!   
!   task void updateFromTimer()
    {
      /* This code supports a maximum dt of MAXINT. If min_remaining and
***************
*** 72,139 ****
  
      call TimerFrom.stop();
-     m_timers_changed = FALSE;
  
      for (num=0; num<NUM_TIMERS; num++)
-     {
-       Timer_t* timer = &m_timers[num];
- 
-       if (timer->isrunning)
        {
! 	uint32_t elapsed = now - timer->t0;
! 
! 	if (elapsed >= timer->dt)
! 	{
! 	  if (timer->isoneshot)
! 	  {
! 	    timer->isrunning = FALSE;
! 	  }
! 	  else
! 	  {
! 	    // Update timer for next event
! 	    timer->t0 += timer->dt;
! 	    // Update elapsed so we compute the time of the next event
! 	    elapsed -= timer->dt;
! 	  }
! 
! 	  signal Timer.fired[num]();
! 	}
  
- 	// Check isrunning in case the timer was stopped in the fired
- 	// 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 a value of remaining <= 0. But we're
- 	// already scheduled an executeTimersNow in that case (and
- 	// suppressed setting TimerFrom)
  	if (timer->isrunning)
! 	{
! 	  int32_t remaining = timer->dt - elapsed;
  
! 	  if (remaining < min_remaining)
! 	    {
! 	      min_remaining = remaining;
! 	      min_remaining_isset = TRUE;
! 	    }
! 	}
        }
-     }
  
!     if (!m_timers_changed && min_remaining_isset)
!     {
!       if (min_remaining <= 0)
! 	post executeTimersNow();
!       else
! 	call TimerFrom.startOneShotAt(now, min_remaining);
!     }
    }
    
- 
    event void TimerFrom.fired()
    {
!     executeTimers();
!   }
! 
!   task void executeTimersNow()
!   {
!     executeTimers();
    }
  
--- 98,131 ----
  
      call TimerFrom.stop();
  
      for (num=0; num<NUM_TIMERS; num++)
        {
! 	Timer_t* timer = &m_timers[num];
  
  	if (timer->isrunning)
! 	  {
! 	    uint32_t elapsed = now - timer->t0;
! 	    int32_t remaining = timer->dt - elapsed;
  
! 	    if (remaining < min_remaining)
! 	      {
! 		min_remaining = remaining;
! 		min_remaining_isset = TRUE;
! 	      }
! 	  }
        }
  
!     if (min_remaining_isset)
!       {
! 	if (min_remaining <= 0)
! 	  fireTimers(now);
! 	else
! 	  call TimerFrom.startOneShotAt(now, min_remaining);
!       }
    }
    
    event void TimerFrom.fired()
    {
!     fireTimers(call TimerFrom.getNow());
    }
  
***************
*** 145,150 ****
      timer->isoneshot = isoneshot;
      timer->isrunning = TRUE;
!     m_timers_changed = TRUE;
!     post executeTimersNow();
    }
  
--- 137,141 ----
      timer->isoneshot = isoneshot;
      timer->isrunning = TRUE;
!     post updateFromTimer();
    }
  



More information about the Tinyos-2-commits mailing list