Contiki 3.x
tsch-schedule.h
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 #ifndef __TSCH_SCHEDULE_H__
34 #define __TSCH_SCHEDULE_H__
35 
36 /********** Includes **********/
37 
38 #include "contiki.h"
39 #include "lib/list.h"
41 #include "net/mac/tsch/tsch-queue.h"
42 #include "net/mac/tsch/tsch-slot-operation.h"
43 #include "net/linkaddr.h"
44 
45 /******** Configuration *******/
46 
47 /* Initializes TSCH with a 6TiSCH minimal schedule */
48 #ifdef TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL
49 #define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL TSCH_SCHEDULE_CONF_WITH_6TISCH_MINIMAL
50 #else
51 #define TSCH_SCHEDULE_WITH_6TISCH_MINIMAL 1
52 #endif
53 
54 /* 6TiSCH Minimal schedule slotframe length */
55 #ifdef TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
56 #define TSCH_SCHEDULE_DEFAULT_LENGTH TSCH_SCHEDULE_CONF_DEFAULT_LENGTH
57 #else
58 #define TSCH_SCHEDULE_DEFAULT_LENGTH 7
59 #endif
60 
61 /* Max number of TSCH slotframes */
62 #ifdef TSCH_SCHEDULE_CONF_MAX_SLOTFRAMES
63 #define TSCH_SCHEDULE_MAX_SLOTFRAMES TSCH_SCHEDULE_CONF_MAX_SLOTFRAMES
64 #else
65 #define TSCH_SCHEDULE_MAX_SLOTFRAMES 4
66 #endif
67 
68 /* Max number of links */
69 #ifdef TSCH_SCHEDULE_CONF_MAX_LINKS
70 #define TSCH_SCHEDULE_MAX_LINKS TSCH_SCHEDULE_CONF_MAX_LINKS
71 #else
72 #define TSCH_SCHEDULE_MAX_LINKS 32
73 #endif
74 
75 /********** Constants *********/
76 
77 /* Link options */
78 #define LINK_OPTION_TX 1
79 #define LINK_OPTION_RX 2
80 #define LINK_OPTION_SHARED 4
81 #define LINK_OPTION_TIME_KEEPING 8
82 
83 /************ Types ***********/
84 
85 /* 802.15.4e link types.
86  * LINK_TYPE_ADVERTISING_ONLY is an extra one: for EB-only links. */
87 enum link_type { LINK_TYPE_NORMAL, LINK_TYPE_ADVERTISING, LINK_TYPE_ADVERTISING_ONLY };
88 
89 struct tsch_link {
90  /* Links are stored as a list: "next" must be the first field */
91  struct tsch_link *next;
92  /* Unique identifier */
93  uint16_t handle;
94  /* MAC address of neighbor */
95  linkaddr_t addr;
96  /* Slotframe identifier */
97  uint16_t slotframe_handle;
98  /* Identifier of Slotframe to which this link belongs
99  * Unused. */
100  /* uint8_t handle; */
101  /* Timeslot for this link */
102  uint16_t timeslot;
103  /* Channel offset for this link */
104  uint16_t channel_offset;
105  /* A bit string that defines
106  * b0 = Transmit, b1 = Receive, b2 = Shared, b3 = Timekeeping, b4 = reserved */
107  uint8_t link_options;
108  /* Type of link. NORMAL = 0. ADVERTISING = 1, and indicates
109  the link may be used to send an Enhanced beacon. */
110  enum link_type link_type;
111  /* Any other data for upper layers */
112  void *data;
113 };
114 
115 struct tsch_slotframe {
116  /* Slotframes are stored as a list: "next" must be the first field */
117  struct tsch_slotframe *next;
118  /* Unique identifier */
119  uint16_t handle;
120  /* Number of timeslots in the slotframe.
121  * Stored as struct asn_divisor_t because we often need ASN%size */
122  struct asn_divisor_t size;
123  /* List of links belonging to this slotframe */
124  LIST_STRUCT(links_list);
125 };
126 
127 /********** Functions *********/
128 
129 /* Module initialization, call only once at startup. Returns 1 is success, 0 if failure. */
130 int tsch_schedule_init(void);
131 /* Create a 6TiSCH minimal schedule */
132 void tsch_schedule_create_minimal(void);
133 /* Prints out the current schedule (all slotframes and links) */
134 void tsch_schedule_print(void);
135 
136 /* Adds and returns a slotframe (NULL if failure) */
137 struct tsch_slotframe *tsch_schedule_add_slotframe(uint16_t handle, uint16_t size);
138 /* Looks for a slotframe from a handle */
139 struct tsch_slotframe *tsch_schedule_get_slotframe_by_handle(uint16_t handle);
140 /* Removes a slotframe Return 1 if success, 0 if failure */
141 int tsch_schedule_remove_slotframe(struct tsch_slotframe *slotframe);
142 /* Removes all slotframes, resulting in an empty schedule */
143 int tsch_schedule_remove_all_slotframes(void);
144 
145 /* Returns next slotframe */
146 struct tsch_slotframe *tsch_schedule_slotframes_next(struct tsch_slotframe *sf);
147 /* Adds a link to a slotframe, return a pointer to it (NULL if failure) */
148 struct tsch_link *tsch_schedule_add_link(struct tsch_slotframe *slotframe,
149  uint8_t link_options, enum link_type link_type, const linkaddr_t *address,
150  uint16_t timeslot, uint16_t channel_offset);
151 /* Looks for a link from a handle */
152 struct tsch_link *tsch_schedule_get_link_by_handle(uint16_t handle);
153 /* Looks within a slotframe for a link with a given timeslot */
154 struct tsch_link *tsch_schedule_get_link_by_timeslot(struct tsch_slotframe *slotframe, uint16_t timeslot);
155 /* Removes a link. Return 1 if success, 0 if failure */
156 int tsch_schedule_remove_link(struct tsch_slotframe *slotframe, struct tsch_link *l);
157 /* Removes a link from slotframe and timeslot. Return a 1 if success, 0 if failure */
158 int tsch_schedule_remove_link_by_timeslot(struct tsch_slotframe *slotframe, uint16_t timeslot);
159 
160 /* Returns the next active link after a given ASN, and a backup link (for the same ASN, with Rx flag) */
161 struct tsch_link * tsch_schedule_get_next_active_link(struct asn_t *asn, uint16_t *time_offset,
162  struct tsch_link **backup_link);
163 
164 #endif /* __TSCH_SCHEDULE_H__ */
static uip_ds6_addr_t * addr
Pointer to a router list entry.
Definition: uip-nd6.c:124
Private TSCH definitions (meant for use by TSCH implementation files only) ...
Header file for the Rime address representation
Linked list manipulation routines.
#define LIST_STRUCT(name)
Declare a linked list inside a structure declaraction.
Definition: list.h:108