CC26xx Driver Library
rfc.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: rfc.c
3 * Revised: 2016-04-07 15:04:05 +0200 (Thu, 07 Apr 2016)
4 * Revision: 46052
5 *
6 * Description: Driver for the RF Core.
7 *
8 * Copyright (c) 2015, Texas Instruments Incorporated
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 *
14 * 1) Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 *
17 * 2) Redistributions in binary form must reproduce the above copyright notice,
18 * this list of conditions and the following disclaimer in the documentation
19 * and/or other materials provided with the distribution.
20 *
21 * 3) Neither the name of the ORGANIZATION nor the names of its contributors may
22 * be used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 *
37 ******************************************************************************/
38 
39 #include <driverlib/rfc.h>
40 
41 #define RFC_RESERVED0 0x40044108
42 #define RFC_RESERVED1 0x40044114
43 #define RFC_RESERVED2 0x4004410C
44 #define RFC_RESERVED3 0x40044100
45 
46 // Position of divider value
47 #define CONFIG_MISC_ADC_DIVIDER 27
48 #define CONFIG_MISC_ADC_DIVIDER_BM 0xF8000000U
49 
50 // RTrim positions
51 #define FCFG1_O_CONFIG_MISC_ADC_PO_TAIL_RES_TRIM_M 0x003C0000
52 #define FCFG1_O_CONFIG_MISC_ADC_PO_TAIL_RES_TRIM_S 18
53 #define FCFG1_O_CONFIG_MISC_ADC_DIV6_PO_TAIL_RES_TRIM_M 0x003C0000
54 #define FCFG1_O_CONFIG_MISC_ADC_DIV6_PO_TAIL_RES_TRIM_S 18
55 #define FCFG1_O_CONFIG_MISC_ADC_DIV10_PO_TAIL_RES_TRIM_M 0x003C0000
56 #define FCFG1_O_CONFIG_MISC_ADC_DIV10_PO_TAIL_RES_TRIM_S 18
57 #define FCFG1_O_CONFIG_MISC_ADC_DIV12_PO_TAIL_RES_TRIM_M 0x003C0000
58 #define FCFG1_O_CONFIG_MISC_ADC_DIV12_PO_TAIL_RES_TRIM_S 18
59 #define FCFG1_O_CONFIG_MISC_ADC_DIV15_PO_TAIL_RES_TRIM_M 0x003C0000
60 #define FCFG1_O_CONFIG_MISC_ADC_DIV15_PO_TAIL_RES_TRIM_S 18
61 #define FCFG1_O_CONFIG_MISC_ADC_DIV30_PO_TAIL_RES_TRIM_M 0x003C0000
62 #define FCFG1_O_CONFIG_MISC_ADC_DIV30_PO_TAIL_RES_TRIM_S 18
63 
64 //*****************************************************************************
65 //
66 // Get and clear CPE interrupt flags
67 //
68 //*****************************************************************************
69 uint32_t
71 {
72  uint32_t ui32Ifg = HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG);
73 
74  do {
75  HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG) = ~ui32Ifg;
76  } while (HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG) & ui32Ifg);
77 
78  return (ui32Ifg);
79 }
80 
81 
82 //*****************************************************************************
83 //
84 // Send command to doorbell and wait for ack
85 //
86 //*****************************************************************************
87 uint32_t
88 RFCDoorbellSendTo(uint32_t pOp)
89 {
90  while(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDR) != 0);
91 
93 
94  HWREG(RFC_DBELL_BASE+RFC_DBELL_O_CMDR) = pOp;
95 
96  while(!HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFACKIFG));
98 
99  return(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA));
100 }
101 
102 
103 //*****************************************************************************
104 //
105 // Turn off synth, NOTE: Radio will no longer respond to commands!
106 //
107 //*****************************************************************************
108 void
110 {
111  // Disable CPE clock, enable FSCA clock. NOTE: Radio will no longer respond to commands!
112  HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = (HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) & ~RFC_PWR_PWMCLKEN_CPE_M) | RFC_PWR_PWMCLKEN_FSCA_M;
113 
114  (*((volatile unsigned long *)(RFC_RESERVED0))) = 3;
115  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x1030;
116  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
117  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x50;
118  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
119  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x650;
120  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
121  (*((volatile unsigned long *)(RFC_RESERVED3))) = 1;
122 }
123 
124 
125 //*****************************************************************************
126 //
127 // Read RF Trim from flash using the CM3
128 //
129 //*****************************************************************************
130 void RFCRfTrimRead(rfc_radioOp_t *pOpSetup, rfTrim_t* pRfTrim)
131 {
132  // Read trim from FCFG1
133  pRfTrim->configIfAdc = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_IF_ADC);
135  pRfTrim->configSynth = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_SYNTH);
136  // Make sure configMiscAdc is not 0 by setting an unused bit to 1
139 }
140 
141 
142 //*****************************************************************************
143 //
144 // Check Override RTrim vs FCFG RTrim
145 //
146 //*****************************************************************************
147 void RFCRTrim(rfc_radioOp_t *pOpSetup)
148 {
149  // Function is left blank due to
150 }
151 
152 
153 //*****************************************************************************
154 //
155 // Write preloaded RF trim values to CM0
156 //
157 //*****************************************************************************
158 void RFCRfTrimSet(rfTrim_t* pRfTrim)
159 {
160  memcpy((void*)&HWREG(0x21000018), (void*)pRfTrim, sizeof(rfTrim_t));
161 }
162 
163 
164 //*****************************************************************************
165 //
166 // Handle support for DriverLib in ROM:
167 // This section will undo prototype renaming made in the header file
168 //
169 //*****************************************************************************
170 #if !defined(DOXYGEN)
171  #undef RFCCpeIntGetAndClear
172  #define RFCCpeIntGetAndClear NOROM_RFCCpeIntGetAndClear
173  #undef RFCDoorbellSendTo
174  #define RFCDoorbellSendTo NOROM_RFCDoorbellSendTo
175  #undef RFCSynthPowerDown
176  #define RFCSynthPowerDown NOROM_RFCSynthPowerDown
177  #undef RFCRfTrimRead
178  #define RFCRfTrimRead NOROM_RFCRfTrimRead
179  #undef RFCRfTrimSet
180  #define RFCRfTrimSet NOROM_RFCRfTrimSet
181  #undef RFCRTrim
182  #define RFCRTrim NOROM_RFCRTrim
183 #endif
184 
185 // See rfc.h for implementation
#define RFC_RESERVED0
Definition: rfc.c:41
uint32_t configSynth
Definition: rfc.h:73
struct __RFC_STRUCT rfc_radioOp_s rfc_radioOp_t
Definition: rf_common_cmd.h:60
#define CONFIG_MISC_ADC_DIVIDER_BM
Definition: rfc.c:48
void RFCRfTrimSet(rfTrim_t *pRfTrim)
Write preloaded RF trim values to CM0.
Definition: rfc.c:158
static void RFCAckIntClear(void)
Clear interrupt flags.
Definition: rfc.h:314
Definition: rfc.h:70
uint32_t RFCCpeIntGetAndClear(void)
Get and clear CPE interrupt flags.
Definition: rfc.c:70
#define CONFIG_MISC_ADC_DIVIDER
Definition: rfc.c:47
#define RFC_RESERVED3
Definition: rfc.c:44
uint32_t configMiscAdc
Definition: rfc.h:74
#define RFC_RESERVED2
Definition: rfc.c:43
void RFCRTrim(rfc_radioOp_t *pOpSetup)
Check Override RTrim vs FCFG RTrim.
Definition: rfc.c:147
uint32_t configRfFrontend
Definition: rfc.h:72
uint32_t configIfAdc
Definition: rfc.h:71
uint32_t RFCDoorbellSendTo(uint32_t pOp)
Send command to doorbell and wait for ack.
Definition: rfc.c:88
void RFCRfTrimRead(rfc_radioOp_t *pOpSetup, rfTrim_t *pRfTrim)
Read RF trim from flash using CM3.
Definition: rfc.c:130
void RFCSynthPowerDown()
Turn off synth, NOTE: Radio will no longer respond to commands!
Definition: rfc.c:109
#define RFC_RESERVED1
Definition: rfc.c:42