Contiki-NG
tsch-const.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 constants
38  * \author
39  * Simon Duquennoy <simonduq@sics.se>
40  */
41 
42 #ifndef __TSCH_CONST_H__
43 #define __TSCH_CONST_H__
44 
45 /********** Includes **********/
46 #include "net/packetbuf.h"
47 #include "net/mac/tsch/tsch-conf.h" /* Required for timestlot timing consts */
48 
49 /********** Constants **********/
50 
51 /* Link options */
52 #define LINK_OPTION_TX 1
53 #define LINK_OPTION_RX 2
54 #define LINK_OPTION_SHARED 4
55 #define LINK_OPTION_TIME_KEEPING 8
56 
57 /* Default IEEE 802.15.4e hopping sequences, obtained from https://gist.github.com/twatteyne/2e22ee3c1a802b685695 */
58 /* 16 channels, sequence length 16 */
59 #define TSCH_HOPPING_SEQUENCE_16_16 (uint8_t[]){ 16, 17, 23, 18, 26, 15, 25, 22, 19, 11, 12, 13, 24, 14, 20, 21 }
60 /* 4 channels, sequence length 16 */
61 #define TSCH_HOPPING_SEQUENCE_4_16 (uint8_t[]){ 20, 26, 25, 26, 15, 15, 25, 20, 26, 15, 26, 25, 20, 15, 20, 25 }
62 /* 4 channels, sequence length 4 */
63 #define TSCH_HOPPING_SEQUENCE_4_4 (uint8_t[]){ 15, 25, 26, 20 }
64 /* 2 channels, sequence length 2 */
65 #define TSCH_HOPPING_SEQUENCE_2_2 (uint8_t[]){ 20, 25 }
66 /* 1 channel, sequence length 1 */
67 #define TSCH_HOPPING_SEQUENCE_1_1 (uint8_t[]){ 20 }
68 
69 /* Max TSCH packet lenght */
70 #define TSCH_PACKET_MAX_LEN MIN(127, PACKETBUF_SIZE)
71 
72 /* The jitter to remove in ticks.
73  * This should be the sum of measurement errors on Tx and Rx nodes.
74  * */
75 #define TSCH_TIMESYNC_MEASUREMENT_ERROR US_TO_RTIMERTICKS(32)
76 
77 /* The approximate number of slots per second */
78 #define TSCH_SLOTS_PER_SECOND (1000000 / TSCH_DEFAULT_TS_TIMESLOT_LENGTH)
79 
80 /* Calculate packet tx/rx duration in rtimer ticks based on sent
81  * packet len in bytes with 802.15.4 250kbps data rate.
82  * One byte = 32us. Add two bytes for CRC and one for len field */
83 #define TSCH_PACKET_DURATION(len) US_TO_RTIMERTICKS(32 * ((len) + 3))
84 
85 /* Convert rtimer ticks to clock and vice versa */
86 #define TSCH_CLOCK_TO_TICKS(c) (((c) * RTIMER_SECOND) / CLOCK_SECOND)
87 #define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length)
88 
89 /* The default timeslot timing in the standard is a guard time of
90  * 2200 us, a Tx offset of 2120 us and a Rx offset of 1120 us.
91  * As a result, the listening device has a guard time not centered
92  * on the expected Tx time. This is to be fixed in the next iteration
93  * of the standard. This can be enabled with:
94  * #define TSCH_DEFAULT_TS_TX_OFFSET 2120
95  * #define TSCH_DEFAULT_TS_RX_OFFSET 1120
96  * #define TSCH_DEFAULT_TS_RX_WAIT 2200
97  *
98  * Instead, we align the Rx guard time on expected Tx time. The Rx
99  * guard time is user-configurable with TSCH_CONF_RX_WAIT.
100 
101  * (TS_TX_OFFSET - (TS_RX_WAIT / 2)) instead */
102 
103 #if TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 10000
104 /* Default timeslot timing as per IEEE 802.15.4e */
105 
106 #define TSCH_DEFAULT_TS_CCA_OFFSET 1800
107 #define TSCH_DEFAULT_TS_CCA 128
108 #define TSCH_DEFAULT_TS_TX_OFFSET 2120
109 #define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2))
110 #define TSCH_DEFAULT_TS_RX_ACK_DELAY 800
111 #define TSCH_DEFAULT_TS_TX_ACK_DELAY 1000
112 #define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT
113 #define TSCH_DEFAULT_TS_ACK_WAIT 400
114 #define TSCH_DEFAULT_TS_RX_TX 192
115 #define TSCH_DEFAULT_TS_MAX_ACK 2400
116 #define TSCH_DEFAULT_TS_MAX_TX 4256
117 #define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 10000
118 
119 #elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 15000
120 /* Default timeslot timing for platforms requiring 15ms slots */
121 
122 #define TSCH_DEFAULT_TS_CCA_OFFSET 1800
123 #define TSCH_DEFAULT_TS_CCA 128
124 #define TSCH_DEFAULT_TS_TX_OFFSET 4000
125 #define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2))
126 #define TSCH_DEFAULT_TS_RX_ACK_DELAY 3600
127 #define TSCH_DEFAULT_TS_TX_ACK_DELAY 4000
128 #define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT
129 #define TSCH_DEFAULT_TS_ACK_WAIT 800
130 #define TSCH_DEFAULT_TS_RX_TX 2072
131 #define TSCH_DEFAULT_TS_MAX_ACK 2400
132 #define TSCH_DEFAULT_TS_MAX_TX 4256
133 #define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 15000
134 
135 #elif TSCH_CONF_DEFAULT_TIMESLOT_LENGTH == 65000U
136 /* 65ms timeslot, i.e. nearly the max length allowed by standard (16-bit unsigned in micro-seconds).
137  * Useful for running link-layer security on sky in Cooja, where only S/W security is supported.
138  * Note: this slot timing would require a total of 120ms. If a slot overlaps with the next active slot,
139  * the latter will be skipped.
140  * This configuration is mostly a work-around to test link-layer security in Cooja, it is recommended
141  * to use it with a 6TiSCH minimal schedule of length >= 2. */
142 
143 #define TSCH_DEFAULT_TS_CCA_OFFSET 1800
144 #define TSCH_DEFAULT_TS_CCA 128
145 #define TSCH_DEFAULT_TS_TX_OFFSET 52000
146 #define TSCH_DEFAULT_TS_RX_OFFSET (TSCH_DEFAULT_TS_TX_OFFSET - (TSCH_CONF_RX_WAIT / 2))
147 #define TSCH_DEFAULT_TS_RX_ACK_DELAY 58600
148 #define TSCH_DEFAULT_TS_TX_ACK_DELAY 59000
149 #define TSCH_DEFAULT_TS_RX_WAIT TSCH_CONF_RX_WAIT
150 #define TSCH_DEFAULT_TS_ACK_WAIT 800
151 #define TSCH_DEFAULT_TS_RX_TX 2072
152 #define TSCH_DEFAULT_TS_MAX_ACK 2400
153 #define TSCH_DEFAULT_TS_MAX_TX 4256
154 #define TSCH_DEFAULT_TS_TIMESLOT_LENGTH 65000
155 
156 #else
157 #error "TSCH: Unsupported default timeslot length"
158 #endif
159 
160 #endif /* __TSCH_CONST_H__ */
161 /** @} */
TSCH configuration.
Header file for the Packet buffer (packetbuf) management