9
Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Embed Size (px)

Citation preview

Page 1: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Code ReviewTime Synchronization

Presented by Yong Chen

Department of Computer ScienceUniversity of Virginia

Page 2: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Outline

ClockTimer GlobalAbsoluteTimerTimeStampingTime Synchronization

Page 3: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Clock

Local time source CPU clock: high resolution (7.37MHz), not stable,

stops in power-down mode (SysTimeC) External clock: low resolution, stable, keeps running

in power-down mode

ClockC component A high precision real time clock (with 1/32768 sec

resolution) The Clock interface (Clock.nc) has been extended to

support the setting and retrieval of the current (actual) clock rate in 1/32768 second units.

Page 4: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Timer

The new Timer component provides timers with 1/32768 sec resolution. If two timers use the same timer id, timer["id"], only the later timer takes effect, the previous one would not work. so timer should be used like TimerC.Timer[unique("Timer")];Provide as many timers as needed Change the setting of TIMER_NUM_TIMERS

Page 5: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

GlobalAbsoluteTimer

Triggered at the absolute time point instead of time interval as previous timerThe resolution is 1/1000 or 1/32768 secondIf two timers use the same timer id, like GlobalAbsoluteTimer[id], only the later timer takes effect, the previous one would not work. so timer should be used like GlobalAbsoluteTimer[unique("AbsoluteTimer")]Provide as many timers as needed

Change the setting of MAX_NUM_ABS_TIMERS

Page 6: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

TimeStamping

Time stamping is a time synchronization primitive: establishing time reference points between a sender and receiver(s) using a single radio message

Sender Sender obtains timestamp when the message was actually

sent in its own local time The message can contain the local time of the sender at the

time of transmission Method addStamp() Adds a time stamp to the next

message sent by the radio. This method must be called immediatelly after SendMsg.send() returns SUCCESS.

Receiver Receiver obtains timestamp when the message was

received in its own local time Method getStamp() Returns the time stamp of the last

received message. This method should be called when the ReceiveMsg.receive() is fired. The returned value contains the local time when the message was received.

Page 7: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Time SynchronizationFlooding Time Synchronization Protocol for Sensor Networks, VUEach node maintains two time variables

Local Time Represents the local physical time Never reset or adjusted

Global Time learns from its neighboring nodes. Reflects the time of the network

Formula for Global Time and Local Time globalTime = localTime + offsetAverage + skew*

(localTime – localAverage) variable offsetAverage, skew, and localAverage are

decided by messages from neighboring nodes

Page 8: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Time SynchronizationRoot

The network is synchronized to the root node Sends out synchronization beacon messages

periodicallyOther nodes are synchronized to the root, after synchronized, it will send out synch beacons periodicallyWho can be the root

The node Set isForceRoot = 1 The node is set to be the root

The node Set isForceRoot = -1 The node is never to be a root

The node Set isForceRoot = 0 The node can be a root if it doesn’t receive any

aynchronization message for a period of time It is possible there are several roots

simultaneously, if so, the root with smaller ID would dominate the network.

Page 9: Code Review Time Synchronization Presented by Yong Chen Department of Computer Science University of Virginia

Time SynchronizationCommentsActually, in the code, the isForceRoot is set to be either 1 or -1, so the code on isForceRoot == 0 can be eliminated.some repeated statements

in command result_t StdControl.init() outgoingMsg->rootID = 0xFFFF; outgoingMsg->nodeID =

TOS_LOCAL_ADDRESS; in command result_t StdControl.start() outgoingMsg->rootID = 0xFFFF; outgoingMsg->nodeID =

TOS_LOCAL_ADDRESS; They can appear once in StdControl.init() only once