Contiki 3.x
tsch-private.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, 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  * \file
35  * Private TSCH definitions
36  * (meant for use by TSCH implementation files only)
37  * \author
38  * Simon Duquennoy <simonduq@sics.se>
39  * Beshr Al Nahas <beshr@sics.se>
40  */
41 
42 #ifndef __TSCH_PRIVATE_H__
43 #define __TSCH_PRIVATE_H__
44 
45 /********** Includes **********/
46 
47 #include "contiki.h"
48 #include "net/linkaddr.h"
49 #include "net/mac/tsch/tsch-asn.h"
50 #include "net/mac/tsch/tsch-conf.h"
51 
52 /************ Types ***********/
53 
54 /* TSCH timeslot timing elements. Used to index timeslot timing
55  * of different units, such as rtimer tick or micro-second */
56 enum tsch_timeslot_timing_elements {
57  tsch_ts_cca_offset,
58  tsch_ts_cca,
59  tsch_ts_tx_offset,
60  tsch_ts_rx_offset,
61  tsch_ts_rx_ack_delay,
62  tsch_ts_tx_ack_delay,
63  tsch_ts_rx_wait,
64  tsch_ts_ack_wait,
65  tsch_ts_rx_tx,
66  tsch_ts_max_ack,
67  tsch_ts_max_tx,
68  tsch_ts_timeslot_length,
69  tsch_ts_elements_count, /* Not a timing element */
70 };
71 
72 /***** External Variables *****/
73 
74 /* 802.15.4 broadcast MAC address */
75 extern const linkaddr_t tsch_broadcast_address;
76 /* The address we use to identify EB queue */
77 extern const linkaddr_t tsch_eb_address;
78 /* The current Absolute Slot Number (ASN) */
79 extern struct asn_t current_asn;
80 extern uint8_t tsch_join_priority;
81 extern struct tsch_link *current_link;
82 /* TSCH channel hopping sequence */
83 extern uint8_t tsch_hopping_sequence[TSCH_HOPPING_SEQUENCE_MAX_LEN];
84 extern struct asn_divisor_t tsch_hopping_sequence_length;
85 /* TSCH timeslot timing (in rtimer ticks) */
86 extern rtimer_clock_t tsch_timing[tsch_ts_elements_count];
87 
88 /* TSCH processes */
89 PROCESS_NAME(tsch_process);
90 PROCESS_NAME(tsch_send_eb_process);
91 PROCESS_NAME(tsch_pending_events_process);
92 
93 /********** Functions *********/
94 
95 /* Set TSCH to send a keepalive message after TSCH_KEEPALIVE_TIMEOUT */
96 void tsch_schedule_keepalive(void);
97 /* Leave the TSCH network */
98 void tsch_disassociate(void);
99 
100 /************ Macros **********/
101 
102 /* Calculate packet tx/rx duration in rtimer ticks based on sent
103  * packet len in bytes with 802.15.4 250kbps data rate.
104  * One byte = 32us. Add two bytes for CRC and one for len field */
105 #define TSCH_PACKET_DURATION(len) US_TO_RTIMERTICKS(32 * ((len) + 3))
106 
107 /* Convert rtimer ticks to clock and vice versa */
108 #define TSCH_CLOCK_TO_TICKS(c) (((c) * RTIMER_SECOND) / CLOCK_SECOND)
109 #define TSCH_CLOCK_TO_SLOTS(c, timeslot_length) (TSCH_CLOCK_TO_TICKS(c) / timeslot_length)
110 
111 /* Wait for a condition with timeout t0+offset. */
112 #define BUSYWAIT_UNTIL_ABS(cond, t0, offset) \
113  while(!(cond) && RTIMER_CLOCK_LT(RTIMER_NOW(), (t0) + (offset))) ;
114 
115 #endif /* __TSCH_PRIVATE_H__ */
TSCH configuration
TSCH 5-Byte Absolute Slot Number (ASN) management
Header file for the Rime address representation
PROCESS_NAME(sample_process)
Process the sampler runs as.