nRF5 SDK for Mesh v5.0.0
instaburst_tx.h
1 /* Copyright (c) 2010 - 2020, 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 
66 #include "instaburst.h"
67 #include "broadcast.h"
68 #include "adv_ext_tx.h"
69 #include "bearer_event.h"
70 #include "packet_buffer.h"
71 #include "bearer_handler.h"
72 
76 #define INSTABURST_TX_BUFFER_MIN_SIZE \
77  (sizeof(packet_buffer_packet_t) + sizeof(adv_ext_tx_event_t) + \
78  (sizeof(adv_ext_tx_packet_t) + ADV_EXT_PACKET_LEN_MAX) * ADV_EXT_TX_CHAIN_MAX_COUNT)
79 
80 
81 typedef struct instaburst_tx instaburst_tx_t;
82 
91 typedef void (*instaburst_tx_complete_t)(struct instaburst_tx * p_tx, nrf_mesh_tx_token_t tx_token, timestamp_t timestamp);
92 
95 typedef struct
96 {
98  uint8_t set_id;
100  const uint8_t * p_channels;
102  uint8_t channel_count;
104  radio_mode_t radio_mode;
106  radio_tx_power_t tx_power;
116  uint32_t interval_ms;
118 
119 #ifdef INSTABURST_TX_DEBUG
120 
121 typedef struct
122 {
123  uint32_t failed_allocs;
124  uint32_t tx_regular_packet;
125  uint32_t tx_adv_ext;
126  uint32_t tx_skipped;
127 } instaburst_tx_debug_t;
128 #endif
129 
135 {
136  instaburst_tx_config_t config;
137 
138  uint8_t channel_index;
139 
140  packet_buffer_t packet_buffer;
141 
142  uint8_t * p_next_alloc;
143  adv_ext_tx_packet_t * p_alloc_packet;
144  packet_buffer_packet_t * p_alloc_buf;
145  packet_buffer_packet_t * p_tx_buf;
147  broadcast_t broadcast;
148  adv_ext_tx_t adv_ext_tx;
149 
150  bearer_event_sequential_t tx_complete_event;
151  timestamp_t prev_tx_timestamp;
152 
153  timer_event_t timer_event;
154 
155 #ifdef INSTABURST_TX_DEBUG
156  instaburst_tx_debug_t debug;
157 #endif
158 };
159 
165 void instaburst_tx_init(uint32_t lfclk_ppm);
166 
175 void instaburst_tx_instance_init(instaburst_tx_t * p_instaburst,
176  const instaburst_tx_config_t * p_config,
177  uint8_t * p_packet_buffer,
178  uint32_t packet_buffer_size);
179 
185 void instaburst_tx_enable(instaburst_tx_t * p_instaburst);
186 
192 void instaburst_tx_disable(instaburst_tx_t * p_instaburst);
193 
201 bool instaburst_tx_is_enabled(const instaburst_tx_t * p_instaburst);
202 
215 uint8_t * instaburst_tx_buffer_alloc(instaburst_tx_t * p_instaburst, uint32_t data_len, nrf_mesh_tx_token_t tx_token);
216 
223 void instaburst_tx_buffer_commit(instaburst_tx_t * p_instaburst, const uint8_t * p_buffer);
224 
231 void instaburst_tx_buffer_discard(instaburst_tx_t * p_instaburst, const uint8_t * p_buffer);
232 
246 bool instaburst_tx_finalize(instaburst_tx_t * p_instaburst);
247 
260 void instaburst_tx_buffer_lock(bool lock);
261 
269 void instaburst_tx_interval_set(instaburst_tx_t * p_instaburst, uint32_t interval_ms);
270 
278 static inline uint32_t instaburst_tx_interval_get(const instaburst_tx_t * p_instaburst)
279 {
280  return p_instaburst->config.interval_ms;
281 }
282 
289 void instaburst_tx_tx_power_set(instaburst_tx_t * p_instaburst, radio_tx_power_t tx_power);
290 
298 static inline radio_tx_power_t instaburst_tx_tx_power_get(const instaburst_tx_t * p_instaburst)
299 {
300  return p_instaburst->config.tx_power;
301 }
302 
305 #endif /* INSTABURST_TX_H__ */
Instaburst TX configuration.
Definition: instaburst_tx.h:95
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:91
uint8_t set_id
Set ID for this Instaburst instance.
Definition: instaburst_tx.h:98
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