1 /*
2  * Copyright (c) 2017, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright notice, this
11  *    list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
18  *    contributors may be used to endorse or promote products derived from this
19  *    software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34 
35 #ifndef NRF_802154_CONFIG_H__
36 #define NRF_802154_CONFIG_H__
37 
38 #ifdef NRF_802154_PROJECT_CONFIG
39 #include NRF_802154_PROJECT_CONFIG
40 #endif
41 
42 #include <nrfx.h>
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
48 /**
49  * @defgroup nrf_802154_config 802.15.4 driver configuration
50  * @{
51  * @ingroup nrf_802154
52  * @brief Configuration of the 802.15.4 radio driver for nRF SoCs.
53  */
54 
55 /**
56  * @defgroup nrf_802154_config_radio Radio driver configuration
57  * @{
58  */
59 
60 /**
61  * @def NRF_802154_CCA_MODE_DEFAULT
62  *
63  * CCA mode used by the driver.
64  *
65  */
66 #ifndef NRF_802154_CCA_MODE_DEFAULT
67 #define NRF_802154_CCA_MODE_DEFAULT NRF_RADIO_CCA_MODE_ED
68 #endif
69 
70 /**
71  * @def NRF_802154_CCA_ED_THRESHOLD_DEFAULT
72  *
73  * Energy detection threshold used in the CCA procedure.
74  *
75  */
76 #ifndef NRF_802154_CCA_ED_THRESHOLD_DEFAULT
77 #define NRF_802154_CCA_ED_THRESHOLD_DEFAULT 0x14
78 #endif
79 
80 /**
81  * @def NRF_802154_CCA_CORR_THRESHOLD_DEFAULT
82  *
83  * Correlator threshold used in the CCA procedure.
84  *
85  */
86 #ifndef NRF_802154_CCA_CORR_THRESHOLD_DEFAULT
87 #define NRF_802154_CCA_CORR_THRESHOLD_DEFAULT 0x14
88 #endif
89 
90 /**
91  * @def NRF_802154_CCA_CORR_LIMIT_DEFAULT
92  *
93  * Correlator limit used in the CCA procedure.
94  *
95  */
96 #ifndef NRF_802154_CCA_CORR_LIMIT_DEFAULT
97 #define NRF_802154_CCA_CORR_LIMIT_DEFAULT 0x02
98 #endif
99 
100 /**
101  * @def NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
102  *
103  * If the driver is expected to internally handle the RADIO IRQ.
104  * If the driver is used in an OS, the RADIO IRQ can be handled by the OS and passed to
105  * the driver by @ref nrf_802154_radio_irq_handler.
106  * In this case, the internal handling must be disabled.
107  *
108  */
109 #ifndef NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
110 #define NRF_802154_INTERNAL_RADIO_IRQ_HANDLING 0
111 #endif
112 
113 /**
114  * @def NRF_802154_INTERNAL_SWI_IRQ_HANDLING
115  *
116  * If the driver is expected to internally handle the SWI IRQ.
117  * If the driver is used in an OS, the SWI IRQ can be handled by the OS and passed to
118  * the driver by @ref nrf_802154_swi_irq_handler.
119  * In this case, the internal handling must be disabled.
120  *
121  */
122 #ifndef NRF_802154_INTERNAL_SWI_IRQ_HANDLING
123 #define NRF_802154_INTERNAL_SWI_IRQ_HANDLING 1
124 #endif
125 
126 /**
127  * @def NRF_802154_IRQ_PRIORITY
128  *
129  * Interrupt priority for RADIO peripheral.
130  * Keep the IRQ priority high (low number) to prevent losing frames due to preemption.
131  *
132  */
133 #ifndef NRF_802154_IRQ_PRIORITY
134 #define NRF_802154_IRQ_PRIORITY 0
135 #endif
136 
137 /**
138  * @def NRF_802154_SWI_PRIORITY
139  *
140  * The priority of software interrupt used for requests and notifications.
141  *
142  */
143 #ifndef NRF_802154_SWI_PRIORITY
144 #define NRF_802154_SWI_PRIORITY 4
145 #endif
146 
147 /**
148  * @def NRF_802154_ECB_PRIORITY
149  *
150  * Interrupt priority for ECB peripheral used for frame encryption.
151  *
152  */
153 #ifndef NRF_802154_ECB_PRIORITY
154 #define NRF_802154_ECB_PRIORITY 3
155 #endif
156 
157 /**
158  * @def NRF_802154_PENDING_SHORT_ADDRESSES
159  *
160  * The number of slots containing short addresses of nodes for which the pending data is stored.
161  *
162  */
163 #ifndef NRF_802154_PENDING_SHORT_ADDRESSES
164 #define NRF_802154_PENDING_SHORT_ADDRESSES 10
165 #endif
166 
167 /**
168  * @def NRF_802154_PENDING_EXTENDED_ADDRESSES
169  *
170  * The number of slots containing extended addresses of nodes for which the pending data is stored.
171  *
172  */
173 #ifndef NRF_802154_PENDING_EXTENDED_ADDRESSES
174 #define NRF_802154_PENDING_EXTENDED_ADDRESSES 10
175 #endif
176 
177 /**
178  * @def NRF_802154_RX_BUFFERS
179  *
180  * The number of buffers in the receive queue.
181  *
182  */
183 #ifndef NRF_802154_RX_BUFFERS
184 #define NRF_802154_RX_BUFFERS 16
185 #endif
186 
187 /**
188  * @def NRF_802154_MAX_DISREGARDABLE_NOTIFICATIONS
189  *
190  * The number of slots in the driver's notification queue intended for notifications that can be
191  * disregarded with no impact on the driver, for instance failed reception notifications.
192  *
193  * @note Setting this macro to 0 will cause the driver to not issue any disregardable notifications.
194  */
195 #ifndef NRF_802154_MAX_DISREGARDABLE_NOTIFICATIONS
196 #define NRF_802154_MAX_DISREGARDABLE_NOTIFICATIONS 4
197 #endif
198 
199 /**
200  * @def NRF_802154_NOTIFY_CRCERROR
201  *
202  * With this flag set to 1, the CRC errors are notified to upper layers. This requires an interrupt
203  * handler to be used.
204  *
205  */
206 #ifndef NRF_802154_NOTIFY_CRCERROR
207 #define NRF_802154_NOTIFY_CRCERROR 1
208 #endif
209 
210 /**
211  * @def NRF_802154_FRAME_TIMESTAMP_ENABLED
212  *
213  * If timestamps are to be added to the frames received.
214  * Enabling this feature enables the function @ref nrf_802154_received_timestamp_raw,
215  * which add timestamps to the frames received.
216  * Enables also proper value of frame timestamp
217  * ( @c nrf_802154_transmit_done_metadata_t::data.transmitted.time ) passed as metadata to
218  * @ref nrf_802154_transmitted_raw .
219  * This option also enables timestamping in stats.
220  *
221  */
222 #ifndef NRF_802154_FRAME_TIMESTAMP_ENABLED
223 #define NRF_802154_FRAME_TIMESTAMP_ENABLED 1
224 #endif
225 
226 /**
227  * @def NRF_802154_DELAYED_TRX_ENABLED
228  *
229  * If the delayed transmission and the receive window features are available.
230  *
231  */
232 #if !defined(CONFIG_NRF_802154_SL_OPENSOURCE)
233 #ifndef NRF_802154_DELAYED_TRX_ENABLED
234 #define NRF_802154_DELAYED_TRX_ENABLED 1
235 #endif
236 #endif
237 
238 /**
239  * @def NRF_802154_TEST_MODES_ENABLED
240  *
241  * Enables test modes. Test modes are normally disabled in end products.
242  * When @ref NRF_802154_TEST_MODES_ENABLED is set to 1, nRF 802.15.4 Radio Driver
243  * provides additional API to enable certain test modes. Setting
244  * @ref NRF_802154_TEST_MODES_ENABLED to 1 without using test mode API does not
245  * change any behavior of the Radio Driver.
246  */
247 #ifndef NRF_802154_TEST_MODES_ENABLED
248 #define NRF_802154_TEST_MODES_ENABLED 0
249 #endif
250 
251 /**
252  * @def NRF_802154_PAN_COORD_GET_ENABLED
253  *
254  * Enables the @ref nrf_802154_pan_coord_get function.
255  */
256 #ifndef NRF_802154_PAN_COORD_GET_ENABLED
257 #define NRF_802154_PAN_COORD_GET_ENABLED 0
258 #endif
259 
260 /**
261  * @}
262  * @defgroup nrf_802154_config_csma CSMA/CA procedure configuration
263  * @{
264  */
265 
266 /**
267  * @def NRF_802154_CSMA_CA_ENABLED
268  *
269  * If CSMA-CA is to be enabled by the driver. Disabling CSMA-CA improves
270  * the driver performance.
271  *
272  */
273 #if !defined(CONFIG_NRF_802154_SL_OPENSOURCE)
274 #ifndef NRF_802154_CSMA_CA_ENABLED
275 #define NRF_802154_CSMA_CA_ENABLED 1
276 #endif
277 #endif
278 
279 /**
280  * @def NRF_802154_CSMA_CA_MIN_BE_DEFAULT
281  *
282  * The default minimum value of the backoff exponent (BE) in the CSMA-CA algorithm
283  * (see IEEE 802.15.4-2015: 6.2.5.1).
284  *
285  * @note The minimum value of the backoff exponent may be changed from default by calling the
286  *       @ref nrf_802154_csma_ca_min_be_set function.
287  *
288  */
289 #ifdef NRF_802154_CSMA_CA_MIN_BE
290 #error "NRF_802154_CSMA_CA_MIN_BE was replaced with NRF_802154_CSMA_CA_MIN_BE_DEFAULT"
291 #endif
292 #ifndef NRF_802154_CSMA_CA_MIN_BE_DEFAULT
293 #define NRF_802154_CSMA_CA_MIN_BE_DEFAULT 3
294 #endif
295 
296 /**
297  * @def NRF_802154_CSMA_CA_MAX_BE_DEFAULT
298  *
299  * The default maximum value of the backoff exponent, BE, in the CSMA-CA algorithm
300  * (see IEEE 802.15.4-2015: 6.2.5.1).
301  *
302  * @note The maximum value of the backoff exponent may be changed from default by calling the
303  *       @ref nrf_802154_csma_ca_max_be_set function.
304  *
305  */
306 #ifdef NRF_802154_CSMA_CA_MAX_BE
307 #error "NRF_802154_CSMA_CA_MAX_BE was replaced with NRF_802154_CSMA_CA_MAX_BE_DEFAULT"
308 #endif
309 #ifndef NRF_802154_CSMA_CA_MAX_BE_DEFAULT
310 #define NRF_802154_CSMA_CA_MAX_BE_DEFAULT 5
311 #endif
312 
313 /**
314  * @def NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT
315  *
316  * The default maximum number of backoffs that the CSMA-CA algorithm will attempt before declaring
317  * a channel access failure.
318  *
319  * @note The maximum number of backoffs may be changed from default by calling the
320  *       @ref nrf_802154_csma_ca_max_backoffs_set function.
321  *
322  */
323 #ifdef NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS
324 #error \
325     "NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS was replaced with NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT"
326 #endif
327 #ifndef NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT
328 #define NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT 4
329 #endif
330 
331 /**
332  * @def NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT
333  *
334  * Indicates whether the CSMA-CA algorithm waits for an available timeslot before it performs
335  * the CCA procedure.
336  *
337  * @note When this option is enabled, the CSMA-CA procedure can be synchronized with timeslots of
338  *       other protocols. This decreases the robustness of the CSMA-CA procedure. On the other hand,
339  *       enabling this function increases the performance of multi-protocol applications, especially
340  *       when protocols other than 802.15.4 use much of the radio time (like the BLE scanning
341  *       operation).
342  *
343  */
344 #ifndef NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT
345 #define NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT 1
346 #endif
347 
348 /**
349  * @}
350  * @defgroup nrf_802154_config_timeout ACK timeout feature configuration
351  * @{
352  */
353 
354 /**
355  * @def NRF_802154_ACK_TIMEOUT_ENABLED
356  *
357  * Indicates whether the ACK timeout feature is to be enabled in the driver.
358  *
359  */
360 #ifndef NRF_802154_ACK_TIMEOUT_ENABLED
361 #define NRF_802154_ACK_TIMEOUT_ENABLED 1
362 #endif
363 
364 /**
365  * @def NRF_802154_ACK_TIMEOUT_DEFAULT_TIMEOUT
366  *
367  * The default timeout in microseconds (us) for the ACK timeout feature.
368  *
369  */
370 #ifndef NRF_802154_ACK_TIMEOUT_DEFAULT_TIMEOUT
371 #define NRF_802154_ACK_TIMEOUT_DEFAULT_TIMEOUT 7000
372 #endif
373 
374 /**
375  * @def NRF_802154_PRECISE_ACK_TIMEOUT_DEFAULT_TIMEOUT
376  *
377  * The default timeout in microseconds (us) for the precise ACK timeout feature.
378  *
379  */
380 #ifndef NRF_802154_PRECISE_ACK_TIMEOUT_DEFAULT_TIMEOUT
381 #define NRF_802154_PRECISE_ACK_TIMEOUT_DEFAULT_TIMEOUT 210
382 #endif
383 
384 /**
385  * @def NRF_802154_MAX_ACK_IE_SIZE
386  *
387  * The maximum supported size of the 802.15.4-2015 IE header and content fields in an Enh-Ack.
388  *
389  */
390 #ifndef NRF_802154_MAX_ACK_IE_SIZE
391 #define NRF_802154_MAX_ACK_IE_SIZE 16
392 #endif
393 
394 /**
395  * @}
396  * @defgroup nrf_802154_config_ifs Interframe spacing feature configuration
397  * @{
398  */
399 
400 /**
401  * @def NRF_802154_IFS_ENABLED
402  *
403  * Indicates whether the Short/Long Interframe spacing feature is to be enabled in the driver.
404  * This is an experimental feature.
405  *
406  */
407 #if !defined(CONFIG_NRF_802154_SL_OPENSOURCE)
408 #ifndef NRF_802154_IFS_ENABLED
409 #define NRF_802154_IFS_ENABLED 0
410 #endif
411 #endif
412 
413 /**
414  * @}
415  * @defgroup nrf_802154_config_transmission Transmission start notification feature configuration
416  * @{
417  */
418 
419 /**
420  * @}
421  * @defgroup nrf_802154_config_stats Statistics configuration
422  * @{
423  */
424 
425 /**
426  * @def NRF_802154_STATS_COUNT_ENERGY_DETECTED_EVENTS
427  *
428  * Configures if energy detected events will be counted in receive mode.
429  * When this option is enabled additional interrupts on energy detected events will occur
430  * increasing power consumption. The events counter is stored in
431  * @ref nrf_802154_stat_counters_t::received_energy_events field and can be retrieved by
432  * a call to @ref nrf_802154_stats_get or @ref nrf_802154_stat_counters_get.
433  */
434 #ifndef NRF_802154_STATS_COUNT_ENERGY_DETECTED_EVENTS
435 #define NRF_802154_STATS_COUNT_ENERGY_DETECTED_EVENTS 1
436 #endif
437 
438 /**
439  * @def NRF_802154_STATS_COUNT_RECEIVED_PREAMBLES
440  *
441  * Configures if number of received preambles will be counted in receive mode.
442  * When this option is enabled additional interrupts on preamble reveived will occur
443  * increasing power consumption. The events counter is stored in
444  * @ref nrf_802154_stat_counters_t::received_preambles field and can be retrieved by
445  * a call to @ref nrf_802154_stats_get or @ref nrf_802154_stat_counters_get.
446  */
447 #ifndef NRF_802154_STATS_COUNT_RECEIVED_PREAMBLES
448 #define NRF_802154_STATS_COUNT_RECEIVED_PREAMBLES 1
449 #endif
450 
451 /**
452  * @}
453  * @defgroup nrf_802154_config_security Security configuration
454  * @{
455  */
456 
457 /**
458  * @def NRF_802154_SECURITY_KEY_STORAGE_SIZE
459  *
460  * Configures the number of keys which are available in the Key Storage.
461  * This configuration is implementation-independent.
462  */
463 #ifndef NRF_802154_SECURITY_KEY_STORAGE_SIZE
464 #define NRF_802154_SECURITY_KEY_STORAGE_SIZE 3
465 #endif
466 
467 /**
468  * @def NRF_802154_SECURITY_WRITER_ENABLED
469  *
470  * Enables the Security Writer module. The module parses the frame being transmitted, validates
471  * frame's security header and injects frame counter associated with the used key.
472  */
473 #ifndef NRF_802154_SECURITY_WRITER_ENABLED
474 #define NRF_802154_SECURITY_WRITER_ENABLED 1
475 #endif
476 
477 /**
478  * @def NRF_802154_ENCRYPTION_ENABLED
479  *
480  * Enables the frame encryption module. The module uses AES-CCM* algorithm to secure frames
481  * transmitted by the driver.
482  */
483 #ifndef NRF_802154_ENCRYPTION_ENABLED
484 #define NRF_802154_ENCRYPTION_ENABLED 1
485 #endif
486 
487 /**
488  * @def NRF_802154_ENCRYPTION_ACCELERATOR_ECB
489  *
490  * Enables ECB peripheral to be used as hardware accelerator for on-the-fly AES-CCM* encryption.
491  */
492 #if !defined(NRF_802154_ENCRYPTION_ACCELERATOR_ECB) || defined(__DOXYGEN__)
493 #if defined(NRF52_SERIES) || defined(NRF5340_XXAA) || defined(__DOXYGEN__)
494 #define NRF_802154_ENCRYPTION_ACCELERATOR_ECB 1
495 #elif defined(NRF54H_SERIES) || defined(NRF54L_SERIES)
496 #define NRF_802154_ENCRYPTION_ACCELERATOR_ECB 0
497 #endif
498 #endif
499 
500 /**
501  * @}
502  * @defgroup nrf_802154_ie Information Elements configuration
503  * @{
504  */
505 
506 /**
507  * @def NRF_802154_IE_WRITER_ENABLED
508  *
509  * Enables the Information Element writer module. The module parses frames being transmitted
510  * for known Information Element IDs. If such elements are found, the writer module shall
511  * fill the elements with appropriate data.
512  */
513 #ifndef NRF_802154_IE_WRITER_ENABLED
514 #define NRF_802154_IE_WRITER_ENABLED 1
515 #endif
516 
517 /**
518  * @def NRF_802154_CARRIER_FUNCTIONS_ENABLED
519  *
520  * Enables functions used for test purposes: nrf_802154_continuous_carrier and
521  * nrf_802154_modulated_carrier
522  */
523 #ifndef NRF_802154_CARRIER_FUNCTIONS_ENABLED
524 #define NRF_802154_CARRIER_FUNCTIONS_ENABLED 1
525 #endif
526 
527 /**
528  * @def NRF_802154_NOTIFICATION_IMPL_DIRECT
529  *
530  * Use nrf_802154_notification_direct.c implementation.
531  * See @ref NRF_802154_NOTIFICATION_IMPL.
532  */
533 #define NRF_802154_NOTIFICATION_IMPL_DIRECT 0
534 
535 /**
536  * @def NRF_802154_NOTIFICATION_IMPL_SWI
537  *
538  * Use nrf_802154_notification_swi.c implementation.
539  * See @ref NRF_802154_NOTIFICATION_IMPL.
540  */
541 #define NRF_802154_NOTIFICATION_IMPL_SWI  1
542 
543 /**
544  * @def NRF_802154_NOTIFICATION_IMPL
545  *
546  * Selects implementation of internal "notification" module.
547  * Possible values:
548  *   @ref NRF_802154_NOTIFICATION_IMPL_DIRECT,
549  *   @ref NRF_802154_NOTIFICATION_IMPL_SWI
550  */
551 #ifndef NRF_802154_NOTIFICATION_IMPL
552 #define NRF_802154_NOTIFICATION_IMPL NRF_802154_NOTIFICATION_IMPL_SWI
553 #endif
554 
555 /**
556  * @def NRF_802154_REQUEST_IMPL_DIRECT
557  *
558  * Use nrf_802154_request_direct.c implementation.
559  * See @ref NRF_802154_NOTIFICATION_IMPL.
560  */
561 #define NRF_802154_REQUEST_IMPL_DIRECT 0
562 
563 /**
564  * @def NRF_802154_REQUEST_IMPL_DIRECT
565  *
566  * Use nrf_802154_request_swi.c implementation.
567  * See @ref NRF_802154_REQUEST_IMPL.
568  */
569 #define NRF_802154_REQUEST_IMPL_SWI    1
570 
571 /**
572  * @def NRF_802154_REQUEST_IMPL
573  *
574  * Selects implementation of internal "request" module.
575  * Possible values:
576  *   @ref NRF_802154_REQUEST_IMPL_DIRECT,
577  *   @ref NRF_802154_REQUEST_IMPL_SWI
578  */
579 #ifndef NRF_802154_REQUEST_IMPL
580 #define NRF_802154_REQUEST_IMPL NRF_802154_REQUEST_IMPL_SWI
581 #endif
582 
583 /** @} */
584 
585 /**
586  *@}
587  **/
588 
589 #ifdef __cplusplus
590 }
591 #endif
592 
593 #endif // NRF_802154_CONFIG_H__
594