/
nrf_802154.c
1240 lines (974 loc) · 34.1 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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) 2018 - 2023, Nordic Semiconductor ASA
* All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*
* 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.
*
*/
#define NRF_802154_MODULE_ID NRF_802154_DRV_MODULE_ID_APPLICATION
#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_nrfx_addons.h"
#include "nrf_802154_pib.h"
#include "nrf_802154_request.h"
#include "nrf_802154_rx_buffer.h"
#include "nrf_802154_tx_power.h"
#include "nrf_802154_stats.h"
#include "hal/nrf_radio.h"
#include "platform/nrf_802154_clock.h"
#include "platform/nrf_802154_random.h"
#include "platform/nrf_802154_temperature.h"
#include "rsch/nrf_802154_rsch.h"
#include "rsch/nrf_802154_rsch_crit_sect.h"
#include "timer/nrf_802154_timer_coord.h"
#include "mac_features/nrf_802154_ack_timeout.h"
#include "mac_features/nrf_802154_delayed_trx.h"
#include "mac_features/nrf_802154_ie_writer.h"
#include "mac_features/nrf_802154_ifs.h"
#include "mac_features/nrf_802154_security_pib.h"
#include "mac_features/ack_generator/nrf_802154_ack_data.h"
#include "nrf_802154_sl_ant_div.h"
#include "nrf_802154_sl_crit_sect_if.h"
#include "nrf_802154_sl_capabilities.h"
#include "nrf_802154_sl_timer.h"
#if !NRF_802154_USE_RAW_API || NRF_802154_CARRIER_FUNCTIONS_ENABLED
/** 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];
#endif // !NRF_802154_USE_RAW_API || NRF_802154_CARRIER_FUNCTIONS_ENABLED
#if !NRF_802154_USE_RAW_API
/**
* @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
#if NRF_802154_CARRIER_FUNCTIONS_ENABLED
/**
* @brief Fill the transmit buffer with given data in order to use it with the
* modulated carrier functionality.
*
* @param[in] p_data Pointer to array containing modulating data.
*/
static void tx_buffer_fill_for_modulated_carrier(const uint8_t * p_data)
{
uint8_t length = p_data[RAW_LENGTH_OFFSET];
assert(length <= MAX_PACKET_SIZE);
memcpy(m_tx_buffer, p_data, RAW_PAYLOAD_OFFSET + length);
}
#endif // NRF_802154_CARRIER_FUNCTIONS_ENABLED
static inline bool are_frame_properties_valid(const nrf_802154_transmitted_frame_props_t * p_props)
{
return p_props->dynamic_data_is_set || !(p_props->is_secured);
}
void nrf_802154_channel_set(uint8_t channel)
{
bool changed = nrf_802154_pib_channel_get() != channel;
nrf_802154_pib_channel_set(channel);
if (changed)
{
(void)nrf_802154_request_channel_update(REQ_ORIG_HIGHER_LAYER);
}
}
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)
{
nrf_802154_fal_tx_power_split_t split_power = {0};
return nrf_802154_tx_power_split_pib_power_get(&split_power);
}
bool nrf_802154_coex_rx_request_mode_set(nrf_802154_coex_rx_request_mode_t mode)
{
return nrf_802154_pib_coex_rx_request_mode_set(mode);
}
nrf_802154_coex_rx_request_mode_t nrf_802154_coex_rx_request_mode_get(void)
{
return nrf_802154_pib_coex_rx_request_mode_get();
}
bool nrf_802154_coex_tx_request_mode_set(nrf_802154_coex_tx_request_mode_t mode)
{
return nrf_802154_pib_coex_tx_request_mode_set(mode);
}
nrf_802154_coex_tx_request_mode_t nrf_802154_coex_tx_request_mode_get(void)
{
return nrf_802154_pib_coex_tx_request_mode_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 nrf_802154_addons_dbm_from_energy_level_calculate(energy_level);
}
uint8_t nrf_802154_ccaedthres_from_dbm_calculate(int8_t dbm)
{
return dbm - ED_RSSIOFFS;
}
uint64_t nrf_802154_first_symbol_timestamp_get(uint64_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);
}
uint64_t nrf_802154_mhr_timestamp_get(uint64_t end_timestamp, uint8_t psdu_length)
{
return end_timestamp - (psdu_length * PHY_SYMBOLS_PER_OCTET * PHY_US_PER_SYMBOL);
}
void nrf_802154_init(void)
{
static const nrf_802154_sl_crit_sect_interface_t crit_sect_int =
{
.enter = nrf_802154_critical_section_enter,
.exit = nrf_802154_critical_section_exit
};
nrf_802154_ack_data_init();
nrf_802154_core_init();
nrf_802154_clock_init();
nrf_802154_critical_section_init();
nrf_802154_sl_crit_sect_init(&crit_sect_int);
nrf_802154_debug_init();
nrf_802154_notification_init();
nrf_802154_pib_init();
nrf_802154_security_pib_init();
nrf_802154_sl_timer_module_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();
#if NRF_802154_ACK_TIMEOUT_ENABLED
nrf_802154_ack_timeout_init();
#endif
#if NRF_802154_DELAYED_TRX_ENABLED
nrf_802154_delayed_trx_init();
#endif
#if NRF_802154_IFS_ENABLED
nrf_802154_ifs_init();
#endif
}
void nrf_802154_deinit(void)
{
nrf_802154_timer_coord_uninit();
nrf_802154_temperature_deinit();
nrf_802154_rsch_uninit();
nrf_802154_random_deinit();
nrf_802154_security_pib_deinit();
nrf_802154_sl_timer_module_uninit();
nrf_802154_clock_deinit();
nrf_802154_core_deinit();
#if NRF_802154_ACK_TIMEOUT_ENABLED
nrf_802154_ack_timeout_deinit();
#endif
#if NRF_802154_DELAYED_TRX_ENABLED
nrf_802154_delayed_trx_deinit();
#endif
#if NRF_802154_IFS_ENABLED
nrf_802154_ifs_deinit();
#endif
}
bool nrf_802154_antenna_diversity_rx_mode_set(nrf_802154_sl_ant_div_mode_t mode)
{
bool result = false;
#if defined(RADIO_INTENSET_SYNC_Msk)
result = nrf_802154_sl_ant_div_cfg_mode_set(NRF_802154_SL_ANT_DIV_OP_RX, mode);
#endif
if (result)
{
nrf_802154_request_antenna_update();
}
return result;
}
nrf_802154_sl_ant_div_mode_t nrf_802154_antenna_diversity_rx_mode_get(void)
{
return nrf_802154_sl_ant_div_cfg_mode_get(NRF_802154_SL_ANT_DIV_OP_RX);
}
bool nrf_802154_antenna_diversity_tx_mode_set(nrf_802154_sl_ant_div_mode_t mode)
{
bool result = false;
#if defined(RADIO_INTENSET_SYNC_Msk)
result = nrf_802154_sl_ant_div_cfg_mode_set(NRF_802154_SL_ANT_DIV_OP_TX, mode);
#endif
if (result)
{
nrf_802154_request_antenna_update();
}
return result;
}
nrf_802154_sl_ant_div_mode_t nrf_802154_antenna_diversity_tx_mode_get(void)
{
return nrf_802154_sl_ant_div_cfg_mode_get(NRF_802154_SL_ANT_DIV_OP_TX);
}
bool nrf_802154_antenna_diversity_rx_antenna_set(nrf_802154_sl_ant_div_antenna_t antenna)
{
bool result =
nrf_802154_sl_ant_div_cfg_antenna_set(NRF_802154_SL_ANT_DIV_OP_RX, antenna);
bool is_manual_mode = nrf_802154_sl_ant_div_cfg_mode_get(NRF_802154_SL_ANT_DIV_OP_RX) ==
NRF_802154_SL_ANT_DIV_MODE_MANUAL;
if (result && is_manual_mode)
{
nrf_802154_request_antenna_update();
}
return result;
}
nrf_802154_sl_ant_div_antenna_t nrf_802154_antenna_diversity_rx_antenna_get(void)
{
return nrf_802154_sl_ant_div_cfg_antenna_get(NRF_802154_SL_ANT_DIV_OP_RX);
}
bool nrf_802154_antenna_diversity_tx_antenna_set(nrf_802154_sl_ant_div_antenna_t antenna)
{
bool result =
nrf_802154_sl_ant_div_cfg_antenna_set(NRF_802154_SL_ANT_DIV_OP_TX, antenna);
bool is_manual_mode = nrf_802154_sl_ant_div_cfg_mode_get(NRF_802154_SL_ANT_DIV_OP_TX) ==
NRF_802154_SL_ANT_DIV_MODE_MANUAL;
if (result && is_manual_mode)
{
nrf_802154_request_antenna_update();
}
return result;
}
nrf_802154_sl_ant_div_antenna_t nrf_802154_antenna_diversity_tx_antenna_get(void)
{
return nrf_802154_sl_ant_div_cfg_antenna_get(NRF_802154_SL_ANT_DIV_OP_TX);
}
nrf_802154_sl_ant_div_antenna_t nrf_802154_antenna_diversity_last_rx_best_antenna_get(void)
{
return nrf_802154_sl_ant_div_last_rx_best_antenna_get();
}
void nrf_802154_antenna_diversity_config_set(const nrf_802154_sl_ant_div_cfg_t * p_cfg)
{
#if defined(RADIO_INTENSET_SYNC_Msk)
nrf_802154_sl_ant_div_cfg_set(p_cfg);
#endif
}
bool nrf_802154_antenna_diversity_config_get(nrf_802154_sl_ant_div_cfg_t * p_cfg)
{
return nrf_802154_sl_ant_div_cfg_get(p_cfg);
}
bool nrf_802154_antenna_diversity_init(void)
{
return nrf_802154_sl_ant_div_init();
}
void nrf_802154_antenna_diversity_timer_irq_handler(void)
{
#if defined(RADIO_INTENSET_SYNC_Msk)
nrf_802154_sl_ant_div_timer_irq_handle();
#endif
}
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;
#if NRF_802154_CARRIER_FUNCTIONS_ENABLED
case RADIO_STATE_CONTINUOUS_CARRIER:
return NRF_802154_STATE_CONTINUOUS_CARRIER;
case RADIO_STATE_MODULATED_CARRIER:
return NRF_802154_STATE_MODULATED_CARRIER;
#endif // NRF_802154_CARRIER_FUNCTIONS_ENABLED
}
return NRF_802154_STATE_INVALID;
}
bool nrf_802154_sleep(void)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_sleep(NRF_802154_TERM_802154);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
nrf_802154_sleep_error_t nrf_802154_sleep_if_idle(void)
{
nrf_802154_sleep_error_t result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result =
nrf_802154_request_sleep(NRF_802154_TERM_NONE) ? NRF_802154_SLEEP_ERROR_NONE :
NRF_802154_SLEEP_ERROR_BUSY;
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
bool nrf_802154_receive(void)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_receive(NRF_802154_TERM_802154,
REQ_ORIG_HIGHER_LAYER,
NULL,
true,
NRF_802154_RESERVED_IMM_RX_WINDOW_ID);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#if NRF_802154_USE_RAW_API
bool nrf_802154_transmit_raw(uint8_t * p_data,
const nrf_802154_transmit_metadata_t * p_metadata)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
if (p_metadata == NULL)
{
static const nrf_802154_transmit_metadata_t metadata_default =
{
.frame_props = NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT,
.cca = true,
.tx_power = {.use_metadata_value = false}
};
p_metadata = &metadata_default;
}
nrf_802154_transmit_params_t params =
{
.frame_props = p_metadata->frame_props,
.tx_power = {0},
.cca = p_metadata->cca,
.immediate = false
};
(void)nrf_802154_tx_power_convert_metadata_to_tx_power_split(nrf_802154_pib_channel_get(),
p_metadata->tx_power,
¶ms.tx_power);
result = are_frame_properties_valid(¶ms.frame_props);
if (result)
{
result = nrf_802154_request_transmit(NRF_802154_TERM_NONE,
REQ_ORIG_HIGHER_LAYER,
p_data,
¶ms,
NULL);
}
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#else // NRF_802154_USE_RAW_API
bool nrf_802154_transmit(const uint8_t * p_data,
uint8_t length,
const nrf_802154_transmit_metadata_t * p_metadata)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
if (p_metadata == NULL)
{
static const nrf_802154_transmit_metadata_t metadata_default =
{
.frame_props = NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT,
.cca = true,
.tx_power = {.use_metadata_value = false}
};
p_metadata = &metadata_default;
}
nrf_802154_transmit_params_t params =
{
.frame_props = p_metadata->frame_props,
.tx_power = {0},
.cca = p_metadata->cca,
.immediate = false
};
(void)nrf_802154_tx_power_convert_metadata_to_tx_power_split(nrf_802154_pib_channel_get(),
p_metadata->tx_power,
¶ms.tx_power);
result = are_frame_properties_valid(¶ms.frame_props);
if (result)
{
tx_buffer_fill(p_data, length);
result = nrf_802154_request_transmit(NRF_802154_TERM_NONE,
REQ_ORIG_HIGHER_LAYER,
m_tx_buffer,
¶ms,
NULL);
}
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#endif // NRF_802154_USE_RAW_API
#if NRF_802154_DELAYED_TRX_ENABLED
bool nrf_802154_transmit_raw_at(uint8_t * p_data,
uint64_t tx_time,
const nrf_802154_transmit_at_metadata_t * p_metadata)
{
bool result;
nrf_802154_transmit_at_metadata_t metadata_default =
{
.frame_props = NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT,
.cca = true,
.tx_power = {.use_metadata_value = false}
};
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
if (p_metadata == NULL)
{
metadata_default.channel = nrf_802154_channel_get();
p_metadata = &metadata_default;
}
result = are_frame_properties_valid(&p_metadata->frame_props);
if (result)
{
result = nrf_802154_request_transmit_raw_at(p_data, tx_time, p_metadata);
}
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
bool nrf_802154_transmit_at_cancel(void)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_transmit_at_cancel();
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
bool nrf_802154_receive_at(uint64_t rx_time,
uint32_t timeout,
uint8_t channel,
uint32_t id)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_receive_at(rx_time, timeout, channel, id);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
bool nrf_802154_receive_at_cancel(uint32_t id)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_receive_at_cancel(id);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#endif // NRF_802154_DELAYED_TRX_ENABLED
bool nrf_802154_energy_detection(uint32_t time_us)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_energy_detection(NRF_802154_TERM_NONE, time_us);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
bool nrf_802154_cca(void)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_cca(NRF_802154_TERM_NONE);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#if NRF_802154_CARRIER_FUNCTIONS_ENABLED
bool nrf_802154_continuous_carrier(void)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
result = nrf_802154_request_continuous_carrier(NRF_802154_TERM_NONE);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
bool nrf_802154_modulated_carrier(const uint8_t * p_data)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
tx_buffer_fill_for_modulated_carrier(p_data);
result = nrf_802154_request_modulated_carrier(NRF_802154_TERM_NONE, m_tx_buffer);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#endif // NRF_802154_CARRIER_FUNCTIONS_ENABLED
#if NRF_802154_USE_RAW_API
void nrf_802154_buffer_free_raw(uint8_t * p_data)
{
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)p_data;
assert(p_buffer->free == false);
(void)p_buffer;
result = nrf_802154_request_buffer_free(p_data);
assert(result);
(void)result;
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
}
bool nrf_802154_buffer_free_immediately_raw(uint8_t * p_data)
{
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)p_data;
assert(p_buffer->free == false);
(void)p_buffer;
result = nrf_802154_request_buffer_free(p_data);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#else // NRF_802154_USE_RAW_API
void nrf_802154_buffer_free(uint8_t * p_data)
{
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)(p_data - RAW_PAYLOAD_OFFSET);
assert(p_buffer->free == false);
(void)p_buffer;
result = nrf_802154_request_buffer_free(p_data - RAW_PAYLOAD_OFFSET);
assert(result);
(void)result;
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
}
bool nrf_802154_buffer_free_immediately(uint8_t * p_data)
{
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
bool result;
rx_buffer_t * p_buffer = (rx_buffer_t *)(p_data - RAW_PAYLOAD_OFFSET);
assert(p_buffer->free == false);
(void)p_buffer;
result = nrf_802154_request_buffer_free(p_data - RAW_PAYLOAD_OFFSET);
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
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);
}
void nrf_802154_src_addr_matching_method_set(nrf_802154_src_addr_match_t match_method)
{
nrf_802154_ack_data_src_addr_matching_method_set(match_method);
}
bool nrf_802154_ack_data_set(const uint8_t * p_addr,
bool extended,
const void * p_data,
uint16_t length,
nrf_802154_ack_data_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,
nrf_802154_ack_data_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
bool nrf_802154_transmit_csma_ca_raw(uint8_t * p_data,
const nrf_802154_transmit_csma_ca_metadata_t * p_metadata)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
if (p_metadata == NULL)
{
static const nrf_802154_transmit_csma_ca_metadata_t metadata_default =
{
.frame_props = NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT,
.tx_power = {.use_metadata_value = false}
};
p_metadata = &metadata_default;
}
result = are_frame_properties_valid(&p_metadata->frame_props);
if (result)
{
nrf_802154_request_csma_ca_start(p_data, p_metadata);
}
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#else // NRF_802154_USE_RAW_API
bool nrf_802154_transmit_csma_ca(const uint8_t * p_data,
uint8_t length,
const nrf_802154_transmit_csma_ca_metadata_t * p_metadata)
{
bool result;
nrf_802154_log_function_enter(NRF_802154_LOG_VERBOSITY_LOW);
if (p_metadata == NULL)
{
static const nrf_802154_transmit_csma_ca_metadata_t metadata_default =
{
.frame_props = NRF_802154_TRANSMITTED_FRAME_PROPS_DEFAULT_INIT,
.tx_power = {.use_metadata_value = false}
};
p_metadata = &metadata_default;
}
result = are_frame_properties_valid(&p_metadata->frame_props);
if (result)
{
tx_buffer_fill(p_data, length);
nrf_802154_request_csma_ca_start(m_tx_buffer, p_metadata);
}
nrf_802154_log_function_exit(NRF_802154_LOG_VERBOSITY_LOW);
return result;
}
#endif // NRF_802154_USE_RAW_API
bool nrf_802154_csma_ca_min_be_set(uint8_t min_be)
{
return nrf_802154_pib_csmaca_min_be_set(min_be);
}
uint8_t nrf_802154_csma_ca_min_be_get(void)
{
return nrf_802154_pib_csmaca_min_be_get();
}
bool nrf_802154_csma_ca_max_be_set(uint8_t max_be)
{
return nrf_802154_pib_csmaca_max_be_set(max_be);
}
uint8_t nrf_802154_csma_ca_max_be_get(void)
{
return nrf_802154_pib_csmaca_max_be_get();
}
void nrf_802154_csma_ca_max_backoffs_set(uint8_t max_backoffs)
{
nrf_802154_pib_csmaca_max_backoffs_set(max_backoffs);
}
uint8_t nrf_802154_csma_ca_max_backoffs_get(void)
{
return nrf_802154_pib_csmaca_max_backoffs_get();
}
#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
#if NRF_802154_IFS_ENABLED
nrf_802154_ifs_mode_t nrf_802154_ifs_mode_get(void)
{
return nrf_802154_pib_ifs_mode_get();
}
bool nrf_802154_ifs_mode_set(nrf_802154_ifs_mode_t mode)
{
return nrf_802154_pib_ifs_mode_set(mode);
}
uint16_t nrf_802154_ifs_min_sifs_period_get(void)
{
return nrf_802154_pib_ifs_min_sifs_period_get();
}
void nrf_802154_ifs_min_sifs_period_set(uint16_t period)
{