nRF5 SDK for Mesh v5.0.0
advertiser.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 ADVERTISER_H__
38 #define ADVERTISER_H__
39 
40 #include "broadcast.h"
41 #include "timer_scheduler.h"
42 #include "packet_buffer.h"
43 #include "nrf_mesh_defines.h"
44 #include "nrf_mesh_config_bearer.h"
45 #include "nrf_mesh.h"
46 #include "bearer_event.h"
47 
56 #define ADVERTISER_INTERVAL_RANDOMIZATION_US MS_TO_US(10)
57 
58 #define ADVERTISER_REPEAT_INFINITE 0xFF
59 
62 #define ADVERTISER_PACKET_BUFFER_PACKET_MAXLEN (sizeof(packet_buffer_packet_t) + sizeof(adv_packet_t))
63 
65 typedef struct
66 {
69  struct
70  {
72  uint8_t repeats;
73  } config;
75  packet_t packet __attribute__((aligned(WORD_SIZE)));
76 } adv_packet_t;
77 
79 typedef struct
80 {
82  uint8_t channel_map[BEARER_ADV_CHANNELS_MAX];
84  uint8_t count;
88 
89 
91 typedef struct
92 {
94  ble_gap_addr_t adv_addr;
100 
102 typedef struct advertiser_t advertiser_t;
103 
117 typedef void (*advertiser_tx_complete_cb_t)(advertiser_t * p_adv, nrf_mesh_tx_token_t token, timestamp_t timestamp);
118 
119 typedef struct
120 {
122  timestamp_t timestamp;
124 
127 {
128  bool enabled;
130  broadcast_t broadcast;
131  timer_event_t timer;
132  packet_buffer_t buf;
135  bearer_event_sequential_t tx_complete_event;
137 };
138 
142 void advertiser_init(void);
143 
158  advertiser_tx_complete_cb_t tx_complete_cb,
159  uint8_t * p_buffer,
160  uint32_t buffer_size);
161 
167 void advertiser_enable(advertiser_t * p_adv);
168 
175 void advertiser_disable(advertiser_t * p_adv);
176 
189 adv_packet_t * advertiser_packet_alloc(advertiser_t * p_adv, uint32_t adv_payload_size);
190 
204 
213 
223 void advertiser_config_set(advertiser_t * p_adv, const advertiser_config_t * p_config);
224 
231 void advertiser_config_get(const advertiser_t * p_adv, advertiser_config_t * p_config);
232 
239 void advertiser_channels_set(advertiser_t * p_adv, const advertiser_channels_t * p_channels);
240 
251 void advertiser_address_set(advertiser_t * p_adv, const ble_gap_addr_t * p_addr);
252 
259 static inline void advertiser_address_get(const advertiser_t * p_adv, ble_gap_addr_t * p_addr)
260 {
261  memcpy(p_addr, &p_adv->config.adv_addr, sizeof(ble_gap_addr_t));
262 }
263 
270 void advertiser_interval_set(advertiser_t * p_adv, uint32_t interval_ms);
271 
279 static inline uint32_t advertiser_interval_get(const advertiser_t * p_adv)
280 {
281  return US_TO_MS(p_adv->config.advertisement_interval_us);
282 }
283 
290 void advertiser_tx_power_set(advertiser_t * p_adv, radio_tx_power_t tx_power);
291 
299 static inline radio_tx_power_t advertiser_tx_power_get(const advertiser_t * p_adv)
300 {
301  return p_adv->broadcast.params.radio_config.tx_power;
302 }
303 
315 void advertiser_flush(advertiser_t * p_adv);
316 
322 void advertiser_address_default_get(ble_gap_addr_t * p_addr);
323 
331 static inline bool advertiser_is_enabled(const advertiser_t * p_adv)
332 {
333  return p_adv->enabled;
334 }
335 
338 #endif /* ADVERTISER_H__ */
uint8_t repeats
Number of times the packet should be transmitted on each channel.
Definition: advertiser.h:72
void advertiser_disable(advertiser_t *p_adv)
Disables the advertiser instance given, so that no more packets are sent from this advertiser even if...
void advertiser_config_get(const advertiser_t *p_adv, advertiser_config_t *p_config)
Gets the current advertiser configuration.
static radio_tx_power_t advertiser_tx_power_get(const advertiser_t *p_adv)
Gets the TX power for the given advertiser.
Definition: advertiser.h:299
void(* advertiser_tx_complete_cb_t)(advertiser_t *p_adv, nrf_mesh_tx_token_t token, timestamp_t timestamp)
Transmit complete callback for notifying the users after a given packet has been sent the desired num...
Definition: advertiser.h:117
timestamp_t timestamp
Timestamp of the last transmission of the packet, in microseconds.
Definition: advertiser.h:122
void advertiser_channels_set(advertiser_t *p_adv, const advertiser_channels_t *p_channels)
Sets the advertiser channels used by the given advertiser instance.
uint32_t advertisement_interval_us
On init the advertiser will use BEARER_ADV_INT_DEFAULT_MS.
Definition: advertiser.h:96
nrf_mesh_tx_token_t token
TX token, set by the application.
Definition: advertiser.h:68
void advertiser_config_set(advertiser_t *p_adv, const advertiser_config_t *p_config)
Updates the advertiser configuration.
void advertiser_init(void)
Initialize the advertiser module.
broadcast_t broadcast
Broadcast module, used as a context to send a single advertisement.
Definition: advertiser.h:130
adv_packet_t * p_packet
Pointer to the current packet, only for internal use.
Definition: advertiser.h:129
void advertiser_packet_discard(advertiser_t *p_adv, adv_packet_t *p_packet)
Discards an allocated advertisement packet.
bearer_event_sequential_t tx_complete_event
Bearer event for executing the TX_COMPLETE event outside the radio interrupt.
Definition: advertiser.h:135
The structure defining the contents of an advertisement packet.
Definition: advertiser.h:65
bool enabled
Flag indicating whether the event is enabled.
Definition: advertiser.h:128
static void advertiser_address_get(const advertiser_t *p_adv, ble_gap_addr_t *p_addr)
Gets the advertiser address used by the given advertiser instance.
Definition: advertiser.h:259
struct __attribute__((packed))
Provisioning data required by the remote provisioning client for command type SERIAL_PB_REMOTE_CLIENT...
bool randomize_order
If set, the advertiser will randomize the order of the advertisement channels before each transmit...
Definition: advertiser.h:86
static uint32_t advertiser_interval_get(const advertiser_t *p_adv)
Gets the given advertiser's advertisement interval.
Definition: advertiser.h:279
timer_event_t timer
Timer event used to set up periodic advertisements.
Definition: advertiser.h:131
void advertiser_address_default_get(ble_gap_addr_t *p_addr)
Gets the default advertisement address from device factory information structure. ...
advertiser_tx_complete_params_t tx_complete_params
Parameters of the TX_COMPLETE event.
Definition: advertiser.h:136
#define BEARER_ADV_CHANNELS_MAX
Maximum number of channels an advertiser can transmit on.
advertiser_config_t config
Advertiser configuration.
Definition: advertiser.h:133
advertiser_tx_complete_cb_t tx_complete_callback
TX complete callback to call at the end of a completed transmission.
Definition: advertiser.h:134
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
uint8_t count
Number of channels in the channel_map.
Definition: advertiser.h:84
void advertiser_instance_init(advertiser_t *p_adv, advertiser_tx_complete_cb_t tx_complete_cb, uint8_t *p_buffer, uint32_t buffer_size)
Initialize an advertiser instance.
void advertiser_packet_send(advertiser_t *p_adv, adv_packet_t *p_packet)
Sends a given packet using the given advertiser instance, this can be called multiple times without h...
ble_gap_addr_t adv_addr
On init the advertiser will use the address in the device FICR.
Definition: advertiser.h:94
static bool advertiser_is_enabled(const advertiser_t *p_adv)
Checks if an advertiser is enabled.
Definition: advertiser.h:331
void advertiser_tx_power_set(advertiser_t *p_adv, radio_tx_power_t tx_power)
Sets the TX power for the given advertiser.
void advertiser_address_set(advertiser_t *p_adv, const ble_gap_addr_t *p_addr)
Sets the advertiser address used by the given advertiser instance.
advertiser_channels_t channels
On init the advertiser will use all the default BLE advertisement channels, without randomization...
Definition: advertiser.h:98
nrf_mesh_tx_token_t token
TX token, set by the application.
Definition: advertiser.h:121
Configuration of the advertiser to be used when sending the packets.
Definition: advertiser.h:91
adv_packet_t * advertiser_packet_alloc(advertiser_t *p_adv, uint32_t adv_payload_size)
Allocates a buffer, if available, from the given advertiser instance.
void advertiser_interval_set(advertiser_t *p_adv, uint32_t interval_ms)
Sets the advertisement interval for the given advertiser.
packet_buffer_t buf
Packet buffer for outgoing packets.
Definition: advertiser.h:132
void advertiser_enable(advertiser_t *p_adv)
Enables the advertiser instance given.
void advertiser_flush(advertiser_t *p_adv)
Flushes the given advertiser's packet queue.
Single advertiser instance.
Definition: advertiser.h:126
Advertiser channel configuration.
Definition: advertiser.h:79

Documentation feedback | Developer Zone | Subscribe | Updated