RF.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2017, 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  */
478 #ifndef ti_drivers_rf__include
479 #define ti_drivers_rf__include
480 
481 #ifdef __cplusplus
482 extern "C" {
483 #endif
484 
485 #include <stdint.h>
486 #include <stdbool.h>
487 
488 #include <ti/drivers/dpl/ClockP.h>
489 #include <ti/drivers/dpl/SemaphoreP.h>
490 
491 #include <ti/devices/DeviceFamily.h>
492 #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
493 #include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h)
494 #include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h)
495 
507 #define RF_EventCmdDone (1<<0)
508 #define RF_EventLastCmdDone (1<<1)
509 #define RF_EventFGCmdDone (1<<2)
510 #define RF_EventLastFGCmdDone (1<<3)
511 #define RF_EventTxDone (1<<4)
512 #define RF_EventTXAck (1<<5)
513 #define RF_EventTxCtrl (1<<6)
514 #define RF_EventTxCtrlAck (1<<7)
515 #define RF_EventTxCtrlAckAck (1<<8)
516 #define RF_EventTxRetrans (1<<9)
517 #define RF_EventTxEntryDone (1<<10)
518 #define RF_EventTxBufferChange (1<<11)
519 #define RF_EventRxOk (1<<16)
520 #define RF_EventRxNOk (1<<17)
521 #define RF_EventRxIgnored (1<<18)
522 #define RF_EventRxEmpty (1<<19)
523 #define RF_EventRxCtrl (1<<20)
524 #define RF_EventRxCtrlAck (1<<21)
525 #define RF_EventRxBufFull (1<<22)
526 #define RF_EventRxEntryDone (1<<23)
527 #define RF_EventDataWritten (1<<24)
528 #define RF_EventNDataWritten (1<<25)
529 #define RF_EventRxAborted (1<<26)
530 #define RF_EventRxCollisionDetected (1<<27)
531 #define RF_EventModulesUnlocked (1<<29)
532 #define RF_EventInternalError (uint32_t)(1<<31)
533 #define RF_EventMdmSoft 0x0000002000000000
534 
543 #define RF_EventCmdCancelled 0x1000000000000000
544 #define RF_EventCmdAborted 0x2000000000000000
545 #define RF_EventCmdStopped 0x4000000000000000
546 #define RF_EventRatCh 0x0800000000000000
547 #define RF_EventPowerUp 0x0400000000000000
548 #define RF_EventError 0x0200000000000000
549 #define RF_EventCmdPreempted 0x0100000000000000
550 #define RF_EventRadioFree 0x0080000000000000
551 
569 #define RF_CTRL_SET_INACTIVITY_TIMEOUT 0
570 
579 #define RF_CTRL_UPDATE_SETUP_CMD 1
580 
585 #define RF_CTRL_SET_POWERUP_DURATION_MARGIN 2
586 
593 #define RF_CTRL_SET_RAT_RTC_ERR_TOL_VAL 3
594 
605 #define RF_CTRL_SET_POWER_MGMT 4
606 
627 #define RF_CTRL_SET_HWI_PRIORITY 5
628 
649 #define RF_CTRL_SET_SWI_PRIORITY 6
650 
656 #define RF_GET_RSSI_ERROR_VAL (-128)
657 #define RF_CMDHANDLE_FLUSH_ALL (-1)
658 #define RF_ALLOC_ERROR (-2)
659 #define RF_SCHEDULE_CMD_ERROR (-3)
660 #define RF_ERROR_RAT_PROG (-255)
661 #define RF_ERROR_INVALID_RFMODE (-256)
662 #define RF_ERROR_CMDFS_SYNTH_PROG (-257)
663 
664 #define RF_NUM_SCHEDULE_MAP_ENTRIES 5
665 #define RF_NUM_SCHEDULE_ACCESS_ENTRIES 2
666 #define RF_NUM_SCHEDULE_COMMAND_ENTRIES (RF_NUM_SCHEDULE_MAP_ENTRIES - RF_NUM_SCHEDULE_ACCESS_ENTRIES)
667 
668 #define RF_SCH_CMD_EXECUTION_TIME_UNKNOWN 0
669 
684 typedef rfc_radioOp_t RF_Op;
685 
686 
695 typedef struct {
696  uint8_t rfMode;
697  void (*cpePatchFxn)(void);
698  void (*mcePatchFxn)(void);
699  void (*rfePatchFxn)(void);
700 } RF_Mode;
701 
702 
713 typedef enum {
717 } RF_Priority;
718 
727 typedef enum {
733  RF_StatError = 0x80,
737 } RF_Stat;
738 
743 typedef uint64_t RF_EventMask;
744 
754 typedef union {
755  rfc_command_t commandId;
756 
758  rfc_CMD_RADIO_SETUP_t common;
759  rfc_CMD_BLE5_RADIO_SETUP_t ble5;
760  rfc_CMD_PROP_RADIO_SETUP_t prop;
761  rfc_CMD_PROP_RADIO_DIV_SETUP_t prop_div;
762 } RF_RadioSetup;
763 
764 
793 typedef enum {
795  RF_ClientEventRadioFree = 0x00000002,
796 
801 
805 typedef uint32_t RF_ClientEventMask;
806 
819 typedef int16_t RF_CmdHandle;
820 
827 typedef struct {
828  uint8_t hwiCpe0Priority;
829  uint8_t hwiHwPriority;
830  uint8_t swiCpe0Priority;
831  uint8_t swiHwPriority;
833 
834 
855 #if defined (RF_SINGLEMODE)
856  typedef struct RF_ObjectSingleMode RF_Object;
857 #else
858  typedef struct RF_ObjectMultiMode RF_Object;
859 #endif
860 
861 /* Definition of the RF_Object structure for single-mode applications.
862  * It is applicable with the single-mode RF driver through the #RF_Object common type.
863  */
864 struct RF_ObjectSingleMode{
866  struct {
867  uint32_t nInactivityTimeout;
868  RF_Mode* pRfMode;
869  RF_RadioSetup* pOpSetup;
870  uint32_t nPowerUpDuration;
871  bool bPowerUpXOSC;
872  bool bUpdateSetup;
873  uint16_t nPowerUpDurationMargin;
874  void* pPowerCb;
875  void* pErrCb;
876  } clientConfig;
878  struct {
879  struct {
880  rfc_CMD_FS_t cmdFs;
881  } mode_state;
882  SemaphoreP_Struct semSync;
883  RF_EventMask volatile eventSync;
884  void* pCbSync;
885  RF_EventMask unpendCause;
886  ClockP_Struct clkInactivity;
887  RF_CmdHandle volatile chLastPosted;
888  bool bYielded;
889  } state;
890 };
891 
895 struct RF_ObjectMultiMode{
897  struct {
898  uint32_t nInactivityTimeout;
899  RF_Mode* pRfMode;
900  RF_RadioSetup* pOpSetup;
901  uint32_t nPowerUpDuration;
902  bool bPowerUpXOSC;
903  bool bUpdateSetup;
904  uint16_t nPowerUpDurationMargin;
905  void* pPowerCb;
906  void* pErrCb;
907  void* pClientEventCb;
908  RF_ClientEventMask nClientEventMask;
909  } clientConfig;
911  struct {
912  struct {
913  rfc_CMD_FS_t cmdFs;
914  } mode_state;
915  SemaphoreP_Struct semSync;
916  RF_EventMask volatile eventSync;
917  void* pCbSync;
918  RF_EventMask unpendCause;
919  ClockP_Struct clkInactivity;
920  ClockP_Struct clkReqAccess;
921  RF_CmdHandle volatile chLastPosted;
922  bool bYielded;
923  } state;
924 };
925 
934 
935 
944 typedef int8_t RF_RatHandle;
945 
946 
950 typedef enum {
955 } RF_InfoType;
956 
962 typedef union {
963  RF_CmdHandle ch;
964  uint16_t availRatCh;
965  bool bRadioState;
966  void *pScheduleMap;
967 } RF_InfoVal;
968 
970 typedef struct {
971  RF_Handle pClient;
972  uint32_t startTime;
973  uint32_t endTime;
976 
978 typedef struct {
982 
983 
1009 typedef void (*RF_Callback)(RF_Handle h, RF_CmdHandle ch, RF_EventMask e);
1010 
1026 typedef void (*RF_ClientCallback)(RF_Handle h, RF_ClientEvent event, void* arg);
1027 
1036 typedef struct {
1038 
1040  uint32_t nPowerUpDuration;
1041 
1045 
1049 
1054 
1059 
1061  RF_ClientEventMask nClientEventMask;
1062 } RF_Params;
1064 
1067 typedef struct {
1068  uint32_t endTime;
1070  bool bIeeeBgCmd;
1072 
1075 typedef struct {
1076  uint32_t duration;
1077  uint32_t startTime;
1080 
1113 extern RF_Handle RF_open(RF_Object *pObj, RF_Mode *pRfMode, RF_RadioSetup *pOpSetup, RF_Params *params);
1114 
1115 
1126 extern void RF_close(RF_Handle h);
1127 
1128 
1139 extern uint32_t RF_getCurrentTime(void);
1140 
1141 
1196 extern RF_CmdHandle RF_postCmd(RF_Handle h, RF_Op* pOp, RF_Priority ePri, RF_Callback pCb, RF_EventMask bmEvent);
1197 
1224 extern RF_CmdHandle RF_scheduleCmd(RF_Handle h, RF_Op* pOp, RF_ScheduleCmdParams *pSchParams, RF_Callback pCb, RF_EventMask bmEvent);
1225 
1285 extern RF_EventMask RF_pendCmd(RF_Handle h, RF_CmdHandle ch, RF_EventMask bmEvent);
1286 
1287 
1315 extern RF_EventMask RF_runCmd(RF_Handle h, RF_Op* pOp, RF_Priority ePri, RF_Callback pCb, RF_EventMask bmEvent);
1316 
1336 extern RF_EventMask RF_runScheduleCmd(RF_Handle h, RF_Op* pOp, RF_ScheduleCmdParams *pSchParams, RF_Callback pCb, RF_EventMask bmEvent);
1337 
1357 extern RF_Stat RF_cancelCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode);
1358 
1359 
1378 extern RF_Stat RF_flushCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode);
1379 
1393 extern RF_Stat RF_runImmediateCmd(RF_Handle h, uint32_t* pCmdStruct);
1394 
1408 extern RF_Stat RF_runDirectCmd(RF_Handle h, uint32_t cmd);
1409 
1421 extern void RF_yield(RF_Handle h);
1422 
1434 extern void RF_Params_init(RF_Params *params);
1435 
1446 extern RF_Stat RF_getInfo(RF_Handle h, RF_InfoType type, RF_InfoVal *pValue);
1447 
1456 extern int8_t RF_getRssi(RF_Handle h);
1457 
1467 extern RF_Op* RF_getCmdOp(RF_Handle h, RF_CmdHandle cmdHnd);
1468 
1496 extern RF_RatHandle RF_ratCompare(RF_Handle h, rfc_CMD_SET_RAT_CMP_t* pCmdStruct, \
1497  uint32_t compareTime, RF_Callback pRatCb);
1523 extern RF_RatHandle RF_ratCapture(RF_Handle h, uint16_t config, RF_Callback pRatCb);
1524 
1535 extern RF_Stat RF_ratHwOutput(RF_Handle h, uint16_t config);
1536 
1552 extern RF_Stat RF_ratDisableChannel(RF_Handle h, RF_RatHandle ratHandle);
1553 
1564 extern RF_Stat RF_control(RF_Handle h, int8_t ctrl, void *args);
1565 
1584 extern RF_Stat RF_requestAccess(RF_Handle h, RF_AccessParams *pParams);
1585 
1586 #ifdef __cplusplus
1587 }
1588 #endif
1589 
1590 #endif /* ti_drivers_rf__include */
RF_RatHandle RF_ratCapture(RF_Handle h, uint16_t config, RF_Callback pRatCb)
Setup a Radio Timer (RAT) channel in capture mode.
RF_CmdHandle ch
Command handle (RF_GET_CURR_CMD).
Definition: RF.h:963
Command not executed because RF core is powered down.
Definition: RF.h:729
void(* RF_ClientCallback)(RF_Handle h, RF_ClientEvent event, void *arg)
Handles events related to a driver instance.
Definition: RF.h:1026
RF driver configuration parameters.
Definition: RF.h:1036
uint32_t startTime
Start time window in RAT Time for radio access.
Definition: RF.h:1077
RF_Stat RF_ratDisableChannel(RF_Handle h, RF_RatHandle ratHandle)
Disable a RAT channel.
RF_InfoType
Selects the entry of interest in RF_getInfo().
Definition: RF.h:950
uint16_t nPowerUpDurationMargin
Definition: RF.h:1053
The RF core has been powered up the radio setup has been finished.
Definition: RF.h:794
RF_ClientEvent
Client-related RF driver events.
Definition: RF.h:793
RF_Stat
Status codes for various RF driver functions.
Definition: RF.h:727
uint8_t rfMode
Specifies which PHY modes should be activated. Must be set to RF_MODE_MULTIPLE for dual-mode operatio...
Definition: RF.h:696
RF_Priority priority
Intra client priority.
Definition: RF.h:1069
void(* RF_Callback)(RF_Handle h, RF_CmdHandle ch, RF_EventMask e)
Handles events related to RF command execution.
Definition: RF.h:1009
uint8_t swiHwPriority
Priority for HW SWI. Used for all RAT channel callbacks.
Definition: RF.h:831
RF_EventMask RF_pendCmd(RF_Handle h, RF_CmdHandle ch, RF_EventMask bmEvent)
Synchronizes the calling task to an RF operation command ch and returns accumulated event flags...
RF_ClientEventMask nClientEventMask
Definition: RF.h:1061
RF schedule map entry structure.
Definition: RF.h:970
RF_CmdHandle RF_postCmd(RF_Handle h, RF_Op *pOp, RF_Priority ePri, RF_Callback pCb, RF_EventMask bmEvent)
Appends RF operation commands to the driver&#39;s command queue and returns a command handle...
Command finished with success.
Definition: RF.h:734
RF_EventMask RF_runScheduleCmd(RF_Handle h, RF_Op *pOp, RF_ScheduleCmdParams *pSchParams, RF_Callback pCb, RF_EventMask bmEvent)
Runs synchronously a (chain of) RF operation(s) for dual or single-mode.
Command not executed because RF driver is busy.
Definition: RF.h:728
Highest priority. Only use this for urgent commands.
Definition: RF.h:714
RF_Stat RF_runImmediateCmd(RF_Handle h, uint32_t *pCmdStruct)
Send any Immediate command.
uint64_t RF_EventMask
Data type for events during command execution.
Definition: RF.h:743
uint32_t RF_ClientEventMask
Event mask for combining RF_ClientEvent event flags in RF_Params::nClientEventMask.
Definition: RF.h:805
uint32_t nPowerUpDuration
Definition: RF.h:1040
Command successfully scheduled for execution.
Definition: RF.h:735
void RF_close(RF_Handle h)
Close client connection to RF driver.
Definition: RF.h:795
Cmd is found in the pool but was already ended.
Definition: RF.h:732
uint8_t hwiCpe0Priority
Priority for INT_RFC_CPE_0 interrupt.
Definition: RF.h:828
RF_Handle RF_open(RF_Object *pObj, RF_Mode *pRfMode, RF_RadioSetup *pOpSetup, RF_Params *params)
Creates a a new client instance of the RF driver.
rfc_CMD_PROP_RADIO_DIV_SETUP_t prop_div
Radio setup command for PROPRIETARY mode on Sub-1 Ghz.
Definition: RF.h:761
RF_Stat RF_ratHwOutput(RF_Handle h, uint16_t config)
Setup RAT HW output. Note radio needs to be ON and and the selected RAT channel should be configured ...
uint32_t RF_getCurrentTime(void)
Return current radio timer value.
Signals the client that the RF driver is about to switch over from another client.
Definition: RF.h:799
Stores output parameters for RF_getInfo().
Definition: RF.h:962
RF_Object * RF_Handle
A handle that is returned by to RF_open().
Definition: RF.h:933
RF_Handle pClient
Pointer to client object.
Definition: RF.h:971
#define RF_NUM_SCHEDULE_ACCESS_ENTRIES
Number of access request entries.
Definition: RF.h:665
RF Hardware attributes.
Definition: RF.h:827
RF_EventMask RF_runCmd(RF_Handle h, RF_Op *pOp, RF_Priority ePri, RF_Callback pCb, RF_EventMask bmEvent)
Runs synchronously an RF operation command or a chain of commands and returns the termination reason...
RF_Priority priority
Priority of the command or access request.
Definition: RF.h:974
rfc_radioOp_t RF_Op
Base type for all radio operation commands.
Definition: RF.h:684
Default priority. Use this in single-client applications.
Definition: RF.h:716
int8_t RF_getRssi(RF_Handle h)
Get RSSI value.
bool bRadioState
Current RF core power state (RF_GET_RADIO_STATE).
Definition: RF.h:965
uint32_t duration
Radio access duration in RAT Ticks requested by the client.
Definition: RF.h:1076
void RF_yield(RF_Handle h)
Signal that radio client is not going to issue more commands in a while.
#define RF_NUM_SCHEDULE_COMMAND_ENTRIES
Number of scheduled command entries.
Definition: RF.h:666
uint32_t startTime
Start time (in RAT tick) of the command or access request.
Definition: RF.h:972
uint32_t endTime
End time in RAT Ticks for the radio command.
Definition: RF.h:1068
Create a bitmask showing available RAT channels.
Definition: RF.h:952
RF_Stat RF_flushCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode)
Abort/stop/cancel command and any subsequent commands in command queue.
RF_Stat RF_cancelCmd(RF_Handle h, RF_CmdHandle ch, uint8_t mode)
Abort/stop/cancel single command in command queue.
RF schedule command parameter struct RF schedule command parameters are used with the RF_scheduleCmd(...
Definition: RF.h:1067
RF_Callback pPowerCb
Definition: RF.h:1044
bool bIeeeBgCmd
IEEE 15.4 background command indication. 0: FG cmd, 1: BG cmd.
Definition: RF.h:1070
int16_t RF_CmdHandle
Command handle that is returned by RF_postCmd().
Definition: RF.h:819
RF_ClientCallback pClientEventCb
Definition: RF.h:1058
uint16_t availRatCh
Available RAT channels (RF_GET_AVAIL_RAT_CH).
Definition: RF.h:964
uint8_t swiCpe0Priority
Priority for CPE_0 SWI.
Definition: RF.h:830
RF_Op * RF_getCmdOp(RF_Handle h, RF_CmdHandle cmdHnd)
Get command structure pointer.
General error specifier.
Definition: RF.h:733
bool bPowerUpXOSC
Definition: RF.h:1048
uint32_t endTime
End time (in RAT tick) of the command or access request.
Definition: RF.h:973
rfc_CMD_RADIO_SETUP_t common
Radio setup command for BLE and IEEE modes.
Definition: RF.h:758
int8_t RF_RatHandle
RAT handle that is returned by RF_ratCompare() or RF_ratCapture().
Definition: RF.h:944
RF request access parameter struct RF request access command parameters are used with the RF_requestA...
Definition: RF.h:1075
RF_Stat RF_getInfo(RF_Handle h, RF_InfoType type, RF_InfoVal *pValue)
Get value for some RF driver parameters.
Command finished with an error.
Definition: RF.h:730
Provide a timetable of all scheduled commands.
Definition: RF.h:954
RF_Priority
Scheduling priority of RF operation commands.
Definition: RF.h:713
Function was called with an invalid parameter.
Definition: RF.h:731
High priority. Use this for time-critical commands in synchronous protocols.
Definition: RF.h:715
RF_RatHandle RF_ratCompare(RF_Handle h, rfc_CMD_SET_RAT_CMP_t *pCmdStruct, uint32_t compareTime, RF_Callback pRatCb)
Setup a Radio Timer (RAT) channel in compare mode.
A unified type for radio setup commands of different PHYs.
Definition: RF.h:754
uint32_t nInactivityTimeout
Definition: RF.h:1037
RF schedule map structure.
Definition: RF.h:978
RF_Stat RF_requestAccess(RF_Handle h, RF_AccessParams *pParams)
Request radio access.
RF_Stat RF_runDirectCmd(RF_Handle h, uint32_t cmd)
Send any Direct command.
Retrieve a command handle of the current command.
Definition: RF.h:951
Specifies a RF core firmware configuration.
Definition: RF.h:695
rfc_command_t commandId
Definition: RF.h:755
rfc_CMD_PROP_RADIO_SETUP_t prop
Radio setup command for PROPRIETARY mode on 2.4 GHz.
Definition: RF.h:760
rfc_CMD_BLE5_RADIO_SETUP_t ble5
Radio setup command for BLE5 mode.
Definition: RF.h:759
Function finished with success.
Definition: RF.h:736
RF_Callback pErrCb
Callback function for driver error events.
Definition: RF.h:1047
RF_CmdHandle RF_scheduleCmd(RF_Handle h, RF_Op *pOp, RF_ScheduleCmdParams *pSchParams, RF_Callback pCb, RF_EventMask bmEvent)
Schedule an RF operation (chain) to the command queue.
RF_Stat RF_control(RF_Handle h, int8_t ctrl, void *args)
Set RF control parameters.
uint8_t hwiHwPriority
Priority for INT_RFC_HW_COMB interrupt.
Definition: RF.h:829
void RF_Params_init(RF_Params *params)
Function to initialize the RF_Params struct to its defaults.
Stores the client&#39;s internal confguration and states.
Show the current RF core power state. 0: Radio OFF, 1: Radio ON.
Definition: RF.h:953
RF_Priority priority
Access priority.
Definition: RF.h:1078
void * pScheduleMap
Pointer to scheduling map (RF_GET_SCHEDULE_MAP).
Definition: RF.h:966
Copyright 2017, Texas Instruments Incorporated