Contiki-NG
orchestra-rule-default-common.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015, Swedish Institute of Computer Science.
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  */
30 /**
31  * \file
32  * Orchestra: a slotframe with a single shared link, common to all nodes
33  * in the network, used for unicast and broadcast.
34  *
35  * \author Simon Duquennoy <simonduq@sics.se>
36  */
37 
38 #include "contiki.h"
39 #include "orchestra.h"
40 
41 static uint16_t slotframe_handle = 0;
42 static uint16_t channel_offset = 0;
43 
44 #if ORCHESTRA_EBSF_PERIOD > 0
45 /* There is a slotframe for EBs, use this slotframe for non-EB traffic only */
46 #define ORCHESTRA_COMMON_SHARED_TYPE LINK_TYPE_NORMAL
47 #else
48 /* There is no slotframe for EBs, use this slotframe both EB and non-EB traffic */
49 #define ORCHESTRA_COMMON_SHARED_TYPE LINK_TYPE_ADVERTISING
50 #endif
51 
52 /*---------------------------------------------------------------------------*/
53 static int
54 select_packet(uint16_t *slotframe, uint16_t *timeslot)
55 {
56  /* We are the default slotframe, select anything */
57  if(slotframe != NULL) {
58  *slotframe = slotframe_handle;
59  }
60  if(timeslot != NULL) {
61  *timeslot = 0;
62  }
63  return 1;
64 }
65 /*---------------------------------------------------------------------------*/
66 static void
67 init(uint16_t sf_handle)
68 {
69  slotframe_handle = sf_handle;
70  channel_offset = slotframe_handle;
71  /* Default slotframe: for broadcast or unicast to neighbors we
72  * do not have a link to */
73  struct tsch_slotframe *sf_common = tsch_schedule_add_slotframe(slotframe_handle, ORCHESTRA_COMMON_SHARED_PERIOD);
74  tsch_schedule_add_link(sf_common,
75  LINK_OPTION_RX | LINK_OPTION_TX | LINK_OPTION_SHARED,
76  ORCHESTRA_COMMON_SHARED_TYPE, &tsch_broadcast_address,
77  0, channel_offset);
78 }
79 /*---------------------------------------------------------------------------*/
80 struct orchestra_rule default_common = {
81  init,
82  NULL,
83  select_packet,
84  NULL,
85  NULL,
86 };
802.15.4e slotframe (contains links)
Definition: tsch-types.h:84
Orchestra header file
struct tsch_slotframe * tsch_schedule_add_slotframe(uint16_t handle, uint16_t size)
Creates and adds a new slotframe.
Definition: tsch-schedule.c:72
struct tsch_link * tsch_schedule_add_link(struct tsch_slotframe *slotframe, uint8_t link_options, enum link_type link_type, const linkaddr_t *address, uint16_t timeslot, uint16_t channel_offset)
Adds a link to a slotframe.