Contiki 3.x
tsch-slot-operation.h
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 #ifndef __TSCH_SLOT_OPERATION_H__
34 #define __TSCH_SLOT_OPERATION_H__
35 
36 /********** Includes **********/
37 
38 #include "contiki.h"
39 #include "lib/ringbufindex.h"
40 #include "net/mac/tsch/tsch-packet.h"
42 
43 /******** Configuration *******/
44 
45 /* Size of the ring buffer storing dequeued outgoing packets (only an array of pointers).
46  * Must be power of two, and greater or equal to QUEUEBUF_NUM */
47 #ifdef TSCH_CONF_DEQUEUED_ARRAY_SIZE
48 #define TSCH_DEQUEUED_ARRAY_SIZE TSCH_CONF_DEQUEUED_ARRAY_SIZE
49 #else
50 /* By default, round QUEUEBUF_CONF_NUM to next power of two
51  * (in the range [4;256]) */
52 #if QUEUEBUF_CONF_NUM <= 4
53 #define TSCH_DEQUEUED_ARRAY_SIZE 4
54 #elif QUEUEBUF_CONF_NUM <= 8
55 #define TSCH_DEQUEUED_ARRAY_SIZE 8
56 #elif QUEUEBUF_CONF_NUM <= 16
57 #define TSCH_DEQUEUED_ARRAY_SIZE 16
58 #elif QUEUEBUF_CONF_NUM <= 32
59 #define TSCH_DEQUEUED_ARRAY_SIZE 32
60 #elif QUEUEBUF_CONF_NUM <= 64
61 #define TSCH_DEQUEUED_ARRAY_SIZE 64
62 #elif QUEUEBUF_CONF_NUM <= 128
63 #define TSCH_DEQUEUED_ARRAY_SIZE 128
64 #else
65 #define TSCH_DEQUEUED_ARRAY_SIZE 256
66 #endif
67 #endif
68 
69 /* Size of the ring buffer storing incoming packets.
70  * Must be power of two */
71 #ifdef TSCH_CONF_MAX_INCOMING_PACKETS
72 #define TSCH_MAX_INCOMING_PACKETS TSCH_CONF_MAX_INCOMING_PACKETS
73 #else
74 #define TSCH_MAX_INCOMING_PACKETS 4
75 #endif
76 
77 /*********** Callbacks *********/
78 
79 /* Called by TSCH form interrupt after receiving a frame, enabled upper-layer to decide
80  * whether to ACK or NACK */
81 #ifdef TSCH_CALLBACK_DO_NACK
82 int TSCH_CALLBACK_DO_NACK(struct tsch_link *link, linkaddr_t *src, linkaddr_t *dst);
83 #endif
84 
85 /************ Types ***********/
86 
87 /* Stores data about an incoming packet */
88 struct input_packet {
89  uint8_t payload[TSCH_PACKET_MAX_LEN]; /* Packet payload */
90  struct asn_t rx_asn; /* ASN when the packet was received */
91  int len; /* Packet len */
92  uint16_t rssi; /* RSSI for this packet */
93 };
94 
95 /***** External Variables *****/
96 
97 /* A ringbuf storing outgoing packets after they were dequeued.
98  * Will be processed layer by tsch_tx_process_pending */
99 extern struct ringbufindex dequeued_ringbuf;
100 extern struct tsch_packet *dequeued_array[TSCH_DEQUEUED_ARRAY_SIZE];
101 /* A ringbuf storing incoming packets.
102  * Will be processed layer by tsch_rx_process_pending */
103 extern struct ringbufindex input_ringbuf;
104 extern struct input_packet input_array[TSCH_MAX_INCOMING_PACKETS];
105 
106 /********** Functions *********/
107 
108 /* Returns a 802.15.4 channel from an ASN and channel offset */
109 uint8_t tsch_calculate_channel(struct asn_t *asn, uint8_t channel_offset);
110 /* Is TSCH locked? */
111 int tsch_is_locked(void);
112 /* Lock TSCH (no link operation) */
113 int tsch_get_lock(void);
114 /* Release TSCH lock */
115 void tsch_release_lock(void);
116 /* Set global time before starting slot operation,
117  * with a rtimer time and an ASN */
118 void tsch_slot_operation_sync(rtimer_clock_t next_slot_start,
119  struct asn_t *next_slot_asn);
120 /* Start actual slot operation */
121 void tsch_slot_operation_start(void);
122 
123 #endif /* __TSCH_SLOT_OPERATION_H__ */
Private TSCH definitions (meant for use by TSCH implementation files only) ...
Header file for the ringbufindex library