nRF5 SDK for Mesh v3.2.0
instaburst_tx.h
1 /* Copyright (c) 2010 - 2019, Nordic Semiconductor ASA
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  *
10  * 2. Redistributions in binary form, except as embedded into a Nordic
11  * Semiconductor ASA integrated circuit in a product or a software update for
12  * such product, must reproduce the above copyright notice, this list of
13  * conditions and the following disclaimer in the documentation and/or other
14  * materials provided with the distribution.
15  *
16  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
17  * contributors may be used to endorse or promote products derived from this
18  * software without specific prior written permission.
19  *
20  * 4. This software, with or without modification, must only be used with a
21  * Nordic Semiconductor ASA integrated circuit.
22  *
23  * 5. Any software provided in binary form under this license must not be reverse
24  * engineered, decompiled, modified and/or disassembled.
25  *
26  * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
27  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
28  * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
29  * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
30  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
32  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
35  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36  */
37 #ifndef INSTABURST_TX_H__
38 #define INSTABURST_TX_H__
39 
67 #include "instaburst.h"
68 #include "broadcast.h"
69 #include "adv_ext_tx.h"
70 #include "bearer_event.h"
71 #include "packet_buffer.h"
72 #include "bearer_handler.h"
73 
77 #define INSTABURST_TX_BUFFER_MIN_SIZE \
78  (sizeof(packet_buffer_packet_t) + sizeof(adv_ext_tx_event_t) + \
79  (sizeof(adv_ext_tx_packet_t) + ADV_EXT_PACKET_LEN_MAX) * ADV_EXT_TX_CHAIN_MAX_COUNT)
80 
81 
82 typedef struct instaburst_tx instaburst_tx_t;
83 
92 typedef void (*instaburst_tx_complete_t)(struct instaburst_tx * p_tx, nrf_mesh_tx_token_t tx_token, timestamp_t timestamp);
93 
96 typedef struct
97 {
99  uint8_t set_id;
101  const uint8_t * p_channels;
103  uint8_t channel_count;
105  radio_mode_t radio_mode;
107  radio_tx_power_t tx_power;
117  uint32_t interval_ms;
119 
120 #ifdef INSTABURST_TX_DEBUG
121 
122 typedef struct
123 {
124  uint32_t failed_allocs;
125  uint32_t tx_regular_packet;
126  uint32_t tx_adv_ext;
127  uint32_t tx_skipped;
128 } instaburst_tx_debug_t;
129 #endif
130 
136 {
137  instaburst_tx_config_t config;
138 
139  uint8_t channel_index;
140 
141  packet_buffer_t packet_buffer;
142 
143  uint8_t * p_next_alloc;
144  adv_ext_tx_packet_t * p_alloc_packet;
145  packet_buffer_packet_t * p_alloc_buf;
146  packet_buffer_packet_t * p_tx_buf;
148  broadcast_t broadcast;
149  adv_ext_tx_t adv_ext_tx;
150 
151  bearer_event_sequential_t tx_complete_event;
152  timestamp_t prev_tx_timestamp;
153 
154  timer_event_t timer_event;
155 
156 #ifdef INSTABURST_TX_DEBUG
157  instaburst_tx_debug_t debug;
158 #endif
159 };
160 
166 void instaburst_tx_init(uint32_t lfclk_ppm);
167 
176 void instaburst_tx_instance_init(instaburst_tx_t * p_instaburst,
177  const instaburst_tx_config_t * p_config,
178  uint8_t * p_packet_buffer,
179  uint32_t packet_buffer_size);
180 
186 void instaburst_tx_enable(instaburst_tx_t * p_instaburst);
187 
193 void instaburst_tx_disable(instaburst_tx_t * p_instaburst);
194 
202 bool instaburst_tx_is_enabled(const instaburst_tx_t * p_instaburst);
203 
216 uint8_t * instaburst_tx_buffer_alloc(instaburst_tx_t * p_instaburst, uint32_t data_len, nrf_mesh_tx_token_t tx_token);
217 
224 void instaburst_tx_buffer_commit(instaburst_tx_t * p_instaburst, const uint8_t * p_buffer);
225 
232 void instaburst_tx_buffer_discard(instaburst_tx_t * p_instaburst, const uint8_t * p_buffer);
233 
247 bool instaburst_tx_finalize(instaburst_tx_t * p_instaburst);
248 
261 void instaburst_tx_buffer_lock(bool lock);
262 
270 void instaburst_tx_interval_set(instaburst_tx_t * p_instaburst, uint32_t interval_ms);
271 
279 static inline uint32_t instaburst_tx_interval_get(const instaburst_tx_t * p_instaburst)
280 {
281  return p_instaburst->config.interval_ms;
282 }
283 
290 void instaburst_tx_tx_power_set(instaburst_tx_t * p_instaburst, radio_tx_power_t tx_power);
291 
299 static inline radio_tx_power_t instaburst_tx_tx_power_get(const instaburst_tx_t * p_instaburst)
300 {
301  return p_instaburst->config.tx_power;
302 }
303 
306 #endif /* INSTABURST_TX_H__ */
Instaburst TX configuration.
Definition: instaburst_tx.h:96
void instaburst_tx_enable(instaburst_tx_t *p_instaburst)
Enables the given Instaburst instance.
uint8_t channel_count
Number of channels in the p_channels array.
uint8_t * p_next_alloc
Pointer to the next location to allocate a buffer in.
radio_mode_t radio_mode
Radio mode to run auxiliary packets in.
bool instaburst_tx_finalize(instaburst_tx_t *p_instaburst)
Finalizes the TX event under construction, putting it up for transmission.
Instaburst instance structure.
const uint8_t * p_channels
Array of radio channels to send on.
radio_tx_power_t tx_power
TX power to transmit auxiliary packets at.
void instaburst_tx_tx_power_set(instaburst_tx_t *p_instaburst, radio_tx_power_t tx_power)
Sets the TX power for the given Instaburst instance.
void instaburst_tx_buffer_lock(bool lock)
Locks the current buffer to prevent it from being automatically transmitted on the next advertisement...
static uint32_t instaburst_tx_interval_get(const instaburst_tx_t *p_instaburst)
Gets the TX interval for the given Instaburst instance.
uint32_t nrf_mesh_tx_token_t
TX Token type, used as a context parameter to notify the application of ended transmissions.
Definition: nrf_mesh.h:105
void instaburst_tx_buffer_commit(instaburst_tx_t *p_instaburst, const uint8_t *p_buffer)
Commits the given buffer for transmission.
packet_buffer_packet_t * p_alloc_buf
Buffer currently being used for allocating new packets.
void(* instaburst_tx_complete_t)(struct instaburst_tx *p_tx, nrf_mesh_tx_token_t tx_token, timestamp_t timestamp)
TX Complete callback to be called when all repeats of a buffer have been sent.
Definition: instaburst_tx.h:92
uint8_t set_id
Set ID for this Instaburst instance.
Definition: instaburst_tx.h:99
uint8_t * instaburst_tx_buffer_alloc(instaburst_tx_t *p_instaburst, uint32_t data_len, nrf_mesh_tx_token_t tx_token)
Allocates a buffer for transmission.
adv_ext_tx_packet_t * p_alloc_packet
Packet being built in the allocate stage.
void instaburst_tx_init(uint32_t lfclk_ppm)
Initializes the Instaburst TX module.
static radio_tx_power_t instaburst_tx_tx_power_get(const instaburst_tx_t *p_instaburst)
Gets the TX power for the given Instaburst instance.
void instaburst_tx_disable(instaburst_tx_t *p_instaburst)
Disables the given Instaburst instance.
void instaburst_tx_buffer_discard(instaburst_tx_t *p_instaburst, const uint8_t *p_buffer)
Discards the given buffer, freeing any memory associated with it.
instaburst_tx_complete_t callback
Callback to call when the transmission was completed.
void instaburst_tx_instance_init(instaburst_tx_t *p_instaburst, const instaburst_tx_config_t *p_config, uint8_t *p_packet_buffer, uint32_t packet_buffer_size)
Initializes an Instaburst TX instance.
void instaburst_tx_interval_set(instaburst_tx_t *p_instaburst, uint32_t interval_ms)
Sets the TX interval for the given Instaburst instance.
packet_buffer_packet_t * p_tx_buf
Buffer currently in transmission.
uint32_t interval_ms
Transmission interval in milliseconds.
bool instaburst_tx_is_enabled(const instaburst_tx_t *p_instaburst)
Checks if the Instaburst instance is enabled.

Documentation feedback | Developer Zone | Subscribe | Updated