Hi,
I think I understand FTSP basics and how sync messaging works, but I
don't understand how to sync two timers.
I made a TestFTSP sandbox where event Receive.receives sync messages
[0x3E] and sends data to BaseStation.
Timer1 should fire simultaneously on all motes - how to accomplish that?
Timer1 is started in Receive.receive event.
I think I should play with: call Timer1. startPeriodicAt(t0, PERIOD);
What should I choose for timerbase t0 to get it sync with globalTime?
I calculated correctionPeriod = (uint32_t)((globalTime - localTime) %
PERIOD); what shows period difference between local and globaltime.
Any ideas how to get timers sync with globalTime?
Andres Vahter
#include "TestFtsp.h"
#include "RadioCountToLeds.h"
#define PERIOD 4096
module TestFtspC
{
uses
{
interface GlobalTime<TMilli>;
interface TimeSyncInfo;
interface Receive;
interface AMSend;
interface Packet;
interface Leds;
interface PacketTimeStamp<TMilli,uint32_t>;
interface Boot;
interface SplitControl as RadioControl;
interface Timer<TMilli> as Timer1;
interface Timer<TMilli> as SyncShotTimer;
}
}
implementation
{
message_t msg;
bool locked = FALSE;
uint32_t localTimestamp;
uint32_t globalTime;
uint32_t localTime;
uint32_t correctionPeriod;
bool is_synced;
bool timerlocked = TRUE;
bool sync_ended = FALSE;
event void Boot.booted() {
call RadioControl.start();
//call Timer1.startPeriodic(PERIOD);
}
event void Timer1.fired(){
call Leds.led2Toggle();
}
event void SyncShotTimer.fired(){
//call Timer1.startPeriodic(PERIOD);
}
// Receive sync message [0x3E]
event message_t* Receive.receive(message_t* msgPtr, void*
payload, uint8_t len)
{
call Leds.led0Toggle();
if (!locked && call PacketTimeStamp.isValid(msgPtr)) {
radio_count_msg_t* rcm = (radio_count_msg_t*)call
Packet.getPayload(msgPtr, sizeof(radio_count_msg_t));
test_ftsp_msg_t* report = (test_ftsp_msg_t*)call
Packet.getPayload(&msg, sizeof(test_ftsp_msg_t));
localTimestamp = call GlobalTime.getLocalTime();
//call
PacketTimeStamp.timestamp(msgPtr);
localTime = localTimestamp;
report->src_addr = TOS_NODE_ID;
report->counter = rcm->counter;
report->local_rx_timestamp = localTimestamp;
is_synced = call GlobalTime.local2Global(&localTimestamp);
//call
GlobalTime.getGlobalTime(&rxTimestamp);
globalTime = localTimestamp; // is_synced = call
GlobalTime.local2Global(&localTimestamp); overwrites "localTimestamp"
report->is_synced = is_synced;
report->global_rx_timestamp = globalTime; //call
Timer1.getdt(); //localTimestamp;
report->skew_times_1000000 = (uint32_t)call
TimeSyncInfo.getSkew()*1000000UL;
report->ftsp_root_addr = call TimeSyncInfo.getRootID();
report->ftsp_seq = call TimeSyncInfo.getSeqNum();
report->ftsp_table_entries = call
TimeSyncInfo.getNumEntries();
correctionPeriod = (uint32_t)((globalTime -
localTime) % PERIOD);
//call GlobalTime.global2Local(&localTimestamp);
if(is_synced == 0){ // Node
is synced with root
//timerlocked = FALSE;
if(sync_ended == FALSE){ //
call
Timer1.startPeriodicAt((localTime +
correctionPeriod) ,PERIOD); // timer started
//call
SyncShotTimer.startOneShot(correctionPeriod);
sync_ended = TRUE;
}
}
else
call Leds.led1Toggle(); // green LED
if (call AMSend.send(AM_BROADCAST_ADDR, &msg,
sizeof(test_ftsp_msg_t)) == SUCCESS) {
locked = TRUE;
}
}
return msgPtr;
}
event void AMSend.sendDone(message_t* ptr, error_t success) {
locked = FALSE;
return;
}
event void RadioControl.startDone(error_t err) {}
event void RadioControl.stopDone(error_t error){}
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help