forked from espressif/arduino-esp32
-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathesp_ieee802154.h
385 lines (340 loc) · 9.63 KB
/
esp_ieee802154.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_ieee802154_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Initialize the IEEE 802.15.4 subsystem.
*
*/
void esp_ieee802154_enable(void);
/**
* @brief Deinitialize the IEEE 802.15.4 subsystem.
*
*/
void esp_ieee802154_disable(void);
/**
* @brief Get the operational channel.
*
* @return The channel number (11~26).
*
*/
uint8_t esp_ieee802154_get_channel(void);
/**
* @brief Set the operational channel.
*
* @param[in] channel The channel number (11-26).
*
*/
void esp_ieee802154_set_channnel(uint8_t channel);
/**
* @brief Get the transmit power.
*
* @return The transmit power in dBm.
*
*/
int8_t esp_ieee802154_get_txpower(void);
/**
* @brief Set the transmit power.
*
* @param[in] power The transmit power in dBm.
*
*/
void esp_ieee802154_set_txpower(int8_t power);
/**
* @brief Get the promiscuous mode.
*
* @return
* - True The promiscuous mode is enabled.
* - False The promiscuous mode is disabled.
*
*/
bool esp_ieee802154_get_promiscuous(void);
/**
* @brief Set the promiscuous mode.
*
* @param[in] enable The promiscuous mode to be set.
*
*/
void esp_ieee802154_set_promiscuous(bool enable);
/**
* @brief Get the IEEE 802.15.4 Radio state.
*
* @return The IEEE 802.15.4 Radio state, refer to esp_ieee802154_state_t.
*
*/
esp_ieee802154_state_t esp_ieee802154_get_state(void);
/**
* @brief Set the IEEE 802.15.4 Radio to sleep state.
*
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure due to invalid state.
*
*/
esp_err_t esp_ieee802154_sleep(void);
/**
* @brief Set the IEEE 802.15.4 Radio to receive state.
*
* @return
* - ESP_OK on success
* - ESP_FAIL on failure due to invalid state.
*
* Note: Radio will continue receiving until it receives a valid frame.
* Ref to esp_ieee802154_receive_done().
*
*/
esp_err_t esp_ieee802154_receive(void);
/**
* @brief Transmit the given frame.
*
* @param[in] frame The pointer to the frame, the frame format:
* |-----------------------------------------------------------------------|
* | Len | MHR | MAC Payload | FCS |
* |-----------------------------------------------------------------------|
* @param[in] cca Perform CCA before transmission if it's true, otherwise transmit the frame directly.
*
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure due to invalid state.
*
* Note: The transmit result will be reported via esp_ieee802154_transmit_done()
* or esp_ieee802154_transmit_failed().
*
*/
esp_err_t esp_ieee802154_transmit(const uint8_t *frame, bool cca);
/**
* @brief Set the time to wait for the ack frame.
*
* @param[in] timeout The time to wait for the ack frame, in symbol unit (16 us).
* Default: 0x006C, Range: 0x0000 - 0xFFFF.
*
*/
void esp_ieee802154_set_ack_timeout(uint32_t timeout);
/**
* @brief Get the device PAN ID.
*
* @return The device PAN ID.
*
*/
uint16_t esp_ieee802154_get_panid(void);
/**
* @brief Set the device PAN ID.
*
* @param[in] panid The device PAN ID.
*
*/
void esp_ieee802154_set_panid(uint16_t panid);
/**
* @brief Get the device short address.
*
* @return The device short address.
*
*/
uint16_t esp_ieee802154_get_short_address(void);
/**
* @brief Set the device short address.
*
* @param[in] short_address The device short address.
*
*/
void esp_ieee802154_set_short_address(uint16_t short_address);
/**
* @brief Get the device extended address.
*
* @param[out] ext_addr The pointer to the device extended address.
*
*/
void esp_ieee802154_get_extended_address(uint8_t *ext_addr);
/**
* @brief Set the device extended address.
*
* @param[in] ext_addr The pointer to the device extended address.
*
*/
void esp_ieee802154_set_extended_address(const uint8_t *ext_addr);
/**
* @brief Get the device coordinator.
*
* @return
* - True The coordinator is enabled.
* - False The coordinator is disabled.
*
*/
bool esp_ieee802154_get_coordinator(void);
/**
* @brief Set the device coordinator role.
*
* @param[in] enable The coordinator role to be set.
*
*/
void esp_ieee802154_set_coordinator(bool enable);
/**
* @brief Get the auto frame pending mode.
*
* @return The auto frame pending mode, refer to esp_ieee802154_pending_mode_t.
*
*/
esp_ieee802154_pending_mode_t esp_ieee802154_get_pending_mode(void);
/**
* @brief Set the auto frame pending mode.
*
* @param[in] pending_mode The auto frame pending mode, refer to esp_ieee802154_pending_mode_t.
*
*/
void esp_ieee802154_set_pending_mode(esp_ieee802154_pending_mode_t pending_mode);
/**
* @brief Add address to the source matching table.
*
* @param[in] addr The pointer to the address.
* @param[in] is_short Short address or Extended address.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_NO_MEM if the pending table is full.
*
*/
esp_err_t esp_ieee802154_add_pending_addr(const uint8_t *addr, bool is_short);
/**
* @brief Remove address from the source matching table.
*
* @param[in] addr The pointer to the address.
* @param[in] is_short Short address or Extended address.
*
* @return
* - ESP_OK on success.
* - ESP_ERR_NOT_FOUND if the address was not found from the source matching table.
*
*/
esp_err_t esp_ieee802154_clear_pending_addr(const uint8_t *addr, bool is_short);
/**
* @brief Clear the source matching table to empty.
*
* @param[in] is_short Clear Short address table or Extended address table.
*
*/
void esp_ieee802154_reset_pending_table(bool is_short);
/**
* @brief Get the CCA threshold.
*
* @return The CCA threshold in dBm.
*
*/
int8_t esp_ieee802154_get_cca_threshold(void);
/**
* @brief Set the CCA threshold.
*
* @param[in] cca_threshold The CCA threshold in dBm.
*
*/
void esp_ieee802154_set_cca_threshold(int8_t cca_threshold);
/**
* @brief Get the CCA mode.
*
* @return The CCA mode, refer to esp_ieee802154_cca_mode_t.
*
*/
esp_ieee802154_cca_mode_t esp_ieee802154_get_cca_mode(void);
/**
* @brief Set the CCA mode.
*
* @param[in] cca_mode The CCA mode, refer to esp_ieee802154_cca_mode_t.
*
*/
void esp_ieee802154_set_cca_mode(esp_ieee802154_cca_mode_t cca_mode);
/**
* @brief Enable rx_on_when_idle mode, radio will receive during idle.
*
* @param[in] enable Enable/Disable rx_on_when_idle mode.
*
*/
void esp_ieee802154_set_rx_when_idle(bool enable);
/**
* @brief Get the rx_on_when_idle mode.
*
* @return rx_on_when_idle mode.
*
*/
bool esp_ieee802154_get_rx_when_idle(void);
/**
* @brief Perform energy detection.
*
* @param[in] duration The duration of energy detection, in symbol unit (16 us).
* The result will be reported via esp_ieee802154_energy_detect_done().
*
* @return
* - ESP_OK on success.
* - ESP_FAIL on failure due to invalid state.
*
*/
esp_err_t esp_ieee802154_energy_detect(uint32_t duration);
/** Below are the events generated by IEEE 802.15.4 subsystem, which are in ISR context **/
/**
* @brief A Frame was received.
*
* @param[in] frame The point to the received frame, frame format:
* |-----------------------------------------------------------------------|
* | Len | MHR | MAC Payload (no FCS) |
* |-----------------------------------------------------------------------|
* @param[in] frame_info More information of the received frame, refer to esp_ieee802154_frame_info_t.
*
*/
extern void esp_ieee802154_receive_done(uint8_t *frame, esp_ieee802154_frame_info_t *frame_info);
/**
* @brief The SFD field of the frame was received.
*
*/
extern void esp_ieee802154_receive_sfd_done(void);
/**
* @brief The Frame Transmission succeeded.
*
* @param[in] frame The pointer to the transmitted frame.
* @param[in] ack The received ACK frame, it could be NULL if the transmitted frame's AR bit is not set.
* @param[in] ack_frame_info More information of the ACK frame, refer to esp_ieee802154_frame_info_t.
*
* Note: refer to esp_ieee802154_transmit().
*
*/
extern void esp_ieee802154_transmit_done(const uint8_t *frame, const uint8_t *ack, esp_ieee802154_frame_info_t *ack_frame_info);
/**
* @brief The Frame Transmission failed.
*
* @param[in] frame The pointer to the frame.
* @param[in] error The transmission failure reason, refer to esp_ieee802154_tx_error_t.
*
* Note: refer to esp_ieee802154_transmit().
*
*/
extern void esp_ieee802154_transmit_failed(const uint8_t *frame, esp_ieee802154_tx_error_t error);
/**
* @brief The SFD field of the frame was transmitted.
*
*/
extern void esp_ieee802154_transmit_sfd_done(uint8_t *frame);
/**
* @brief The energy detection done.
*
* @param[in] power The detected power level, in dBm.
*
* Note: refer to esp_ieee802154_energy_detect().
*
*/
extern void esp_ieee802154_energy_detect_done(int8_t power);
#ifdef __cplusplus
}
#endif