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 /* Period between two consecutive EBs */
75 #ifdef TSCH_CONF_EB_PERIOD
76 #define TSCH_EB_PERIOD TSCH_CONF_EB_PERIOD
77 #else
78 #define TSCH_EB_PERIOD (16 * CLOCK_SECOND)
79 #endif
80 
81 /* Max Period between two consecutive EBs */
82 #ifdef TSCH_CONF_MAX_EB_PERIOD
83 #define TSCH_MAX_EB_PERIOD TSCH_CONF_MAX_EB_PERIOD
84 #else
85 #define TSCH_MAX_EB_PERIOD (16 * CLOCK_SECOND)
86 #endif
87 
88 /* Use SFD timestamp for synchronization? By default we merely rely on rtimer and busy wait
89  * until SFD is high, which we found to provide greater accuracy on JN516x and CC2420.
90  * Note: for association, however, we always use SFD timestamp to know the time of arrival
91  * of the EB (because we do not busy-wait for the whole scanning process)
92  * */
93 #ifdef TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
94 #define TSCH_RESYNC_WITH_SFD_TIMESTAMPS TSCH_CONF_RESYNC_WITH_SFD_TIMESTAMPS
95 #else
96 #define TSCH_RESYNC_WITH_SFD_TIMESTAMPS 0
97 #endif
98 
99 /* If enabled, remove jitter due to measurement errors */
100 #ifdef TSCH_CONF_TIMESYNC_REMOVE_JITTER
101 #define TSCH_TIMESYNC_REMOVE_JITTER TSCH_CONF_TIMESYNC_REMOVE_JITTER
102 #else
103 #define TSCH_TIMESYNC_REMOVE_JITTER TSCH_RESYNC_WITH_SFD_TIMESTAMPS
104 #endif
105 
106 /* Base drift value.
107  * Used to compensate locally know inaccuracies, such as
108  * the effect of having a binary 32.768 kHz timer as the TSCH time base. */
109 #ifdef TSCH_CONF_BASE_DRIFT_PPM
110 #define TSCH_BASE_DRIFT_PPM TSCH_CONF_BASE_DRIFT_PPM
111 #else
112 #define TSCH_BASE_DRIFT_PPM 0
113 #endif
114 
115 /* Estimate the drift of the time-source neighbor and compensate for it? */
116 #ifdef TSCH_CONF_ADAPTIVE_TIMESYNC
117 #define TSCH_ADAPTIVE_TIMESYNC TSCH_CONF_ADAPTIVE_TIMESYNC
118 #else
119 #define TSCH_ADAPTIVE_TIMESYNC 1
120 #endif
121 
122 /* An ad-hoc mechanism to have TSCH select its time source without the
123  * help of an upper-layer, simply by collecting statistics on received
124  * EBs and their join priority. Disabled by default as we recomment
125  * mapping the time source on the RPL preferred parent
126  * (via tsch_rpl_callback_parent_switch) */
127 #ifdef TSCH_CONF_AUTOSELECT_TIME_SOURCE
128 #define TSCH_AUTOSELECT_TIME_SOURCE TSCH_CONF_AUTOSELECT_TIME_SOURCE
129 #else
130 #define TSCH_AUTOSELECT_TIME_SOURCE 0
131 #endif /* TSCH_CONF_EB_AUTOSELECT */
132 
133 /******** Configuration: channel hopping *******/
134 
135 /* Default hopping sequence, used in case hopping sequence ID == 0 */
136 #ifdef TSCH_CONF_DEFAULT_HOPPING_SEQUENCE
137 #define TSCH_DEFAULT_HOPPING_SEQUENCE TSCH_CONF_DEFAULT_HOPPING_SEQUENCE
138 #else
139 #define TSCH_DEFAULT_HOPPING_SEQUENCE TSCH_HOPPING_SEQUENCE_4_4
140 #endif
141 
142 /* Hopping sequence used for joining (scan channels) */
143 #ifdef TSCH_CONF_JOIN_HOPPING_SEQUENCE
144 #define TSCH_JOIN_HOPPING_SEQUENCE TSCH_CONF_JOIN_HOPPING_SEQUENCE
145 #else
146 #define TSCH_JOIN_HOPPING_SEQUENCE TSCH_DEFAULT_HOPPING_SEQUENCE
147 #endif
148 
149 /* Maximum length of the TSCH channel hopping sequence. Must be greater or
150  * equal to the length of TSCH_DEFAULT_HOPPING_SEQUENCE. */
151 #ifdef TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN
152 #define TSCH_HOPPING_SEQUENCE_MAX_LEN TSCH_CONF_HOPPING_SEQUENCE_MAX_LEN
153 #else
154 #define TSCH_HOPPING_SEQUENCE_MAX_LEN sizeof(TSCH_DEFAULT_HOPPING_SEQUENCE)
155 #endif
156 
157 /******** Configuration: association *******/
158 
159 /* Start TSCH automatically after init? If not, the upper layers
160  * must call NETSTACK_MAC.on() to start it. Useful when the
161  * application needs to control when the nodes are to start
162  * scanning or advertising.*/
163 #ifdef TSCH_CONF_AUTOSTART
164 #define TSCH_AUTOSTART TSCH_CONF_AUTOSTART
165 #else
166 #define TSCH_AUTOSTART 1
167 #endif
168 
169 /* Max acceptable join priority */
170 #ifdef TSCH_CONF_MAX_JOIN_PRIORITY
171 #define TSCH_MAX_JOIN_PRIORITY TSCH_CONF_MAX_JOIN_PRIORITY
172 #else
173 #define TSCH_MAX_JOIN_PRIORITY 32
174 #endif
175 
176 /* Join only secured networks? (discard EBs with security disabled) */
177 #ifdef TSCH_CONF_JOIN_SECURED_ONLY
178 #define TSCH_JOIN_SECURED_ONLY TSCH_CONF_JOIN_SECURED_ONLY
179 #else
180 /* By default, set if LLSEC802154_ENABLED is also non-zero */
181 #define TSCH_JOIN_SECURED_ONLY LLSEC802154_ENABLED
182 #endif
183 
184 /* By default, join any PAN ID. Otherwise, wait for an EB from IEEE802154_PANID */
185 #ifdef TSCH_CONF_JOIN_MY_PANID_ONLY
186 #define TSCH_JOIN_MY_PANID_ONLY TSCH_CONF_JOIN_MY_PANID_ONLY
187 #else
188 #define TSCH_JOIN_MY_PANID_ONLY 1
189 #endif
190 
191 /* The radio polling frequency (in Hz) during association process */
192 #ifdef TSCH_CONF_ASSOCIATION_POLL_FREQUENCY
193 #define TSCH_ASSOCIATION_POLL_FREQUENCY TSCH_CONF_ASSOCIATION_POLL_FREQUENCY
194 #else
195 #define TSCH_ASSOCIATION_POLL_FREQUENCY 100
196 #endif
197 
198 /* When associating, check ASN against our own uptime (time in minutes)..
199  * Useful to force joining only with nodes started roughly at the same time.
200  * Set to the max number of minutes acceptable. */
201 #ifdef TSCH_CONF_CHECK_TIME_AT_ASSOCIATION
202 #define TSCH_CHECK_TIME_AT_ASSOCIATION TSCH_CONF_CHECK_TIME_AT_ASSOCIATION
203 #else
204 #define TSCH_CHECK_TIME_AT_ASSOCIATION 0
205 #endif
206 
207 /* By default: initialize schedule from EB when associating, using the
208  * slotframe and links Information Element */
209 #ifdef TSCH_CONF_INIT_SCHEDULE_FROM_EB
210 #define TSCH_INIT_SCHEDULE_FROM_EB TSCH_CONF_INIT_SCHEDULE_FROM_EB
211 #else
212 #define TSCH_INIT_SCHEDULE_FROM_EB 1
213 #endif
214 
215 /* How long to scan each channel in the scanning phase */
216 #ifdef TSCH_CONF_CHANNEL_SCAN_DURATION
217 #define TSCH_CHANNEL_SCAN_DURATION TSCH_CONF_CHANNEL_SCAN_DURATION
218 #else
219 #define TSCH_CHANNEL_SCAN_DURATION CLOCK_SECOND
220 #endif
221 
222 /* TSCH EB: include timeslot timing Information Element? */
223 #ifdef TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING
224 #define TSCH_PACKET_EB_WITH_TIMESLOT_TIMING TSCH_PACKET_CONF_EB_WITH_TIMESLOT_TIMING
225 #else
226 #define TSCH_PACKET_EB_WITH_TIMESLOT_TIMING 0
227 #endif
228 
229 /* TSCH EB: include hopping sequence Information Element? */
230 #ifdef TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE
231 #define TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE TSCH_PACKET_CONF_EB_WITH_HOPPING_SEQUENCE
232 #else
233 #define TSCH_PACKET_EB_WITH_HOPPING_SEQUENCE 0
234 #endif
235 
236 /* TSCH EB: include slotframe and link Information Element? */
237 #ifdef TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK
238 #define TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK TSCH_PACKET_CONF_EB_WITH_SLOTFRAME_AND_LINK
239 #else
240 #define TSCH_PACKET_EB_WITH_SLOTFRAME_AND_LINK 0
241 #endif
242 
243 /******** Configuration: queues *******/
244 
245 /* Size of the ring buffer storing dequeued outgoing packets (only an array of pointers).
246  * Must be power of two, and greater or equal to QUEUEBUF_NUM */
247 #ifdef TSCH_CONF_DEQUEUED_ARRAY_SIZE
248 #define TSCH_DEQUEUED_ARRAY_SIZE TSCH_CONF_DEQUEUED_ARRAY_SIZE
249 #else
250 /* By default, round QUEUEBUF_CONF_NUM to next power of two
251  * (in the range [4;256]) */
252 #if QUEUEBUF_CONF_NUM <= 4
253 #define TSCH_DEQUEUED_ARRAY_SIZE 4
254 #elif QUEUEBUF_CONF_NUM <= 8
255 #define TSCH_DEQUEUED_ARRAY_SIZE 8
256 #elif QUEUEBUF_CONF_NUM <= 16
257 #define TSCH_DEQUEUED_ARRAY_SIZE 16
258 #elif QUEUEBUF_CONF_NUM <= 32
259 #define TSCH_DEQUEUED_ARRAY_SIZE 32
260 #elif QUEUEBUF_CONF_NUM <= 64
261 #define TSCH_DEQUEUED_ARRAY_SIZE 64
262 #elif QUEUEBUF_CONF_NUM <= 128
263 #define TSCH_DEQUEUED_ARRAY_SIZE 128
264 #else
265 #define TSCH_DEQUEUED_ARRAY_SIZE 256
266 #endif
267 #endif
268 
269 /* Size of the ring buffer storing incoming packets.
270  * Must be power of two */
271 #ifdef TSCH_CONF_MAX_INCOMING_PACKETS
272 #define TSCH_MAX_INCOMING_PACKETS TSCH_CONF_MAX_INCOMING_PACKETS
273 #else
274 #define TSCH_MAX_INCOMING_PACKETS 4
275 #endif
276 
277 /* The maximum number of outgoing packets towards each neighbor
278  * Must be power of two to enable atomic ringbuf operations.
279  * Note: the total number of outgoing packets in the system (for
280  * all neighbors) is defined via QUEUEBUF_CONF_NUM */
281 #ifdef TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR
282 #define TSCH_QUEUE_NUM_PER_NEIGHBOR TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR
283 #else
284 /* By default, round QUEUEBUF_CONF_NUM to next power of two
285  * (in the range [4;256]) */
286 #if QUEUEBUF_CONF_NUM <= 4
287 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 4
288 #elif QUEUEBUF_CONF_NUM <= 8
289 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 8
290 #elif QUEUEBUF_CONF_NUM <= 16
291 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 16
292 #elif QUEUEBUF_CONF_NUM <= 32
293 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 32
294 #elif QUEUEBUF_CONF_NUM <= 64
295 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 64
296 #elif QUEUEBUF_CONF_NUM <= 128
297 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 128
298 #else
299 #define TSCH_QUEUE_NUM_PER_NEIGHBOR 256
300 #endif
301 #endif
302 
303 /* The number of neighbor queues. There are two queues allocated at all times:
304  * one for EBs, one for broadcasts. Other queues are for unicast to neighbors */
305 #ifdef TSCH_QUEUE_CONF_MAX_NEIGHBOR_QUEUES
306 #define TSCH_QUEUE_MAX_NEIGHBOR_QUEUES TSCH_QUEUE_CONF_MAX_NEIGHBOR_QUEUES
307 #else
308 #define TSCH_QUEUE_MAX_NEIGHBOR_QUEUES ((NBR_TABLE_CONF_MAX_NEIGHBORS) + 2)
309 #endif
310 
311 /******** Configuration: scheduling *******/
312 
313 /* Initializes TSCH with a 6TiSCH minimal schedule */
314 #ifdef TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL
315 #define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL
316 #else
317 #define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL (!(BUILD_WITH_ORCHESTRA))
318 #endif
319 
320 /* Set an upper bound on burst length. Set to 0 to never set the frame pending
321  * bit, i.e., never trigger a burst. Note that receiver-side support for burst
322  * is always enabled, as it is part of IEEE 802.1.5.4-2015 (Section 7.2.1.3)*/
323 #ifdef TSCH_CONF_BURST_MAX_LEN
324 #define TSCH_BURST_MAX_LEN TSCH_CONF_BURST_MAX_LEN
325 #else
326 #define TSCH_BURST_MAX_LEN 32
327 #endif
328 
329 /* 6TiSCH Minimal schedule slotframe length */
330 #ifdef TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
331 #define TSCH_SCHEDULE_DEFAULT_LENGTH TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
332 #else
333 #define TSCH_SCHEDULE_DEFAULT_LENGTH 7
334 #endif
335 
336 /* Max number of TSCH slotframes */
337 #ifdef TSCH_SCHEDULE_CONF_MAX_SLOTFRAMES
338 #define TSCH_SCHEDULE_MAX_SLOTFRAMES TSCH_SCHEDULE_CONF_MAX_SLOTFRAMES
339 #else
340 #define TSCH_SCHEDULE_MAX_SLOTFRAMES 4
341 #endif
342 
343 /* Max number of links */
344 #ifdef TSCH_SCHEDULE_CONF_MAX_LINKS
345 #define TSCH_SCHEDULE_MAX_LINKS TSCH_SCHEDULE_CONF_MAX_LINKS
346 #else
347 #define TSCH_SCHEDULE_MAX_LINKS 32
348 #endif
349 
350 /* To include Sixtop Implementation */
351 #ifdef TSCH_CONF_WITH_SIXTOP
352 #define TSCH_WITH_SIXTOP TSCH_CONF_WITH_SIXTOP
353 #else
354 #define TSCH_WITH_SIXTOP 0
355 #endif
356 
357 /* A custom feature allowing upper layers to assign packets to
358  * a specific slotframe and link */
359 #ifdef TSCH_CONF_WITH_LINK_SELECTOR
360 #define TSCH_WITH_LINK_SELECTOR TSCH_CONF_WITH_LINK_SELECTOR
361 #else /* TSCH_CONF_WITH_LINK_SELECTOR */
362 #define TSCH_WITH_LINK_SELECTOR (BUILD_WITH_ORCHESTRA)
363 #endif /* TSCH_CONF_WITH_LINK_SELECTOR */
364 
365 /******** Configuration: CSMA *******/
366 
367 /* TSCH CSMA-CA parameters, see IEEE 802.15.4e-2012 */
368 
369 /* Min backoff exponent */
370 #ifdef TSCH_CONF_MAC_MIN_BE
371 #define TSCH_MAC_MIN_BE TSCH_CONF_MAC_MIN_BE
372 #else
373 #define TSCH_MAC_MIN_BE 1
374 #endif
375 
376 /* Max backoff exponent */
377 #ifdef TSCH_CONF_MAC_MAX_BE
378 #define TSCH_MAC_MAX_BE TSCH_CONF_MAC_MAX_BE
379 #else
380 #define TSCH_MAC_MAX_BE 5
381 #endif
382 
383 /* Max number of re-transmissions */
384 #ifdef TSCH_CONF_MAC_MAX_FRAME_RETRIES
385 #define TSCH_MAC_MAX_FRAME_RETRIES TSCH_CONF_MAC_MAX_FRAME_RETRIES
386 #else
387 #define TSCH_MAC_MAX_FRAME_RETRIES 7
388 #endif
389 
390 /* Include source address in ACK? */
391 #ifdef TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR
392 #define TSCH_PACKET_EACK_WITH_SRC_ADDR TSCH_PACKET_CONF_EACK_WITH_SRC_ADDR
393 #else
394 #define TSCH_PACKET_EACK_WITH_SRC_ADDR 0
395 #endif
396 
397 /* Perform CCA before sending? */
398 #ifdef TSCH_CONF_CCA_ENABLED
399 #define TSCH_CCA_ENABLED TSCH_CONF_CCA_ENABLED
400 #else
401 #define TSCH_CCA_ENABLED 0
402 #endif
403 
404 /* Include destination address in ACK? */
405 #ifdef TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR
406 #define TSCH_PACKET_EACK_WITH_DEST_ADDR TSCH_PACKET_CONF_EACK_WITH_DEST_ADDR
407 #else
408 #define TSCH_PACKET_EACK_WITH_DEST_ADDR 1 /* Include destination address
409 by default, useful in case of duplicate seqno */
410 #endif
411 
412 /******** Configuration: hardware-specific settings *******/
413 
414 /* HW frame filtering enabled */
415 #ifdef TSCH_CONF_HW_FRAME_FILTERING
416 #define TSCH_HW_FRAME_FILTERING TSCH_CONF_HW_FRAME_FILTERING
417 #else /* TSCH_CONF_HW_FRAME_FILTERING */
418 #define TSCH_HW_FRAME_FILTERING 1
419 #endif /* TSCH_CONF_HW_FRAME_FILTERING */
420 
421 /* Keep radio always on within TSCH timeslot (1) or turn it off between packet and ACK? (0) */
422 #ifdef TSCH_CONF_RADIO_ON_DURING_TIMESLOT
423 #define TSCH_RADIO_ON_DURING_TIMESLOT TSCH_CONF_RADIO_ON_DURING_TIMESLOT
424 #else
425 #define TSCH_RADIO_ON_DURING_TIMESLOT 0
426 #endif
427 
428 /* TSCH timeslot timing template */
429 #ifdef TSCH_CONF_DEFAULT_TIMESLOT_TIMING
430 #define TSCH_DEFAULT_TIMESLOT_TIMING TSCH_CONF_DEFAULT_TIMESLOT_TIMING
431 #else
432 #define TSCH_DEFAULT_TIMESLOT_TIMING tsch_timeslot_timing_us_10000
433 #endif
434 
435 /* Configurable Rx guard time is micro-seconds */
436 #ifndef TSCH_CONF_RX_WAIT
437 #define TSCH_CONF_RX_WAIT 2200
438 #endif /* TSCH_CONF_RX_WAIT */
439 
440 #endif /* __TSCH_CONF_H__ */
441 /** @} */