nRF5 SDK for Mesh v1.0.1
advertiser.h
1  /* Copyright (c) 2010 - 2017, 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 
120 typedef void (*advertiser_tx_complete_cb_t)(advertiser_t * p_adv, nrf_mesh_tx_token_t token, uint32_t timestamp);
121 
122 typedef struct
123 {
125  uint32_t timestamp;
127 
130 {
131  bool enabled;
133  broadcast_t broadcast;
134  timer_event_t timer;
135  packet_buffer_t buf;
138  bearer_event_sequential_t tx_complete_event;
140 };
141 
145 void advertiser_init(void);
146 
161  advertiser_tx_complete_cb_t tx_complete_cb,
162  uint8_t * p_buffer,
163  uint32_t buffer_size);
164 
170 void advertiser_enable(advertiser_t * p_adv);
171 
178 void advertiser_disable(advertiser_t * p_adv);
179 
192 adv_packet_t * advertiser_packet_alloc(advertiser_t * p_adv, uint32_t adv_payload_size);
193 
207 
216 
226 void advertiser_config_set(advertiser_t * p_adv, const advertiser_config_t * p_config);
227 
234 void advertiser_config_get(const advertiser_t * p_adv, advertiser_config_t * p_config);
235 
242 void advertiser_channels_set(advertiser_t * p_adv, const advertiser_channels_t * p_channels);
243 
254 void advertiser_address_set(advertiser_t * p_adv, const ble_gap_addr_t * p_addr);
255 
262 void advertiser_interval_set(advertiser_t * p_adv, uint32_t interval_ms);
263 
272 void advertiser_flush(advertiser_t * p_adv);
273 
279 void advertiser_address_default_get(ble_gap_addr_t * p_addr);
280 
283 #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.
void advertiser_channels_set(advertiser_t *p_adv, const advertiser_channels_t *p_channels)
Set 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)
Update the advertiser configuration.
void advertiser_init(void)
Initialize the advertiser module.
uint32_t timestamp
Timestamp of the last transmission of the packet, in microseconds.
Definition: advertiser.h:125
broadcast_t broadcast
Broadcast module, used as a context to send a single advertisement.
Definition: advertiser.h:133
adv_packet_t * p_packet
Pointer to the current packet, only for internal use.
Definition: advertiser.h:132
void advertiser_packet_discard(advertiser_t *p_adv, adv_packet_t *p_packet)
Discard an allocated advertisement packet.
void(* advertiser_tx_complete_cb_t)(advertiser_t *p_adv, nrf_mesh_tx_token_t token, uint32_t timestamp)
Transmit complete callback for notifying the users after a given packet has been sent the desired num...
Definition: advertiser.h:120
bearer_event_sequential_t tx_complete_event
Bearer event for executing the TX_COMPLETE event outside the radio interrupt.
Definition: advertiser.h:138
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:131
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
timer_event_t timer
Timer event used to set up periodic advertisements.
Definition: advertiser.h:134
void advertiser_address_default_get(ble_gap_addr_t *p_addr)
Get 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:139
#define BEARER_ADV_CHANNELS_MAX
Maximum number of channels an advertiser can transmit on.
advertiser_config_t config
Advertiser configuration.
Definition: advertiser.h:136
advertiser_tx_complete_cb_t tx_complete_callback
TX complete callback to call at the end of a completed transmission.
Definition: advertiser.h:137
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:79
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
void advertiser_address_set(advertiser_t *p_adv, const ble_gap_addr_t *p_addr)
Set 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:124
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)
Set the advertisement interval for the given advertiser.
packet_buffer_t buf
Packet buffer for outgoing packets.
Definition: advertiser.h:135
void advertiser_enable(advertiser_t *p_adv)
Enables the advertiser instance given.
void advertiser_flush(advertiser_t *p_adv)
Flush the given advertiser's packet queue.
Single advertiser instance.
Definition: advertiser.h:129
Advertiser channel configuration.
Definition: advertiser.h:79

Documentation feedback | Developer Zone | Subscribe | Updated