[Tinyos-2-commits] CVS: tinyos-2.x/tos/lib/timer AlarmToTimerC.nc,
1.1.2.7, 1.1.2.8 TransformAlarmCounterC.nc, 1.1.2.4,
1.1.2.5 VirtualizeTimerC.nc, 1.1.2.9, 1.1.2.10
David Gay
idgay at users.sourceforge.net
Fri Sep 22 12:27:43 PDT 2006
Update of /cvsroot/tinyos/tinyos-2.x/tos/lib/timer
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv18984
Modified Files:
Tag: tinyos-2_0_devel-BRANCH
AlarmToTimerC.nc TransformAlarmCounterC.nc VirtualizeTimerC.nc
Log Message:
head merge
Index: AlarmToTimerC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/timer/AlarmToTimerC.nc,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -C2 -d -r1.1.2.7 -r1.1.2.8
*** AlarmToTimerC.nc 30 Jan 2006 21:31:27 -0000 1.1.2.7
--- AlarmToTimerC.nc 22 Sep 2006 19:27:41 -0000 1.1.2.8
***************
*** 42,46 ****
// there might be ways to save bytes here, but I'll do it in the obviously
// right way for now
- uint32_t m_t0;
uint32_t m_dt;
bool m_oneshot;
--- 42,45 ----
***************
*** 48,52 ****
void start(uint32_t t0, uint32_t dt, bool oneshot)
{
- m_t0 = t0;
m_dt = dt;
m_oneshot = oneshot;
--- 47,50 ----
***************
*** 89,93 ****
command uint32_t Timer.gett0()
! { return m_t0; }
command uint32_t Timer.getdt()
--- 87,91 ----
command uint32_t Timer.gett0()
! { return call Alarm.getAlarm() - m_dt; }
command uint32_t Timer.getdt()
Index: TransformAlarmCounterC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/timer/TransformAlarmCounterC.nc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** TransformAlarmCounterC.nc 30 Jan 2006 21:31:27 -0000 1.1.2.4
--- TransformAlarmCounterC.nc 22 Sep 2006 19:27:41 -0000 1.1.2.5
***************
*** 147,151 ****
atomic
{
-
m_upper++;
if ((m_upper & OVERFLOW_MASK) == 0)
--- 147,150 ----
***************
*** 169,173 ****
async command bool Alarm.isRunning()
{
! return call AlarmFrom.isRunning();
}
--- 168,172 ----
async command bool Alarm.isRunning()
{
! atomic return call AlarmFrom.isRunning() || m_skip_overflows;
}
***************
*** 179,207 ****
void set_alarm()
{
! to_size_type now = call Counter.get(), expires, remaining;
!
! /* m_t0 is assumed to be in the past. If it's > now, we assume
! that time has wrapped around */
!
! expires = m_t0 + m_dt;
!
! /* The cast is necessary to get correct wrap-around arithmetic */
! remaining = (to_size_type)(expires - now);
! /* if (expires <= now) remaining = 0; in wrap-around arithmetic */
! if (m_t0 <= now)
! {
! if (expires >= m_t0 && // if it wraps, it's > now
! expires <= now)
! remaining = 0;
! }
else
! {
! if (expires >= m_t0 || // didn't wrap so < now
! expires <= now)
! remaining = 0;
! }
! if (remaining > MAX_DELAY * 2)
{
if (remaining >= MAX_DELAY * 2 * (to_size_type)256)
--- 178,198 ----
void set_alarm()
{
! to_size_type now = call Counter.get(), elapsed = now - m_t0, remaining;
! m_skip_overflows = 0;
! if (elapsed >= m_dt)
! {
! remaining = 0;
! m_t0 += m_dt;
! m_dt = 0;
! }
else
! {
! remaining = m_dt - elapsed;
! /* MAX_DELAY is 1/2 an underlying counter overflow time. Just count
! overflows if the timer is far in the future, and we'll set an
! alarm once we're close to the deadline. */
! if (remaining > MAX_DELAY * 2)
{
if (remaining >= MAX_DELAY * 2 * (to_size_type)256)
***************
*** 211,218 ****
return;
}
- else
- m_skip_overflows = 0;
! if (remaining > MAX_DELAY)
{
m_t0 = now + MAX_DELAY;
--- 202,207 ----
return;
}
! if (remaining > MAX_DELAY)
{
m_t0 = now + MAX_DELAY;
***************
*** 220,228 ****
remaining = MAX_DELAY;
}
! else
{
m_t0 += m_dt;
m_dt = 0;
}
call AlarmFrom.startAt((from_size_type)now << bit_shift_right,
(from_size_type)remaining << bit_shift_right);
--- 209,218 ----
remaining = MAX_DELAY;
}
! else
{
m_t0 += m_dt;
m_dt = 0;
}
+ }
call AlarmFrom.startAt((from_size_type)now << bit_shift_right,
(from_size_type)remaining << bit_shift_right);
***************
*** 262,265 ****
--- 252,256 ----
{
}
+
default async event void Counter.overflow()
{
Index: VirtualizeTimerC.nc
===================================================================
RCS file: /cvsroot/tinyos/tinyos-2.x/tos/lib/timer/VirtualizeTimerC.nc,v
retrieving revision 1.1.2.9
retrieving revision 1.1.2.10
diff -C2 -d -r1.1.2.9 -r1.1.2.10
*** VirtualizeTimerC.nc 26 Jul 2006 18:57:52 -0000 1.1.2.9
--- VirtualizeTimerC.nc 22 Sep 2006 19:27:41 -0000 1.1.2.10
***************
*** 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
***************
*** 56,141 ****
Timer_t m_timers[NUM_TIMERS];
! task void executeTimersNow();
! void executeTimers(uint32_t then)
{
! int32_t min_remaining = (1UL<<31)-1; //max signed int32_t
! bool min_remaining_isset = FALSE;
! int num;
!
! for(num=0; num<NUM_TIMERS; num++)
! {
! Timer_t* timer = &m_timers[num];
! if (timer->isrunning)
{
! // Calculate "remaining" before the timer is fired. If a timer
! // restarts itself in a fired event, then we 1) need a consistent
! // "remaining" value to work with, and no worries because 2) all
! // start commands post executeTimersNow, so the timer will be
! // recomputed later, anyway.
! int32_t elapsed = then - timer->t0;
! int32_t remaining = timer->dt - elapsed;
! bool compute_min_remaining = TRUE;
! // 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)
! {
! timer->isrunning = FALSE;
! compute_min_remaining = FALSE;
! }
! else
! {
! // The remaining time is non-positive (the timer had fired).
! // So add dt to convert it to remaining for the next event.
! timer->t0 += timer->dt;
! remaining += timer->dt;
}
! signal Timer.fired[num]();
! }
! // check isrunning in case the timer was stopped in the fired event
! if (compute_min_remaining && timer->isrunning)
! {
! if (remaining < 0)
! min_remaining = 0;
! else if (remaining < min_remaining)
! min_remaining = remaining;
! min_remaining_isset = TRUE;
! }
}
- }
if (min_remaining_isset)
! {
! uint32_t now = call TimerFrom.getNow();
! uint32_t elapsed = now - then;
! if (min_remaining <= elapsed)
! post executeTimersNow();
! else
! call TimerFrom.startOneShotAt(now, min_remaining - elapsed);
! }
}
-
event void TimerFrom.fired()
{
! executeTimers(call TimerFrom.gett0() + call TimerFrom.getdt());
! }
!
! task void executeTimersNow()
! {
! call TimerFrom.stop();
! executeTimers(call TimerFrom.getNow());
}
--- 56,131 ----
Timer_t m_timers[NUM_TIMERS];
+ 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
+ remaining were switched to uint32_t, and the logic changed a
+ little, dt's up to 2^32-1 should work (but at a slightly higher
+ runtime cost). */
+ uint32_t now = call TimerFrom.getNow();
+ int32_t min_remaining = (1UL << 31) - 1; /* max int32_t */
+ bool min_remaining_isset = FALSE;
+ uint8_t num;
! 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());
}
***************
*** 147,151 ****
timer->isoneshot = isoneshot;
timer->isrunning = TRUE;
! post executeTimersNow();
}
--- 137,141 ----
timer->isoneshot = isoneshot;
timer->isrunning = TRUE;
! post updateFromTimer();
}
More information about the Tinyos-2-commits
mailing list