Skip to content

Commit bb5e5d5

Browse files
committed
TSCH: use RTIMER_CLOCK_DIFF to compute estimated drift, fixing a bug that would occur on 16-bit rtimer platforms
1 parent 5b5f07b commit bb5e5d5

File tree

14 files changed

+24
-22
lines changed

14 files changed

+24
-22
lines changed

core/net/mac/tsch/tsch-slot-operation.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ PT_THREAD(tsch_rx_slot(struct pt *pt, struct rtimer *t))
737737
if(linkaddr_cmp(&destination_address, &linkaddr_node_addr)
738738
|| linkaddr_cmp(&destination_address, &linkaddr_null)) {
739739
int do_nack = 0;
740-
estimated_drift = ((int32_t)expected_rx_time - (int32_t)rx_start_time);
740+
estimated_drift = RTIMER_CLOCK_DIFF(expected_rx_time, rx_start_time);
741741

742742
#if TSCH_TIMESYNC_REMOVE_JITTER
743743
/* remove jitter due to measurement errors */

core/sys/rtimer.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@
5555

5656
#include "contiki-conf.h"
5757

58-
#ifndef RTIMER_CLOCK_LT
58+
#ifndef RTIMER_CLOCK_DIFF
5959
typedef unsigned short rtimer_clock_t;
60-
#define RTIMER_CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
61-
#endif /* RTIMER_CLOCK_LT */
60+
#define RTIMER_CLOCK_DIFF(a,b) ((signed short)((a)-(b)))
61+
#endif /* RTIMER_CLOCK_DIFF */
62+
63+
#define RTIMER_CLOCK_LT(a, b) (RTIMER_CLOCK_DIFF((a),(b)) < 0)
6264

6365
#include "rtimer-arch.h"
6466

cpu/arm/aducrf101/aducrf101-contiki.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef uint32_t clock_time_t;
4646
typedef uint16_t uip_stats_t;
4747

4848
typedef uint32_t rtimer_clock_t;
49-
#define RTIMER_CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0)
49+
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
5050
rtimer_clock_t rtimer_arch_now(void);
5151

5252
#endif

cpu/mc1322x/contiki-mc1322x-conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ typedef unsigned short uip_stats_t;
5555

5656
typedef uint32_t clock_time_t;
5757

58-
/* Core rtimer.h defaults to 16 bit timer unless RTIMER_CLOCK_LT is defined */
58+
/* Core rtimer.h defaults to 16 bit timer unless RTIMER_CLOCK_DIFF is defined */
5959
typedef unsigned long rtimer_clock_t;
60-
#define RTIMER_CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
60+
#define RTIMER_CLOCK_DIFF(a,b) ((signed long)((a)-(b)))
6161

6262
#endif

platform/cc2538dk/contiki-conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ typedef uint32_t uip_stats_t;
3434

3535
/*
3636
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
37-
* RTIMER_CLOCK_LT to override this
37+
* RTIMER_CLOCK_DIFF to override this
3838
*/
3939
typedef uint32_t rtimer_clock_t;
40-
#define RTIMER_CLOCK_LT(a,b) ((int32_t)((a)-(b)) < 0)
40+
#define RTIMER_CLOCK_DIFF(a,b) ((int32_t)((a)-(b)))
4141
/** @} */
4242
/*---------------------------------------------------------------------------*/
4343
/**

platform/cooja/contiki-conf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ typedef unsigned short uip_stats_t;
201201
#define CLOCK_CONF_SECOND 1000L
202202
typedef unsigned long clock_time_t;
203203
typedef unsigned long rtimer_clock_t;
204-
#define RTIMER_CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
204+
#define RTIMER_CLOCK_DIFF(a,b) ((signed long)((a)-(b)))
205205

206206
#define AODV_COMPLIANCE
207207
#define AODV_NUM_RT_ENTRIES 32

platform/galileo/contiki-conf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ typedef unsigned long clock_time_t;
4646

4747
typedef uint64_t rtimer_clock_t;
4848
#define RTIMER_ARCH_SECOND 1024
49-
#define RTIMER_CLOCK_LT(a, b) ((int64_t)((a) - (b)) < 0)
49+
#define RTIMER_CLOCK_DIFF(a, b) ((int64_t)((a) - (b)))
5050

5151
/* We define the following macros and types otherwise Contiki does not
5252
* compile.

platform/jn516x/platform-conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@
8080
#define JN516X_EXTERNAL_CRYSTAL_OSCILLATOR (RTIMER_USE_32KHZ || JN516X_SLEEP_ENABLED)
8181
#endif /* JN516X_EXTERNAL_CRYSTAL_OSCILLATOR */
8282

83-
/* Core rtimer.h defaults to 16 bit timer unless RTIMER_CLOCK_LT is defined */
83+
/* Core rtimer.h defaults to 16 bit timer unless RTIMER_CLOCK_DIFF is defined */
8484
typedef uint32_t rtimer_clock_t;
85-
#define RTIMER_CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0)
85+
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
8686

8787
/* 8ms timer tick */
8888
#define CLOCK_CONF_SECOND 125

platform/mbxxx/platform-conf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ typedef unsigned long clock_time_t;
8787

8888
typedef unsigned long rtimer_clock_t;
8989

90-
#define RTIMER_CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
90+
#define RTIMER_CLOCK_DIFF(a,b) ((signed long)((a)-(b)))
9191

9292
#define LEDS_CONF_RED_PIN boardDescription->io->leds[1].gpioPin
9393
#define LEDS_CONF_GREEN_PIN boardDescription->io->leds[0].gpioPin

platform/openmote-cc2538/contiki-conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ typedef uint32_t uip_stats_t;
7373

7474
/*
7575
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
76-
* RTIMER_CLOCK_LT to override this
76+
* RTIMER_CLOCK_DIFF to override this
7777
*/
7878
typedef uint32_t rtimer_clock_t;
79-
#define RTIMER_CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0)
79+
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
8080
/** @} */
8181
/*---------------------------------------------------------------------------*/
8282
/**

platform/seedeye/contiki-conf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ typedef uint16_t uip_stats_t;
6060
typedef uint32_t clock_time_t;
6161

6262
typedef uint32_t rtimer_clock_t;
63-
#define RTIMER_CLOCK_LT(a,b) ((int32_t)((a)-(b)) < 0)
63+
#define RTIMER_CLOCK_DIFF(a,b) ((int32_t)((a)-(b)))
6464

6565
#define RF_CHANNEL 13
6666

platform/srf06-cc26xx/contiki-conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ typedef uint32_t uip_stats_t;
325325

326326
/*
327327
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
328-
* RTIMER_CLOCK_LT to override this
328+
* RTIMER_CLOCK_DIFF to override this
329329
*/
330330
typedef uint32_t rtimer_clock_t;
331-
#define RTIMER_CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0)
331+
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
332332
/** @} */
333333
/*---------------------------------------------------------------------------*/
334334
/* board.h assumes that basic configuration is done */

platform/stm32nucleo-spirit1/platform-conf.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
#define CLOCK_CONF_SECOND 128
7979
/* One tick: 62.5 ms */
8080

81-
#define RTIMER_CLOCK_LT(a, b) ((signed short)((a) - (b)) < 0)
81+
#define RTIMER_CLOCK_DIFF(a, b) ((signed short)((a) - (b)))
8282
/*---------------------------------------------------------------------------*/
8383
typedef unsigned long clock_time_t;
8484
typedef unsigned long long rtimer_clock_t;

platform/zoul/contiki-conf.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ typedef uint32_t uip_stats_t;
7171

7272
/*
7373
* rtimer.h typedefs rtimer_clock_t as unsigned short. We need to define
74-
* RTIMER_CLOCK_LT to override this
74+
* RTIMER_CLOCK_DIFF to override this
7575
*/
7676
typedef uint32_t rtimer_clock_t;
77-
#define RTIMER_CLOCK_LT(a, b) ((int32_t)((a) - (b)) < 0)
77+
#define RTIMER_CLOCK_DIFF(a, b) ((int32_t)((a) - (b)))
7878
/** @} */
7979
/*---------------------------------------------------------------------------*/
8080
/**

0 commit comments

Comments
 (0)