CC26xx Driver Library
rfc.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: rfc.c
3 * Revised: 2016-05-27 08:27:46 +0200 (Fri, 27 May 2016)
4 * Revision: 46517
5 *
6 * Description: Driver for the RF Core.
7 *
8 * Copyright (c) 2015 - 2016, 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 #include <string.h>
41 
42 //*****************************************************************************
43 //
44 // Handle support for DriverLib in ROM:
45 // This section will undo prototype renaming made in the header file
46 //
47 //*****************************************************************************
48 #if !defined(DOXYGEN)
49  #undef RFCCpeIntGetAndClear
50  #define RFCCpeIntGetAndClear NOROM_RFCCpeIntGetAndClear
51  #undef RFCDoorbellSendTo
52  #define RFCDoorbellSendTo NOROM_RFCDoorbellSendTo
53  #undef RFCSynthPowerDown
54  #define RFCSynthPowerDown NOROM_RFCSynthPowerDown
55  #undef RFCRfTrimRead
56  #define RFCRfTrimRead NOROM_RFCRfTrimRead
57  #undef RFCRfTrimSet
58  #define RFCRfTrimSet NOROM_RFCRfTrimSet
59  #undef RFCRTrim
60  #define RFCRTrim NOROM_RFCRTrim
61  #undef RFCCPEPatchReset
62  #define RFCCPEPatchReset NOROM_RFCCPEPatchReset
63  #undef RFCAdi3VcoLdoVoltageMode
64  #define RFCAdi3VcoLdoVoltageMode NOROM_RFCAdi3VcoLdoVoltageMode
65 #endif
66 
67 #define RFC_RESERVED0 0x40044108
68 #define RFC_RESERVED1 0x40044114
69 #define RFC_RESERVED2 0x4004410C
70 #define RFC_RESERVED3 0x40044100
71 
72 // Position of divider value
73 #define CONFIG_MISC_ADC_DIVIDER 27
74 #define CONFIG_MISC_ADC_DIVIDER_BM 0xF8000000U
75 
76 #define _CPERAM_START 0x21000000
77 #define _PARSER_PATCH_TAB_OFFSET 0x0334
78 #define _PATCH_TAB_OFFSET 0x033C
79 #define _IRQPATCH_OFFSET 0x03AC
80 #define _PATCH_VEC_OFFSET 0x0404
81 
82 static const uint16_t rfc_defaultIrqAddr[] =
83 {
84  0x398b,
85  0x3805,
86  0x3825,
87  0x3839,
88  0x0acf,
89  0x3857,
90  0x38d7,
91  0x09dd,
92  0x5819,
93  0x0ab3,
94  0x38f7,
95 };
96 
97 //*****************************************************************************
98 //
99 // Get and clear CPE interrupt flags
100 //
101 //*****************************************************************************
102 uint32_t
104 {
105  uint32_t ui32Ifg = HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG);
106 
107  do {
108  HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG) = ~ui32Ifg;
109  } while (HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG) & ui32Ifg);
110 
111  return (ui32Ifg);
112 }
113 
114 
115 //*****************************************************************************
116 //
117 // Send command to doorbell and wait for ack
118 //
119 //*****************************************************************************
120 uint32_t
121 RFCDoorbellSendTo(uint32_t pOp)
122 {
123  while(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDR) != 0);
124 
125  RFCAckIntClear();
126 
127  HWREG(RFC_DBELL_BASE+RFC_DBELL_O_CMDR) = pOp;
128 
129  while(!HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFACKIFG));
130  RFCAckIntClear();
131 
132  return(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA));
133 }
134 
135 
136 //*****************************************************************************
137 //
138 // Turn off synth, NOTE: Radio will no longer respond to commands!
139 //
140 //*****************************************************************************
141 void
143 {
144  // Disable CPE clock, enable FSCA clock. NOTE: Radio will no longer respond to commands!
145  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;
146 
147  (*((volatile unsigned long *)(RFC_RESERVED0))) = 3;
148  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x1030;
149  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
150  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x50;
151  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
152  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x650;
153  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
154  (*((volatile unsigned long *)(RFC_RESERVED3))) = 1;
155 }
156 
157 
158 //*****************************************************************************
159 //
160 // Read RF Trim from flash using the CM3
161 //
162 //*****************************************************************************
163 void RFCRfTrimRead(rfc_radioOp_t *pOpSetup, rfTrim_t* pRfTrim)
164 {
165  // Read trim from FCFG1
166  pRfTrim->configIfAdc = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_IF_ADC);
168  pRfTrim->configSynth = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_SYNTH);
169  // Make sure configMiscAdc is not 0 by setting an unused bit to 1
172 }
173 
174 
175 //*****************************************************************************
176 //
177 // Check Override RTrim vs FCFG RTrim
178 //
179 //*****************************************************************************
180 void RFCRTrim(rfc_radioOp_t *pOpSetup)
181 {
182  // Function is left blank for compatibility with CC13xx.
183 }
184 
185 
186 //*****************************************************************************
187 //
188 // Write preloaded RF trim values to CM0
189 //
190 //*****************************************************************************
191 void RFCRfTrimSet(rfTrim_t* pRfTrim)
192 {
193  memcpy((void*)&HWREG(0x21000018), (void*)pRfTrim, sizeof(rfTrim_t));
194 }
195 
196 
197 //*****************************************************************************
198 //
199 // Reset previously patched CPE RAM to a state where it can be patched again
200 //
201 //*****************************************************************************
203 {
204  uint8_t *pPatchTab = (uint8_t *) (_CPERAM_START + _PARSER_PATCH_TAB_OFFSET);
205  uint32_t *pIrqPatch = (uint32_t *) (_CPERAM_START + _IRQPATCH_OFFSET);
206 
207  memset(pPatchTab, 0xFF, _IRQPATCH_OFFSET - _PARSER_PATCH_TAB_OFFSET);
208 
209  int i;
210  for (i = 0; i < sizeof(rfc_defaultIrqAddr)/sizeof(rfc_defaultIrqAddr[0]); i++)
211  {
212  pIrqPatch[i * 2 + 1] = rfc_defaultIrqAddr[i];
213  }
214 }
215 
216 
217 //*****************************************************************************
218 //
219 // Function to set VCOLDO reference to voltage mode
220 //
221 //*****************************************************************************
222 void RFCAdi3VcoLdoVoltageMode(bool bEnable)
223 {
224  // Function is left blank for compatibility with CC13xx.
225 }
226 
227 
228 
229 //*****************************************************************************
230 //
231 // Handle support for DriverLib in ROM:
232 // This section will undo prototype renaming made in the header file
233 //
234 //*****************************************************************************
235 #if !defined(DOXYGEN)
236  #undef RFCCpeIntGetAndClear
237  #define RFCCpeIntGetAndClear NOROM_RFCCpeIntGetAndClear
238  #undef RFCDoorbellSendTo
239  #define RFCDoorbellSendTo NOROM_RFCDoorbellSendTo
240  #undef RFCSynthPowerDown
241  #define RFCSynthPowerDown NOROM_RFCSynthPowerDown
242  #undef RFCRfTrimRead
243  #define RFCRfTrimRead NOROM_RFCRfTrimRead
244  #undef RFCRfTrimSet
245  #define RFCRfTrimSet NOROM_RFCRfTrimSet
246  #undef RFCRTrim
247  #define RFCRTrim NOROM_RFCRTrim
248  #undef RFCCPEPatchReset
249  #define RFCCPEPatchReset NOROM_RFCCPEPatchReset
250  #undef RFCAdi3VcoLdoVoltageMode
251  #define RFCAdi3VcoLdoVoltageMode NOROM_RFCAdi3VcoLdoVoltageMode
252 #endif
253 
254 // See rfc.h for implementation
#define RFC_RESERVED0
Definition: rfc.c:67
uint32_t configSynth
Definition: rfc.h:75
static const uint16_t rfc_defaultIrqAddr[]
Definition: rfc.c:82
#define _IRQPATCH_OFFSET
Definition: rfc.c:79
struct __RFC_STRUCT rfc_radioOp_s rfc_radioOp_t
Definition: rf_common_cmd.h:60
#define CONFIG_MISC_ADC_DIVIDER_BM
Definition: rfc.c:74
void RFCRfTrimSet(rfTrim_t *pRfTrim)
Write preloaded RF trim values to CM0.
Definition: rfc.c:191
static void RFCAckIntClear(void)
Clear interrupt flags.
Definition: rfc.h:318
Definition: rfc.h:72
uint32_t RFCCpeIntGetAndClear(void)
Get and clear CPE interrupt flags.
Definition: rfc.c:103
#define CONFIG_MISC_ADC_DIVIDER
Definition: rfc.c:73
#define RFC_RESERVED3
Definition: rfc.c:70
uint32_t configMiscAdc
Definition: rfc.h:76
#define RFC_RESERVED2
Definition: rfc.c:69
void RFCRTrim(rfc_radioOp_t *pOpSetup)
Check Override RTrim vs FCFG RTrim.
Definition: rfc.c:180
uint32_t configRfFrontend
Definition: rfc.h:74
void RFCCPEPatchReset(void)
Reset previously patched CPE RAM to a state where it can be patched again.
Definition: rfc.c:202
uint32_t configIfAdc
Definition: rfc.h:73
uint32_t RFCDoorbellSendTo(uint32_t pOp)
Send command to doorbell and wait for ack.
Definition: rfc.c:121
void RFCAdi3VcoLdoVoltageMode(bool bEnable)
Function to set VCOLDO reference to voltage mode.
Definition: rfc.c:222
void RFCRfTrimRead(rfc_radioOp_t *pOpSetup, rfTrim_t *pRfTrim)
Read RF trim from flash using CM3.
Definition: rfc.c:163
#define _CPERAM_START
Definition: rfc.c:76
#define _PARSER_PATCH_TAB_OFFSET
Definition: rfc.c:77
void RFCSynthPowerDown()
Turn off synth, NOTE: Radio will no longer respond to commands!
Definition: rfc.c:142
#define RFC_RESERVED1
Definition: rfc.c:68