1 /*
2  * Copyright (c) 2017 - 2023, 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 #if NRF_802154_USE_INTERNAL_INCLUDES
45 #include "nrf_802154_config_internal.h"
46 #endif
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 /**
53  * @defgroup nrf_802154_config 802.15.4 driver configuration
54  * @{
55  * @ingroup nrf_802154
56  * @brief Configuration of the 802.15.4 radio driver for nRF SoCs.
57  */
58 
59 /**
60  * @defgroup nrf_802154_config_radio Radio driver configuration
61  * @{
62  */
63 
64 /**
65  * @def NRF_802154_CCA_MODE_DEFAULT
66  *
67  * CCA mode used by the driver.
68  *
69  */
70 #ifndef NRF_802154_CCA_MODE_DEFAULT
71 #define NRF_802154_CCA_MODE_DEFAULT NRF_RADIO_CCA_MODE_ED
72 #endif
73 
74 /**
75  * @def NRF_802154_CCA_ED_THRESHOLD_DEFAULT
76  *
77  * Energy detection threshold used in the CCA procedure.
78  *
79  */
80 #ifndef NRF_802154_CCA_ED_THRESHOLD_DEFAULT
81 #define NRF_802154_CCA_ED_THRESHOLD_DEFAULT 0x14
82 #endif
83 
84 /**
85  * @def NRF_802154_CCA_CORR_THRESHOLD_DEFAULT
86  *
87  * Correlator threshold used in the CCA procedure.
88  *
89  */
90 #ifndef NRF_802154_CCA_CORR_THRESHOLD_DEFAULT
91 #define NRF_802154_CCA_CORR_THRESHOLD_DEFAULT 0x14
92 #endif
93 
94 /**
95  * @def NRF_802154_CCA_CORR_LIMIT_DEFAULT
96  *
97  * Correlator limit used in the CCA procedure.
98  *
99  */
100 #ifndef NRF_802154_CCA_CORR_LIMIT_DEFAULT
101 #define NRF_802154_CCA_CORR_LIMIT_DEFAULT 0x02
102 #endif
103 
104 /**
105  * @def NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
106  *
107  * If the driver is expected to internally handle the RADIO IRQ.
108  * If the driver is used in an OS, the RADIO IRQ can be handled by the OS and passed to
109  * the driver by @ref nrf_802154_radio_irq_handler.
110  * In this case, the internal handling must be disabled.
111  *
112  */
113 #ifndef NRF_802154_INTERNAL_RADIO_IRQ_HANDLING
114 #define NRF_802154_INTERNAL_RADIO_IRQ_HANDLING 0
115 #endif
116 
117 /**
118  * @def NRF_802154_INTERNAL_SWI_IRQ_HANDLING
119  *
120  * If the driver is expected to internally handle the SWI IRQ.
121  * If the driver is used in an OS, the SWI IRQ can be handled by the OS and passed to
122  * the driver by @ref nrf_802154_swi_irq_handler.
123  * In this case, the internal handling must be disabled.
124  *
125  */
126 #ifndef NRF_802154_INTERNAL_SWI_IRQ_HANDLING
127 #define NRF_802154_INTERNAL_SWI_IRQ_HANDLING 1
128 #endif
129 
130 /**
131  * @def NRF_802154_IRQ_PRIORITY
132  *
133  * Interrupt priority for RADIO peripheral.
134  * Keep the IRQ priority high (low number) to prevent losing frames due to preemption.
135  *
136  */
137 #ifndef NRF_802154_IRQ_PRIORITY
138 #define NRF_802154_IRQ_PRIORITY 0
139 #endif
140 
141 /**
142  * @def NRF_802154_SWI_PRIORITY
143  *
144  * The priority of software interrupt used for requests and notifications.
145  *
146  */
147 #ifndef NRF_802154_SWI_PRIORITY
148 #define NRF_802154_SWI_PRIORITY 4
149 #endif
150 
151 /**
152  * @def NRF_802154_ECB_PRIORITY
153  *
154  * Interrupt priority for ECB peripheral used for frame encryption.
155  *
156  */
157 #ifndef NRF_802154_ECB_PRIORITY
158 #define NRF_802154_ECB_PRIORITY 3
159 #endif
160 
161 /**
162  * @def NRF_802154_USE_RAW_API
163  *
164  * When this flag is set, the RAW API is available for the MAC layer. It is recommended to use
165  * the RAW API because it provides more optimized functions.
166  *
167  * @note If the RAW API is not enabled for the MAC layer, only less optimized functions performing
168  *       copy are available.
169  *
170  */
171 #ifndef NRF_802154_USE_RAW_API
172 #define NRF_802154_USE_RAW_API 1
173 #endif
174 
175 /**
176  * @def NRF_802154_PENDING_SHORT_ADDRESSES
177  *
178  * The number of slots containing short addresses of nodes for which the pending data is stored.
179  *
180  */
181 #ifndef NRF_802154_PENDING_SHORT_ADDRESSES
182 #define NRF_802154_PENDING_SHORT_ADDRESSES 10
183 #endif
184 
185 /**
186  * @def NRF_802154_PENDING_EXTENDED_ADDRESSES
187  *
188  * The number of slots containing extended addresses of nodes for which the pending data is stored.
189  *
190  */
191 #ifndef NRF_802154_PENDING_EXTENDED_ADDRESSES
192 #define NRF_802154_PENDING_EXTENDED_ADDRESSES 10
193 #endif
194 
195 /**
196  * @def NRF_802154_RX_BUFFERS
197  *
198  * The number of buffers in the receive queue.
199  *
200  */
201 #ifndef NRF_802154_RX_BUFFERS
202 #define NRF_802154_RX_BUFFERS 16
203 #endif
204 
205 /**
206  * @def NRF_802154_NOTIFY_CRCERROR
207  *
208  * With this flag set to 1, the CRC errors are notified to upper layers. This requires an interrupt
209  * handler to be used.
210  *
211  */
212 #ifndef NRF_802154_NOTIFY_CRCERROR
213 #define NRF_802154_NOTIFY_CRCERROR 1
214 #endif
215 
216 /**
217  * @def NRF_802154_FRAME_TIMESTAMP_ENABLED
218  *
219  * If timestamps are to be added to the frames received.
220  * Enabling this feature enables the functions @ref nrf_802154_received_timestamp_raw,
221  * @ref nrf_802154_received_timestamp which add timestamps to the frames received.
222  * Enables also proper value of frame timestamp
223  * ( @c nrf_802154_transmit_done_metadata_t::data.transmitted.time ) passed as metadata to
224  * @ref nrf_802154_transmitted and @ref nrf_802154_transmitted_raw,
225  * This option also enables timestamping in stats.
226  *
227  */
228 #ifndef NRF_802154_FRAME_TIMESTAMP_ENABLED
229 #define NRF_802154_FRAME_TIMESTAMP_ENABLED 1
230 #endif
231 
232 /**
233  * @def NRF_802154_TOTAL_TIMES_MEASUREMENT_ENABLED
234  *
235  * If measurement of total time spent in certain states is to be calculated.
236  *
237  * This option can be enabled when @ref NRF_802154_FRAME_TIMESTAMP_ENABLED is 1.
238  */
239 #ifndef NRF_802154_TOTAL_TIMES_MEASUREMENT_ENABLED
240 #define NRF_802154_TOTAL_TIMES_MEASUREMENT_ENABLED \
241     (1 && NRF_802154_FRAME_TIMESTAMP_ENABLED)
242 #endif
243 
244 /**
245  * @def NRF_802154_DELAYED_TRX_ENABLED
246  *
247  * If the delayed transmission and the receive window features are available.
248  *
249  */
250 #ifndef NRF_802154_DELAYED_TRX_ENABLED
251 #define NRF_802154_DELAYED_TRX_ENABLED 1
252 #endif
253 
254 /**
255  * @def NRF_802154_TEST_MODES_ENABLED
256  *
257  * Enables test modes. Test modes are normally disabled in end products.
258  * When @ref NRF_802154_TEST_MODES_ENABLED is set to 1, nRF 802.15.4 Radio Driver
259  * provides additional API to enable certain test modes. Setting
260  * @ref NRF_802154_TEST_MODES_ENABLED to 1 without using test mode API does not
261  * change any behavior of the Radio Driver.
262  */
263 #ifndef NRF_802154_TEST_MODES_ENABLED
264 #define NRF_802154_TEST_MODES_ENABLED 0
265 #endif
266 
267 /**
268  * @}
269  * @defgroup nrf_802154_config_csma CSMA/CA procedure configuration
270  * @{
271  */
272 
273 /**
274  * @def NRF_802154_CSMA_CA_ENABLED
275  *
276  * If CSMA-CA is to be enabled by the driver. Disabling CSMA-CA improves
277  * the driver performance.
278  *
279  */
280 #ifndef NRF_802154_CSMA_CA_ENABLED
281 #define NRF_802154_CSMA_CA_ENABLED 1
282 #endif
283 
284 /**
285  * @def NRF_802154_CSMA_CA_MIN_BE_DEFAULT
286  *
287  * The default minimum value of the backoff exponent (BE) in the CSMA-CA algorithm
288  * (see IEEE 802.15.4-2015: 6.2.5.1).
289  *
290  * @note The minimum value of the backoff exponent may be changed from default by calling the
291  *       @ref nrf_802154_csma_ca_min_be_set function.
292  *
293  */
294 #ifdef NRF_802154_CSMA_CA_MIN_BE
295 #error "NRF_802154_CSMA_CA_MIN_BE was replaced with NRF_802154_CSMA_CA_MIN_BE_DEFAULT"
296 #endif
297 #ifndef NRF_802154_CSMA_CA_MIN_BE_DEFAULT
298 #define NRF_802154_CSMA_CA_MIN_BE_DEFAULT 3
299 #endif
300 
301 /**
302  * @def NRF_802154_CSMA_CA_MAX_BE_DEFAULT
303  *
304  * The default maximum value of the backoff exponent, BE, in the CSMA-CA algorithm
305  * (see IEEE 802.15.4-2015: 6.2.5.1).
306  *
307  * @note The maximum value of the backoff exponent may be changed from default by calling the
308  *       @ref nrf_802154_csma_ca_max_be_set function.
309  *
310  */
311 #ifdef NRF_802154_CSMA_CA_MAX_BE
312 #error "NRF_802154_CSMA_CA_MAX_BE was replaced with NRF_802154_CSMA_CA_MAX_BE_DEFAULT"
313 #endif
314 #ifndef NRF_802154_CSMA_CA_MAX_BE_DEFAULT
315 #define NRF_802154_CSMA_CA_MAX_BE_DEFAULT 5
316 #endif
317 
318 /**
319  * @def NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT
320  *
321  * The default maximum number of backoffs that the CSMA-CA algorithm will attempt before declaring
322  * a channel access failure.
323  *
324  * @note The maximum number of backoffs may be changed from default by calling the
325  *       @ref nrf_802154_csma_ca_max_backoffs_set function.
326  *
327  */
328 #ifdef NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS
329 #error \
330     "NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS was replaced with NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT"
331 #endif
332 #ifndef NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT
333 #define NRF_802154_CSMA_CA_MAX_CSMA_BACKOFFS_DEFAULT 4
334 #endif
335 
336 /**
337  * @def NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT
338  *
339  * Indicates whether the CSMA-CA algorithm waits for an available timeslot before it performs
340  * the CCA procedure.
341  *
342  * @note When this option is enabled, the CSMA-CA procedure can be synchronized with timeslots of
343  *       other protocols. This decreases the robustness of the CSMA-CA procedure. On the other hand,
344  *       enabling this function increases the performance of multi-protocol applications, especially
345  *       when protocols other than 802.15.4 use much of the radio time (like the BLE scanning
346  *       operation).
347  *
348  */
349 #ifndef NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT
350 #define NRF_802154_CSMA_CA_WAIT_FOR_TIMESLOT 1
351 #endif
352 
353 /**
354  * @}
355  * @defgroup nrf_802154_config_timeout ACK timeout feature configuration
356  * @{
357  */
358 
359 /**
360  * @def NRF_802154_ACK_TIMEOUT_ENABLED
361  *
362  * Indicates whether the ACK timeout feature is to be enabled in the driver.
363  *
364  */
365 #ifndef NRF_802154_ACK_TIMEOUT_ENABLED
366 #define NRF_802154_ACK_TIMEOUT_ENABLED 1
367 #endif
368 
369 /**
370  * @def NRF_802154_ACK_TIMEOUT_DEFAULT_TIMEOUT
371  *
372  * The default timeout in microseconds (us) for the ACK timeout feature.
373  *
374  */
375 #ifndef NRF_802154_ACK_TIMEOUT_DEFAULT_TIMEOUT
376 #define NRF_802154_ACK_TIMEOUT_DEFAULT_TIMEOUT 7000
377 #endif
378 
379 /**
380  * @def NRF_802154_PRECISE_ACK_TIMEOUT_DEFAULT_TIMEOUT
381  *
382  * The default timeout in microseconds (us) for the precise ACK timeout feature.
383  *
384  */
385 #ifndef NRF_802154_PRECISE_ACK_TIMEOUT_DEFAULT_TIMEOUT
386 #define NRF_802154_PRECISE_ACK_TIMEOUT_DEFAULT_TIMEOUT 210
387 #endif
388 
389 /**
390  * @def NRF_802154_MAX_ACK_IE_SIZE
391  *
392  * The maximum supported size of the 802.15.4-2015 IE header and content fields in an Enh-Ack.
393  *
394  */
395 #ifndef NRF_802154_MAX_ACK_IE_SIZE
396 #define NRF_802154_MAX_ACK_IE_SIZE 8
397 #endif
398 
399 /**
400  * @}
401  * @defgroup nrf_802154_config_ifs Interframe spacing feature configuration
402  * @{
403  */
404 
405 /**
406  * @def NRF_802154_IFS_ENABLED
407  *
408  * Indicates whether the Short/Long Interframe spacing feature is to be enabled in the driver.
409  *
410  */
411 #ifndef NRF_802154_IFS_ENABLED
412 #define NRF_802154_IFS_ENABLED 1
413 #endif
414 
415 /**
416  * @}
417  * @defgroup nrf_802154_config_transmission Transmission start notification feature configuration
418  * @{
419  */
420 
421 /**
422  * @}
423  * @defgroup nrf_802154_config_coex WiFi coexistence feature configuration
424  * @{
425  */
426 
427 /**
428  * @def NRF_802154_COEX_INITIALLY_ENABLED
429  *
430  * Configures if WiFi coex is initially enabled or disabled.
431  */
432 #ifndef NRF_802154_COEX_INITIALLY_ENABLED
433 #define NRF_802154_COEX_INITIALLY_ENABLED 1
434 #endif
435 
436 /**
437  * @}
438  * @defgroup nrf_802154_config_stats Statistics configuration
439  * @{
440  */
441 
442 /**
443  * @def NRF_802154_STATS_COUNT_ENERGY_DETECTED_EVENTS
444  *
445  * Configures if energy detected events will be counted in receive mode.
446  * When this option is enabled additional interrupts on energy detected events will occur
447  * increasing power consumption. The events counter is stored in
448  * @ref nrf_802154_stat_counters_t::received_energy_events field and can be retrieved by
449  * a call to @ref nrf_802154_stats_get or @ref nrf_802154_stat_counters_get.
450  */
451 #ifndef NRF_802154_STATS_COUNT_ENERGY_DETECTED_EVENTS
452 #define NRF_802154_STATS_COUNT_ENERGY_DETECTED_EVENTS 1
453 #endif
454 
455 /**
456  * @def NRF_802154_STATS_COUNT_RECEIVED_PREAMBLES
457  *
458  * Configures if number of received preambles will be counted in receive mode.
459  * When this option is enabled additional interrupts on preamble reveived will occur
460  * increasing power consumption. The events counter is stored in
461  * @ref nrf_802154_stat_counters_t::received_preambles field and can be retrieved by
462  * a call to @ref nrf_802154_stats_get or @ref nrf_802154_stat_counters_get.
463  */
464 #ifndef NRF_802154_STATS_COUNT_RECEIVED_PREAMBLES
465 #define NRF_802154_STATS_COUNT_RECEIVED_PREAMBLES 1
466 #endif
467 
468 /**
469  * @}
470  * @defgroup nrf_802154_config_security Security configuration
471  * @{
472  */
473 
474 /**
475  * @def NRF_802154_SECURITY_KEY_STORAGE_SIZE
476  *
477  * Configures the number of keys which are available in the Key Storage.
478  * This configuration is implementation-independent.
479  */
480 #ifndef NRF_802154_SECURITY_KEY_STORAGE_SIZE
481 #define NRF_802154_SECURITY_KEY_STORAGE_SIZE 3
482 #endif
483 
484 /**
485  * @def NRF_802154_SECURITY_WRITER_ENABLED
486  *
487  * Enables the Security Writer module. The module parses the frame being transmitted, validates
488  * frame's security header and injects frame counter associated with the used key.
489  */
490 #ifndef NRF_802154_SECURITY_WRITER_ENABLED
491 #define NRF_802154_SECURITY_WRITER_ENABLED 1
492 #endif
493 
494 /**
495  * @def NRF_802154_ENCRYPTION_ENABLED
496  *
497  * Enables the frame encryption module. The module uses AES-CCM* algorithm to secure frames
498  * transmitted by the driver.
499  */
500 #ifndef NRF_802154_ENCRYPTION_ENABLED
501 #define NRF_802154_ENCRYPTION_ENABLED 1
502 #endif
503 
504 /**
505  * @def NRF_802154_ENCRYPTION_ACCELERATOR_ECB
506  *
507  * Enables ECB peripheral to be used as hardware accelerator for on-the-fly AES-CCM* encryption.
508  */
509 #ifndef NRF_802154_ENCRYPTION_ACCELERATOR_ECB
510 #define NRF_802154_ENCRYPTION_ACCELERATOR_ECB 1
511 #endif
512 
513 /**
514  * @}
515  * @defgroup nrf_802154_ie Information Elements configuration
516  * @{
517  */
518 
519 /**
520  * @def NRF_802154_IE_WRITER_ENABLED
521  *
522  * Enables the Information Element writer module. The module parses frames being transmitted
523  * for known Information Element IDs. If such elements are found, the writer module shall
524  * fill the elements with appropriate data.
525  */
526 #ifndef NRF_802154_IE_WRITER_ENABLED
527 #define NRF_802154_IE_WRITER_ENABLED 1
528 #endif
529 
530 /**
531  * @def NRF_802154_CARRIER_FUNCTIONS_ENABLED
532  *
533  * Enables functions used for test purposes: nrf_802154_continuous_carrier and
534  * nrf_802154_modulated_carrier
535  */
536 #ifndef NRF_802154_CARRIER_FUNCTIONS_ENABLED
537 #define NRF_802154_CARRIER_FUNCTIONS_ENABLED 1
538 #endif
539 
540 /**
541  *@}
542  **/
543 
544 /**
545  *@}
546  **/
547 
548 #ifdef __cplusplus
549 }
550 #endif
551 
552 #endif // NRF_802154_CONFIG_H__
553