TPSync¶
TPSync is a rudimentary node-to-node synchronization library for MSP430-based transiently-powered wireless sensors. It provides a simple API to synchronize radio schedules of a transmitter and a receiver based on timing information collected with an intermittency-safe timekeeper (e.g., the CHRT).
Radio synchronization¶
TPSync allows a receiving node to synchronize to a periodic transmission schedule of a transmitting node. For this to work, the transmitter attaches the current transmission period, i.e., the time interval between two packets, to every sent packet.
If the transmission period is somewhat stable, the receiver can try to latch to that (or a multiple of that, in case the energy is not enough), and turn on its radio only when a packet is being transmitted. As soon as the receiver successfully receives a packet, it uses the transmission period contained in the packet to calculate how long to delay its next reception attempt. For instance, in the figure below, the receiver latches to the transmitter’s schedule after successfully receiving the third packet.
As shown below, the transmitter could compute its average wake-up period (transmission period) and send it using the radio
/* Get elapsed time using CHRT. */
elapsed_time = get_elapsed_time();
/* Compute average TX period and add it to packet. */
avg_tx_period = get_avg_wakeup_period(elapsed_time);
packet.avg_tx_period = avg_tx_period;
/* Send packet. */
send_packet(&packet);
and the receiver could use the transmission period to delay its next listening activity
/* Get elapsed time using CHRT. */
elapsed_time = get_elapsed_time();
/* Delay listening activity (avg_tx_period received in previous cycle). */
delay_radio_listening(elapsed_time, packet.avg_tx_period, 0);
/* Try to receive another packet. */
receive_packet(&packet);
The methods used in the examples above are documented here.
-
uint16_t
get_avg_wakeup_period
(uint16_t last_period)¶ Compute average wake-up period over a sliding window.
This function calculates the average over a sliding window of the last wake-up periods.
- Return
average of last
AVG_WINDOW
periods- Parameters
last_period
: duration of the last wake-up cycle
- See
-
int
delay_radio_listening
(uint16_t rx_wakeup_period, uint16_t tx_wakeup_period, uint16_t error)¶ Delay radio reception to aligh to synchronized schedule.
The delay is implemented as a low-power mode (LPM1) sleep interrupted by a timeout. SMCLK and TA1 are used to implement the timeout.
- Return
TPSYNC_NULL_TX_WUP
in case the wake-up cycle of the transmitting node has null duration,TPSYNC_NULL_DELAY
in case reception is not delayed,TPSYNC_NO_RX_SUCCESS
in case a packed was not received (and reception is not delayed),TPSYNC_SUCCESS
otherwise- Parameters
rx_wakeup_period
: duration of the last wake-up cycletx_wakeup_period
: duration of the last wake-up cycle of the transmitting nodeerror
: nominal timekeeping error
Synchronization error¶
When the receiver starts listening too early, some radio time is wasted (idle listening), potentially leading to premature power loss and packet miss. To correct for such a synchronization error, the receiver can track idle time and try to minimize it in the next cycle.
To do so, it is sufficient for the receiver to call track_sync_error_start()
just before turning on its radio, and track_sync_error_stop()
when
successfully receiving a packet. The receiver’s code can be extended as
follows:
/* Get elapsed time using CHRT. */
elapsed_time = get_elapsed_time();
/* Delay listening activity (avg_tx_period received in previous cycle). */
delay_radio_listening(elapsed_time, packet.avg_tx_period, 0);
/* Start tracking sync error. */
track_sync_error_start();
/* Try to receive another packet. */
receive_packet(&packet);
/* Stop tracking sync error. */
track_sync_error_stop();
TPSync will internally calculate the receiver’s idle time, after receiving a
packer, and try to minimize it in the next delay_radio_listening()
.
-
void
track_sync_error_start
(void)¶ Start tracking synchronization error.
This function can be called when the receiving node wakes up to start tracking how much time is wasted waiting for a packet with the radio on.
-
void
track_sync_error_stop
(void)¶ Stop tracking synchronization error.
This function can be called upon reception of a packet to compute the total idle listening time. This information can be used in a subsequent radio cycle as a feedback control to minimize idle listening.
ERROR_CORR_COEFF
can be used to scale down the magnitude of the synchronization error, effectively working as the P parameter in a proportional feedback controller.
Fine-tuning TPSync¶
-
AVG_WINDOW
¶ Number of power cycles to use when computing the average wake-up period.
-
ERROR_CORR_COEFF
¶ Controls the scaling factor for error synchronization (use with track_sync_error_start and track_sync_error_stop).
-
SYNC_SLACK_MS
¶ Controls how much the receiver wakes up ahead of schedule. A larger
SYNC_SLACK_MS
allows for more synchronization error, but increases energy consumption, and consequently the chance of missing a packet.