forked from hubertmis/nRF-IEEE-802.15.4-radio-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nrf_802154.c
837 lines (653 loc) · 22.7 KB
/
nrf_802154.c
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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
/* Copyright (c) 2017 - 2019, Nordic Semiconductor ASA
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of Nordic Semiconductor ASA nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/**
* @file
* This file implements the nrf 802.15.4 radio driver.
*
*/
#include "nrf_802154.h"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "nrf_802154_config.h"
#include "nrf_802154_const.h"
#include "nrf_802154_core.h"
#include "nrf_802154_critical_section.h"
#include "nrf_802154_debug.h"
#include "nrf_802154_notification.h"
#include "nrf_802154_pib.h"
#include "nrf_802154_priority_drop.h"
#include "nrf_802154_request.h"
#include "nrf_802154_rssi.h"
#include "nrf_802154_rx_buffer.h"
#include "nrf_802154_timer_coord.h"
#include "nrf_radio.h"
#include "platform/clock/nrf_802154_clock.h"
#include "platform/lp_timer/nrf_802154_lp_timer.h"
#include "platform/random/nrf_802154_random.h"
#include "platform/temperature/nrf_802154_temperature.h"
#include "rsch/nrf_802154_rsch.h"
#include "rsch/nrf_802154_rsch_crit_sect.h"
#include "timer_scheduler/nrf_802154_timer_sched.h"
#include "mac_features/nrf_802154_ack_timeout.h"
#include "mac_features/nrf_802154_csma_ca.h"
#include "mac_features/nrf_802154_delayed_trx.h"
#include "mac_features/ack_generator/nrf_802154_ack_data.h"
#if ENABLE_FEM
#include "fem/nrf_fem_protocol_api.h"
#endif
#define RAW_LENGTH_OFFSET 0
#define RAW_PAYLOAD_OFFSET 1
#if !NRF_802154_USE_RAW_API
/** Static transmit buffer used by @sa nrf_802154_transmit() family of functions.
*
* If none of functions using this buffer is called and link time optimization is enabled, this
* buffer should be removed by linker.
*/
static uint8_t m_tx_buffer[RAW_PAYLOAD_OFFSET + MAX_PACKET_SIZE];
/**
* @brief Fill transmit buffer with given data.
*
* @param[in] p_data Pointer to array containing payload of a data to transmit. The array
* should exclude PHR or FCS fields of 802.15.4 frame.
* @param[in] length Length of given frame. This value shall exclude PHR and FCS fields from
* the given frame (exact size of buffer pointed by @p p_data).
*/
static void tx_buffer_fill(const uint8_t * p_data, uint8_t length)
{
assert(length <= MAX_PACKET_SIZE - FCS_SIZE);
m_tx_buffer[RAW_LENGTH_OFFSET] = length + FCS_SIZE;
memcpy(&m_tx_buffer[RAW_PAYLOAD_OFFSET], p_data, length);
}
#endif // !NRF_802154_USE_RAW_API
/**
* @brief Get timestamp of the last received frame.
*
* @note This function increments the returned value by 1 us if the timestamp is equal to the
* @ref NRF_802154_NO_TIMESTAMP value to indicate that the timestamp is available.
*
* @returns Timestamp [us] of the last received frame or @ref NRF_802154_NO_TIMESTAMP if
* the timestamp is inaccurate.
*/
static uint32_t last_rx_frame_timestamp_get(void)
{
#if NRF_802154_FRAME_TIMESTAMP_ENABLED
uint32_t timestamp;
bool timestamp_received = nrf_802154_timer_coord_timestamp_get(×tamp);
if (!timestamp_received)
{
timestamp = NRF_802154_NO_TIMESTAMP;
}
else
{
if (timestamp == NRF_802154_NO_TIMESTAMP)
{
timestamp++;
}
}
return timestamp;
#else // NRF_802154_FRAME_TIMESTAMP_ENABLED
return NRF_802154_NO_TIMESTAMP;
#endif // NRF_802154_FRAME_TIMESTAMP_ENABLED
}
void nrf_802154_channel_set(uint8_t channel)
{
bool changed = nrf_802154_pib_channel_get() != channel;
nrf_802154_pib_channel_set(channel);
if (changed)
{
nrf_802154_request_channel_update();
}
}
uint8_t nrf_802154_channel_get(void)
{
return nrf_802154_pib_channel_get();
}
void nrf_802154_tx_power_set(int8_t power)
{
nrf_802154_pib_tx_power_set(power);
}
int8_t nrf_802154_tx_power_get(void)
{
return nrf_802154_pib_tx_power_get();
}
void nrf_802154_temperature_changed(void)
{
nrf_802154_request_cca_cfg_update();
}
void nrf_802154_pan_id_set(const uint8_t * p_pan_id)
{
nrf_802154_pib_pan_id_set(p_pan_id);
}
void nrf_802154_extended_address_set(const uint8_t * p_extended_address)
{
nrf_802154_pib_extended_address_set(p_extended_address);
}
void nrf_802154_short_address_set(const uint8_t * p_short_address)
{
nrf_802154_pib_short_address_set(p_short_address);
}
int8_t nrf_802154_dbm_from_energy_level_calculate(uint8_t energy_level)
{
return ED_MIN_DBM + (energy_level / ED_RESULT_FACTOR);
}
uint8_t nrf_802154_ccaedthres_from_dbm_calculate(int8_t dbm)
{
return dbm - ED_MIN_DBM;
}
uint32_t nrf_802154_first_symbol_timestamp_get(uint32_t end_timestamp, uint8_t psdu_length)
{
uint32_t frame_symbols = PHY_SHR_SYMBOLS;
frame_symbols += (PHR_SIZE + psdu_length) * PHY_SYMBOLS_PER_OCTET;
return end_timestamp - (frame_symbols * PHY_US_PER_SYMBOL);
}
void nrf_802154_init(void)
{
nrf_802154_ack_data_init();
nrf_802154_core_init();
nrf_802154_clock_init();
nrf_802154_critical_section_init();
nrf_802154_debug_init();
nrf_802154_notification_init();
nrf_802154_lp_timer_init();
nrf_802154_pib_init();
nrf_802154_priority_drop_init();
nrf_802154_random_init();
nrf_802154_request_init();
nrf_802154_rsch_crit_sect_init();
nrf_802154_rsch_init();
nrf_802154_rx_buffer_init();
nrf_802154_temperature_init();
nrf_802154_timer_coord_init();
nrf_802154_timer_sched_init();
}
void nrf_802154_deinit(void)
{
nrf_802154_timer_sched_deinit();
nrf_802154_timer_coord_uninit();
nrf_802154_temperature_deinit();
nrf_802154_rsch_uninit();
nrf_802154_random_deinit();
nrf_802154_lp_timer_deinit();
nrf_802154_clock_deinit();
nrf_802154_core_deinit();
}
#if !NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
void nrf_802154_radio_irq_handler(void)
{
nrf_802154_core_irq_handler();
}
#endif // !NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
#if ENABLE_FEM
void nrf_802154_fem_control_cfg_set(nrf_802154_fem_control_cfg_t const * const p_cfg)
{
nrf_fem_interface_config_t config;
nrf_fem_interface_configuration_get(&config);
config.lna_pin_config.active_high = p_cfg->lna_cfg.active_high;
config.lna_pin_config.enable = p_cfg->lna_cfg.enable;
config.lna_pin_config.gpio_pin = p_cfg->lna_cfg.gpio_pin;
config.lna_pin_config.gpiote_ch_id = p_cfg->lna_gpiote_ch_id;
config.pa_pin_config.active_high = p_cfg->pa_cfg.active_high;
config.pa_pin_config.enable = p_cfg->pa_cfg.enable;
config.pa_pin_config.gpio_pin = p_cfg->pa_cfg.gpio_pin;
config.pa_pin_config.gpiote_ch_id = p_cfg->pa_gpiote_ch_id;
config.ppi_ch_id_set = p_cfg->ppi_ch_id_set;
config.ppi_ch_id_clr = p_cfg->ppi_ch_id_clr;
nrf_fem_interface_configuration_set(&config);
}
void nrf_802154_fem_control_cfg_get(nrf_802154_fem_control_cfg_t * p_cfg)
{
nrf_fem_interface_config_t config;
nrf_fem_interface_configuration_get(&config);
p_cfg->lna_cfg.active_high = config.lna_pin_config.active_high;
p_cfg->lna_cfg.enable = config.lna_pin_config.enable;
p_cfg->lna_cfg.gpio_pin = config.lna_pin_config.gpio_pin;
p_cfg->pa_cfg.active_high = config.pa_pin_config.active_high;
p_cfg->pa_cfg.enable = config.pa_pin_config.enable;
p_cfg->pa_cfg.gpio_pin = config.pa_pin_config.gpio_pin;
p_cfg->lna_gpiote_ch_id = config.lna_pin_config.gpiote_ch_id;
p_cfg->pa_gpiote_ch_id = config.pa_pin_config.gpiote_ch_id;
p_cfg->ppi_ch_id_clr = config.ppi_ch_id_clr;
p_cfg->ppi_ch_id_set = config.ppi_ch_id_set;
}
#endif // ENABLE_FEM
nrf_802154_state_t nrf_802154_state_get(void)
{
switch (nrf_802154_core_state_get())
{
case RADIO_STATE_SLEEP:
case RADIO_STATE_FALLING_ASLEEP:
return NRF_802154_STATE_SLEEP;
case RADIO_STATE_RX:
case RADIO_STATE_TX_ACK:
return NRF_802154_STATE_RECEIVE;
case RADIO_STATE_CCA_TX:
case RADIO_STATE_TX:
case RADIO_STATE_RX_ACK:
return NRF_802154_STATE_TRANSMIT;
case RADIO_STATE_ED:
return NRF_802154_STATE_ENERGY_DETECTION;
case RADIO_STATE_CCA:
return NRF_802154_STATE_CCA;
case RADIO_STATE_CONTINUOUS_CARRIER:
return NRF_802154_STATE_CONTINUOUS_CARRIER;
}
return NRF_802154_STATE_INVALID;
}
bool nrf_802154_sleep(void)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_SLEEP);
result = nrf_802154_request_sleep(NRF_802154_TERM_802154);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_SLEEP);
return result;
}
nrf_802154_sleep_error_t nrf_802154_sleep_if_idle(void)
{
nrf_802154_sleep_error_t result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_SLEEP);
result =
nrf_802154_request_sleep(NRF_802154_TERM_NONE) ? NRF_802154_SLEEP_ERROR_NONE :
NRF_802154_SLEEP_ERROR_BUSY;
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_SLEEP);
return result;
}
bool nrf_802154_receive(void)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_RECEIVE);
result = nrf_802154_request_receive(NRF_802154_TERM_802154, REQ_ORIG_HIGHER_LAYER, NULL, true);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_RECEIVE);
return result;
}
#if NRF_802154_USE_RAW_API
bool nrf_802154_transmit_raw(const uint8_t * p_data, bool cca)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_TRANSMIT);
result = nrf_802154_request_transmit(NRF_802154_TERM_NONE,
REQ_ORIG_HIGHER_LAYER,
p_data,
cca,
false,
NULL);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_TRANSMIT);
return result;
}
#else // NRF_802154_USE_RAW_API
bool nrf_802154_transmit(const uint8_t * p_data, uint8_t length, bool cca)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_TRANSMIT);
tx_buffer_fill(p_data, length);
result = nrf_802154_request_transmit(NRF_802154_TERM_NONE,
REQ_ORIG_HIGHER_LAYER,
m_tx_buffer,
cca,
false,
NULL);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_TRANSMIT);
return result;
}
#endif // NRF_802154_USE_RAW_API
bool nrf_802154_transmit_raw_at(const uint8_t * p_data,
bool cca,
uint32_t t0,
uint32_t dt,
uint8_t channel)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_TRANSMIT_AT);
result = nrf_802154_delayed_trx_transmit(p_data, cca, t0, dt, channel);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_TRANSMIT_AT);
return result;
}
bool nrf_802154_transmit_at_cancel(void)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_TRANSMIT_AT_CANCEL);
result = nrf_802154_delayed_trx_transmit_cancel();
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_TRANSMIT_AT_CANCEL);
return result;
}
bool nrf_802154_receive_at(uint32_t t0,
uint32_t dt,
uint32_t timeout,
uint8_t channel)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_RECEIVE_AT);
result = nrf_802154_delayed_trx_receive(t0, dt, timeout, channel);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_RECEIVE_AT);
return result;
}
bool nrf_802154_receive_at_cancel(void)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_RECEIVE_AT_CANCEL);
result = nrf_802154_delayed_trx_receive_cancel();
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_RECEIVE_AT_CANCEL);
return result;
}
bool nrf_802154_energy_detection(uint32_t time_us)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_ENERGY_DETECTION);
result = nrf_802154_request_energy_detection(NRF_802154_TERM_NONE, time_us);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_ENERGY_DETECTION);
return result;
}
bool nrf_802154_cca(void)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_CCA);
result = nrf_802154_request_cca(NRF_802154_TERM_NONE);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_CCA);
return result;
}
bool nrf_802154_continuous_carrier(void)
{
bool result;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_CONTINUOUS_CARRIER);
result = nrf_802154_request_continuous_carrier(NRF_802154_TERM_NONE);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_CONTINUOUS_CARRIER);
return result;
}
#if NRF_802154_USE_RAW_API
void nrf_802154_buffer_free_raw(uint8_t * p_data)
{
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)p_data;
assert(p_buffer->free == false);
(void)p_buffer;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_BUFFER_FREE);
result = nrf_802154_request_buffer_free(p_data);
assert(result);
(void)result;
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_BUFFER_FREE);
}
bool nrf_802154_buffer_free_immediately_raw(uint8_t * p_data)
{
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)p_data;
assert(p_buffer->free == false);
(void)p_buffer;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_BUFFER_FREE);
result = nrf_802154_request_buffer_free(p_data);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_BUFFER_FREE);
return result;
}
#else // NRF_802154_USE_RAW_API
void nrf_802154_buffer_free(uint8_t * p_data)
{
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)(p_data - RAW_PAYLOAD_OFFSET);
assert(p_buffer->free == false);
(void)p_buffer;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_BUFFER_FREE);
result = nrf_802154_request_buffer_free(p_data - RAW_PAYLOAD_OFFSET);
assert(result);
(void)result;
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_BUFFER_FREE);
}
bool nrf_802154_buffer_free_immediately(uint8_t * p_data)
{
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)(p_data - RAW_PAYLOAD_OFFSET);
assert(p_buffer->free == false);
(void)p_buffer;
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_BUFFER_FREE);
result = nrf_802154_request_buffer_free(p_data - RAW_PAYLOAD_OFFSET);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_BUFFER_FREE);
return result;
}
#endif // NRF_802154_USE_RAW_API
bool nrf_802154_rssi_measure_begin(void)
{
return nrf_802154_request_rssi_measure();
}
int8_t nrf_802154_rssi_last_get(void)
{
int8_t result = 0;
if (!nrf_802154_request_rssi_measurement_get(&result))
{
result = NRF_802154_RSSI_INVALID;
}
return result;
}
bool nrf_802154_promiscuous_get(void)
{
return nrf_802154_pib_promiscuous_get();
}
void nrf_802154_promiscuous_set(bool enabled)
{
nrf_802154_pib_promiscuous_set(enabled);
}
void nrf_802154_auto_ack_set(bool enabled)
{
nrf_802154_pib_auto_ack_set(enabled);
}
bool nrf_802154_auto_ack_get(void)
{
return nrf_802154_pib_auto_ack_get();
}
bool nrf_802154_pan_coord_get(void)
{
return nrf_802154_pib_pan_coord_get();
}
void nrf_802154_pan_coord_set(bool enabled)
{
nrf_802154_pib_pan_coord_set(enabled);
}
bool nrf_802154_ack_data_set(const uint8_t * p_addr,
bool extended,
const void * p_data,
uint16_t length,
uint8_t data_type)
{
return nrf_802154_ack_data_for_addr_set(p_addr, extended, data_type, p_data, length);
}
bool nrf_802154_ack_data_clear(const uint8_t * p_addr, bool extended, uint8_t data_type)
{
return nrf_802154_ack_data_for_addr_clear(p_addr, extended, data_type);
}
void nrf_802154_auto_pending_bit_set(bool enabled)
{
nrf_802154_ack_data_enable(enabled);
}
bool nrf_802154_pending_bit_for_addr_set(const uint8_t * p_addr, bool extended)
{
return nrf_802154_ack_data_for_addr_set(p_addr,
extended,
NRF_802154_ACK_DATA_PENDING_BIT,
NULL,
0);
}
bool nrf_802154_pending_bit_for_addr_clear(const uint8_t * p_addr, bool extended)
{
return nrf_802154_ack_data_for_addr_clear(p_addr, extended, NRF_802154_ACK_DATA_PENDING_BIT);
}
void nrf_802154_pending_bit_for_addr_reset(bool extended)
{
nrf_802154_ack_data_reset(extended, NRF_802154_ACK_DATA_PENDING_BIT);
}
void nrf_802154_cca_cfg_set(const nrf_802154_cca_cfg_t * p_cca_cfg)
{
nrf_802154_pib_cca_cfg_set(p_cca_cfg);
nrf_802154_request_cca_cfg_update();
}
void nrf_802154_cca_cfg_get(nrf_802154_cca_cfg_t * p_cca_cfg)
{
nrf_802154_pib_cca_cfg_get(p_cca_cfg);
}
#if NRF_802154_CSMA_CA_ENABLED
#if NRF_802154_USE_RAW_API
void nrf_802154_transmit_csma_ca_raw(const uint8_t * p_data)
{
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_CSMACA);
nrf_802154_csma_ca_start(p_data);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_CSMACA);
}
#else // NRF_802154_USE_RAW_API
void nrf_802154_transmit_csma_ca(const uint8_t * p_data, uint8_t length)
{
nrf_802154_log(EVENT_TRACE_ENTER, FUNCTION_CSMACA);
tx_buffer_fill(p_data, length);
nrf_802154_csma_ca_start(m_tx_buffer);
nrf_802154_log(EVENT_TRACE_EXIT, FUNCTION_CSMACA);
}
#endif // NRF_802154_USE_RAW_API
#endif // NRF_802154_CSMA_CA_ENABLED
#if NRF_802154_ACK_TIMEOUT_ENABLED
void nrf_802154_ack_timeout_set(uint32_t time)
{
nrf_802154_ack_timeout_time_set(time);
}
#endif // NRF_802154_ACK_TIMEOUT_ENABLED
__WEAK void nrf_802154_tx_ack_started(const uint8_t * p_data)
{
(void)p_data;
}
#if NRF_802154_USE_RAW_API
__WEAK void nrf_802154_received_raw(uint8_t * p_data, int8_t power, uint8_t lqi)
{
nrf_802154_received_timestamp_raw(p_data, power, lqi, last_rx_frame_timestamp_get());
}
__WEAK void nrf_802154_received_timestamp_raw(uint8_t * p_data,
int8_t power,
uint8_t lqi,
uint32_t time)
{
(void)power;
(void)lqi;
(void)time;
nrf_802154_buffer_free_raw(p_data);
}
#else // NRF_802154_USE_RAW_API
__WEAK void nrf_802154_received(uint8_t * p_data, uint8_t length, int8_t power, uint8_t lqi)
{
nrf_802154_received_timestamp(p_data, length, power, lqi, last_rx_frame_timestamp_get());
}
__WEAK void nrf_802154_received_timestamp(uint8_t * p_data,
uint8_t length,
int8_t power,
uint8_t lqi,
uint32_t time)
{
(void)length;
(void)power;
(void)lqi;
(void)time;
nrf_802154_buffer_free(p_data);
}
#endif // !NRF_802154_USE_RAW_API
__WEAK void nrf_802154_receive_failed(nrf_802154_rx_error_t error)
{
(void)error;
}
__WEAK void nrf_802154_tx_started(const uint8_t * p_frame)
{
(void)p_frame;
}
#if NRF_802154_USE_RAW_API
__WEAK void nrf_802154_transmitted_raw(const uint8_t * p_frame,
uint8_t * p_ack,
int8_t power,
uint8_t lqi)
{
uint32_t timestamp = (p_ack == NULL) ? NRF_802154_NO_TIMESTAMP : last_rx_frame_timestamp_get();
nrf_802154_transmitted_timestamp_raw(p_frame, p_ack, power, lqi, timestamp);
}
__WEAK void nrf_802154_transmitted_timestamp_raw(const uint8_t * p_frame,
uint8_t * p_ack,
int8_t power,
uint8_t lqi,
uint32_t time)
{
(void)p_frame;
(void)power;
(void)lqi;
(void)time;
if (p_ack != NULL)
{
nrf_802154_buffer_free_raw(p_ack);
}
}
#else // NRF_802154_USE_RAW_API
__WEAK void nrf_802154_transmitted(const uint8_t * p_frame,
uint8_t * p_ack,
uint8_t length,
int8_t power,
uint8_t lqi)
{
uint32_t timestamp = (p_ack == NULL) ? NRF_802154_NO_TIMESTAMP : last_rx_frame_timestamp_get();
nrf_802154_transmitted_timestamp(p_frame, p_ack, length, power, lqi, timestamp);
}
__WEAK void nrf_802154_transmitted_timestamp(const uint8_t * p_frame,
uint8_t * p_ack,
uint8_t length,
int8_t power,
uint8_t lqi,
uint32_t time)
{
(void)p_frame;
(void)length;
(void)power;
(void)lqi;
(void)time;
if (p_ack != NULL)
{
nrf_802154_buffer_free(p_ack);
}
}
#endif // NRF_802154_USE_RAW_API
__WEAK void nrf_802154_transmit_failed(const uint8_t * p_frame, nrf_802154_tx_error_t error)
{
(void)p_frame;
(void)error;
}
__WEAK void nrf_802154_energy_detected(uint8_t result)
{
(void)result;
}
__WEAK void nrf_802154_energy_detection_failed(nrf_802154_ed_error_t error)
{
(void)error;
}
__WEAK void nrf_802154_cca_done(bool channel_free)
{
(void)channel_free;
}
__WEAK void nrf_802154_cca_failed(nrf_802154_cca_error_t error)
{
(void)error;
}