1 /*
2  * Copyright (c) 2016-2020, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * *  Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * *  Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * *  Neither the name of Texas Instruments Incorporated nor the names of
17  *    its contributors may be used to endorse or promote products derived
18  *    from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33 @file   RFCC26X2.h
34 @brief  Radio Frequency (RF) Core Driver for the CC13X2 and CC26X2 device
35         family.
36 
37 To use the RF driver, ensure that the correct driver library for your device
38 is linked in and include the top-level header file as follows:
39 
40 @code
41 #include <ti/drivers/rf/RF.h>
42 @endcode
43 
44 <hr>
45 @anchor rf_overview
46 Overview
47 ========
48 
49 The RF driver provides access to the radio core on the CC13x2/CC26x2 device
50 family. It offers a high-level interface for command execution and to the
51 radio timer (RAT). The RF driver ensures the lowest possible power consumption
52 by providing automatic power management that is fully transparent for the
53 application.
54 
55 @note This document describes the features and usage of the RF driver API. For a
56 detailed explanation of the RF core, please refer to the
57 <a href='../../proprietary-rf/technical-reference-manual.html'><b>Technical
58 Reference Manual</b></a> or the
59 <a href='../../proprietary-rf/proprietary-rf-users-guide.html'><b>Proprietary
60 RF User Guide</b></a>.
61 
62 <b>Key features are:</b>
63 
64 @li @ref rf_command_execution "Synchronous execution of direct and immediate radio commands"
65 @li @ref rf_command_execution "Synchronous and asynchronous execution of radio operation commands"
66 @li Various @ref rf_event_callbacks "event hooks" to interact with RF commands and the RF driver
67 @li Automatic @ref rf_power_management "power management"
68 @li @ref rf_scheduling "Preemptive scheduler for RF operations" of different RF driver instances
69 @li Convenient @ref rf_rat "Access to the radio timer" (RAT)
70 @li @ref rf_tx_power "Programming the TX power level"
71 
72 @anchor rf_setup_and_configuration
73 Setup and configuration
74 =======================
75 
76 The RF driver can be configured at 4 different places:
77 
78 1. In the build configuration by choosing either the single-client or
79    multi-client driver version.
80 
81 2. At compile-time by setting hardware and software interrupt priorities
82    in the board support file.
83 
84 3. During run-time initialization by setting #RF_Params when calling
85    #RF_open().
86 
87 4. At run-time via #RF_control().
88 
89 
90 Build configuration
91 -------------------
92 
93 The RF driver comes in two versions: single-client and multi-client. The
94 single-client version allows only one driver instance to access the RF core at
95 a time. The multi-client driver version allows concurrent access to the RF
96 core with different RF settings. The multi-client driver has a slightly larger
97 footprint and is not needed for many proprietary applications. The driver
98 version can be selected in the build configuration by linking against a
99 RFCC26X2_multiMode pre-built library. The multi-client driver is the default
100 configuration in the SimpleLink SDKs.
101 
102 
103 Board configuration
104 -------------------
105 
106 The RF driver handles RF core hardware interrupts and uses software interrupts
107 for its internal state machine. For managing the interrupt priorities, it
108 expects the existence of a global #RFCC26XX_HWAttrsV2 object. This is
109 usually defined in the board support file, for example `CC2652RB_LAUNCHXL.c`,
110 but when developing on custom boards, it might be kept anywhere in the
111 application. By default, the priorities are set to the lowest possible value:
112 
113 @code
114 const RFCC26XX_HWAttrsV2 RFCC26XX_hwAttrs = {
115     .hwiPriority        = INT_PRI_LEVEL7,  // Lowest HWI priority:  INT_PRI_LEVEL7
116                                            // Highest HWI priority: INT_PRI_LEVEL1
117 
118     .swiPriority        = 0,               // Lowest SWI priority:  0
119                                            // Highest SWI priority: Swi.numPriorities - 1
120 
121     .xoscHfAlwaysNeeded = true             // Power driver always starts XOSC-HF:       true
122                                            // RF driver will request XOSC-HF if needed: false
123 };
124 @endcode
125 
126 
127 Initialization
128 --------------
129 
130 When initiating an RF driver instance, the function #RF_open() accepts a
131 pointer to a #RF_Params object which might set several driver parameters. In
132 addition, it expects an #RF_Mode object and a setup command which is usually
133 generated by SmartRF Studio:
134 
135 @code
136 RF_Params rfParams;
137 RF_Params_init(&rfParams);
138 rfParams.nInactivityTimeout = 2000;
139 
140 RF_Handle rfHandle = RF_open(&rfObject, &RF_prop,
141         (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
142 @endcode
143 
144 The function #RF_open() returns a driver handle that is used for accessing the
145 correct driver instance. Please note that the first RF operation command
146 before an RX or TX operation command must be a `CMD_FS` to set the synthesizer
147 frequency. The RF driver caches both, the pointer to the setup command and the
148 physical `CMD_FS` for automatic power management.
149 
150 
151 Run-time configuration
152 ----------------------
153 
154 While a driver instance is opened, it can be re-configured with the function
155 #RF_control(). Various configuration parameters @ref RF_CTRL are available.
156 Example:
157 
158 @code
159 uint32_t timeoutUs = 2000;
160 RF_control(rfHandle, RF_CTRL_SET_INACTIVITY_TIMEOUT, &timeoutUs);
161 @endcode
162 
163 <hr>
164 @anchor rf_command_execution
165 Command execution
166 =================
167 
168 The RF core supports 3 different kinds of commands:
169 
170 1. Direct commands
171 2. Immediate commands
172 3. Radio operation commands
173 
174 Direct and immediate commands are dispatched via #RF_runDirectCmd() and
175 #RF_runImmediateCmd() respectively. These functions block until the command
176 has completed and return a status code of the type #RF_Stat when done.
177 
178 @code
179 #include <ti/devices/${DEVICE_FAMILY}/driverlib/rf_common_cmd.h>
180 
181 RF_Stat status = RF_runDirectCmd(rfHandle, CMD_ABORT);
182 assert(status == RF_StatCmdDoneSuccess);
183 @endcode
184 
185 Radio operation commands are potentially long-running commands and support
186 different triggers as well as conditional execution. Only one command can be
187 executed at a time, but the RF driver provides an internal queue that stores
188 commands until the RF core is free. Two interfaces are provided for radio
189 operation commands:
190 
191 1. Asynchronous: #RF_postCmd() and #RF_pendCmd()
192 2. Synchronous: #RF_runCmd()
193 
194 The asynchronous function #RF_postCmd() posts a radio operation into the
195 driver's internal command queue and returns a command handle of the type
196 #RF_CmdHandle which is an index in the command queue. The command is
197 dispatched as soon as the RF core has completed any previous radio operation
198 command.
199 
200 @code
201 #include <ti/devices/${DEVICE_FAMILY}/driverlib/rf_common_cmd.h>
202 
203 RF_Callback callback = NULL;
204 RF_EventMask subscribedEvents = 0;
205 RF_CmdHandle rxCommandHandle = RF_postCmd(rfHandle, (RF_Op*)&RF_cmdRx,
206         RF_PriorityNormal, callback, subscribedEvents);
207 
208 assert(rxCommandHandle != RF_ALLOC_ERROR); // The command queue is full.
209 @endcode
210 
211 Command execution happens in background. The calling task may proceed with
212 other work or execute direct and immediate commands to interact with the
213 posted radio operation. But beware that the posted command might not have
214 started, yet. By calling the function #RF_pendCmd() and subscribing events of
215 the type #RF_EventMask, it is possible to re-synchronize to a posted command:
216 
217 @code
218 // RF_EventRxEntryDone must have been subscribed in RF_postCmd().
219 RF_EventMask events = RF_pendCmd(rfHandle, rxCommandHandle,
220         RF_EventRxEntryDone);
221 
222 // Program proceeds after RF_EventRxEntryDone or after a termination event.
223 @endcode
224 
225 The function #RF_runCmd() is a combination of both, #RF_postCmd() and
226 #RF_pendCmd() and allows synchronous execution.
227 
228 A pending or already running command might be aborted at any time by calling
229 the function #RF_cancelCmd() or #RF_flushCmd(). These functions take command
230 handles as parameters, but can also just abort anything in the RF driver's
231 queue:
232 
233 @code
234 uint8_t abortGraceful = 1;
235 
236 // Abort a single command
237 RF_cancelCmd(rfHandle, rxCommandHandle, abortGraceful);
238 
239 // Abort anything
240 RF_flushCmd(rfHandle, RF_CMDHANDLE_FLUSH_ALL, abortGraceful);
241 @endcode
242 
243 When aborting a command, the return value of #RF_runCmd() or #RF_pendCmd()
244 will contain the termination reason in form of event flags. If the command is
245 in the RF driver queue, but has not yet start, the #RF_EventCmdCancelled event is
246 raised.
247 
248 <hr>
249 @anchor rf_event_callbacks
250 Event callbacks
251 ===============
252 
253 The RF core generates multiple interrupts during command execution. The RF
254 driver maps these interrupts 1:1 to callback events of the type #RF_EventMask.
255 Hence, it is unnecessary to implement own interrupt handlers. Callback events
256 are divided into 3 groups:
257 
258 - Command-specific events, documented for each radio operation command. An example
259   is the #RF_EventRxEntryDone for the `CMD_PROP_RX`.
260 
261 - Generic events, defined for all radio operations and originating on the RF core.
262   These are for instance #RF_EventCmdDone and #RF_EventLastCmdDone. Both events
263   indicate the termination of one or more RF operations.
264 
265 - Generic events, defined for all radio operations and originating in the RF driver,
266   for instance #RF_EventCmdCancelled.
267 
268 @sa @ref RF_Core_Events, @ref RF_Driver_Events.
269 
270 How callback events are subscribed was shown in the previous section. The
271 following snippet shows a typical event handler callback for a proprietary RX
272 operation:
273 
274 @code
275 void rxCallback(RF_Handle handle, RF_CmdHandle command, RF_EventMask events)
276 {
277     if (events & RF_EventRxEntryDone)
278     {
279         Semaphore_post(rxPacketSemaphore);
280     }
281     if (events & RF_EventLastCmdDone)
282     {
283         // ...
284     }
285 }
286 @endcode
287 
288 In addition, the RF driver can generate error and power-up events that do not
289 relate directly to the execution of a radio command. Such events can be
290 subscribed by specifying the callback function pointers #RF_Params::pErrCb and
291 #RF_Params::pPowerCb.
292 
293 All callback functions run in software interrupt (SWI) context. Therefore,
294 only a minimum amount of code should be executed. When using absolute timed
295 commands with tight timing constraints, then it is recommended to set the RF
296 driver SWIs to a high priority.
297 See @ref rf_setup_and_configuration "Setup and configuration" for more details.
298 
299 <hr>
300 @anchor rf_power_management
301 Power management
302 ================
303 
304 The RF core is a hardware peripheral and can be switched on and off. The RF
305 driver handles that automatically and provides the following power
306 optimization features:
307 
308 - Lazy power-up and radio setup caching
309 - Power-down on inactivity
310 - Deferred dispatching of commands with absolute timing
311 
312 
313 Lazy power-up and radio setup caching
314 -------------------------------------
315 
316 The RF core optimizes the power consumption by enabling the RF core as late as
317 possible. For instance does #RF_open() not power up the RF core immediately.
318 Instead, it waits until the first radio operation command is dispatched by
319 #RF_postCmd() or #RF_runCmd().
320 
321 The function #RF_open() takes a radio setup command as parameter and expects a
322 `CMD_FS` command to follow. The pointer to the radio setup command and the
323 whole `CMD_FS` command are cached internally in the RF driver. They will be
324 used for every proceeding power-up procedure. Whenever the client re-runs a
325 setup command or a `CMD_FS` command, the driver updates its internal cache
326 with the new settings.
327 
328 By default, the RF driver measures the time that it needs for the power-up
329 procedure and uses that as an estimate for the next power cycle. On the
330 CC13x0/CC26x0 devices, power-up takes usually 1.6 ms. Automatic measurement
331 can be suppressed by specifying a custom power-up time with
332 #RF_Params::nPowerUpDuration. In addition, the client might set
333 #RF_Params::nPowerUpDurationMargin to cover any uncertainty when doing
334 automatic measurements. This is necessary in applications with a high hardware
335 interrupt load which can delay the RF driver's internal state machine
336 execution.
337 
338 
339 Power-down on inactivity
340 ------------------------
341 
342 Whenever a radio operation completes and there is no other radio operation in
343 the queue, the RF core might be powered down. There are two options in the RF
344 driver:
345 
346 - **Automatic power-down** by setting the parameter
347   #RF_Params::nInactivityTimeout. The RF core will then start a timer after
348   the last command in the queue has completed. The default timeout is "forever"
349   and this feature is disabled.
350 
351 - **Manual power-down** by calling #RF_yield(). The client should do this
352   whenever it knows that no further radio operation will be executed for a
353   couple of milliseconds.
354 
355 During the power-down procedure the RF driver stops the radio timer and saves
356 a synchronization timestamp for the next power-up. This keeps the radio timer
357 virtually in sync with the RTC even though it is not running all the time. The
358 synchronization is done in hardware.
359 
360 
361 Deferred dispatching of commands with absolute timing
362 -----------------------------------------------------
363 
364 When dispatching a radio operation command with an absolute start trigger that
365 is ahead in the future, the RF driver defers the execution and powers the RF
366 core down until the command is due. It does that only, when:
367 
368 1. `cmd.startTrigger.triggerType` is set to `TRIG_ABSTIME`
369 
370 2. The difference between #RF_getCurrentTime() and `cmd.startTime`
371    is at not more than 3/4 of a full RAT cycle. Otherwise the driver assumes
372    that `cmd.startTime` is in the past.
373 
374 3. There is enough time to run a full power cycle before `cmd.startTime` is
375    due. That includes:
376 
377    - the power-down time (fixed value, 1 ms) if the RF core is already
378      powered up,
379 
380    - the measured power-up duration or the value specified by
381      #RF_Params::nPowerUpDuration,
382 
383    - the power-up safety margin #RF_Params::nPowerUpDurationMargin
384      (the default is 282 microseconds).
385 
386 If one of the conditions are not fulfilled, the RF core is kept up and
387 running and the command is dispatched immediately. This ensures, that the
388 command will execute on-time and not miss the configured start trigger.
389 
390 <hr>
391 @anchor rf_scheduling
392 Preemptive scheduling of RF commands in multi-client applications
393 =================================================================
394 
395 Schedule BLE and proprietary radio commands.
396 
397 @code
398 RF_Object rfObject_ble;
399 RF_Object rfObject_prop;
400 
401 RF_Handle rfHandle_ble, rfHandle_prop;
402 RF_Params rfParams_ble, rfParams_prop;
403 RF_ScheduleCmdParams schParams_ble, schParams_prop;
404 
405 RF_Mode rfMode_ble =
406 {
407   .rfMode      = RF_MODE_MULTIPLE,  // rfMode for dual mode
408   .cpePatchFxn = &rf_patch_cpe_ble,
409   .mcePatchFxn = 0,
410   .rfePatchFxn = &rf_patch_rfe_ble,
411 };
412 
413 RF_Mode rfMode_prop =
414 {
415   .rfMode      = RF_MODE_MULTIPLE,  // rfMode for dual mode
416   .cpePatchFxn = &rf_patch_cpe_genfsk,
417   .mcePatchFxn = 0,
418   .rfePatchFxn = 0,
419 };
420 
421 // Init RF and specify non-default parameters
422 RF_Params_init(&rfParams_ble);
423 rfParams_ble.nInactivityTimeout = 200;     // 200us
424 
425 RF_Params_init(&rfParams_prop);
426 rfParams_prop.nInactivityTimeout = 200;    // 200us
427 
428 // Configure RF schedule command parameters directly.
429 schParams_ble.priority    = RF_PriorityNormal;
430 schParams_ble.endTime     = 0;
431 schParams_ble.allowDelay  = RF_AllowDelayAny;
432 
433 // Alternatively, use the helper function to configure the default behavior
434 RF_ScheduleCmdParams_init(&schParams_prop);
435 
436 // Open BLE and proprietary RF handles
437 rfHandle_ble  = RF_open(rfObj_ble,  &rfMode_ble,  (RF_RadioSetup*)&RF_cmdRadioSetup,        &rfParams_ble);
438 rfHandle_prop = RF_open(rfObj_prop, &rfMode_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams_prop);
439 
440 // Run a proprietary Fs command
441 RF_runCmd(rfHandle_pro, (RF_Op*)&RF_cmdFs, RF_PriorityNormal, NULL, NULL);
442 
443 // Schedule a proprietary RX command
444 RF_scheduleCmd(rfHandle_pro, (RF_Op*)&RF_cmdPropRx, &schParams_prop, &prop_callback, RF_EventRxOk);
445 
446 // Schedule a BLE advertiser command
447 RF_scheduleCmd(rfHandle_ble, (RF_Op*)&RF_cmdBleAdv, &schParams_ble, &ble_callback,
448              (RF_EventLastCmdDone | RF_EventRxEntryDone | RF_EventTxEntryDone));
449 
450 @endcode
451 
452 <hr>
453 @anchor rf_rat
454 Accessing the Radio Timer (RAT)
455 ==============================
456 
457 The Radio Timer on the RF core is an independent 32 bit timer running at a
458 tick rate of 4 ticks per microsecond. It is only physically active while the
459 RF core is on. But because the RF driver resynchronizes the RAT to the RTC on
460 every power-up, it appears to the application as the timer is always running.
461 The RAT accuracy depends on the system HF clock while the RF core is active
462 and on the LF clock while the RF core is powered down.
463 
464 The current RAT time stamp can be obtained by #RF_getCurrentTime():
465 
466 @code
467 uint32_t now = RF_getCurrentTime();
468 @endcode
469 
470 The RAT has 8 independent channels that can be set up in capture and compare
471 mode by #RF_ratCapture() and #RF_ratCompare() respectively. Three of these
472 channels are accessible by the RF driver. Each channel may be connected to
473 physical hardware signals for input and output or may trigger a callback
474 function.
475 
476 In order to allocate a RAT channel and trigger a callback function at a
477 certain time stamp, use #RF_ratCompare():
478 
479 @code
480 RF_Handle rfDriver;
481 RF_RatConfigCompare config;
482 RF_RatConfigCompare_init(&config);
483 config.callback = &onRatTriggered;
484 config.channel = RF_RatChannelAny;
485 config.timeout = RF_getCurrentTime() + RF_convertMsToRatTicks(1701);
486 
487 RF_RatHandle ratHandle = RF_ratCompare(rfDriver, &config, nullptr);
488 assert(ratHandle != RF_ALLOC_ERROR);
489 
490 void onRatTriggered(RF_Handle h, RF_RatHandle rh, RF_EventMask e, uint32_t compareCaptureTime)
491 {
492     if (e & RF_EventError)
493     {
494         // RF driver failed to trigger the callback on time.
495     }
496     printf("RAT has triggered at %u.", compareCaptureTime);
497 
498     // Trigger precisely with the same period again
499     config.timeout = compareCaptureTime + RF_convertMsToRatTicks(1701);
500     ratHandle = RF_ratCompare(rfDriver, &config, nullptr);
501     assert(ratHandle != RF_ALLOC_ERROR);
502 }
503 @endcode
504 
505 The RAT may be used to capture a time stamp on an edge of a physical pin. This
506 can be achieved with #RF_ratCapture().
507 
508 @code
509 #include <ti/drivers/pin/PINCC26XX.h>
510 // Map IO 26 to RFC_GPI0
511 PINCC26XX_setMux(pinHandle, IOID_26, PINCC26XX_MUX_RFC_GPI0);
512 
513 RF_Handle rfDriver;
514 RF_RatConfigCapture config;
515 RF_RatConfigCapture_init(&config);
516 config.callback = &onSignalTriggered;
517 config.channel = RF_RatChannelAny;
518 config.source = RF_RatCaptureSourceRfcGpi0;
519 config.captureMode = RF_RatCaptureModeRising;
520 config.repeat = RF_RatCaptureRepeat;
521 
522 RF_RatHandle ratHandle = RF_ratCapture(rfDriver, &config, nullptr);
523 assert(ratHandle != RF_ALLOC_ERROR);
524 
525 void onSignalTriggered(RF_Handle h, RF_RatHandle rh, RF_EventMask e, uint32_t compareCaptureTime)
526 {
527     if (e & RF_EventError)
528     {
529         // An internal error has occurred
530     }
531     printf("Rising edge detected on IO 26 at %u.", compareCaptureTime);
532 }
533 @endcode
534 
535 In both cases, the RAT may generate an output signal when being triggered. The
536 signal can be routed to a physical IO pin:
537 
538 @code
539 // Generate a pulse on an internal RAT output signal
540 RF_RatConfigOutput output;
541 RF_RatConfigOutput_init(&output);
542 output.mode = RF_RatOutputModePulse;
543 output.select = RF_RatOutputSelectRatGpo3;
544 RF_ratCompare(...);
545 
546 // Map RatGpo3 to one of four intermediate doorbell signals.
547 // This has to be done in the override list in order to take permanent effect.
548 // The override list can be found in the RF settings .c file exported from
549 // SmartRF Studio.
550 // Attention: This will change the default mapping of the PA and LNA signal as well.
551 #include <ti/devices/[DEVICE_FAMILY]/inc/hw_rfc_dbell.h>
552 static uint32_t pOverrides[] =
553 {
554     HW_REG_OVERRIDE(0x1110, RFC_DBELL_SYSGPOCTL_GPOCTL2_RATGPO3),
555     // ...
556 }
557 
558 // Finally, route the intermediate doorbell signal to a physical pin.
559 #include <ti/drivers/pin/PINCC26XX.h>
560 PINCC26XX_setMux(pinHandle, IOID_17, PINCC26XX_MUX_RFC_GPO2);
561 @endcode
562 
563 <hr>
564 @anchor rf_tx_power
565 Programming the TX power level
566 ==============================
567 
568 The application can program a TX power level for each RF client with the function
569 #RF_setTxPower(). The new value takes immediate effect if the RF core is up and
570 running. Otherwise, it is stored in the RF driver client configuration.
571 
572 TX power may be stored in a lookup table in ascending order. This table is usually
573 generated and exported from SmartRF Studio together with the rest of the PHY configuration.
574 A typical power table my look as follows:
575 @code
576 RF_TxPowerTable_Entry txPowerTable[] = {
577     { .power = 11,  .value = { 0x1233, RF_TxPowerTable_DefaultPA }},
578     { .power = 13,  .value = { 0x1234, RF_TxPowerTable_DefaultPA }},
579     // ...
580     RF_TxPowerTable_TERMINATION_ENTRY
581 };
582 @endcode
583 
584 @note Some devices offer a high-power PA in addition to the default PA.
585 A client must not mix configuration values in the same power table and must
586 not hop from a default PA configuration to a high-power PA configuration unless it
587 can guarantee that the RF setup command is re-executed in between.
588 
589 Given this power table format, the application may program a new power level in multiple
590 ways. It can use convenience functions to search a certain power level
591 in the power table or may access the table index-based:
592 @code
593 // Set a certain power level. Search a matching level.
594 RF_setTxPower(h, RF_TxPowerTable_findValue(txPowerTable, 17));
595 
596 // Set a certain power level with a known level.
597 RF_setTxPower(h, txPowerTable[3].value);
598 
599 // Set a certain power without using a human readable level.
600 RF_setTxPower(h, value);
601 
602 // Set maximum power. Search the value.
603 RF_setTxPower(h, RF_TxPowerTable_findValue(txPowerTable, RF_TxPowerTable_MAX_DBM));
604 
605 // Set minimum power without searching.
606 RF_setTxPower(h, txPowerTable[0].value);
607 
608 // Set minimum power. Search the value.
609 RF_setTxPower(h, RF_TxPowerTable_findValue(txPowerTable, RF_TxPowerTable_MIN_DBM));
610 
611 // Set maximum power without searching.
612 int32_t lastIndex = sizeof(txPowerTable) / sizeof(RF_TxPowerTable_Entry) - 2;
613 RF_setTxPower(h, txPowerTable[lastIndex].value);
614 @endcode
615 
616 The current configured power level for a client can be retrieved by #RF_getTxPower().
617 @code
618 // Get the current configured power level.
619 int8_t power = RF_TxPowerTable_findPowerLevel(txPowerTable, RF_getTxPower(h));
620 @endcode
621 
622 <hr>
623 @anchor rf_convenience_features
624 Convenience features
625 ====================
626 
627 The RF driver simplifies often needed tasks and provides additional functions.
628 For instance, it can read the RSSI while the RF core is in RX mode using the
629 function :tidrivers_api:`RF_getRssi`:
630 
631 @code
632 int8_t rssi = RF_getRssi(rfHandle);
633 assert (rssi != RF_GET_RSSI_ERROR_VAL); // Could not read the RSSI
634 @endcode
635 
636 <hr>
637  ******************************************************************************
638  */
639 
640 //*****************************************************************************
641 //
642 //! \addtogroup rf_driver
643 //! @{
644 //! \addtogroup rf_driver_cc13x2_cc26x2
645 //! @{
646 //
647 //*****************************************************************************
648 
649 #ifndef ti_drivers_rfcc26x2__include
650 #define ti_drivers_rfcc26x2__include
651 
652 #ifdef __cplusplus
653 extern "C" {
654 #endif
655 
656 #include <stdint.h>
657 #include <stdbool.h>
658 
659 #include <ti/drivers/dpl/ClockP.h>
660 #include <ti/drivers/dpl/SemaphoreP.h>
661 #include <ti/drivers/utils/List.h>
662 
663 #include <ti/devices/DeviceFamily.h>
664 #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
665 #include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h)
666 #include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h)
667 
668 /**
669  *  @name RF Core Events
670  *  @anchor RF_Core_Events
671  *
672  *  Events originating on the RF core and caused during command execution.
673  *  They are aliases for the corresponding interrupt flags.
674  *  RF Core Events are command-specific and are explained in the Technical Reference Manual.
675  *
676  *  @sa RF_postCmd(), RF_pendCmd(), RF_runCmd()
677  *  @{
678  */
679 #define   RF_EventCmdDone             (1 << 0)   ///< A radio operation command in a chain finished.
680 #define   RF_EventLastCmdDone         (1 << 1)   ///< A stand-alone radio operation command or the last radio operation command in a chain finished.
681 #define   RF_EventFGCmdDone           (1 << 2)   ///< A IEEE-mode radio operation command in a chain finished.
682 #define   RF_EventLastFGCmdDone       (1 << 3)   ///< A stand-alone IEEE-mode radio operation command or the last command in a chain finished.
683 #define   RF_EventTxDone              (1 << 4)   ///< Packet transmitted
684 #define   RF_EventTXAck               (1 << 5)   ///< ACK packet transmitted
685 #define   RF_EventTxCtrl              (1 << 6)   ///< Control packet transmitted
686 #define   RF_EventTxCtrlAck           (1 << 7)   ///< Acknowledgement received on a transmitted control packet
687 #define   RF_EventTxCtrlAckAck        (1 << 8)   ///< Acknowledgement received on a transmitted control packet, and acknowledgement transmitted for that packet
688 #define   RF_EventTxRetrans           (1 << 9)   ///< Packet retransmitted
689 #define   RF_EventTxEntryDone         (1 << 10)  ///< Tx queue data entry state changed to Finished
690 #define   RF_EventTxBufferChange      (1 << 11)  ///< A buffer change is complete
691 #define   RF_EventPaChanged           (1 << 14)  ///< The PA was reconfigured on the fly.
692 #define   RF_EventSamplesEntryDone    (1 << 15)  ///< CTE data has been copied, only valid if autocopy feature is enabled
693 #define   RF_EventRxOk                (1 << 16)  ///< Packet received with CRC OK, payload, and not to be ignored
694 #define   RF_EventRxNOk               (1 << 17)  ///< Packet received with CRC error
695 #define   RF_EventRxIgnored           (1 << 18)  ///< Packet received with CRC OK, but to be ignored
696 #define   RF_EventRxEmpty             (1 << 19)  ///< Packet received with CRC OK, not to be ignored, no payload
697 #define   RF_EventRxCtrl              (1 << 20)  ///< Control packet received with CRC OK, not to be ignored
698 #define   RF_EventRxCtrlAck           (1 << 21)  ///< Control packet received with CRC OK, not to be ignored, then ACK sent
699 #define   RF_EventRxBufFull           (1 << 22)  ///< Packet received that did not fit in the Rx queue
700 #define   RF_EventRxEntryDone         (1 << 23)  ///< Rx queue data entry changing state to Finished
701 #define   RF_EventDataWritten         (1 << 24)  ///< Data written to partial read Rx buffer
702 #define   RF_EventNDataWritten        (1 << 25)  ///< Specified number of bytes written to partial read Rx buffer
703 #define   RF_EventRxAborted           (1 << 26)  ///< Packet reception stopped before packet was done
704 #define   RF_EventRxCollisionDetected (1 << 27)  ///< A collision was indicated during packet reception
705 #define   RF_EventModulesUnlocked     (1 << 29)  ///< As part of the boot process, the CM0 has opened access to RF core modules and memories
706 #define   RF_EventInternalError       (uint32_t)(1 << 31) ///< Internal error observed
707 #define   RF_EventMdmSoft             0x0000002000000000  ///< Synchronization word detected (MDMSOFT interrupt flag)
708 /** @}*/
709 
710 /**
711  *  @name RF Driver Events
712  *  @anchor RF_Driver_Events
713  *
714  *  Event flags generated by the RF Driver.
715  *  @{
716  */
717 #define   RF_EventCmdCancelled        0x1000000000000000  ///< Command canceled before it was started.
718 #define   RF_EventCmdAborted          0x2000000000000000  ///< Abrupt command termination caused by RF_cancelCmd() or RF_flushCmd().
719 #define   RF_EventCmdStopped          0x4000000000000000  ///< Graceful command termination caused by RF_cancelCmd() or RF_flushCmd().
720 #define   RF_EventRatCh               0x0800000000000000  ///< A user-programmable RAT channel triggered an event.
721 #define   RF_EventPowerUp             0x0400000000000000  ///< RF power up event. \deprecated This event is deprecated. Use #RF_ClientEventPowerUpFinished instead.
722 #define   RF_EventError               0x0200000000000000  ///< Event flag used for error callback functions to indicate an error. See RF_Params::pErrCb.
723 #define   RF_EventCmdPreempted        0x0100000000000000  ///< Command preempted by another command with higher priority. Applies only to multi-client applications.
724 /** @}*/
725 
726 /**
727  *  @name Control codes for driver configuration
728  *  @anchor RF_CTRL
729  *
730  *  Control codes are used in RF_control().
731  *
732  *  @{
733  */
734 
735 /*!
736  * @brief Control code used by RF_control to set inactivity timeout
737  *
738  * Setting this control allows RF to power down the radio upon completion of a radio
739  * command after a specified timeout period (in us)
740  * With this control code @b arg is a pointer to the timeout variable and returns RF_StatSuccess.
741  */
742 #define RF_CTRL_SET_INACTIVITY_TIMEOUT            0
743 /*!
744  * @brief Control code used by RF_control to update setup command
745  *
746  * Setting this control notifies RF that the setup command is to be updated, so that RF will take
747  * proper actions when executing the next setup command.
748  * Note the updated setup command will take effect in the next power up cycle when RF executes the
749  * setup command. Prior to updating the setup command, user should make sure all pending commands
750  * have completed.
751  */
752 #define RF_CTRL_UPDATE_SETUP_CMD                  1
753 /*!
754  * @brief Control code used by RF_control to set powerup duration margin
755  *
756  * Setting this control updates the powerup duration margin. Default is RF_DEFAULT_POWER_UP_MARGIN.
757  */
758 #define RF_CTRL_SET_POWERUP_DURATION_MARGIN       2
759 /*!
760  * @brief Control code used by RF_control to set the phy switching margin
761  *
762  * Setting this control updates the phy switching duration margin, which is used to calculate when
763  * run-time conflicts shall be evaluated in case of colliding radio operations issued from two
764  * different clients. Default is RF_DEFAULT_PHY_SWITCHING_MARGIN.
765  */
766 #define RF_CTRL_SET_PHYSWITCHING_DURATION_MARGIN  3
767 /*!
768  * @brief Control code used by RF_control to set max error tolerance for RAT/RTC
769  *
770  * Setting this control updates the error tol for how frequently the CMD_RAT_SYNC_STOP is sent.
771  * Default is RF_DEFAULT_RAT_RTC_ERR_TOL_IN_US (5 us)
772  * Client is recommeneded to change this setting before sending any commands.
773  */
774 #define RF_CTRL_SET_RAT_RTC_ERR_TOL_VAL           4
775 /*!
776  * @brief Control code used by RF_control to set power management
777  *
778  * Setting this control configures RF driver to enable or disable power management.
779  * By default power management is enabled.
780  * If disabled, once RF core wakes up, RF driver will not go to standby and will not power down RF core.
781  * To configure power management, use this control to pass a parameter value of 0 to disable power management,
782  * and pass a parameter value of 1 to re-enable power management.
783  * This control is valid for dual-mode code only. Setting this control when using single-mode code has no effect
784  * (power management always enabled).
785  */
786 #define RF_CTRL_SET_POWER_MGMT                    5
787 /*!
788  * @brief Control code used by RF_control to set the hardware interrupt priority level of the RF driver.
789  *
790  * This control code sets the hardware interrupt priority level that is used by the RF driver. Valid
791  * values are INT_PRI_LEVEL1 (highest) until INT_PRI_LEVEL7 (lowest). The default interrupt priority is
792  * set in the board support file. The default value is -1 which means "lowest possible priority".
793  *
794  * When using the TI-RTOS kernel, INT_PRI_LEVEL0 is reserved for zero-latency interrupts and must not be used.
795  *
796  * Execute this control code only while the RF core is powered down and the RF driver command queue is empty.
797  * This is usually the case after calling RF_open(). Changing the interrupt priority level while the RF driver
798  * is active will result in RF_StatBusyError being returned.
799  *
800  * Example:
801  * @code
802  * #include DeviceFamily_constructPath(driverlib/interrupt.h)
803  *
804  * int32_t hwiPriority = INT_PRI_LEVEL5;
805  * RF_control(rfHandle, RF_CTRL_SET_HWI_PRIORITY, &hwiPriority);
806  * @endcode
807  */
808 #define RF_CTRL_SET_HWI_PRIORITY                  6
809 /*!
810  * @brief Control code used by RF_control to set the software interrupt priority level of the RF driver.
811  *
812  * This control code sets the software interrupt priority level that is used by the RF driver. Valid
813  * values are integers starting at 0 (lowest) until <tt>Swi_numPriorities - 1</tt> (highest). The default
814  * interrupt priority is set in the board support file. The default value is 0 which means means
815  * "lowest possible priority".
816  *
817  * Execute this control code only while the RF core is powered down and the RF driver command queue is empty.
818  * This is usually the case after calling RF_open(). Changing the interrupt priority level while the RF driver
819  * is active will result in RF_StatBusyError being returned.
820  *
821  * Example:
822  * @code
823  * #include <ti/sysbios/knl/Swi.h>
824  *
825  * // Set highest possible priority
826  * uint32_t swiPriority = ~0;
827  * RF_control(rfHandle, RF_CTRL_SET_SWI_PRIORITY, &swiPriority);
828  * @endcode
829  */
830 #define RF_CTRL_SET_SWI_PRIORITY                  7
831 /*!
832  * @brief Control code used by RF_control to mask the available RAT channels manually.
833  *
834  * This control code can be used to manually disallow/allow access to certain RAT channels from the RAT APIs.
835  * A typical use case is when a RAT channel is programmed through chained radio operations, and hence is
836  * used outside the scope of the RF driver. By disallowing access to this channel one can prevent collision
837  * between the automatic channel allocation through #RF_ratCompare()/#RF_ratCapture() and the direct
838  * configuration through #RF_postCmd().
839  */
840 #define RF_CTRL_SET_AVAILABLE_RAT_CHANNELS_MASK   8
841 /*!
842  * @brief Control code used by RF_control to enable or disable the coexistence feature at runtime
843  *
844  * This control code can be used to manually override the statically configured setting for global enable/disable
845  * of the coexistence feature. It will have no effect if coexistence is not originally enabled and included
846  * in the compiled project.
847  *
848  * Example:
849  * @code
850  * // Disable the CoEx feature
851  * uint32_t coexEnabled = 0;
852  * RF_control(rfHandle, RF_CTRL_COEX_CONTROL, &coexEnabled);
853  * @endcode
854  */
855 #define RF_CTRL_COEX_CONTROL  9
856 /** @}*/
857 
858 /**
859  * @name TX Power Table defines
860  * @{
861  */
862 
863 /**
864  * Refers to the the minimum available power in dBm when accessing a power
865  * table.
866  *
867  * \sa #RF_TxPowerTable_findValue()
868  */
869 #define RF_TxPowerTable_MIN_DBM   -128
870 
871 /**
872  * Refers to the the maximum available power in dBm when accessing a power
873  * table.
874  *
875  * \sa #RF_TxPowerTable_findValue()
876  */
877 #define RF_TxPowerTable_MAX_DBM   126
878 
879 /**
880  * Refers to an invalid power level in a TX power table.
881  *
882  * \sa #RF_TxPowerTable_findPowerLevel()
883  */
884 #define RF_TxPowerTable_INVALID_DBM   127
885 
886 /**
887  * Refers to an invalid power value in a TX power table.
888  *
889  * This is the raw value part of a TX power configuration. In order to check
890  * whether a given power configuration is valid, do:
891  *
892  * @code
893  * RF_TxPowerTable_Value value = ...;
894  * if (value.rawValue == RF_TxPowerTable_INVALID_VALUE) {
895  *     // error, value not valid
896  * }
897  * @endcode
898  *
899  * A TX power table is always terminated by an invalid power configuration.
900  *
901  * \sa #RF_getTxPower(), RF_TxPowerTable_findValue
902  */
903 #define RF_TxPowerTable_INVALID_VALUE 0x3fffff
904 
905 /**
906  * Marks the last entry in a TX power table.
907  *
908  * In order to use #RF_TxPowerTable_findValue() and #RF_TxPowerTable_findPowerLevel(),
909  * every power table must be terminated by a %RF_TxPowerTable_TERMINATION_ENTRY:
910  *
911  * @code
912  * RF_TxPowerTable_Entry txPowerTable[] =
913  * {
914  *     { 20,  RF_TxPowerTable_HIGH_PA_ENTRY(1, 2, 3) },
915  *     // ... ,
916  *     RF_TxPowerTable_TERMINATION_ENTRY
917  * };
918  * @endcode
919  */
920 #define RF_TxPowerTable_TERMINATION_ENTRY \
921         { .power = RF_TxPowerTable_INVALID_DBM, .value = { .rawValue = RF_TxPowerTable_INVALID_VALUE, .paType = RF_TxPowerTable_DefaultPA } }
922 
923 /**
924  * Creates a TX power table entry for the default PA.
925  *
926  * The values for \a bias, \a gain, \a boost and \a coefficient are usually measured by Texas Instruments
927  * for a specific front-end configuration. They can then be obtained from SmartRFStudio.
928  */
929 #define RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost, coefficient) \
930         { .rawValue = ((bias) << 0) | ((gain) << 6) | ((boost) << 8) | ((coefficient) << 9), .paType = RF_TxPowerTable_DefaultPA }
931 
932 /**
933  * Creates a TX power table entry for the High-power PA.
934  *
935  * The values for \a bias, \a ibboost, \a boost, \a coefficient and \a ldoTrim are usually measured by Texas Instruments
936  * for a specific front-end configuration. They can then be obtained from SmartRFStudio.
937  */
938 #define RF_TxPowerTable_HIGH_PA_ENTRY(bias, ibboost, boost, coefficient, ldotrim) \
939         { .rawValue = ((bias) << 0) | ((ibboost) << 6) | ((boost) << 8) | ((coefficient) << 9) | ((ldotrim) << 16), .paType = RF_TxPowerTable_HighPA }
940 
941 
942 /** @} */
943 
944 /**
945  * @name Other defines
946  * @{
947  */
948 #define RF_GET_RSSI_ERROR_VAL                   (-128)   ///< Error return value for RF_getRssi()
949 #define RF_CMDHANDLE_FLUSH_ALL                  (-1)     ///< RF command handle to flush all RF commands
950 #define RF_ALLOC_ERROR                          (-2)     ///< RF command or RAT channel allocation error
951 #define RF_SCHEDULE_CMD_ERROR                   (-3)     ///< RF command schedule error
952 #define RF_ERROR_RAT_PROG                       (-255)   ///< A rat channel could not be programmed.
953 #define RF_ERROR_INVALID_RFMODE                 (-256)   ///< Invalid RF_Mode. Used in error callback.
954 #define RF_ERROR_CMDFS_SYNTH_PROG               (-257)   ///< Synthesizer error with CMD_FS. Used in error callback. If this error occurred in error callback, user needs to resend CMD_FS to recover. See the device's errata for more details.
955 
956 #define RF_NUM_SCHEDULE_ACCESS_ENTRIES          2        ///< Number of access request entries
957 #define RF_NUM_SCHEDULE_COMMAND_ENTRIES         8        ///< Number of scheduled command entries
958 #define RF_NUM_SCHEDULE_MAP_ENTRIES             (RF_NUM_SCHEDULE_ACCESS_ENTRIES + RF_NUM_SCHEDULE_COMMAND_ENTRIES) ///< Number of schedule map entries. This is the sum of access request and scheduled command entries
959 #define RF_SCH_MAP_CURRENT_CMD_OFFSET           RF_NUM_SCHEDULE_ACCESS_ENTRIES      ///< Offset of the current command entry in the schedule map
960 #define RF_SCH_MAP_PENDING_CMD_OFFSET           (RF_SCH_MAP_CURRENT_CMD_OFFSET + 2) ///< Offset of the first pending command entry in the schedule map
961 
962 #define RF_ABORT_PREEMPTION                     (1<<2)   ///< Used with RF_cancelCmd() to provoke subscription to RadioFreeCallback
963 #define RF_ABORT_GRACEFULLY                     (1<<0)   ///< Used with RF_cancelCmd() for graceful command termination
964 
965 #define RF_SCH_CMD_EXECUTION_TIME_UNKNOWN       0        ///< For unknown execution time for RF scheduler
966 
967 #define RF_RAT_ANY_CHANNEL                      (-1)     ///< To be used within the channel configuration structure. Allocate any of the available channels.
968 #define RF_RAT_TICKS_PER_US                     4        ///< Radio timer (RAT) ticks per microsecond.
969 
970 #define RF_LODIVIDER_MASK                       0x7F     ///< Mask to be used to determine the effective value of the setup command's loDivider field.
971 
972 /**
973  *  @name Stack ID defines
974  *  @anchor RF_Stack_ID
975  *
976  *  Reserved values to identify which stack owns an RF_Handle h (stored as h->clientConfig.nID)
977  *  @{
978  */
979 #define RF_STACK_ID_DEFAULT                     0x00000000  ///< No value is set.
980 #define RF_STACK_ID_154                         0x8000F154  ///< ID for TI 15.4 Stack
981 #define RF_STACK_ID_BLE                         0x8000FB1E  ///< ID for TI BLE Stack
982 #define RF_STACK_ID_EASYLINK                    0x8000FEA2  ///< ID for TI EasyLink Stack
983 #define RF_STACK_ID_THREAD                      0x8000FEAD  ///< ID for TI Thread Stack
984 #define RF_STACK_ID_TOF                         0x8000F00F  ///< ID for TI TOF Stack
985 #define RF_STACK_ID_CUSTOM                      0x0000FC00  ///< ID for Custom Stack
986 /** @} */
987 
988 /*!
989 \brief Converts a duration given in \a microseconds into radio timer (RAT) ticks.
990 */
991 #define RF_convertUsToRatTicks(microseconds) \
992     ((microseconds) * (RF_RAT_TICKS_PER_US))
993 
994 /*!
995 \brief Converts a duration given in \a milliseconds into radio timer (RAT) ticks.
996 */
997 #define RF_convertMsToRatTicks(milliseconds) \
998     ((milliseconds) * 1000 * (RF_RAT_TICKS_PER_US))
999 
1000 /*!
1001 \brief Converts a duration given in radio timer (RAT) \a ticks into microseconds.
1002 */
1003 #define RF_convertRatTicksToUs(ticks) \
1004     ((ticks) / (RF_RAT_TICKS_PER_US))
1005 
1006 /*!
1007 \brief Converts a duration given in radio timer (RAT) \a ticks into milliseconds.
1008 */
1009 #define RF_convertRatTicksToMs(ticks) \
1010     ((ticks) / (1000 * (RF_RAT_TICKS_PER_US)))
1011 
1012 
1013 /** @}*/
1014 
1015 
1016 /**
1017  * \brief PA configuration value for a certain power level.
1018  *
1019  * A %RF_TxPowerTable_Value contains the power amplifier (PA) configuration for a certain power level.
1020  * It encodes the PA type as well as a raw configuration value for the RF core hardware.
1021  *
1022  * \sa #RF_getTxPower(), #RF_setTxPower(), #RF_TxPowerTable_Entry, #RF_TxPowerTable_PAType.
1023  */
1024 typedef struct {
1025     uint32_t rawValue:22;      ///< Hardware configuration value.
1026                                ///<
1027                                ///< - \c [15:0] used for default PA,
1028                                ///< - \c [21:0] used for High-power PA
1029     uint32_t __dummy:9;
1030     uint32_t paType:1;         ///< Selects the PA type to be used.
1031                                ///<
1032                                ///< - 0: #RF_TxPowerTable_DefaultPA
1033                                ///< - 1: #RF_TxPowerTable_HighPA
1034 } RF_TxPowerTable_Value;
1035 
1036 /**
1037  * \brief TX power configuration entry in a TX power table.
1038  *
1039  * A %RF_TxPowerTable_Entry defines an entry in a lookup table. Each entry contains a
1040  * human-readable power level \a power as key and a hardware configuration \a value.
1041  *
1042  * Example of a typical power table:
1043  * \code
1044  * RF_TxPowerTable_Entry txPowerTable[] = {
1045  *    { .power = 20,  .value = { .rawValue = 0x1234, .paType = RF_TxPowerTable_HighPA }},
1046  *    { .power = 19,  .value = { .rawValue = 0x1233, .paType = RF_TxPowerTable_HighPA }},
1047  *    // ...
1048  *    RF_TxPowerTable_TERMINATION_ENTRY
1049  * };
1050  * \endcode
1051  *
1052  * \sa #RF_TxPowerTable_findPowerLevel(), #RF_TxPowerTable_findPowerLevel()
1053  */
1054 typedef struct
1055 {
1056     int8_t power;                 ///< Human readable power value representing
1057                                   ///< the output in dBm.
1058 
1059     RF_TxPowerTable_Value value;  ///< PA hardware configuration for that power level.
1060 } __attribute__((packed)) RF_TxPowerTable_Entry;
1061 
1062 
1063 /**
1064  * \brief Selects a power amplifier path in a TX power value.
1065  *
1066  * %RF_TxPowerTable_PAType selects one of the available power amplifiers
1067  * on the RF core. It is usually included in a #RF_TxPowerTable_Value.
1068  */
1069 typedef enum {
1070     RF_TxPowerTable_DefaultPA = 0, ///< Default PA
1071     RF_TxPowerTable_HighPA = 1,    ///< High-power PA
1072 } RF_TxPowerTable_PAType;
1073 
1074 
1075 /** @brief Base type for all radio operation commands.
1076  *
1077  *  All radio operation commands share a common part.
1078  *  That includes the command id, a status field, chaining properties
1079  *  and a start trigger.
1080  *  Whenever an RF operation command is used with the RF driver, it needs
1081  *  to be casted to an RF_Op.
1082  *
1083  *  More information about RF operation commands can be found in the Proprietary RF
1084  *  User's Guide.
1085  *
1086  *  @sa RF_runCmd(), RF_postCmd(), RF_pendCmd()
1087  */
1088 typedef rfc_radioOp_t RF_Op;
1089 
1090 
1091 /** @brief Specifies a RF core firmware configuration.
1092  *
1093  *  %RF_Mode selects a mode of operation and points to firmware patches for the RF core.
1094  *  There exists one instance per radio PHY configuration, usually generated by
1095  *  SmartRF Studio.
1096  *  After assigning %RF_Mode configuration to the RF driver via RF_open(), the
1097  *  driver caches the containing information and re-uses it on every power-up.
1098  */
1099 typedef struct {
1100     uint8_t rfMode;             ///< Specifies which PHY modes should be activated. Must be set to RF_MODE_MULTIPLE for dual-mode operation.
1101     void (*cpePatchFxn)(void);  ///< Pointer to CPE patch function
1102     void (*mcePatchFxn)(void);  ///< Pointer to MCE patch function
1103     void (*rfePatchFxn)(void);  ///< Pointer to RFE patch function
1104 } RF_Mode;
1105 
1106 /** @brief Scheduling priority of RF operation commands.
1107  *
1108  *  When multiple RF driver instances are used at the same time,
1109  *  commands from different clients may overlap.
1110  *  If an RF operation with a higher priority than the currently
1111  *  running operation is scheduled by RF_scheduleCmd(), then the
1112  *  running operation is interrupted.
1113  *
1114  *  In single-client applications, %RF_PriorityNormal should be used.
1115  */
1116 typedef enum {
1117     RF_PriorityHighest = 2, ///< Highest priority. Only use this for urgent commands.
1118     RF_PriorityHigh    = 1, ///< High priority. Use this for time-critical commands in synchronous protocols.
1119     RF_PriorityNormal  = 0, ///< Default priority. Use this in single-client applications.
1120 } RF_Priority;
1121 
1122 /**
1123  *  @brief Priority level for coexistence priority signal.
1124  *
1125  *  When the RF driver is configured for three-wire coexistence mode, one of the
1126  *  output wires will signal the priority level of the coexistence request. When
1127  *  RF operations are scheduled with RF_scheduleCmd(), the scheduler can be configured
1128  *  to override the default coexistence priority level for the RF operation.
1129  *
1130  *  The coexistence priority level is binary because it translates to a high/low output signal.
1131  */
1132 typedef enum {
1133     RF_PriorityCoexDefault  = 0,  ///< Default priority. Use value configured by setup command.
1134     RF_PriorityCoexLow      = 1,  ///< Low priority. Override default value configured by setup command.
1135     RF_PriorityCoexHigh     = 2,  ///< High priority. Override default value configured by setup command.
1136 } RF_PriorityCoex;
1137 
1138 /**
1139  *  @brief Behavior for coexistence request signal.
1140  *
1141  *  When the RF driver is configured for three-wire coexistence mode, one of the
1142  *  output wires will signal the request level of the coexistence request. When
1143  *  RF operations are scheduled with RF_scheduleCmd(), the scheduler can be configured
1144  *  to override the default coexistence request line behavior for the RF operation in RX.
1145  *
1146  *  This override will be ignored if the option to set request for an entire chain is active.
1147  */
1148 typedef enum {
1149     RF_RequestCoexDefault     = 0, ///< Default request line behavior. Use value configured by setup command.
1150     RF_RequestCoexAssertRx    = 1, ///< Assert REQUEST in RX. Override default value configured by setup command.
1151     RF_RequestCoexNoAssertRx  = 2, ///< Do not assert REQUEST in RX. Override default value configured by setup command.
1152 } RF_RequestCoex;
1153 
1154 /**
1155  *  @brief Runtime coexistence override parameters
1156  *
1157  *  When  RF operations are scheduled with RF_scheduleCmd(), the scheduler can be configured
1158  *  to override the default coexistence behavior. This structure encapsulates the available parameters.
1159  */
1160 typedef struct {
1161     RF_PriorityCoex   priority;   ///< Priority level for coexistence priority signal.
1162     RF_RequestCoex    request;    ///< Behavior for coexistence request signal.
1163 } RF_CoexOverride;
1164 
1165 /**
1166  *  @brief Coexistence override settings for BLE5 application scenarios
1167  *
1168  *  This configuration is provided to the BLE Stack to override the default coexistence configuration
1169  *  depending on the current application and stack states.
1170  */
1171 typedef struct {
1172     RF_CoexOverride    bleInitiator;
1173     RF_CoexOverride    bleConnected;
1174     RF_CoexOverride    bleBroadcaster;
1175     RF_CoexOverride    bleObserver;
1176 } RF_CoexOverride_BLEUseCases;
1177 
1178 /** @brief Status codes for various RF driver functions.
1179  *
1180  *  RF_Stat is reported as return value for RF driver functions which
1181  *  execute direct and immediate commands.
1182  *  Such commands are executed by RF_runDirectCmd() and RF_runImmediateCmd() in the
1183  *  first place, but also by some convenience functions like RF_cancelCmd(),
1184  *  RF_flushCmd(), RF_getInfo() and others.
1185  */
1186 typedef enum {
1187     RF_StatBusyError,          ///< Command not executed because RF driver is busy.
1188     RF_StatRadioInactiveError, ///< Command not executed because RF core is powered down.
1189     RF_StatCmdDoneError,       ///< Command finished with an error.
1190     RF_StatInvalidParamsError, ///< Function was called with an invalid parameter.
1191     RF_StatCmdEnded,           ///< Cmd is found in the pool but was already ended.
1192     RF_StatError   = 0x80,     ///< General error specifier.
1193     RF_StatCmdDoneSuccess,     ///< Command finished with success.
1194     RF_StatCmdSch,             ///< Command successfully scheduled for execution.
1195     RF_StatSuccess             ///< Function finished with success.
1196 } RF_Stat;
1197 
1198 /** @brief Data type for events during command execution.
1199  *
1200  *  Possible event flags are listed in @ref RF_Core_Events and @ref RF_Driver_Events.
1201  */
1202 typedef uint64_t RF_EventMask;
1203 
1204 /** @brief A unified type for radio setup commands of different PHYs.
1205  *
1206  *  Radio setup commands are used to initialize a PHY on the RF core.
1207  *  Various partially similar commands exist, each one represented
1208  *  by a different data type.
1209  *  RF_RadioSetup is a generic container for all types.
1210  *  A specific setup command is usually exported from SmartRF Studio
1211  *  and then passed to the RF driver in RF_open().
1212  */
1213 typedef union {
1214     rfc_command_t                      commandId;   ///< Generic command identifier. This is the first field
1215                                                     ///< in every radio operation command.
1216     rfc_CMD_RADIO_SETUP_t              common;      ///< Radio setup command for BLE and IEEE modes
1217     rfc_CMD_BLE5_RADIO_SETUP_t         ble5;        ///< Radio setup command for BLE5 mode
1218     rfc_CMD_PROP_RADIO_SETUP_t         prop;        ///< Radio setup command for PROPRIETARY mode on 2.4 GHz
1219     rfc_CMD_PROP_RADIO_DIV_SETUP_t     prop_div;    ///< Radio setup command for PROPRIETARY mode on Sub-1 Ghz
1220     rfc_CMD_RADIO_SETUP_PA_t           common_pa;   ///< Radio setup command for BLE and IEEE modes with High Gain PA
1221     rfc_CMD_BLE5_RADIO_SETUP_PA_t      ble5_pa;     ///< Radio setup command for BLE5 mode with High Gain PA
1222     rfc_CMD_PROP_RADIO_SETUP_PA_t      prop_pa;     ///< Radio setup command for PROPRIETARY mode on 2.4 GHz with High Gain PA
1223     rfc_CMD_PROP_RADIO_DIV_SETUP_PA_t  prop_div_pa; ///< Radio setup command for PROPRIETARY mode on Sub-1 Ghz with High Gain PA
1224 } RF_RadioSetup;
1225 
1226 /** @brief Client-related RF driver events.
1227  *
1228  *  Events originating in the RF driver but not directly related to a specific radio command,
1229  *  are called client events.
1230  *  Clients may subscribe to these events by specifying a callback function RF_Params::pClientEventCb.
1231  *  Events are activated by specifying a bitmask RF_Params::nClientEventMask.
1232  *  The callback is called separately for every event providing an optional argument.
1233  *
1234  *  @code
1235  *  void onClientEvent(RF_Handle h, RF_ClientEvent event, void* arg)
1236  *  {
1237  *      switch (event)
1238  *      {
1239  *      case RF_ClientEventPowerUpFinished:
1240  *          // Set output port
1241  *          break;
1242  *      default:
1243  *          // Unsubscribed events must not be issued.
1244  *          assert(false);
1245  *      }
1246  *  }
1247  *
1248  *  RF_Params params;
1249  *  params.pClientEventCb = &onClientEvent;
1250  *  params.nClientEventMask = RF_ClientEventPowerUpFinished;
1251  *  RF_open(...);
1252  *  @endcode
1253  */
1254 typedef enum {
1255     RF_ClientEventPowerUpFinished     = (1 << 0),   ///< The RF core has been powered up the radio setup has been finished.
1256     RF_ClientEventRadioFree           = (1 << 1),   ///< Radio becomes free after a command has been preempted by a high-priority command of another client.
1257                                                     ///< This event is only triggered on a client that has been preempted.
1258                                                     ///< Clients may use this event to retry running their low-priority RF operation.
1259 
1260     RF_ClientEventSwitchClientEntered = (1 << 2)    ///< Signals the client that the RF driver is about to switch over from another client.
1261 } RF_ClientEvent;
1262 
1263 /** @brief Global RF driver events.
1264  *
1265  *  The RF driver provides an interface through the global \c RFCC26XX_hwAttrs
1266  *  struct to register a global, client independent callback. This callback is
1267  *  typically used to control board related configurations such as antenna
1268  *  switches.
1269  *
1270  *  @code
1271  *  void globalCallback(RF_Handle h, RF_GlobalEvent event, void* arg)
1272  *  {
1273  *      switch (event)
1274  *      {
1275  *      case RF_GlobalEventRadioSetup:
1276  *      {
1277  *          RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
1278  *          // Select antenna path
1279  *          if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) {
1280  *              // Sub-1 GHz ...
1281  *          } else {
1282  *              // 2.4 GHz ...
1283  *          }
1284  *      }
1285  *          break;
1286  *
1287  *      case RF_GlobalEventRadioPowerDown:
1288  *          // Disable antenna switch
1289  *          break;
1290  *
1291  *      default:
1292  *          // Unsubscribed events must not be issued.
1293  *          assert(false);
1294  *      }
1295  *  }
1296  *  @endcode
1297  *
1298  *  For the coexistence (coex) feature, some of the events are used to handle
1299  *  the I/O muxing of the GPIO signals for REQUEST, PRIORITY and GRANT.
1300  *
1301  *  @code
1302  *  void globalCallback(RF_Handle h, RF_GlobalEvent event, void* arg)
1303  *  {
1304  *      RF_Cmd* pCurrentCmd = (RF_Cmd*)arg;
1305  *
1306  *      if (event & RF_GlobalEventInit) {
1307  *          // Initialize and mux coex I/O pins to RF Core I/O signals
1308  *      }
1309  *      else if (event & RF_GlobalEventCmdStart) {
1310  *          if (pCurrentCmd->coexPriority != RF_PriorityCoexDefault){
1311  *              // Release PRIORITY pin from RF Core and set it to value of coexPriority
1312  *          }
1313  *      }
1314  *      else if (event & RF_GlobalEventCmdStop) {
1315  *          if (pCurrentCmd->coexPriority != RF_PriorityCoexDefault) {
1316  *              // Mux PRIORITY pin to RF Core signal to return to default priority level
1317  *          }
1318  *      }
1319  *  }
1320  *  @endcode
1321  *
1322  * \sa #RF_GlobalCallback
1323  */
1324 typedef enum {
1325     RF_GlobalEventRadioSetup     = (1 << 0),             ///< The RF core is being reconfigured through a setup command.
1326                                                          ///< The \a arg argument is a pointer to the setup command.
1327                                                          ///< HWI context.
1328 
1329     RF_GlobalEventRadioPowerDown = (1 << 1),             ///< The RF core is being powered down.
1330                                                          ///< The \a arg argument is empty.
1331                                                          ///< SWI context.
1332 
1333     RF_GlobalEventInit           = (1 << 2),             ///< RF_open() is called for the first time (number of registered clients changes from 0 to 1).
1334                                                          ///< The \a arg argument is empty.
1335                                                          ///< Task context.
1336 
1337     RF_GlobalEventCmdStart       = (1 << 3),             ///< A command chain is being dispatched to the radio.
1338                                                          ///< The \a arg argument is a pointer to the current command.
1339                                                          ///< HWI context.
1340 
1341     RF_GlobalEventCmdStop        = (1 << 4),             ///< Command termination event is handled.
1342                                                          ///< The \a arg argument is a pointer to the current command.
1343                                                          ///< HWI context.
1344 
1345     RF_GlobalEventCoexControl    = (1 << 5),             ///< Change to coex configuration is requested
1346                                                          ///< The \a arg argument is pointer to at least 8-bit wide int with value 1=enable, or 0=disable
1347                                                          ///< Task/HWI context.
1348 } RF_GlobalEvent;
1349 
1350 
1351 /** @brief Event mask for combining #RF_ClientEvent event flags in #RF_Params::nClientEventMask.
1352  *
1353  */
1354 typedef uint32_t RF_ClientEventMask;
1355 
1356 /** @brief Event mask for combining #RF_GlobalEvent event flags in #RFCC26XX_HWAttrsV2::globalEventMask.
1357  *
1358  */
1359 typedef uint32_t RF_GlobalEventMask;
1360 
1361 /** @brief Command handle that is returned by RF_postCmd().
1362  *
1363  *  A command handle is an integer number greater equals zero and identifies
1364  *  a command container in the RF driver's internal command queue. A client
1365  *  can dispatch a command with RF_postCmd() and use the command handle
1366  *  later on to make the RF driver interact with the command.
1367  *
1368  *  A negative value has either a special meaning or indicates an error.
1369  *
1370  *  @sa RF_pendCmd(), RF_flushCmd(), RF_cancelCmd(), ::RF_ALLOC_ERROR,
1371  *      ::RF_CMDHANDLE_FLUSH_ALL
1372  */
1373 typedef int16_t RF_CmdHandle;
1374 
1375 /** @struct RF_Object
1376  *  @brief Stores the client's internal configuration and states.
1377  *
1378  *  Before RF_open() can be called, an instance of RF_Object must be created where
1379  *  the RF driver can store its internal configuration and states.
1380  *  This object must remain persistent throughout application run-time and must not be
1381  *  modified by the application.
1382  *
1383  *  The size of #RF_Object can be optimized for single-mode applications by providing a
1384  *  `RF_SINGLEMODE` symbol at compilation time. The pre-built single-mode archive was generated
1385  *  with this symbol defined, hence any project using this archive must also define `RF_SINGLEMODE`
1386  *  on project level.
1387  *
1388  *  @note Except configuration fields before call to RF_open(), modification of
1389  *        any field in %RF_Object is forbidden.
1390  */
1391 
1392 
1393 /** @cond */
1394 
1395 typedef struct RF_ObjectMultiMode RF_Object;
1396 
1397 /** Definition of the RF_Object structure for multi mode applications.
1398  *  It is applicable with the multi mode RF driver through the #RF_Object common type.
1399  */
1400 struct RF_ObjectMultiMode{
1401     /// Configuration
1402     struct {
1403         uint32_t            nInactivityTimeout;          ///< Inactivity timeout in us.
1404         RF_Mode*            pRfMode;                     ///< Mode of operation.
1405         RF_RadioSetup*      pRadioSetup;                 ///< Pointer to the setup command to be executed at power up.
1406         uint32_t            nPhySwitchingDuration;       ///< Radio reconfiguration time to this client's phy and protocol.
1407         uint32_t            nPowerUpDuration;            ///< Radio power up time to be used to calculate future wake-up events.
1408         bool                bMeasurePowerUpDuration;     ///< Indicates if nPowerUpDuration holds a fix value or being measured and updated at every power up.
1409         bool                bUpdateSetup;                ///< Indicates if an analog configuration update should be performed at the next setup command execution.
1410         uint16_t            nPowerUpDurationMargin;      ///< Power up duration margin in us.
1411         void*               pPowerCb;                    ///< \deprecated Power up callback, will go away in future versions, see clientConfig::pClienteventCb instead
1412         void*               pErrCb;                      ///< Error callback.
1413         void*               pClientEventCb;              ///< Client event callback.
1414         RF_ClientEventMask  nClientEventMask;            ///< Client event mask to activate client event callback.
1415         uint16_t            nPhySwitchingDurationMargin; ///< Phy switching duration margin in us. It is used to calculate when run-time conflicts shall be resolved.
1416         uint32_t            nID;                         ///< RF handle identifier.
1417     } clientConfig;
1418     /// State & variables
1419     struct {
1420         struct {
1421             rfc_CMD_FS_t        cmdFs;              ///< FS command to be executed when the radio is powered up.
1422         } mode_state;                               ///< (Mode-specific) state structure
1423         SemaphoreP_Struct       semSync;            ///< Semaphore used by RF_runCmd(), RF_pendCmd() and power down sequence.
1424         RF_EventMask volatile   eventSync;          ///< Event mask/value used by RF_runCmd() and RF_pendCmd().
1425         void*                   pCbSync;            ///< Internal storage of user callbacks when RF_runCmd() is used.
1426         RF_EventMask            unpendCause;        ///< Internal storage of the return value of RF_pendCmd().
1427         ClockP_Struct           clkReqAccess;       ///< Clock used for request access timeout.
1428         bool                    bYielded;           ///< Flag indicates that the radio can be powered down at the earliest convenience.
1429     } state;
1430 };
1431 
1432 /** @endcond */
1433 
1434 /** @brief A handle that is returned by to RF_open().
1435  *
1436  *  %RF_Handle is used for further RF client interaction with the RF driver.
1437  *  An invalid handle has the value NULL.
1438  */
1439 typedef RF_Object* RF_Handle;
1440 
1441 
1442 /** @brief RAT handle that is returned by RF_ratCompare() or RF_ratCapture().
1443  *
1444  *  An %RF_RatHandle is an integer number with value greater than or equal to zero and identifies
1445  *  a Radio Timer Channel in the RF driver's internal RAT module. A client can interact with the
1446  *  RAT module through the RF_ratCompare(), RF_ratCapture() or RF_ratDisableChannel() APIs.
1447  *
1448  *  A negative value indicates an error. A typical example when RF_ratCompare() returns with RF_ALLOC_ERROR.
1449  */
1450 typedef int8_t RF_RatHandle;
1451 
1452 /** @brief Selects the entry of interest in RF_getInfo().
1453  *
1454  */
1455 typedef enum {
1456     RF_GET_CURR_CMD,                              ///< Retrieve a command handle of the current command.
1457     RF_GET_AVAIL_RAT_CH,                          ///< Create a bitmask showing available RAT channels.
1458     RF_GET_RADIO_STATE,                           ///< Show the current RF core power state. 0: Radio OFF, 1: Radio ON.
1459     RF_GET_SCHEDULE_MAP,                          ///< Deprecated. Not supported.
1460     RF_GET_CLIENT_LIST,                           ///< Provide the client list.
1461     RF_GET_CLIENT_SWITCHING_TIME,                 ///< Provide the client to client switching times
1462 } RF_InfoType;
1463 
1464 /** @brief Stores output parameters for RF_getInfo().
1465  *
1466  *  This union structure holds one out of multiple data types.
1467  *  The contained value is selected by #RF_InfoType.
1468  */
1469 typedef union {
1470     RF_CmdHandle ch;                              ///< Command handle (#RF_GET_CURR_CMD).
1471     uint16_t     availRatCh;                      ///< Available RAT channels (RF_GET_AVAIL_RAT_CH).
1472     bool         bRadioState;                     ///< Current RF core power state (#RF_GET_RADIO_STATE).
1473     RF_Handle    pClientList[2];                  ///< Client pointer list, [0]: client 1, [1]: client 2.
1474     uint32_t     phySwitchingTimeInUs[2];         ///< Phy switching time 0: client 1 -> 2, 1 : client 2 -> 1.
1475     void         *pScheduleMap;                   ///< Deprecated. Not supported.
1476 } RF_InfoVal;
1477 
1478 /** @brief RF schedule map entry structure.
1479  *
1480  */
1481 typedef struct {
1482     RF_CmdHandle ch;                               ///< Command handle
1483     RF_Handle    pClient;                          ///< Pointer to client object
1484     uint32_t     startTime;                        ///< Start time (in RAT tick) of the command or access request
1485     uint32_t     endTime;                          ///< End time (in RAT tick) of the command or access request
1486     RF_Priority  priority;                         ///< Priority of the command or access request
1487 } RF_ScheduleMapElement;
1488 
1489 /** @brief RF schedule map structure.
1490  *
1491  */
1492 typedef struct {
1493     RF_ScheduleMapElement  accessMap[RF_NUM_SCHEDULE_ACCESS_ENTRIES];    ///< Access request schedule map
1494     RF_ScheduleMapElement  commandMap[RF_NUM_SCHEDULE_COMMAND_ENTRIES];  ///< Command schedule map
1495 } RF_ScheduleMap;
1496 
1497 /** @brief Handles events related to RF command execution.
1498  *
1499  *  RF command callbacks notify the application of any events happening during RF command execution.
1500  *  Events may either refer to RF core interrupts (@ref RF_Core_Events) or may be generated by the RF driver
1501  *  (@ref RF_Driver_Events).
1502  *
1503  *  RF command callbacks are set up as parameter to RF_postCmd() or RF_runCmd() and provide:
1504  *
1505  *  - the relevant driver client handle \a h which was returned by RF_open(),
1506  *  - the relevant radio operation command handle \a ch,
1507  *  - an event mask \a e containing the occurred events.
1508  *
1509  *  RF command callbacks are executed in Software Interrupt (SWI) context and must not perform any
1510  *  blocking operation.
1511  *  The priority is configurable via #RFCC26XX_HWAttrsV2 in the board file or #RF_CTRL_SET_SWI_PRIORITY in RF_control().
1512  *
1513  *  The %RF_Callback function type is also used for signaling power events and
1514  *  errors.
1515  *  These are set in #RF_Params::pPowerCb and #RF_Params::pErrCb respectively.
1516  *  In case of a power event, \a ch can be ignored and \a e has #RF_EventPowerUp set.
1517  *  In case of an error callback, \a ch contains an error code instead of a command handle and
1518  *  \a e has the #RF_EventError flag set.
1519  *
1520  *  @note Error and power callbacks will be replaced by #RF_ClientCallback in future releases.
1521  */
1522 typedef void (*RF_Callback)(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
1523 
1524 /** @brief Handles events related to the Radio Timer (RAT).
1525  *
1526  *  The RF driver provides an interface to the Radio Timer through RF_ratCompare(), RF_ratCapture() and
1527  *  RF_ratDisableChannel() APIs. Each API call receives an optional input argument of the type
1528  *  RF_RatCallback. When a timer event occurs (compare, capture or error events), the registered
1529  *  callback is invoked.
1530  *
1531  *  The RF_RatCallback provides the following argument:
1532  *  - the relevant driver client handle \a h which was returned by RF_open(),
1533  *  - the relevant rat timer handle \a rh which the event is caused by,
1534  *  - an event mask \a e containing the occurred event (RF_EventRatCh or RF_EventError)
1535  *  - the captured value or the compare time \a compareCaptureTime read from the Radio Timer channel.
1536  */
1537 typedef void (*RF_RatCallback)(RF_Handle h, RF_RatHandle rh, RF_EventMask e, uint32_t compareCaptureTime);
1538 
1539 /**
1540  *  @brief Handles events related to a driver instance.
1541  *
1542  *  The RF driver produces additional events that are not directly related to the execution of a certain command, but
1543  *  happen during general RF driver operations.
1544  *  This includes power-up events, client switching events and others.
1545  *
1546  *  A client callback provides the following arguments:
1547  *  - the relevant driver client handle \a h which was returned by RF_open(),
1548  *  - an event identifier \a event,
1549  *  - an optional argument \a arg depending on the event.
1550  *
1551  *  RF client callbacks are executed in Software Interrupt (SWI) context and must not perform any blocking operation.
1552  *  The priority is configurable via #RFCC26XX_HWAttrsV2 in the board file or #RF_CTRL_SET_SWI_PRIORITY in RF_control().
1553  */
1554 typedef void (*RF_ClientCallback)(RF_Handle h, RF_ClientEvent event, void* arg);
1555 
1556 /**
1557  *  @brief Handles global events as part of PHY configuration.
1558  *
1559  *  The RF driver serves additional global, client independent events by invoking the #RF_GlobalCallback function
1560  *  registered through #RFCC26XX_HWAttrsV2::globalCallback in the board file. The function can subscribe to
1561  *  particular events through the #RFCC26XX_HWAttrsV2::globalEventMask, and receives the following arguments:
1562  *  - the relevant driver client handle \a h which was returned by RF_open(),
1563  *  - an event identifier \a event,
1564  *  - an optional argument \a arg depending on the event.
1565  *
1566  *  If multiple events happen at the same time, the callback is always invoked separately for each event.
1567  *  Depending on the event, the callback might be invoked in SWI or HWI context.
1568  */
1569 typedef void (*RF_GlobalCallback)(RF_Handle h, RF_GlobalEvent event, void* arg);
1570 
1571 /** @brief RF driver configuration parameters.
1572  *
1573  *  %RF_Params is used for initial RF driver configuration.
1574  *  It is initialized by RF_Params_init() and used by RF_open().
1575  *  Each client has its own set of parameters.
1576  *  They are reconfigured on a client switch.
1577  *  Some of the parameters can be changed during run-time using RF_control().
1578  */
1579 typedef struct {
1580     uint32_t            nInactivityTimeout;      ///< Inactivity timeout in microseconds.
1581                                                  ///< The default value is 0xFFFFFFFF (infinite).
1582 
1583     uint32_t            nPowerUpDuration;        ///< A custom power-up duration in microseconds.
1584                                                  ///< If 0, the RF driver will start with a conservative value and measure the actual time during the first power-up.
1585                                                  ///< The default value is 0.
1586 
1587     RF_Callback         pPowerCb;                ///< \deprecated Power up callback, will be removed future versions, see RF_Params::pClienteventCb instead.
1588                                                  ///< The default value is NULL.
1589 
1590     RF_Callback         pErrCb;                  ///< \deprecated Callback function for driver error events.
1591 
1592     uint16_t            nPowerUpDurationMargin;  ///< An additional safety margin to be added to #RF_Params::nPowerUpDuration.
1593                                                  ///< This is necessary because of other hardware and software interrupts
1594                                                  ///< preempting the RF driver interrupt handlers and state machine.
1595                                                  ///< The default value is platform-dependent.
1596 
1597     uint16_t            nPhySwitchingDurationMargin; ///< An additional safety margin to be used to calculate when conflicts shall be evaluated run-time.
1598 
1599     RF_ClientCallback   pClientEventCb;          ///< Callback function for client-related events.
1600                                                  ///< The default value is NULL.
1601 
1602     RF_ClientEventMask  nClientEventMask;        ///< Event mask used to subscribe certain client events.
1603                                                  ///< The purpose is to keep the number of callback executions small.
1604 
1605     uint32_t            nID;                     ///< RF handle identifier.
1606 } RF_Params;
1607 
1608 /** @brief Controls the behavior of the RF_scheduleCmd() API.
1609  *
1610  */
1611 typedef enum {
1612     RF_StartNotSpecified = 0,
1613     RF_StartAbs          = 1,
1614 } RF_StartType;
1615 
1616 /** @brief Controls the behavior of the RF_scheduleCmd() API.
1617  *
1618  */
1619 typedef enum {
1620     RF_EndNotSpecified = 0,
1621     RF_EndAbs          = 1,
1622     RF_EndRel          = 2,
1623     RF_EndInfinit      = 3,
1624  } RF_EndType;
1625 
1626 /* RF command. */
1627 typedef struct RF_Cmd_s RF_Cmd;
1628 
1629 /* RF command . */
1630 struct RF_Cmd_s {
1631     List_Elem            _elem;       /* Pointer to next and previous elements. */
1632     RF_Callback volatile pCb;         /* Pointer to callback function */
1633     RF_Op*               pOp;         /* Pointer to (chain of) RF operations(s) */
1634     RF_Object*           pClient;     /* Pointer to client */
1635     RF_EventMask         bmEvent;     /* Enable mask for interrupts from the command */
1636     RF_EventMask         pastifg;     /* Accumulated value of events happened within a command chain */
1637     RF_EventMask         rfifg;       /* Return value for callback 0:31 - RF_CPE0_INT, 32:63 - RF_HW_INT */
1638     RF_CmdHandle         ch;          /* Command handle */
1639     RF_Priority          ePri;        /* Priority of RF command */
1640     uint8_t volatile     flags;       /* [0: Aborted, 1: Stopped, 2: canceled] */
1641     uint32_t             startTime;   /* Command start time (in RAT ticks) */
1642     RF_StartType         startType;   /* Command start time type */
1643     uint32_t             allowDelay;  /* Delay allowed if the start time cannot be met. */
1644     uint32_t             endTime;     /* Command end time (in RAT ticks) */
1645     RF_EndType           endType;     /* Command end type */
1646     uint32_t             duration;    /* Command duration (in RAT ticks) */
1647     uint32_t             activityInfo; /* General value supported by user */
1648     RF_PriorityCoex      coexPriority; /* Command priority to use for coexistence request. */
1649     RF_RequestCoex       coexRequest; /* Command REQUEST line behavior to use for coexistence request. */
1650 };
1651 
1652 /** @brief RF Hardware attributes.
1653  *
1654  *  This data structure contains platform-specific driver configuration.
1655  *  It is usually defined globally in a board support file.
1656  */
1657 typedef struct {
1658     uint8_t             hwiPriority;        ///< Priority for HWIs belong to the RF driver.
1659     uint8_t             swiPriority;        ///< Priority for SWIs belong to the RF driver.
1660     bool                xoscHfAlwaysNeeded; ///< Indicate that the XOSC HF should be turned on by the power driver
1661     RF_GlobalCallback   globalCallback;     ///< Pointer to a callback function serving client independent events listed in #RF_GlobalEvent.
1662     RF_GlobalEventMask  globalEventMask;    ///< Event mask which the globalCallback is invoked upon.
1663 } RFCC26XX_HWAttrsV2;
1664 
1665 /** @brief Controls the behavior of the state machine of the RF driver when a conflict is identified
1666  *         run-time between the commands waiting on the pend queue and the commands being actively executed
1667  *         by the radio.
1668  */
1669 typedef enum
1670 {
1671     RF_ExecuteActionNone             = 0,  ///< Execute if no conflict, let current command finish if conflict.
1672     RF_ExecuteActionRejectIncoming   = 1,  ///< Abort the incoming command, letting the ongoing command finish.
1673     RF_ExecuteActionAbortOngoing     = 2,  ///< Abort the ongoing command and run dispatcher again.
1674 } RF_ExecuteAction;
1675 
1676 /** @brief Describes the location within the pend queue where the new command was inserted by the scheduler.
1677  */
1678 typedef enum
1679 {
1680     RF_ScheduleStatusError   = -3,
1681     RF_ScheduleStatusNone    = 0,
1682     RF_ScheduleStatusTop     = 1,
1683     RF_ScheduleStatusMiddle  = 2,
1684     RF_ScheduleStatusTail    = 4,
1685     RF_ScheduleStatusPreempt = 8
1686 } RF_ScheduleStatus;
1687 
1688 /**
1689  *  @brief Handles the queue sorting algorithm when a new command is submitted to the driver from any of
1690  *         the active clients.
1691  *
1692  *  The function is invoked within the RF_scheduleCmd API.
1693  *
1694  *  The default algorithm is subscribed through the #RFCC26XX_SchedulerPolicy::submitHook and implemented
1695  *  in the RF driver. The arguments are:
1696  *      - \a pCmdNew points to the command to be submitted.
1697  *      - \a pCmdBg is the running background command.
1698  *      - \a pCmdFg is the running foreground command.
1699  *      - \a pPendQueue points to the head structure of pend queue.
1700  *      - \a pDoneQueue points to the head structure of done queue.
1701  *
1702  *  In case the radio APIs do not distinguish between background and foreground contexts, the active operation
1703  *  will be returned within the pCmdBg pointer. If there are no commands being executed, both the
1704  *  pCmdBg and pCmdFg pointers are returned as NULL.
1705  */
1706 typedef RF_ScheduleStatus (*RF_SubmitHook)(RF_Cmd* pCmdNew, RF_Cmd* pCmdBg, RF_Cmd* pCmdFg, List_List* pPendQueue, List_List* pDoneQueue);
1707 
1708 /**
1709  *  @brief Defines the execution and conflict resolution hook  at runtime.
1710  *
1711  *  The function is invoked before a scheduled command is about to be executed.
1712  *  If a conflict is identified before the start-time of the next radio command
1713  *  in the pending queue, this information is passed to the hook. The return
1714  *  value of type #RF_ExecuteAction determines the policy to be followed by the RF
1715  *  driver.
1716  *
1717  *  The arguments are:
1718  *      - \a pCmdBg is the running background command.
1719  *      - \a pCmdFg is the running foreground command.
1720  *      - \a pPendQueue points to the head structure of pend queue.
1721  *      - \a pDoneQueue points to the head structure of done queue.
1722  *      - \a bConflict whether the incoming command conflicts with ongoing.
1723  *      - \a conflictCmd command that conflicts with ongoing.
1724  */
1725 typedef RF_ExecuteAction (*RF_ExecuteHook)(RF_Cmd* pCmdBg, RF_Cmd* pCmdFg, List_List* pPendQueue, List_List* pDoneQueue, bool bConflict, RF_Cmd* conflictCmd);
1726 
1727 /** @brief RF scheduler policy.
1728  *
1729  *  This data structure contains function hooks which implements the scheduling
1730  *  algorithm used to inter-align one or more independent protocol stacks.
1731  */
1732 typedef struct {
1733   RF_SubmitHook   submitHook;   ///< Function hook implements the scheduling policy to be executed at the time of RF_scheduleCmd API call.
1734   RF_ExecuteHook  executeHook; ///< Function hook implements the runtime last second go-no-go execute decision
1735 } RFCC26XX_SchedulerPolicy;
1736 
1737 /** @brief Controls the behavior of the RF_scheduleCmd() API.
1738  *
1739  */
1740 typedef enum {
1741     RF_AllowDelayNone = 0,
1742     RF_AllowDelayAny  = UINT32_MAX
1743 } RF_AllowDelay;
1744 
1745 /* @brief RF schedule command parameter struct
1746  *
1747  * RF schedule command parameters are used with the RF_scheduleCmd() call.
1748  */
1749 typedef struct {
1750     uint32_t            startTime;          ///< Start time in RAT Ticks for the radio command
1751     RF_StartType        startType;          ///< Start type for the start time
1752     uint32_t            allowDelay;         ///< Control word to define the policy of the scheduler if the timing of a command cannot be met.
1753                                             ///< Only applicable on CC13x2 and CC26x2 devices.
1754                                             ///<  RF_AllowDelayNone: Reject the command.
1755                                             ///<  RF_AllowDelayAny:  Append the command to the end of the queue.
1756    uint32_t            endTime;             ///< End time in RAT Ticks for the radio command
1757    RF_EndType          endType;             ///< End type for the end time
1758    uint32_t            duration;            ///< Duration in RAT Ticks for the radio command
1759    uint32_t            activityInfo;        ///< Activity info provided by user
1760    RF_PriorityCoex     coexPriority;        ///< Priority to use for coexistence request.
1761    RF_RequestCoex      coexRequest;         ///< REQUEST line behavior to use for coexistence request.
1762 } RF_ScheduleCmdParams;
1763 
1764 /** @brief RF request access parameter struct
1765  *
1766  *  RF request access command parameters are used with the RF_requestAccess() call.
1767  */
1768 typedef struct {
1769     uint32_t            duration;           ///< Radio access duration in RAT Ticks requested by the client
1770     uint32_t            startTime;          ///< Start time window in RAT Time for radio access
1771     RF_Priority         priority;           ///< Access priority
1772 } RF_AccessParams;
1773 
1774 /** @brief Select the preferred RAT channel through the configuration of #RF_ratCompare() or #RF_ratCapture().
1775  *
1776  *  If RF_RatChannelAny is provided within the channel configuration (default), the API will
1777  *  allocate the first available channel. Otherwise, it tries to allocate the requested channel,
1778  *  and if it is not available, returns with #RF_ALLOC_ERROR.
1779  */
1780 typedef enum {
1781     RF_RatChannelAny = -1,                  ///< Chose the first available channel.
1782     RF_RatChannel0   =  0,                  ///< Use RAT user channel 0.
1783     RF_RatChannel1   =  1,                  ///< Use RAT user channel 1.
1784     RF_RatChannel2   =  2,                  ///< Use RAT user channel 2.
1785 } RF_RatSelectChannel;
1786 
1787 /** @brief Selects the source signal for #RF_ratCapture().
1788  *
1789  *  The source of a capture event can be selected through the source field of the
1790  *  #RF_RatConfigCapture configuration structure.
1791  */
1792 typedef enum {
1793       RF_RatCaptureSourceRtcUpdate    = 20, ///< Selects the RTC update signal source.
1794       RF_RatCaptureSourceEventGeneric = 21, ///< Selects the Generic event of Event Fabric as source.
1795       RF_RatCaptureSourceRfcGpi0      = 22, ///< Selects the RFC_GPI[0] as source. This can be used i.e.
1796                                             ///< to capture events on a GPIO. This requires that the GPIO
1797                                             ///< is connected to RFC_GPO[0] from the GPIO driver.
1798       RF_RatCaptureSourceRfcGpi1      = 23  ///< Selects the RFC_GPO[1] as source. This can be used i.e.
1799                                             ///< to capture events on a GPIO. This requires that the GPIO
1800                                             ///< is connected to RFC_GPO[1] from the GPIO driver.
1801 } RF_RatCaptureSource;
1802 
1803 /** @brief Selects the mode of #RF_ratCapture().
1804  *
1805  *  The trigger mode of a capture event can be selected through the mode field of
1806  *  #RF_RatConfigCapture configuration structure.
1807  */
1808 typedef enum {
1809     RF_RatCaptureModeRising       = 0,      ///< Rising edge of the selected source will trigger a capture event.
1810     RF_RatCaptureModeFalling      = 1,      ///< Falling edge of the selected source will trigger a capture event.
1811     RF_RatCaptureModeBoth         = 2       ///< Both rising and falling edges of the selected source will generate
1812                                             ///< capture events.
1813 } RF_RatCaptureMode;
1814 
1815 /** @brief Selects the repetition of #RF_ratCapture().
1816  *
1817  *  The configuration of a capture channel also defines whether the channel should be
1818  *  freed or automatically rearmed after a capture event occurred. In the latter case, the
1819  *  user needs to free the channel manually through the #RF_ratDisableChannel() API.
1820  */
1821 typedef enum {
1822     RF_RatCaptureSingle           = 0,      ///< Free the channel after the first capture event.
1823     RF_RatCaptureRepeat           = 1       ///< Rearm the channel after each capture events.
1824 } RF_RatCaptureRepetition;
1825 
1826 /** @brief Selects the mode of the RAT_GPO[x] for #RF_ratCompare() or #RF_ratCapture().
1827  *
1828  *  In case of compare mode, the channel can generate an output signal of the selected
1829  *  mode on the configured RAT_GPO[x] interface, and can be interconnected with
1830  *  other subsystems through the RFC_GPO[x] or Event Fabric. An example use case is
1831  *  to generate a pulse on a GPIO.
1832  *
1833  *  In case of capture mode, the channel can also generate an output signal of the
1834  *  selected mode on the configured RAT_GPO[x] interface. Note that the configuration
1835  *  of this output event is independent of the source signal of the capture event.
1836  *  An example use case is to generate a pulse on a GPIO on each raising edge of another
1837  *  GPIO source.
1838  *
1839  */
1840 typedef enum {
1841     RF_RatOutputModePulse         = 0,      ///< Generates a one-clock period width pulse.
1842     RF_RatOutputModeSet           = 1,      ///< Sets the output high on a RAT event.
1843     RF_RatOutputModeClear         = 2,      ///< Sets the output low on a RAT event.
1844     RF_RatOutputModeToggle        = 3,      ///< Inverts the polarity of the output.
1845     RF_RatOutputModeAlwaysZero    = 4,      ///< Sets the output low independently of any RAT events.
1846     RF_RatOutputModeAlwaysOne     = 5,      ///< Sets the output high independently of any RAT events.
1847 } RF_RatOutputMode;
1848 
1849 /** @brief Selects GPO to be used with #RF_ratCompare() or #RF_ratCapture().
1850  *
1851  *  RAT_GPO[0]   - Reserved by the RF core. User shall not modify the configuration,
1852  *                 but can observe the signal through any of RFC_GPO[0:3].
1853  *  RAT_GPO[1]   - Reserved by the RF core only if sync word detection is enabled.
1854  *                 Otherwise can be used through RFC_GPO[0:3].
1855  *  RAT_GPO[2:3] - Available and can be used through any of the RFC_GPO[0:3].
1856  *  RAT_GPO[4:7] - Available and can be used through the Event fabric.
1857  */
1858 typedef enum {
1859     RF_RatOutputSelectRatGpo1     = 1,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[1]
1860     RF_RatOutputSelectRatGpo2     = 2,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[2]
1861     RF_RatOutputSelectRatGpo3     = 3,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[3]
1862     RF_RatOutputSelectRatGpo4     = 4,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[4]
1863     RF_RatOutputSelectRatGpo5     = 5,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[5]
1864     RF_RatOutputSelectRatGpo6     = 6,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[6]
1865     RF_RatOutputSelectRatGpo7     = 7,      ///< Configure RAT_CHANNEL[x] to interface with RAT_GPO[7]
1866 } RF_RatOutputSelect;
1867 
1868 /** @brief RF_ratCapture parameter structure.
1869  *
1870  *  %RF_RatCapture parameters are used with the #RF_ratCapture() call.
1871  */
1872 typedef struct {
1873     RF_RatCallback            callback;         ///< Callback function to be invoked upon a capture event (optional).
1874     RF_RatHandle              channel;          ///< RF_RatHandle identifies the channel to be allocated.
1875     RF_RatCaptureSource       source;           ///< Configuration of the event source to cause a capture event.
1876     RF_RatCaptureMode         captureMode;      ///< Configuration of the mode of event to cause a capture event.
1877     RF_RatCaptureRepetition   repeat;           ///< Configuration of the channel to be used in single or repeated mode.
1878 } RF_RatConfigCapture;
1879 
1880 /** @brief RF_ratCompare parameter structure.
1881  *
1882  *  %RF_RatCompare parameters are used with the #RF_ratCompare() call.
1883  */
1884 typedef struct {
1885     RF_RatCallback            callback;         ///< Callback function to be invoked upon a capture event (optional).
1886     RF_RatHandle              channel;          ///< RF_RatHandle identifies the channel to be allocated.
1887     uint32_t                  timeout;          ///< Timeout value in RAT ticks to be programmed in the timer as the
1888                                                 ///< trigger of compare event.
1889 } RF_RatConfigCompare;
1890 
1891 /** @brief RAT related IO parameter structure.
1892  *
1893  *  These parameters are used with the #RF_ratCompare() or #RF_ratCapture() calls.
1894  */
1895 typedef struct {
1896     RF_RatOutputMode          mode;            ///< The mode the GPO should operate in.
1897     RF_RatOutputSelect        select;          ///< The signal which shall be connected to the GPO.
1898 } RF_RatConfigOutput;
1899 
1900 /** @brief Creates a a new client instance of the RF driver.
1901  *
1902  *  This function initializes an RF driver client instance using \a pObj as storage.
1903  *  It does not power up the RF core.
1904  *  Once the client starts the first RF operation command later in the application,
1905  *  the RF core is powered up and set into a PHY mode specified by \a pRfMode.
1906  *  The chosen PHY is then configured by a radio setup command \a pRadioSetup.
1907  *  Whenever the RF core is powered up, the RF driver re-executes the radio setup command \a pRadioSetup.
1908  *  Additional driver behavior may be set by an optional \a params.
1909  *
1910  *  @code
1911  *  // Define parameters
1912  *  RF_Params rfParams;
1913  *  rfParams.nInactivityTimeout = 4;
1914  *  RF_Params_init(&rfParams);
1915  *  rfParams.nInactivityTimeout = 1701; // microseconds
1916  *
1917  *  RF_Handle rfHandle = RF_open(&rfObject, &RF_prop, (RF_RadioSetup*)&RF_cmdPropRadioDivSetup, &rfParams);
1918  *  @endcode
1919  *
1920  *  @note Calling context : Task
1921  *
1922  *  @param pObj         Pointer to a #RF_Object that will hold the state for this
1923  *                      RF client. The object must be in persistent and writable
1924  *                      memory.
1925  *  @param pRfMode      Pointer to a #RF_Mode struct holding PHY information
1926  *  @param pRadioSetup  Pointer to the radio setup command used for this client.
1927  *                      This is re-executed by the RF Driver on each power-up.
1928  *  @param params       Pointer to an RF_Params object with the desired driver configuration.
1929  *                      A NULL pointer results in the default configuration being loaded.
1930  *  @return             A handle for further RF driver calls on success. Otherwise NULL.
1931  */
1932 extern RF_Handle RF_open(RF_Object *pObj, RF_Mode *pRfMode, RF_RadioSetup *pRadioSetup, RF_Params *params);
1933 
1934 /**
1935  *  @brief  Close client connection to RF driver
1936  *
1937  *  Allows a RF client (high-level driver or application) to close its connection
1938  *  to the RF driver.
1939  *
1940  *  @note Calling context : Task
1941  *
1942  *  @param h  Handle previously returned by RF_open()
1943  */
1944 extern void RF_close(RF_Handle h);
1945 
1946 /**
1947  *  @brief  Return current radio timer value
1948  *
1949  *  If the radio is powered returns the current radio timer value, if not returns
1950  *  a conservative estimate of the current radio timer value
1951  *
1952  *  @note Calling context : Task/SWI/HWI
1953  *
1954  *  @return     Current radio timer value
1955  */
1956 extern uint32_t RF_getCurrentTime(void);
1957 
1958 /**
1959  *  @brief  Appends RF operation commands to the driver's command queue and returns a
1960  *          command handle.
1961  *
1962  *  The RF operation \a pOp may either represent a single operation or may be the first
1963  *  operation in a chain.
1964  *  If the command queue is empty, the \a pCmd is dispatched immediately. If there are
1965  *  other operations pending, then \a pCmd is processed after all other commands have been
1966  *  finished.
1967  *  The RF operation command must be compatible to the RF_Mode selected by RF_open(), e.g.
1968  *  proprietary commands can only be used when the RF core is configured for proprietary mode.
1969  *
1970  *  The returned command handle is an identifier that can be used to control command execution
1971  *  later on, for instance with RF_pendCmd() or RF_cancelCmd().
1972  *  It is a 16 Bit signed integer value, incremented on every new command.
1973  *  If the RF driver runs out of command containers, RF_ALLOC_ERROR is returned.
1974  *
1975  *  The priority \a ePri is only relevant in multi-client applications where commands of distinct
1976  *  clients may interrupt each other.
1977  *  Only commands started by RF_scheduleCmd() can preempt
1978  *  running commands. #RF_postCmd() or RF_runCmd() do never interrupt a running command.
1979  *  In single-client applications, \a ePri is ignored and should be set to ::RF_PriorityNormal.
1980  *
1981  *  A callback function \a pCb might be specified to get notified about events during command
1982  *  execution. Events are subscribed by the bit mask \a bmEvent.
1983  *  Valid event flags are specified in @ref RF_Core_Events and @ref RF_Driver_Events.
1984  *  If no callback is set, RF_pendCmd() can be used to synchronize the current task to command
1985  *  execution. For this it is necessary to subscribe all relevant events.
1986  *  The termination events ::RF_EventLastCmdDone, ::RF_EventCmdCancelled, ::RF_EventCmdAborted and
1987  *  ::RF_EventCmdStopped are always implicitly subscribed.
1988  *
1989  *  The following limitations apply to the execution of command chains:
1990  *
1991  *  - If TRIG_ABSTIME is used as a start trigger for the first command, TRIG_REL_FIRST_START
1992  *    can not be used for any other command. This is because the RF driver may insert a
1993  *    frequency-select command (CMD_FS) at the front of the chain when it performs an
1994  *    automatic power-up.
1995  *  - Having more than one CMD_FS in a chain may lead to unexpected behavior.
1996  *    If a chain contains a CMD_FS and the command can be reached by iterating over the pNextOp
1997  *    field, then RF driver will always update the cached CMD_FS with the new settings. On the
1998  *    next automatic power-up, the RF driver will use the updated frequency.
1999  *
2000  *  @note Calling context : Task/SWI
2001  *
2002  *  @sa RF_pendCmd(), RF_runCmd(), RF_scheduleCmd(), RF_RF_cancelCmd(), RF_flushCmd(), RF_getCmdOp()
2003  *
2004  *  @param h         Driver handle previously returned by RF_open()
2005  *  @param pOp       Pointer to the RF operation command.
2006  *  @param ePri      Priority of this RF command (used for arbitration in multi-client systems)
2007  *  @param pCb       Callback function called during command execution and upon completion.
2008  *                   If RF_postCmd() fails, no callback is made.
2009  *  @param bmEvent   Bitmask of events that will trigger the callback or that can be pended on.
2010  *  @return          A handle to the RF command. Return value of RF_ALLOC_ERROR indicates error.
2011  */
2012 extern RF_CmdHandle RF_postCmd(RF_Handle h, RF_Op *pOp, RF_Priority ePri, RF_Callback pCb, RF_EventMask bmEvent);
2013 
2014 /**
2015  *  @brief  Sorts and adds commands to the RF driver internal command queue.
2016  *
2017  *  @param pCmdNew    Pointer to the command to be submitted.
2018  *  @param pCmdBg     Running background command.
2019  *  @param pCmdFg     Running foreground command.
2020  *  @param pPendQueue Pointer to the head structure of pend queue.
2021  *  @param pDoneQueue Pointer to the head structure of done queue..
2022  *  @return           RF_defaultSubmitPolicy identifies the success or failure of queuing.
2023  */
2024 extern RF_ScheduleStatus RF_defaultSubmitPolicy(RF_Cmd* pCmdNew, RF_Cmd* pCmdBg, RF_Cmd* pCmdFg, List_List* pPendQueue, List_List* pDoneQueue);
2025 
2026 /**
2027  *  @brief  Makes a final decision before dispatching a scheduled command.
2028  *
2029  *  @param pCmdBg       Running background command.
2030  *  @param pCmdFg       Running foreground command.
2031  *  @param pPendQueue   Pointer to the head structure of pend queue.
2032  *  @param pDoneQueue   Pointer to the head structure of done queue.
2033  *  @param bConflict    Whether the incoming command conflicts with the ongoing.
2034  *  @param conflictCmd  Command that conflicts with ongoing.
2035  *  @return             RF_defaultSubmitPolicy identifies the success or failure of queuing.
2036  */
2037 extern RF_ExecuteAction RF_defaultExecutionPolicy(RF_Cmd* pCmdBg, RF_Cmd* pCmdFg, List_List* pPendQueue, List_List* pDoneQueue, bool bConflict, RF_Cmd* conflictCmd);
2038 
2039 
2040 /**
2041  *  @brief  Initialize the configuration structure to default values to be used with the RF_scheduleCmd() API.
2042  *
2043  *  @note Calling context : Task/SWI/HWI
2044  *
2045  *  @param  pSchParams Pointer to the configuration structure.
2046  *  @return none
2047  */
2048 extern void RF_ScheduleCmdParams_init(RF_ScheduleCmdParams *pSchParams);
2049 
2050 /**
2051  *  @brief  Schedule an RF operation (chain) to the command queue.
2052  *
2053  *  Schedule an #RF_Op to the RF command queue of the client with handle h. <br>
2054  *  The command can be the first in a chain of RF operations or a standalone RF operation.
2055  *  If a chain of operations are posted they are treated atomically, i.e. either all
2056  *  or none of the chained operations are run. <br>
2057  *  All operations must be posted in strictly increasing chronological order. Function returns
2058  *  immediately. <br>
2059  *
2060  *  Limitations apply to the operations posted:
2061  *  - The operation must be in the set supported in the chosen radio mode when
2062  *    RF_open() was called
2063  *  - Only a subset of radio operations are supported
2064  *  - Only some of the trigger modes are supported with potential power saving (TRIG_NOW, TRIG_ABSTIME)
2065  *
2066  *  @note Calling context : Task/SWI
2067  *
2068  *  @param h         Handle previously returned by RF_open()
2069  *  @param pOp       Pointer to the #RF_Op. Must normally be in persistent and writable memory
2070  *  @param pSchParams Pointer to the schedule command parameter structure
2071  *  @param pCb       Callback function called upon command completion (and some other events).
2072  *                   If RF_scheduleCmd() fails no callback is made
2073  *  @param bmEvent   Bitmask of events that will trigger the callback.
2074  *  @return          A handle to the RF command. Return value of RF_ALLOC_ERROR indicates error.
2075  */
2076 extern RF_CmdHandle RF_scheduleCmd(RF_Handle h, RF_Op *pOp, RF_ScheduleCmdParams *pSchParams, RF_Callback pCb, RF_EventMask bmEvent);
2077 
2078 /**
2079  *  @brief  Synchronizes the calling task to an RF operation command \a ch and
2080  *          returns accumulated event flags.
2081  *
2082  *  After having dispatched an RF operation represented by \a ch with RF_postCmd(), the
2083  *  command is running in parallel on the RF core. Thus, it might be desirable to synchronize
2084  *  the calling task to the execution of the command.
2085  *  With #RF_pendCmd(), the application can block until one of the events specified in
2086  *  \a bmEvent occurs or until the command finishes.
2087  *  The function consumes and returns all accumulated event flags that occurred during
2088  *  execution if they have been previously subscribed by RF_postCmd().
2089  *  Possible events are specified in @ref RF_Core_Events and @ref RF_Driver_Events.
2090  *  The termination events ::RF_EventLastCmdDone, ::RF_EventCmdCancelled,
2091  *  ::RF_EventCmdAborted and ::RF_EventCmdStopped are always implicitly subscribed and
2092  *  can not be masked.
2093  *
2094  *  #RF_pendCmd() may be called multiple times for the same command.
2095  *
2096  *  If #RF_pendCmd() is called for a command handle representing a finished command,
2097  *  then only the ::RF_EventLastCmdDone flag is returned, regardless of how the command
2098  *  finished.
2099  *
2100  *  If the command has also a callback set, the callback is executed before #RF_pendCmd()
2101  *  returns.
2102  *
2103  *  Example:
2104  *  @code
2105  *  // Dispatch a command to the RF driver's command queue
2106  *  RF_CmdHandle ch = RF_postCmd(driver, (RF_Op*)&CMD_PROP_RX, RF_PriorityNormal, NULL, RF_EventRxEntryDone);
2107  *  assert(ch != RF_ALLOC_ERROR);
2108  *
2109  *  bool finished = false;
2110  *  while (finished == false)
2111  *  {
2112  *      // Synchronize to events during command execution.
2113  *      uint32_t events = RF_pendCmd(driver, ch, RF_EventRxEntryDone);
2114  *      // Check events that happen during execution
2115  *      if (events & RF_EventRxEntryDone)
2116  *      {
2117  *          // Process packet
2118  *      }
2119  *      if (events & (RF_EventLastCmdDone | RF_EventCmdStopped | RF_EventCmdAborted | RF_EventCmdCancelled))
2120  *      {
2121  *          finished = true;
2122  *      }
2123  *      // ...
2124  *  }
2125  *  @endcode
2126  *
2127  *  @note Calling context : Task
2128  *
2129  *  @param h        Driver handle previously returned by RF_open()
2130  *  @param ch       Command handle previously returned by RF_postCmd().
2131  *  @param bmEvent  Bitmask of events that make RF_pendCmd() return. Termination events
2132  *                  are always implicitly subscribed.
2133  *  @return         Event flags accumulated during command execution.
2134  *
2135  *  @sa RF_postCmd()
2136  */
2137 extern RF_EventMask RF_pendCmd(RF_Handle h, RF_CmdHandle ch, RF_EventMask bmEvent);
2138 
2139 /**
2140  *  @brief  Runs synchronously an RF operation command or a chain of commands and returns
2141  *          the termination reason.
2142  *
2143  *  This function appends an RF operation command or a chain of commands to the RF driver's
2144  *  command queue and then waits for it to complete.
2145  *  A command is completed if one of the termination events ::RF_EventLastCmdDone,
2146  *  ::RF_EventCmdCancelled, ::RF_EventCmdAborted, ::RF_EventCmdStopped occurred.
2147  *
2148  *  This function is a combination of RF_postCmd() and RF_pendCmd().
2149  *  All options and limitations for RF_postCmd() apply here as well.
2150  *
2151  *  An application should always ensure that the command completed in the expected way and
2152  *  with an expected status code.
2153  *
2154  *  @note Calling context : Task
2155  *
2156  *  @param h         Driver handle previously returned by RF_open()
2157  *  @param pOp       Pointer to the RF operation command.
2158  *  @param ePri      Priority of this RF command (used for arbitration in multi-client systems)
2159  *  @param pCb       Callback function called during command execution and upon completion.
2160  *                   If RF_runCmd() fails, no callback is made.
2161  *  @param bmEvent   Bitmask of events that will trigger the callback or that can be pended on.
2162  *  @return          The relevant termination event.
2163  *
2164  *  @sa RF_postCmd(), RF_pendCmd(), RF_cancelCmd(), RF_flushCmd()
2165  */
2166 extern RF_EventMask RF_runCmd(RF_Handle h, RF_Op *pOp, RF_Priority ePri, RF_Callback pCb, RF_EventMask bmEvent);
2167 
2168 /**
2169  *  @brief  Runs synchronously a (chain of) RF operation(s) for dual or single-mode.
2170  *
2171  *  Allows a (chain of) operation(s) to be scheduled to the command queue and then waits
2172  *  for it to complete. <br> A command is completed if one of the RF_EventLastCmdDone,
2173  *  RF_EventCmdCancelled, RF_EventCmdAborted, RF_EventCmdStopped occurred.
2174  *
2175  *  @note Calling context : Task
2176  *  @note Only one call to RF_pendCmd() or RF_runScheduleCmd() can be made at a time for
2177  *        each client
2178  *
2179  *  @param h         Handle previously returned by RF_open()
2180  *  @param pOp       Pointer to the #RF_Op. Must normally be in persistent and writable memory
2181  *  @param pSchParams Pointer to the schedule command parameter structure
2182  *  @param pCb       Callback function called upon command completion (and some other events).
2183  *                   If RF_runScheduleCmd() fails, no callback is made.
2184  *  @param bmEvent   Bitmask of events that will trigger the callback.
2185  *  @return          The relevant command completed event.
2186  */
2187 extern RF_EventMask RF_runScheduleCmd(RF_Handle h, RF_Op *pOp, RF_ScheduleCmdParams *pSchParams, RF_Callback pCb, RF_EventMask bmEvent);
2188 
2189 /**
2190  *  @brief  Abort/stop/cancel single command in command queue.
2191  *
2192  *  If command is running, aborts/stops it and posts callback for the
2193  *  aborted/stopped command. <br>
2194  *  If command has not yet run, cancels it it and posts callback for the
2195  *  canceled command. <br>
2196  *  If command has already run or been aborted/stopped/canceled, has no effect.<br>
2197  *  If RF_cancelCmd is called from a Swi context with same or higher priority
2198  *  than RF Driver Swi, when the RF core is powered OFF -> the cancel callback will be delayed
2199  *  until the next power-up cycle.<br>
2200  *
2201  *  @note Calling context : Task/SWI
2202  *
2203  *  @param h            Handle previously returned by RF_open()
2204  *  @param ch           Command handle previously returned by RF_postCmd().
2205  *  @param mode         1: Stop gracefully, 0: abort abruptly
2206  *  @return             RF_Stat indicates if command was successfully completed
2207  */
2208 extern RF_Stat RF_cancelCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode);
2209 
2210 /**
2211  *  @brief  Abort/stop/cancel command and any subsequent commands in command queue.
2212  *
2213  *  If command is running, aborts/stops it and then cancels all later commands in queue.<br>
2214  *  If command has not yet run, cancels it and all later commands in queue.<br>
2215  *  If command has already run or been aborted/stopped/canceled, has no effect.<br>
2216  *  The callbacks for all canceled commands are issued in chronological order.<br>
2217  *  If RF_flushCmd is called from a Swi context with same or higher priority
2218  *  than RF Driver Swi, when the RF core is powered OFF -> the cancel callback will be delayed
2219  *  until the next power-up cycle.<br>
2220  *
2221  *  @note Calling context : Task/SWI
2222  *
2223  *  @param h            Handle previously returned by RF_open()
2224  *  @param ch           Command handle previously returned by RF_postCmd().
2225  *  @param mode         1: Stop gracefully, 0: abort abruptly
2226  *  @return             RF_Stat indicates if command was successfully completed
2227  */
2228 extern RF_Stat RF_flushCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode);
2229 
2230 /**
2231  *  @brief Send any Immediate command. <br>
2232  *
2233  *  Immediate Command is send to RDBELL, if radio is active and the RF_Handle points
2234  *  to the current client. <br>
2235  *  In other appropriate RF_Stat values are returned. <br>
2236  *
2237  *  @note Calling context : Task/SWI/HWI
2238  *
2239  *  @param h            Handle previously returned by RF_open()
2240  *  @param pCmdStruct   Pointer to the immediate command structure
2241  *  @return             RF_Stat indicates if command was successfully completed
2242  */
2243 extern RF_Stat RF_runImmediateCmd(RF_Handle h, uint32_t *pCmdStruct);
2244 
2245 /**
2246  *  @brief Send any Direct command. <br>
2247  *
2248  *  Direct Command value is send to RDBELL immediately, if radio is active and
2249  *  the RF_Handle point to the current client. <br>
2250  *  In other appropriate RF_Stat values are returned. <br>
2251  *
2252  *  @note Calling context : Task/SWI/HWI
2253  *
2254  *  @param h            Handle previously returned by RF_open()
2255  *  @param cmd          Direct command value.
2256  *  @return             RF_Stat indicates if command was successfully completed.
2257  */
2258 extern RF_Stat RF_runDirectCmd(RF_Handle h, uint32_t cmd);
2259 
2260 /**
2261  *  @brief  Signal that radio client is not going to issue more commands in a while. <br>
2262  *
2263  *  Hint to RF driver that, irrespective of inactivity timeout, no new further
2264  *  commands will be issued for a while and thus the radio can be powered down at
2265  *  the earliest convenience. In case the RF_yield() is called within a callback,
2266  *  the callback will need to finish and return before the power down sequence is
2267  *  initiated. Posting new commands to the queue will cancel any pending RF_yield()
2268  *  request. <br>
2269  *
2270  *  @note Calling context : Task
2271  *
2272  *  @param h       Handle previously returned by RF_open()
2273  */
2274 extern void RF_yield(RF_Handle h);
2275 
2276 /**
2277  *  @brief  Function to initialize the RF_Params struct to its defaults.
2278  *
2279  *  @param  params      An pointer to RF_Params structure for
2280  *                      initialization
2281  *
2282  *  Defaults values are:
2283  *      nInactivityTimeout = BIOS_WAIT_FOREVER
2284  *      nPowerUpDuration   = RF_DEFAULT_POWER_UP_TIME
2285  */
2286 extern void RF_Params_init(RF_Params *params);
2287 
2288 /**
2289  *  @brief Get value for some RF driver parameters. <br>
2290  *
2291  *  @note Calling context : Task/SWI/HWI
2292  *
2293  *  @param h            Handle previously returned by RF_open()
2294  *  @param type         Request value parameter defined by RF_InfoType
2295  *  @param pValue       Pointer to return parameter values specified by RF_InfoVal
2296  *  @return             RF_Stat indicates if command was successfully completed
2297  */
2298 extern RF_Stat RF_getInfo(RF_Handle h, RF_InfoType type, RF_InfoVal *pValue);
2299 
2300 /**
2301  *  @brief Get RSSI value.
2302  *
2303  *  @note Calling context : Task/SWI/HWI
2304  *
2305  *  @param  h            Handle previously returned by RF_open()
2306  *  @return              RSSI value. Return value of RF_GET_RSSI_ERROR_VAL indicates error case.
2307  */
2308 extern int8_t RF_getRssi(RF_Handle h);
2309 
2310 /**
2311  *  @brief  Get command structure pointer.
2312  *
2313  *  @note Calling context : Task/SWI/HWI
2314  *
2315  *  @param h            Handle previously returned by RF_open()
2316  *  @param cmdHnd       Command handle returned by RF_postCmd()
2317  *  @return             Pointer to the command structure.
2318  */
2319 extern RF_Op* RF_getCmdOp(RF_Handle h, RF_CmdHandle cmdHnd);
2320 
2321 /**
2322  *  @brief  Initialize the configuration structure to be used to set up a RAT compare event.
2323  *
2324  *  @note Calling context : Task/SWI/HWI
2325  *
2326  *  @param  channelConfig Pointer to the compare configuration structure.
2327  *  @return none
2328  */
2329 extern void RF_RatConfigCompare_init(RF_RatConfigCompare* channelConfig);
2330 
2331 /**
2332  *  @brief  Initialize the configuration structure to be used to set up a RAT capture event.
2333  *
2334  *  @note Calling context : Task/SWI/HWI
2335  *
2336  *  @param  channelConfig Pointer to the capture configuration structure.
2337  *  @return none
2338  */
2339 extern void RF_RatConfigCapture_init(RF_RatConfigCapture* channelConfig);
2340 
2341 /**
2342  *  @brief  Initialize the configuration structure to be used to set up a RAT IO.
2343  *
2344  *  @note Calling context : Task/SWI/HWI
2345  *
2346  *  @param  ioConfig Pointer to the IO configuration structure.
2347  *  @return none
2348  */
2349 extern void RF_RatConfigOutput_init(RF_RatConfigOutput* ioConfig);
2350 
2351 /**
2352  *  @brief  Setup a Radio Timer (RAT) channel in compare mode.
2353  *
2354  *  The %RF_ratCompare() API sets up one of the three available RAT channels in compare mode.
2355  *  When the compare event happens at the given compare time, the registered callback
2356  *  is invoked.
2357  *
2358  *  The RF driver handles power management. If the provided compare time is far into the future
2359  *  (and there is no other constraint set i.e. due to radio command execution), the RF core will be
2360  *  powered OFF and the device will enter the lowest possible power state. The RF core will be
2361  *  automatically powered ON just before the registered compare event. The callback function is
2362  *  served upon expiration of the allocated channel. The function is invoked with event type
2363  *  #RF_EventRatCh and runs in SWI context.
2364  *
2365  *  The API generates a "one-shot" compare event. Since the channel is automatically freed before
2366  *  the callback is served, the same channel can be reallocated from the callback itself through a
2367  *  new API call.
2368  *
2369  *  In case there were no available channels at the time of API call, the function returns with
2370  *  #RF_ALLOC_ERROR and no callback is invoked.
2371  *
2372  *  In case a runtime error occurs after the API successfully allocated a channel, the registered
2373  *  callback is invoked with event type #RF_EventError. A typical example is when the provided compare
2374  *  time is in the past and rejected by the RF core itself.
2375  *
2376  *  The events issued by the RAT timer can be output from the timer module through the RAT_GPO
2377  *  interface, and can be interconnected with other parts of the system through the RFC_GPO or
2378  *  the Event Fabric. The mapping between the allocated RAT channel and the selected RAT_GPO
2379  *  can be controlled through the optional ioConfig argument of %RF_ratCompare(). The possible
2380  *  RAT_GPO[x] are defined in #RF_RatOutputSelect.
2381  *
2382  *  @note Calling context : Task/SWI
2383  *
2384  *  @param rfHandle      Handle previously returned by RF_open().
2385  *  @param channelConfig Pointer to configuration structure needed to set up a channel in compare mode.
2386  *  @param ioConfig      Pointer to a configuration structure to set up the RAT_GPOs for the allocated
2387  *                       channel (optional).
2388  *  @return              Allocated RAT channel. If allocation fails, #RF_ALLOC_ERROR is returned.
2389  *
2390  *  \sa #RF_RatConfigCompare_init(), #RF_RatConfigOutput_init(), #RF_ratDisableChannel(), #RF_ratCapture()
2391  */
2392 extern RF_RatHandle RF_ratCompare(RF_Handle rfHandle, RF_RatConfigCompare* channelConfig, RF_RatConfigOutput* ioConfig);
2393 
2394 /**
2395  *  @brief  Setup a Radio Timer (RAT) channel in capture mode.
2396  *
2397  *  The %RF_ratCapture() API sets up one of the three available RAT channels in capture mode.
2398  *  The registered callback is invoked on the capture event.
2399  *
2400  *  The RF driver handles power management. If the RF core is OFF when the %RF_ratCapture() is called,
2401  *  it will be powered ON immediately and the RAT channel will be configured to capture mode. As long as
2402  *  at least one of the three RAT channels are in capture mode, the RF core will be kept ON. The callback
2403  *  function is served upon a capture event occurs. The function is invoked with event type RF_EventRatCh
2404  *  and runs in SWI context.
2405  *
2406  *  In case the channel is configured into single capture mode, the channel is automatically freed before
2407  *  the callback is called. In repeated capture mode, the channel remains allocated and automatically rearmed.
2408  *
2409  *  In case there were no available channels at the time of API call, the function returns with
2410  *  #RF_ALLOC_ERROR and no callback is invoked.
2411  *
2412  *  In case a runtime error occurs after the API successfully allocated a channel, the registered
2413  *  callback is invoked with event type #RF_EventError. A typical example is when the provided compare
2414  *  time is in the past and rejected by the RF core itself.
2415  *
2416  *  The events issued by the RAT timer can be output from the timer module through the RAT_GPO
2417  *  interface, and can be interconnected with other parts of the system through the RFC_GPO or
2418  *  the Event Fabric. The mapping between the allocated RAT channel and the selected RAT_GPO
2419  *  can be controlled through the optional ioConfig argument of %RF_ratCapture(). The possible
2420  *  RAT_GPO[x] are defined in #RF_RatOutputSelect. Note that this configuration is independent of
2421  *  the source signal of the capture event.
2422  *
2423  *  @note Calling context : Task/SWI
2424  *
2425  *  @param rfHandle      Handle previously returned by RF_open().
2426  *  @param channelConfig Pointer to configuration structure needed to set up a channel in compare mode.
2427  *  @param ioConfig      Pointer to a configuration structure to set up the RAT_GPO for the allocated
2428  *                       channel (optional).
2429  *  @return              Allocated RAT channel. If allocation fails, #RF_ALLOC_ERROR is returned.
2430  *
2431  *  \sa #RF_RatConfigCapture_init(), #RF_RatConfigOutput_init() , #RF_ratDisableChannel(), #RF_ratCompare()
2432  */
2433 extern RF_RatHandle RF_ratCapture(RF_Handle rfHandle, RF_RatConfigCapture* channelConfig, RF_RatConfigOutput* ioConfig);
2434 
2435 /**
2436  *  @brief  Disable a RAT channel.
2437  *
2438  *  The #RF_RatHandle returned by the #RF_ratCompare() or #RF_ratCapture() APIs can be used for further interaction with the
2439  *  Radio Timer. Passing the handle to %RF_ratDisableChannel() will abort a compare/capture event, and the provided channel
2440  *  is deallocated. No callback is invoked. This API can be called both if the RF core is ON or OFF. After the channel is
2441  *  freed, the next radio event will be rescheduled. A typical use case if a channel is configured in repeated capture mode,
2442  *  and the application decides to abort this operation.
2443  *
2444  *  @note Calling context : Task/SWI
2445  *
2446  *  @param rfHandle      Handle previously returned by RF_open().
2447  *  @param ratHandle     #RF_RatHandle returned by #RF_ratCompare() or #RF_ratCapture().
2448  *  @return              #RF_Stat indicates if command was successfully completed.
2449  *
2450  *  \sa #RF_ratCompare(), #RF_ratCapture()
2451  */
2452 extern RF_Stat RF_ratDisableChannel(RF_Handle rfHandle, RF_RatHandle ratHandle);
2453 
2454 /**
2455  *  @brief  Set RF control parameters.
2456  *
2457  *  @note Calling context : Task
2458  *
2459  *  @param h             Handle previously returned by RF_open()
2460  *  @param ctrl          Control codes
2461  *  @param args          Pointer to control arguments
2462  *  @return              RF_Stat indicates if API call was successfully completed.
2463  */
2464 extern RF_Stat RF_control(RF_Handle h, int8_t ctrl, void *args);
2465 
2466 /**
2467  *  @brief  Request radio access. <br>
2468  *
2469  *  Scope:
2470  *  1. Only supports request access which start immediately.<br>
2471  *  2. The #RF_AccessParams duration should be less than a pre-defined value
2472  *     RF_REQ_ACCESS_MAX_DUR_US in RFCC26X2_multiMode.c.<br>
2473  *  3. The #RF_AccessParams priority should be set RF_PriorityHighest.<br>
2474  *  4. Single request for a client at anytime.<br>
2475  *  5. Command from different client are blocked until the radio access
2476  *     period is completed.<br>
2477  *
2478  *  @note Calling context : Task
2479  *
2480  *  @param h             Handle previously returned by RF_open()
2481  *  @param pParams       Pointer to RF_AccessRequest parameters
2482  *  @return              RF_Stat indicates if API call was successfully completed.
2483  */
2484 extern RF_Stat RF_requestAccess(RF_Handle h, RF_AccessParams *pParams);
2485 
2486 /**
2487  * @brief Returns the currently configured transmit power configuration.
2488  *
2489  * This function returns the currently configured transmit power configuration under the assumption
2490  * that it has been previously set by #RF_setTxPower(). The value might be used for reverse
2491  * lookup in a TX power table. If no power has been programmed, it returns an invalid value.
2492  *
2493  * @code
2494  * RF_TxPowerTable_Value value = RF_getTxPower(handle);
2495  * if (value.rawValue == RF_TxPowerTable_INVALID_VALUE) {
2496  *     // error, value not valid
2497  * }
2498  * @endcode
2499  *
2500  * @param h         Handle previously returned by #RF_open()
2501  * @return          PA configuration struct
2502  *
2503  * @sa #RF_setTxPower(), #RF_TxPowerTable_findPowerLevel()
2504  */
2505 extern RF_TxPowerTable_Value RF_getTxPower(RF_Handle h);
2506 
2507 /**
2508  * @brief Updates the transmit power configuration of the RF core.
2509  *
2510  * This function programs a new TX power \a value and returns a status code. The API will return
2511  * with RF_StatBusyError if there are still pending commands in the internal queue. In case of
2512  * success, RF_StatSuccess is returned and the new configuration becomes effective from the next
2513  * radio operation.
2514  *
2515  * Some devices provide an integrated high-power PA in addition to the Default PA. On these devices
2516  * the API accepts configurations for both, and if \a value selects a different PA, the
2517  * \a globalCallback is invoked. The implementation of \a globalCallback is board specific and can
2518  * be used to reconfigure the external RF switches (if any).
2519  *
2520  * @param h         Handle previously returned by #RF_open()
2521  * @param value     TX power configuration value.
2522  * @return          #RF_StatSuccess on success, otherwise an error code.
2523  *
2524  * @sa #RF_getTxPower(), #RF_TxPowerTable_Value, #RF_TxPowerTable_findValue()
2525  */
2526 extern RF_Stat RF_setTxPower(RF_Handle h, RF_TxPowerTable_Value value);
2527 
2528 /**
2529  * @brief Retrieves a power level in dBm for a given power configuration value.
2530  *
2531  * \c %RF_TxPowerTable_findPowerLevel() searches in a lookup \a table for a given transmit power
2532  * configuration \a value and returns the power level in dBm if a matching configuration is found.
2533  * If \a value can not be found, #RF_TxPowerTable_INVALID_DBM is returned.
2534  *
2535  * This function does a reverse lookup compared to #RF_TxPowerTable_findValue() and has
2536  * O(n). It is assumed that \a table is terminated by a #RF_TxPowerTable_TERMINATION_ENTRY.
2537  *
2538  * @param table         List of #RF_TxPowerTable_Entry entries,
2539  *                      terminated by #RF_TxPowerTable_TERMINATION_ENTRY.
2540  *
2541  * @param value         Power configuration value.
2542  *
2543  * @return              Human readable power level in dBm on success,
2544  *                      otherwise #RF_TxPowerTable_INVALID_DBM.
2545  */
2546 extern int8_t RF_TxPowerTable_findPowerLevel(RF_TxPowerTable_Entry table[], RF_TxPowerTable_Value value);
2547 
2548 /**
2549  * @brief Retrieves a power configuration value for a given power level in dBm.
2550  *
2551  * \c %RF_TxPowerTable_findValue() searches in a lookup \a table for a given transmit power level
2552  * \a powerLevel in dBm and returns a matching power configuration. If \a powerLevel can not be
2553  * found, #RF_TxPowerTable_INVALID_VALUE is returned.
2554  *
2555  * This function performs a linear search in \a table and has O(n).
2556  * It is assumed that \a table is defined in ascending order and is terminated by a
2557  * #RF_TxPowerTable_TERMINATION_ENTRY.
2558  *
2559  * The following special values for \a powerLevel are also accepted:
2560  *
2561  * - #RF_TxPowerTable_MIN_DBM which returns always the lowest power value in the table
2562  * - #RF_TxPowerTable_MAX_DBM which returns always the highest power value in the table
2563  *
2564  * @param table         List of #RF_TxPowerTable_Entry entries,
2565  *                      terminated by #RF_TxPowerTable_TERMINATION_ENTRY.
2566  *
2567  * @param powerLevel    Human-readable power level in dBm.
2568  *
2569  * @return              PA configuration value on success.
2570  *                      otherwise #RF_TxPowerTable_INVALID_VALUE.
2571  */
2572 extern RF_TxPowerTable_Value RF_TxPowerTable_findValue(RF_TxPowerTable_Entry table[], int8_t powerLevel);
2573 
2574 
2575 /**
2576  * @brief Enables temperature monitoring and temperature based drift compensation
2577  *
2578  */
2579 extern void RF_enableHPOSCTemperatureCompensation(void);
2580 
2581 #ifdef __cplusplus
2582 }
2583 #endif
2584 
2585 #endif /* ti_drivers_rfcc26x2__include */
2586 
2587 //*****************************************************************************
2588 //
2589 //! Close the Doxygen group.
2590 //! @}
2591 //! @}
2592 //
2593 //*****************************************************************************
2594