CC26xx Driver Library
rfc.c
Go to the documentation of this file.
1 /******************************************************************************
2 * Filename: rfc.c
3 * Revised: 2016-02-17 14:00:56 +0100 (Wed, 17 Feb 2016)
4 * Revision: 45684
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 //*****************************************************************************
51 //
52 // Get and clear CPE interrupt flags
53 //
54 //*****************************************************************************
55 uint32_t
57 {
58  uint32_t ui32Ifg = HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG);
59 
60  do {
61  HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG) = ~ui32Ifg;
62  } while (HWREG(RFC_DBELL_BASE+RFC_DBELL_O_RFCPEIFG) & ui32Ifg);
63 
64  return (ui32Ifg);
65 }
66 
67 
68 //*****************************************************************************
69 //
70 // Send command to doorbell and wait for ack
71 //
72 //*****************************************************************************
73 uint32_t
74 RFCDoorbellSendTo(uint32_t pOp)
75 {
76  while(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDR) != 0);
77 
79 
80  HWREG(RFC_DBELL_BASE+RFC_DBELL_O_CMDR) = pOp;
81 
82  while(!HWREG(RFC_DBELL_BASE + RFC_DBELL_O_RFACKIFG));
84 
85  return(HWREG(RFC_DBELL_BASE + RFC_DBELL_O_CMDSTA));
86 }
87 
88 
89 //*****************************************************************************
90 //
91 // Turn off synth, NOTE: Radio will no longer respond to commands!
92 //
93 //*****************************************************************************
94 void
96 {
97  // Disable CPE clock, enable FSCA clock. NOTE: Radio will no longer respond to commands!
98  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;
99 
100  (*((volatile unsigned long *)(RFC_RESERVED0))) = 3;
101  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x1030;
102  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
103  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x50;
104  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
105  (*((volatile unsigned long *)(RFC_RESERVED1))) = 0x650;
106  (*((volatile unsigned long *)(RFC_RESERVED2))) = 1;
107  (*((volatile unsigned long *)(RFC_RESERVED3))) = 1;
108 }
109 
110 
111 //*****************************************************************************
112 //
113 // Read RF Trim from flash using the CM3
114 //
115 //*****************************************************************************
116 void RFCRfTrimRead(rfc_radioOp_t *pOpSetup, rfTrim_t* pRfTrim)
117 {
118  // Read trim from FCFG1
119  pRfTrim->configIfAdc = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_IF_ADC);
121  pRfTrim->configSynth = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_SYNTH);
122  // Make sure configMiscAdc is not 0 by setting an unused bit to 1
125 }
126 
127 
128 
129 //*****************************************************************************
130 //
131 // Write preloaded RF trim values to CM0
132 //
133 //*****************************************************************************
134 void RFCRfTrimSet(rfTrim_t* pRfTrim)
135 {
136  memcpy((void*)&HWREG(0x21000018), (void*)pRfTrim, sizeof(rfTrim_t));
137 }
138 
139 
140 //*****************************************************************************
141 //
142 // Handle support for DriverLib in ROM:
143 // This section will undo prototype renaming made in the header file
144 //
145 //*****************************************************************************
146 #if !defined(DOXYGEN)
147  #undef RFCCpeIntGetAndClear
148  #define RFCCpeIntGetAndClear NOROM_RFCCpeIntGetAndClear
149  #undef RFCDoorbellSendTo
150  #define RFCDoorbellSendTo NOROM_RFCDoorbellSendTo
151  #undef RFCSynthPowerDown
152  #define RFCSynthPowerDown NOROM_RFCSynthPowerDown
153  #undef RFCRfTrimRead
154  #define RFCRfTrimRead NOROM_RFCRfTrimRead
155  #undef RFCRfTrimSet
156  #define RFCRfTrimSet NOROM_RFCRfTrimSet
157 #endif
158 
159 // 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:134
static void RFCAckIntClear(void)
Clear interrupt flags.
Definition: rfc.h:313
Definition: rfc.h:70
uint32_t RFCCpeIntGetAndClear(void)
Get and clear CPE interrupt flags.
Definition: rfc.c:56
#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
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:74
void RFCRfTrimRead(rfc_radioOp_t *pOpSetup, rfTrim_t *pRfTrim)
Read RF trim from flash using CM3.
Definition: rfc.c:116
void RFCSynthPowerDown()
Turn off synth, NOTE: Radio will no longer respond to commands!
Definition: rfc.c:95
#define RFC_RESERVED1
Definition: rfc.c:42