OpenWSN Firmware
adaptive_sync.h
Go to the documentation of this file.
1 #ifndef __ADAPTIVE_SYNC_H
2 #define __ADAPTIVE_SYNC_H
3 
4 #include "board.h"
5 #include "openwsn.h"
6 #include "opentimers.h"
18 //=========================== define ==========================================
19 
20 typedef enum {
21  S_NONE = 0x00,
22  S_FASTER = 0x01,
23  S_SLOWER = 0x02,
25 
26 //=========================== typedef =========================================
27 
28 //=========================== module variables ================================
29 
30 typedef struct {
32  uint16_t compensationSlots; // compensation interval, in slots
34 
35 typedef struct {
37  PORT_RADIOTIMER_WIDTH elapsedSlots; // since last synchronizatino, this number of slots have elapsed.
38  uint16_t compensationTimeout; // decrease one every slot, when it reach zero, adjust currectly slot length by 2 tick(60us).
39  uint16_t compensateTicks; // record how many ticks are compensated
40  asn_t oldASN; // the asn when synchronized previous time
41  compensationInfo_t compensationInfo_vars; // keep each time soures' compensation informatio( should be 9, since there would be more timesources)
42  int16_t sumOfTC; // record the sum of ticks between two time point which need to calculate compensation period.
43  uint16_t compensateThreshold; // number of slots. calculate the compensation period only when elapsed slot number is greater than this threshold
44  bool driftChanged; // drift is changed or not.
46 
47 //=========================== prototypes ======================================
48 
49 void adaptive_sync_init(void);
50 void adaptive_sync_preprocess(int16_t timeCorrection, open_addr_t timesource);
51 void adaptive_sync_calculateCompensatedSlots(int16_t timeCorrection);
52 
54 void adaptive_sync_countCompensationTimeout_compoundSlots(uint16_t compoundSlots);
56 
61 #endif
62 
PORT_RADIOTIMER_WIDTH elapsedSlots
Definition: adaptive_sync.h:37
asn_t oldASN
Definition: adaptive_sync.h:40
uint16_t compensationSlots
Definition: adaptive_sync.h:32
adaptive_sync_state_t clockState
Definition: adaptive_sync.h:36
void adaptive_sync_preprocess(int16_t timeCorrection, open_addr_t timesource)
Calculated how many slots have elapsed since last synchronized.
Definition: adaptive_sync.c:51
void adaptive_sync_countCompensationTimeout()
update compensationTimeout at the beginning of each slot and adjust current slot length when the elap...
Definition: adaptive_sync.c:167
Definition: adaptive_sync.h:35
Definition: adaptive_sync.h:30
compensationInfo_t compensationInfo_vars
Definition: adaptive_sync.h:41
Definition: openwsn.h:268
void adaptive_sync_driftChanged()
set driftChanged to true.
Definition: adaptive_sync.c:249
Definition: adaptive_sync.h:22
void adaptive_sync_calculateCompensatedSlots(int16_t timeCorrection)
Calculate the compensation interval, in number of slots.
Definition: adaptive_sync.c:117
void adaptive_sync_init()
initial this module
Definition: adaptive_sync.c:35
Definition: adaptive_sync.h:21
Definition: adaptive_sync.h:23
Definition: openwsn.h:276
void adaptive_sync_countCompensationTimeout_compoundSlots(uint16_t compoundSlots)
update compensationTimeout when compound slots are scheduled and adjust the slot when the elapsed slo...
Definition: adaptive_sync.c:202
int16_t sumOfTC
Definition: adaptive_sync.h:42
uint16_t compensationTimeout
Definition: adaptive_sync.h:38
adaptive_sync_state_t
Definition: adaptive_sync.h:20
uint16_t compensateThreshold
Definition: adaptive_sync.h:43
uint16_t compensateTicks
Definition: adaptive_sync.h:39
open_addr_t neighborID
Definition: adaptive_sync.h:31
bool driftChanged
Definition: adaptive_sync.h:44