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 
43 #if ORCHESTRA_EBSF_PERIOD > 0
44 /* There is a slotframe for EBs, use this slotframe for non-EB traffic only */
45 #define ORCHESTRA_COMMON_SHARED_TYPE LINK_TYPE_NORMAL
46 #else
47 /* There is no slotframe for EBs, use this slotframe both EB and non-EB traffic */
48 #define ORCHESTRA_COMMON_SHARED_TYPE LINK_TYPE_ADVERTISING
49 #endif
50 
51 /*---------------------------------------------------------------------------*/
52 static int
53 select_packet(uint16_t *slotframe, uint16_t *timeslot, uint16_t *channel_offset)
54 {
55  /* We are the default slotframe, select anything */
56  if(slotframe != NULL) {
57  *slotframe = slotframe_handle;
58  }
59  if(timeslot != NULL) {
60  *timeslot = 0;
61  }
62  return 1;
63 }
64 /*---------------------------------------------------------------------------*/
65 static void
66 init(uint16_t sf_handle)
67 {
68  slotframe_handle = sf_handle;
69  /* Default slotframe: for broadcast or unicast to neighbors we
70  * do not have a link to */
71  struct tsch_slotframe *sf_common = tsch_schedule_add_slotframe(slotframe_handle, ORCHESTRA_COMMON_SHARED_PERIOD);
72  tsch_schedule_add_link(sf_common,
73  LINK_OPTION_RX | LINK_OPTION_TX | LINK_OPTION_SHARED,
74  ORCHESTRA_COMMON_SHARED_TYPE, &tsch_broadcast_address,
75  0, ORCHESTRA_DEFAULT_COMMON_CHANNEL_OFFSET, 1);
76 }
77 /*---------------------------------------------------------------------------*/
78 struct orchestra_rule default_common = {
79  init,
80  NULL,
81  select_packet,
82  NULL,
83  NULL,
84  "default common",
85  ORCHESTRA_COMMON_SHARED_PERIOD,
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:73
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, uint8_t do_remove)
Adds a link to a slotframe.