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