Contiki-NG
tsch-slot-operation.h
Go to the documentation of this file.
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 /**
34  * \addtogroup tsch
35  * @{
36  * \file
37  * TSCH runtime operation within timeslots
38 */
39 
40 #ifndef __TSCH_SLOT_OPERATION_H__
41 #define __TSCH_SLOT_OPERATION_H__
42 
43 /********** Includes **********/
44 
45 #include "contiki.h"
46 #include "lib/ringbufindex.h"
47 
48 /***** External Variables *****/
49 
50 /* A ringbuf storing outgoing packets after they were dequeued.
51  * Will be processed layer by tsch_tx_process_pending */
52 extern struct ringbufindex dequeued_ringbuf;
53 extern struct tsch_packet *dequeued_array[TSCH_DEQUEUED_ARRAY_SIZE];
54 /* A ringbuf storing incoming packets.
55  * Will be processed layer by tsch_rx_process_pending */
56 extern struct ringbufindex input_ringbuf;
57 extern struct input_packet input_array[TSCH_MAX_INCOMING_PACKETS];
58 /* Last clock_time_t where synchronization happened */
59 extern clock_time_t tsch_last_sync_time;
60 /* Counts the length of the current burst */
61 extern int tsch_current_burst_count;
62 
63 /********** Functions *********/
64 
65 /**
66  * Returns a 802.15.4 channel from an ASN and channel offset. Basically adds
67  * The offset to the ASN and performs a hopping sequence lookup.
68  *
69  * \param asn A given ASN
70  * \param channel_offset A given channel offset
71  * \return The resulting channel
72  */
73 uint8_t tsch_calculate_channel(struct tsch_asn_t *asn, uint8_t channel_offset);
74 /**
75  * Checks if the TSCH lock is set. Accesses to global structures outside of
76  * interrupts must be done through the lock, unless the sturcutre has
77  * atomic read/write
78  *
79  * \return 1 if the lock is taken, 0 otherwise
80  */
81 int tsch_is_locked(void);
82 /**
83  * Takes the TSCH lock. When the lock is taken, slot operation will be skipped
84  * until release.
85  *
86  * \return 1 if the lock was successfully taken, 0 otherwise
87  */
88 int tsch_get_lock(void);
89 /**
90  * Releases the TSCH lock.
91  */
92 void tsch_release_lock(void);
93 /**
94  * Set global time before starting slot operation, with a rtimer time and an ASN
95  *
96  * \param next_slot_start the time to the start of the next slot, in rtimer ticks
97  * \param next_slot_asn the ASN of the next slot
98  */
99 void tsch_slot_operation_sync(rtimer_clock_t next_slot_start,
100  struct tsch_asn_t *next_slot_asn);
101 /**
102  * Start actual slot operation
103  */
104 void tsch_slot_operation_start(void);
105 
106 #endif /* __TSCH_SLOT_OPERATION_H__ */
107 /** @} */
TSCH packet information.
Definition: tsch-types.h:97
Header file for the ringbufindex library
int tsch_get_lock(void)
Takes the TSCH lock.
void tsch_release_lock(void)
Releases the TSCH lock.
uint8_t tsch_calculate_channel(struct tsch_asn_t *asn, uint8_t channel_offset)
Returns a 802.15.4 channel from an ASN and channel offset.
int tsch_is_locked(void)
Checks if the TSCH lock is set.
void tsch_slot_operation_sync(rtimer_clock_t next_slot_start, struct tsch_asn_t *next_slot_asn)
Set global time before starting slot operation, with a rtimer time and an ASN.
Stores data about an incoming packet.
Definition: tsch-types.h:152
void tsch_slot_operation_start(void)
Start actual slot operation.
The ASN is an absolute slot number over 5 bytes.
Definition: tsch-asn.h:48