Contiki-NG
tsch-conf.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015, SICS Swedish ICT.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34* \addtogroup tsch
35* @{
36 * \file
37 * TSCH configuration
38 * \author
39 * Simon Duquennoy <simonduq@sics.se>
40 */
41
42#ifndef TSCH_CONF_H_
43#define TSCH_CONF_H_
44
45/********** Includes **********/
46
47#include "contiki.h"
48
49/******** Configuration: synchronization *******/
50
51/* Max time before sending a unicast keep-alive message to the time source */
52#ifdef TSCH_CONF_KEEPALIVE_TIMEOUT
53#define TSCH_KEEPALIVE_TIMEOUT TSCH_CONF_KEEPALIVE_TIMEOUT
54#else
55/* Time to desynch assuming a drift of 40 PPM (80 PPM between two nodes) and guard time of +/-1ms: 12.5s. */
56#define TSCH_KEEPALIVE_TIMEOUT (12 * CLOCK_SECOND)
57#endif
58
59/* With TSCH_ADAPTIVE_TIMESYNC enabled: keep-alive timeout used after reaching
60 * accurate drift compensation. */
61#ifdef TSCH_CONF_MAX_KEEPALIVE_TIMEOUT
62#define TSCH_MAX_KEEPALIVE_TIMEOUT TSCH_CONF_MAX_KEEPALIVE_TIMEOUT
63#else
64#define TSCH_MAX_KEEPALIVE_TIMEOUT (60 * CLOCK_SECOND)
65#endif
66
67/* Max time without synchronization before leaving the PAN */
68#ifdef TSCH_CONF_DESYNC_THRESHOLD
69#define TSCH_DESYNC_THRESHOLD TSCH_CONF_DESYNC_THRESHOLD
70#else
71#define TSCH_DESYNC_THRESHOLD (2 * TSCH_MAX_KEEPALIVE_TIMEOUT)
72#endif
73
74/* The default period between two consecutive EBs (not taking into account any randomization).
75 * When TSCH_CONF_EB_PERIOD is set to 0, sending EBs is disabled completely; the EB process is not started.
76 * Otherwise, if RPL is used, TSCH_CONF_EB_PERIOD used only before joining the RPL network;
77 * afterwards, the EB period is set dynamically based on RPL DIO period, updated whenever
78 * the DIO period changes, and is upper bounded by TSCH_MAX_EB_PERIOD.
79 */
80#ifdef TSCH_CONF_EB_PERIOD
81#define TSCH_EB_PERIOD TSCH_CONF_EB_PERIOD
82#else
83#define TSCH_EB_PERIOD (16 * CLOCK_SECOND)
84#endif
85
86/* Max Period between two consecutive EBs.
87 * Has no effect when TSCH_EB_PERIOD is zero. */
88#ifdef TSCH_CONF_MAX_EB_PERIOD
89#define TSCH_MAX_EB_PERIOD TSCH_CONF_MAX_EB_PERIOD
90#else
91#define TSCH_MAX_EB_PERIOD (16 * CLOCK_SECOND)
92#endif
93
94/* Use SFD timestamp for synchronization? By default we merely rely on rtimer and busy wait
95 * until SFD is high, which we found to provide greater accuracy on JN516x and CC2420.
96 * Note: for association, however, we always use SFD timestamp to know the time of arrival
97 * of the EB (because we do not busy-wait for the whole scanning process)
98 * */
99#ifdef TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
100#define TSCH_RESYNC_WITH_SFD_TIMESTAMPS TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
101#else
102#define TSCH_RESYNC_WITH_SFD_TIMESTAMPS 0
103#endif
104
105/* If enabled, remove jitter due to measurement errors */
106#ifdef TSCH_CONF_TIMESYNC_REMOVE_JITTER
107#define TSCH_TIMESYNC_REMOVE_JITTER TSCH_CONF_TIMESYNC_REMOVE_JITTER
108#else
109#define TSCH_TIMESYNC_REMOVE_JITTER TSCH_RESYNC_WITH_SFD_TIMESTAMPS
110#endif
111
112/* Base drift value.
113 * Used to compensate locally know inaccuracies, such as
114 * the effect of having a binary 32.768 kHz timer as the TSCH time base. */
115#ifdef TSCH_CONF_BASE_DRIFT_PPM
116#define TSCH_BASE_DRIFT_PPM TSCH_CONF_BASE_DRIFT_PPM
117#else
118#define TSCH_BASE_DRIFT_PPM 0
119#endif
120
121/* Estimate the drift of the time-source neighbor and compensate for it? */
122#ifdef TSCH_CONF_ADAPTIVE_TIMESYNC
123#define TSCH_ADAPTIVE_TIMESYNC TSCH_CONF_ADAPTIVE_TIMESYNC
124#else
125#define TSCH_ADAPTIVE_TIMESYNC 1
126#endif
127
128/* An ad-hoc mechanism to have TSCH select its time source without the
129 * help of an upper-layer, simply by collecting statistics on received
130 * EBs and their join priority. Disabled by default as we recomment
131 * mapping the time source on the RPL preferred parent
132 * (via tsch_rpl_callback_parent_switch) */
133#ifdef TSCH_CONF_AUTOSELECT_TIME_SOURCE
134#define TSCH_AUTOSELECT_TIME_SOURCE TSCH_CONF_AUTOSELECT_TIME_SOURCE
135#else
136#define TSCH_AUTOSELECT_TIME_SOURCE 0
137#endif /* TSCH_CONF_EB_AUTOSELECT */
138
139/******** Configuration: channel hopping *******/
140
141/* Default hopping sequence, used in case hopping sequence ID == 0 */
142#ifdef TSCH_CONF_DEFAULT_HOPPING_SEQUENCE
143#define TSCH_DEFAULT_HOPPING_SEQUENCE TSCH_CONF_DEFAULT_HOPPING_SEQUENCE
144#else
145#define TSCH_DEFAULT_HOPPING_SEQUENCE TSCH_HOPPING_SEQUENCE_4_4
146#endif
147
148/* Hopping sequence used for joining (scan channels) */
149#ifdef TSCH_CONF_JOIN_HOPPING_SEQUENCE
150#define TSCH_JOIN_HOPPING_SEQUENCE TSCH_CONF_JOIN_HOPPING_SEQUENCE
151#else
152#define TSCH_JOIN_HOPPING_SEQUENCE TSCH_DEFAULT_HOPPING_SEQUENCE
153#endif
154
155/* Maximum length of the TSCH channel hopping sequence. Must be greater or
156 * equal to the length of TSCH_DEFAULT_HOPPING_SEQUENCE. */
157#ifdef TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN
158#define TSCH_HOPPING_SEQUENCE_MAX_LEN TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN
159#else
160#define TSCH_HOPPING_SEQUENCE_MAX_LEN sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE)
161#endif
162
163/******** Configuration: association *******/
164
165/* Start TSCH automatically after init? If not, the upper layers
166 * must call NETSTACK_MAC.on() to start it. Useful when the
167 * application needs to control when the nodes are to start
168 * scanning or advertising.*/
169#ifdef TSCH_CONF_AUTOSTART
170#define TSCH_AUTOSTART TSCH_CONF_AUTOSTART
171#else
172#define TSCH_AUTOSTART 1
173#endif
174
175/* Max acceptable join priority */
176#ifdef TSCH_CONF_MAX_JOIN_PRIORITY
177#define TSCH_MAX_JOIN_PRIORITY TSCH_CONF_MAX_JOIN_PRIORITY
178#else
179#define TSCH_MAX_JOIN_PRIORITY 32
180#endif
181
182/* Join only secured networks? (discard EBs with security disabled) */
183#ifdef TSCH_CONF_JOIN_SECURED_ONLY
184#define TSCH_JOIN_SECURED_ONLY TSCH_CONF_JOIN_SECURED_ONLY
185#else
186/* By default, set if LLSEC802154_ENABLED is also non-zero */
187#define TSCH_JOIN_SECURED_ONLY LLSEC802154_ENABLED
188#endif
189
190/* By default, join any PAN ID. Otherwise, wait for an EB from IEEE802154_PANID */
191#ifdef TSCH_CONF_JOIN_MY_PANID_ONLY
192#define TSCH_JOIN_MY_PANID_ONLY TSCH_CONF_JOIN_MY_PANID_ONLY
193#else
194#define TSCH_JOIN_MY_PANID_ONLY 1
195#endif
196
197/* The radio polling frequency (in Hz) during association process */
198#ifdef TSCH_CONF_ASSOCIATION_POLL_FREQUENCY
199#define TSCH_ASSOCIATION_POLL_FREQUENCY TSCH_CONF_ASSOCIATION_POLL_FREQUENCY
200#else
201#define TSCH_ASSOCIATION_POLL_FREQUENCY 100
202#endif
203
204/* When associating, check ASN against our own uptime (time in minutes)..
205 * Useful to force joining only with nodes started roughly at the same time.
206 * Set to the max number of minutes acceptable. */
207#ifdef TSCH_CONF_CHECK_TIME_AT_ASSOCIATION
208#define TSCH_CHECK_TIME_AT_ASSOCIATION TSCH_CONF_CHECK_TIME_AT_ASSOCIATION
209#else
210#define TSCH_CHECK_TIME_AT_ASSOCIATION 0
211#endif
212
213/* By default: initialize schedule from EB when associating, using the
214 * slotframe and links Information Element */
215#ifdef TSCH_CONF_INIT_SCHEDULE_FROM_EB
216#define TSCH_INIT_SCHEDULE_FROM_EB TSCH_CONF_INIT_SCHEDULE_FROM_EB
217#else
218#define TSCH_INIT_SCHEDULE_FROM_EB 1
219#endif
220
221/* How long to scan each channel in the scanning phase */
222#ifdef TSCH_CONF_CHANNEL_SCAN_DURATION
223#define TSCH_CHANNEL_SCAN_DURATION TSCH_CONF_CHANNEL_SCAN_DURATION
224#else
225#define TSCH_CHANNEL_SCAN_DURATION CLOCK_SECOND
226#endif
227
228/* TSCH EB: include timeslot timing Information Element? */
229#ifdef TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING
230#define TSCH_PACKET_EB_WITH_TIMESLOT_TIMING TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING
231#else
232#define TSCH_PACKET_EB_WITH_TIMESLOT_TIMING 0
233#endif
234
235/* TSCH EB: include hopping sequence Information Element? */
236#ifdef TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE
237#define TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE
238#else
239#define TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE 0
240#endif
241
242/* TSCH EB: include slotframe and link Information Element? */
243#ifdef TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK
244#define TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK
245#else
246#define TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK 0
247#endif
248
249/******** Configuration: queues *******/
250
251/* Size of the ring buffer storing dequeued outgoing packets (only an array of pointers).
252 * Must be power of two, and greater or equal to QUEUEBUF_NUM */
253#ifdef TSCH_CONF_DEQUEUED_ARRAY_SIZE
254#define TSCH_DEQUEUED_ARRAY_SIZE TSCH_CONF_DEQUEUED_ARRAY_SIZE
255#else
256/* By default, round QUEUEBUF_CONF_NUM to next power of two
257 * (in the range [4;256]) */
258#if QUEUEBUF_CONF_NUM <= 4
259#define TSCH_DEQUEUED_ARRAY_SIZE 4
260#elif QUEUEBUF_CONF_NUM <= 8
261#define TSCH_DEQUEUED_ARRAY_SIZE 8
262#elif QUEUEBUF_CONF_NUM <= 16
263#define TSCH_DEQUEUED_ARRAY_SIZE 16
264#elif QUEUEBUF_CONF_NUM <= 32
265#define TSCH_DEQUEUED_ARRAY_SIZE 32
266#elif QUEUEBUF_CONF_NUM <= 64
267#define TSCH_DEQUEUED_ARRAY_SIZE 64
268#elif QUEUEBUF_CONF_NUM <= 128
269#define TSCH_DEQUEUED_ARRAY_SIZE 128
270#else
271#define TSCH_DEQUEUED_ARRAY_SIZE 256
272#endif
273#endif
274
275/* Size of the ring buffer storing incoming packets.
276 * Must be power of two */
277#ifdef TSCH_CONF_MAX_INCOMING_PACKETS
278#define TSCH_MAX_INCOMING_PACKETS TSCH_CONF_MAX_INCOMING_PACKETS
279#else
280#define TSCH_MAX_INCOMING_PACKETS 4
281#endif
282
283/* The maximum number of outgoing packets towards each neighbor
284 * Must be power of two to enable atomic ringbuf operations.
285 * Note: the total number of outgoing packets in the system (for
286 * all neighbors) is defined via QUEUEBUF_CONF_NUM */
287#ifdef TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR
288#define TSCH_QUEUE_NUM_PER_NEIGHBOR TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR
289#else
290/* By default, round QUEUEBUF_CONF_NUM to next power of two
291 * (in the range [4;256]) */
292#if QUEUEBUF_CONF_NUM <= 4
293#define TSCH_QUEUE_NUM_PER_NEIGHBOR 4
294#elif QUEUEBUF_CONF_NUM <= 8
295#define TSCH_QUEUE_NUM_PER_NEIGHBOR 8
296#elif QUEUEBUF_CONF_NUM <= 16
297#define TSCH_QUEUE_NUM_PER_NEIGHBOR 16
298#elif QUEUEBUF_CONF_NUM <= 32
299#define TSCH_QUEUE_NUM_PER_NEIGHBOR 32
300#elif QUEUEBUF_CONF_NUM <= 64
301#define TSCH_QUEUE_NUM_PER_NEIGHBOR 64
302#elif QUEUEBUF_CONF_NUM <= 128
303#define TSCH_QUEUE_NUM_PER_NEIGHBOR 128
304#else
305#define TSCH_QUEUE_NUM_PER_NEIGHBOR 256
306#endif
307#endif
308
309/* The number of neighbor queues. There are two queues allocated at all times:
310 * one for EBs, one for broadcasts. Other queues are for unicast to neighbors */
311#ifdef TSCH_QUEUE_CONF_MAX_NEIGHBOR_QUEUES
312#define TSCH_QUEUE_MAX_NEIGHBOR_QUEUES TSCH_QUEUE_CONF_MAX_NEIGHBOR_QUEUES
313#else
314#define TSCH_QUEUE_MAX_NEIGHBOR_QUEUES ((NBR_TABLE_CONF_MAX_NEIGHBORS) + 2)
315#endif
316
317/******** Configuration: scheduling *******/
318
319/* Initializes TSCH with a 6TiSCH minimal schedule */
320#ifdef TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL
321#define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL
322#else
323#define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL (!(BUILD_WITH_ORCHESTRA))
324#endif
325
326/* Set an upper bound on burst length. Set to 0 to never set the frame pending
327 * bit, i.e., never trigger a burst. Note that receiver-side support for burst
328 * is always enabled, as it is part of IEEE 802.1.5.4-2015 (Section 7.2.1.3)*/
329#ifdef TSCH_CONF_BURST_MAX_LEN
330#define TSCH_BURST_MAX_LEN TSCH_CONF_BURST_MAX_LEN
331#else
332#define TSCH_BURST_MAX_LEN 0
333#endif
334
335/* 6TiSCH Minimal schedule slotframe length */
336#ifdef TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
337#define TSCH_SCHEDULE_DEFAULT_LENGTH TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
338#else
339#define TSCH_SCHEDULE_DEFAULT_LENGTH 7
340#endif
341
342/* Max number of TSCH slotframes */
343#ifdef TSCH_SCHEDULE_CONF_MAX_SLOTFRAMES
344#define TSCH_SCHEDULE_MAX_SLOTFRAMES TSCH_SCHEDULE_CONF_MAX_SLOTFRAMES
345#else
346#define TSCH_SCHEDULE_MAX_SLOTFRAMES 5
347#endif
348
349/* Max number of links */
350#ifdef TSCH_SCHEDULE_CONF_MAX_LINKS
351#define TSCH_SCHEDULE_MAX_LINKS TSCH_SCHEDULE_CONF_MAX_LINKS
352#else
353#define TSCH_SCHEDULE_MAX_LINKS 32
354#endif
355
356/* To include Sixtop Implementation */
357#ifdef TSCH_CONF_WITH_SIXTOP
358#define TSCH_WITH_SIXTOP TSCH_CONF_WITH_SIXTOP
359#else
360#define TSCH_WITH_SIXTOP 0
361#endif
362
363/* A custom feature allowing upper layers to assign packets to
364 * a specific slotframe and link */
365#ifdef TSCH_CONF_WITH_LINK_SELECTOR
366#define TSCH_WITH_LINK_SELECTOR TSCH_CONF_WITH_LINK_SELECTOR
367#else /* TSCH_CONF_WITH_LINK_SELECTOR */
368#define TSCH_WITH_LINK_SELECTOR (BUILD_WITH_ORCHESTRA)
369#endif /* TSCH_CONF_WITH_LINK_SELECTOR */
370
371/* Configurable link comparator in case multiple links are scheduled at the same slot */
372#ifdef TSCH_CONF_LINK_COMPARATOR
373#define TSCH_LINK_COMPARATOR TSCH_CONF_LINK_COMPARATOR
374#else
375#define TSCH_LINK_COMPARATOR(a, b) default_tsch_link_comparator(a, b)
376#endif
377
378/******** Configuration: CSMA *******/
379
380/* TSCH CSMA-CA parameters, see IEEE 802.15.4e-2012 */
381
382/* Min backoff exponent */
383#ifdef TSCH_CONF_MAC_MIN_BE
384#define TSCH_MAC_MIN_BE TSCH_CONF_MAC_MIN_BE
385#else
386#define TSCH_MAC_MIN_BE 1
387#endif
388
389/* Max backoff exponent */
390#ifdef TSCH_CONF_MAC_MAX_BE
391#define TSCH_MAC_MAX_BE TSCH_CONF_MAC_MAX_BE
392#else
393#define TSCH_MAC_MAX_BE 5
394#endif
395
396/* Avoid potential 16-bit integer overflow */
397#if TSCH_MAC_MAX_BE > 16
398#error TSCH_MAC_MAX_BE must be 16 or lower to avoid uint16_t overflows
399#endif
400
401/* Max number of re-transmissions */
402#ifdef TSCH_CONF_MAC_MAX_FRAME_RETRIES
403#define TSCH_MAC_MAX_FRAME_RETRIES TSCH_CONF_MAC_MAX_FRAME_RETRIES
404#else
405#define TSCH_MAC_MAX_FRAME_RETRIES 7
406#endif
407
408/* Include source address in ACK? */
409#ifdef TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR
410#define TSCH_PACKET_EACK_WITH_SRC_ADDR TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR
411#else
412#define TSCH_PACKET_EACK_WITH_SRC_ADDR 0
413#endif
414
415/* Perform CCA before sending? */
416#ifdef TSCH_CONF_CCA_ENABLED
417#define TSCH_CCA_ENABLED TSCH_CONF_CCA_ENABLED
418#else
419#define TSCH_CCA_ENABLED 0
420#endif
421
422/* Include destination address in ACK? */
423#ifdef TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR
424#define TSCH_PACKET_EACK_WITH_DEST_ADDR TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR
425#else
426#define TSCH_PACKET_EACK_WITH_DEST_ADDR 1 /* Include destination address
427by default, useful in case of duplicate seqno */
428#endif
429
430/******** Configuration: hardware-specific settings *******/
431
432/* HW frame filtering enabled */
433#ifdef TSCH_CONF_HW_FRAME_FILTERING
434#define TSCH_HW_FRAME_FILTERING TSCH_CONF_HW_FRAME_FILTERING
435#else /* TSCH_CONF_HW_FRAME_FILTERING */
436#define TSCH_HW_FRAME_FILTERING 1
437#endif /* TSCH_CONF_HW_FRAME_FILTERING */
438
439/* Keep radio always on within TSCH timeslot (1) or turn it off between packet and ACK? (0) */
440#ifdef TSCH_CONF_RADIO_ON_DURING_TIMESLOT
441#define TSCH_RADIO_ON_DURING_TIMESLOT TSCH_CONF_RADIO_ON_DURING_TIMESLOT
442#else
443#define TSCH_RADIO_ON_DURING_TIMESLOT 0
444#endif
445
446/* TSCH timeslot timing template */
447#ifdef TSCH_CONF_DEFAULT_TIMESLOT_TIMING
448#define TSCH_DEFAULT_TIMESLOT_TIMING TSCH_CONF_DEFAULT_TIMESLOT_TIMING
449#else
450#define TSCH_DEFAULT_TIMESLOT_TIMING tsch_timeslot_timing_us_10000
451#endif
452
453/* Configurable Rx guard time is micro-seconds */
454#ifndef TSCH_CONF_RX_WAIT
455#define TSCH_CONF_RX_WAIT 2200
456#endif /* TSCH_CONF_RX_WAIT */
457
458#endif /* TSCH_CONF_H_ */
459/** @} */