1 /******************************************************************************
2 *  Filename:       rfc.h
3 *  Revised:        2018-08-08 14:03:25 +0200 (Wed, 08 Aug 2018)
4 *  Revision:       52338
5 *
6 *  Description:    Defines and prototypes for the RF Core.
7 *
8 *  Copyright (c) 2015 - 2017, 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 //*****************************************************************************
40 //
41 //! \addtogroup rfc_api
42 //! @{
43 //
44 //*****************************************************************************
45 
46 #ifndef __RFC_H__
47 #define __RFC_H__
48 
49 //*****************************************************************************
50 //
51 // If building with a C++ compiler, make all of the definitions in this header
52 // have a C binding.
53 //
54 //*****************************************************************************
55 #ifdef __cplusplus
56 extern "C"
57 {
58 #endif
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <ti/devices/DeviceFamily.h>
63 #include DeviceFamily_constructPath(inc/hw_types.h)
64 #include DeviceFamily_constructPath(inc/hw_memmap.h)
65 #include DeviceFamily_constructPath(inc/hw_rfc_pwr.h)
66 #include DeviceFamily_constructPath(inc/hw_rfc_dbell.h)
67 #include DeviceFamily_constructPath(inc/hw_fcfg1.h)
68 #include DeviceFamily_constructPath(inc/hw_adi_3_refsys.h)
69 #include DeviceFamily_constructPath(inc/hw_adi.h)
70 #include DeviceFamily_constructPath(inc/hw_prcm.h)
71 #include "rf_common_cmd.h"
72 #include "rf_prop_cmd.h"
73 #include "rf_ble_cmd.h"
74 
75 // Definition of RFTRIM container
76 typedef struct {
77    uint32_t configIfAdc;
78    uint32_t configRfFrontend;
79    uint32_t configSynth;
80    uint32_t configMiscAdc;
81 } rfTrim_t;
82 
83 // Definition of maximum search depth used by the RFCOverrideUpdate function
84 #define RFC_MAX_SEARCH_DEPTH     5
85 #define RFC_PA_TYPE_ADDRESS		 0x21000385
86 #define RFC_PA_TYPE_MASK 		 0x04
87 #define RFC_PA_GAIN_ADDRESS		 0x21000398
88 #define RFC_PA_GAIN_MASK		 0x003FFFFF
89 #define RFC_FE_MODE_ESCAPE_VALUE 0xFF
90 #define RFC_FE_OVERRIDE_ADDRESS  0x0703
91 #define RFC_FE_OVERRIDE_MASK     0x0000FFFF
92 
93 //*****************************************************************************
94 //
95 // Support for DriverLib in ROM:
96 // This section renames all functions that are not "static inline", so that
97 // calling these functions will default to implementation in flash. At the end
98 // of this file a second renaming will change the defaults to implementation in
99 // ROM for available functions.
100 //
101 // To force use of the implementation in flash, e.g. for debugging:
102 // - Globally: Define DRIVERLIB_NOROM at project level
103 // - Per function: Use prefix "NOROM_" when calling the function
104 //
105 //*****************************************************************************
106 #if !defined(DOXYGEN)
107     #define RFCCpeIntGetAndClear            NOROM_RFCCpeIntGetAndClear
108     #define RFCDoorbellSendTo               NOROM_RFCDoorbellSendTo
109     #define RFCSynthPowerDown               NOROM_RFCSynthPowerDown
110     #define RFCCpePatchReset                NOROM_RFCCpePatchReset
111     #define RFCOverrideSearch               NOROM_RFCOverrideSearch
112     #define RFCOverrideUpdate               NOROM_RFCOverrideUpdate
113     #define RFCHwIntGetAndClear             NOROM_RFCHwIntGetAndClear
114     #define RFCAnaDivTxOverride             NOROM_RFCAnaDivTxOverride
115 #endif
116 
117 //*****************************************************************************
118 //
119 // API Functions and prototypes
120 //
121 //*****************************************************************************
122 
123 //*****************************************************************************
124 //
125 //! \brief Enable the RF core clocks.
126 //!
127 //! As soon as the RF core is started it will handle clock control
128 //! autonomously. No check should be performed to check the clocks. Instead
129 //! the radio can be ping'ed through the command interface.
130 //!
131 //! \return None
132 //
133 //*****************************************************************************
134 __STATIC_INLINE void
RFCClockEnable(void)135 RFCClockEnable(void)
136 {
137     // Enable basic clocks to get the CPE run
138     HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = RFC_PWR_PWMCLKEN_CPERAM
139                                                     | RFC_PWR_PWMCLKEN_CPE
140                                                     | RFC_PWR_PWMCLKEN_RFC;
141 }
142 
143 
144 //*****************************************************************************
145 //
146 //! \brief Disable the RF core clocks.
147 //!
148 //! As soon as the RF core is started it will handle clock control
149 //! autonomously. No check should be performed to check the clocks. Instead
150 //! the radio can be ping'ed through the command interface.
151 //!
152 //! When disabling clocks it is the programmers responsibility that the
153 //! RF core clocks are safely gated. I.e. the RF core should be safely
154 //! 'parked'.
155 //!
156 //! \return None
157 //
158 //*****************************************************************************
159 __STATIC_INLINE void
RFCClockDisable(void)160 RFCClockDisable(void)
161 {
162     // Disable all clocks
163     HWREG(RFC_PWR_NONBUF_BASE + RFC_PWR_O_PWMCLKEN) = 0x0;
164 }
165 
166 
167 //*****************************************************************************
168 //
169 //! Clear HW interrupt flags
170 //
171 //*****************************************************************************
172 __STATIC_INLINE void
RFCCpeIntClear(uint32_t ui32Mask)173 RFCCpeIntClear(uint32_t ui32Mask)
174 {
175     // Clear the masked pending interrupts.
176     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEIFG) = ~ui32Mask;
177 }
178 
179 
180 //*****************************************************************************
181 //
182 //! Clear CPE interrupt flags.
183 //
184 //*****************************************************************************
185 __STATIC_INLINE void
RFCHwIntClear(uint32_t ui32Mask)186 RFCHwIntClear(uint32_t ui32Mask)
187 {
188     // Clear the masked pending interrupts.
189     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFHWIFG) = ~ui32Mask;
190 }
191 
192 
193 //*****************************************************************************
194 //
195 //! Select interrupt sources to CPE0 (assign to INT_RFC_CPE_0 interrupt vector).
196 //
197 //*****************************************************************************
198 __STATIC_INLINE void
RFCCpe0IntSelect(uint32_t ui32Mask)199 RFCCpe0IntSelect(uint32_t ui32Mask)
200 {
201     // Multiplex RF Core interrupts to CPE0 IRQ.
202     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEISL) &= ~ui32Mask;
203 }
204 
205 
206 //*****************************************************************************
207 //
208 //! Select interrupt sources to CPE1 (assign to INT_RFC_CPE_1 interrupt vector).
209 //
210 //*****************************************************************************
211 __STATIC_INLINE void
RFCCpe1IntSelect(uint32_t ui32Mask)212 RFCCpe1IntSelect(uint32_t ui32Mask)
213 {
214     // Multiplex RF Core interrupts to CPE1 IRQ.
215     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEISL) |= ui32Mask;
216 }
217 
218 
219 //*****************************************************************************
220 //
221 //! Enable CPEx interrupt sources.
222 //
223 //*****************************************************************************
224 __STATIC_INLINE void
RFCCpeIntEnable(uint32_t ui32Mask)225 RFCCpeIntEnable(uint32_t ui32Mask)
226 {
227     // Enable CPE interrupts from RF Core.
228     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEIEN) |= ui32Mask;
229 }
230 
231 
232 //*****************************************************************************
233 //
234 //! Select, clear, and enable interrupt sources to CPE0.
235 //
236 //*****************************************************************************
237 __STATIC_INLINE void
RFCCpe0IntSelectClearEnable(uint32_t ui32Mask)238 RFCCpe0IntSelectClearEnable(uint32_t ui32Mask)
239 {
240     // Multiplex RF Core interrupts to CPE0 IRQ.
241     RFCCpe0IntSelect(ui32Mask);
242 
243     // Clear the masked interrupts.
244     RFCCpeIntClear(ui32Mask);
245 
246     // Enable the masked interrupts.
247     RFCCpeIntEnable(ui32Mask);
248 }
249 
250 
251 //*****************************************************************************
252 //
253 //! Select, clear, and enable interrupt sources to CPE1.
254 //
255 //*****************************************************************************
256 __STATIC_INLINE void
RFCCpe1IntSelectClearEnable(uint32_t ui32Mask)257 RFCCpe1IntSelectClearEnable(uint32_t ui32Mask)
258 {
259     // Multiplex RF Core interrupts to CPE1 IRQ.
260     RFCCpe1IntSelect(ui32Mask);
261 
262     // Clear the masked interrupts.
263     RFCCpeIntClear(ui32Mask);
264 
265     // Enable the masked interrupts.
266     RFCCpeIntEnable(ui32Mask);
267 }
268 
269 
270 //*****************************************************************************
271 //
272 //! Enable HW interrupt sources.
273 //
274 //*****************************************************************************
275 __STATIC_INLINE void
RFCHwIntEnable(uint32_t ui32Mask)276 RFCHwIntEnable(uint32_t ui32Mask)
277 {
278     // Enable the masked interrupts
279     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFHWIEN) |= ui32Mask;
280 }
281 
282 
283 //*****************************************************************************
284 //
285 //! Disable CPE interrupt sources.
286 //
287 //*****************************************************************************
288 __STATIC_INLINE void
RFCCpeIntDisable(uint32_t ui32Mask)289 RFCCpeIntDisable(uint32_t ui32Mask)
290 {
291     // Disable the masked interrupts
292     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFCPEIEN) &= ~ui32Mask;
293 }
294 
295 
296 //*****************************************************************************
297 //
298 //! Disable HW interrupt sources.
299 //
300 //*****************************************************************************
301 __STATIC_INLINE void
RFCHwIntDisable(uint32_t ui32Mask)302 RFCHwIntDisable(uint32_t ui32Mask)
303 {
304     // Disable the masked interrupts
305     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFHWIEN) &= ~ui32Mask;
306 }
307 
308 
309 //*****************************************************************************
310 //
311 //! Get and clear CPE interrupt flags.
312 //
313 //*****************************************************************************
314 extern uint32_t RFCCpeIntGetAndClear(uint32_t ui32Mask);
315 
316 
317 //*****************************************************************************
318 //
319 //! Clear ACK interrupt flag.
320 //
321 //*****************************************************************************
322 __STATIC_INLINE void
RFCAckIntClear(void)323 RFCAckIntClear(void)
324 {
325     // Clear any pending interrupts.
326     HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFACKIFG) = 0x0;
327 }
328 
329 
330 //*****************************************************************************
331 //
332 //! Send a radio operation to the doorbell and wait for an acknowledgment.
333 //
334 //*****************************************************************************
335 extern uint32_t RFCDoorbellSendTo(uint32_t pOp);
336 
337 
338 //*****************************************************************************
339 //
340 //! This function implements a fast way to turn off the synthesizer.
341 //
342 //*****************************************************************************
343 extern void RFCSynthPowerDown(void);
344 
345 
346 //*****************************************************************************
347 //
348 //! Reset previously patched CPE RAM to a state where it can be patched again.
349 //
350 //*****************************************************************************
351 extern void RFCCpePatchReset(void);
352 
353 
354 //*****************************************************************************
355 //
356 // Function to search an override list for the provided pattern within the search depth.
357 //
358 //*****************************************************************************
359 extern uint8_t RFCOverrideSearch(const uint32_t *pOverride, const uint32_t pattern, const uint32_t mask, const uint8_t searchDepth);
360 
361 
362 //*****************************************************************************
363 //
364 //! Function to update override list
365 //
366 //*****************************************************************************
367 extern uint8_t RFCOverrideUpdate(rfc_radioOp_t *pOpSetup, uint32_t *pParams);
368 
369 
370 //*****************************************************************************
371 //
372 //! Get and clear HW interrupt flags.
373 //
374 //*****************************************************************************
375 extern uint32_t RFCHwIntGetAndClear(uint32_t ui32Mask);
376 
377 
378 //*****************************************************************************
379 //
380 //! Get the type of currently selected PA.
381 //
382 //*****************************************************************************
383 __STATIC_INLINE bool
RFCGetPaType(void)384 RFCGetPaType(void)
385 {
386     return (bool)(HWREGB(RFC_PA_TYPE_ADDRESS) & RFC_PA_TYPE_MASK);
387 }
388 
389 //*****************************************************************************
390 //
391 //! Get the gain of currently selected PA.
392 //
393 //*****************************************************************************
394 __STATIC_INLINE uint32_t
RFCGetPaGain(void)395 RFCGetPaGain(void)
396 {
397     return (HWREG(RFC_PA_GAIN_ADDRESS) & RFC_PA_GAIN_MASK);
398 }
399 
400 //*****************************************************************************
401 //
402 //! Get the power domain status of the radio core
403 //
404 //*****************************************************************************
405 __STATIC_INLINE uint32_t
RFCGetPowerDomainStatus(void)406 RFCGetPowerDomainStatus(void)
407 {
408     return (HWREG(PRCM_BASE + PRCM_O_PDCTL1RFC) |
409             HWREG(PRCM_BASE + PRCM_O_PDSTAT0RFC));
410 }
411 
412 //*****************************************************************************
413 //
414 //! Function to calculate the proper override run-time for the High Gain PA.
415 //
416 //*****************************************************************************
417 extern uint32_t RFCAnaDivTxOverride(uint8_t loDivider, uint8_t frontEndMode);
418 
419 
420 //*****************************************************************************
421 //
422 // Support for DriverLib in ROM:
423 // Redirect to implementation in ROM when available.
424 //
425 //*****************************************************************************
426 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
427     #include DeviceFamily_constructPath(driverlib/rom.h)
428     #ifdef ROM_RFCCpeIntGetAndClear
429         #undef  RFCCpeIntGetAndClear
430         #define RFCCpeIntGetAndClear            ROM_RFCCpeIntGetAndClear
431     #endif
432     #ifdef ROM_RFCDoorbellSendTo
433         #undef  RFCDoorbellSendTo
434         #define RFCDoorbellSendTo               ROM_RFCDoorbellSendTo
435     #endif
436     #ifdef ROM_RFCSynthPowerDown
437         #undef  RFCSynthPowerDown
438         #define RFCSynthPowerDown               ROM_RFCSynthPowerDown
439     #endif
440     #ifdef ROM_RFCCpePatchReset
441         #undef  RFCCpePatchReset
442         #define RFCCpePatchReset                ROM_RFCCpePatchReset
443     #endif
444     #ifdef ROM_RFCOverrideSearch
445         #undef  RFCOverrideSearch
446         #define RFCOverrideSearch               ROM_RFCOverrideSearch
447     #endif
448     #ifdef ROM_RFCOverrideUpdate
449         #undef  RFCOverrideUpdate
450         #define RFCOverrideUpdate               ROM_RFCOverrideUpdate
451     #endif
452     #ifdef ROM_RFCHwIntGetAndClear
453         #undef  RFCHwIntGetAndClear
454         #define RFCHwIntGetAndClear             ROM_RFCHwIntGetAndClear
455     #endif
456     #ifdef ROM_RFCAnaDivTxOverride
457         #undef  RFCAnaDivTxOverride
458         #define RFCAnaDivTxOverride             ROM_RFCAnaDivTxOverride
459     #endif
460 #endif
461 
462 //*****************************************************************************
463 //
464 // Mark the end of the C bindings section for C++ compilers.
465 //
466 //*****************************************************************************
467 #ifdef __cplusplus
468 }
469 #endif
470 
471 #endif //  __RFC_H__
472 
473 //*****************************************************************************
474 //
475 //! Close the Doxygen group.
476 //! @}
477 //
478 //*****************************************************************************
479