CC13xx 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  int divider;
119  // Check which setup command is used
120  switch (pOpSetup->commandNo)
121  {
122  case CMD_RADIO_SETUP:
123  divider = ((rfc_CMD_RADIO_SETUP_t *)pOpSetup)->loDivider;
124  break;
126  divider = ((rfc_CMD_PROP_RADIO_DIV_SETUP_t *)pOpSetup)->loDivider;
127  break;
128  default:
129  divider = 0; // Use 2.4 GHz
130  break;
131  }
132 
133  // Read trim from FCFG1
134  pRfTrim->configIfAdc = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_IF_ADC);
135  switch (divider)
136  {
137  case 5:
142  break;
143 
144  case 6:
149  break;
150 
151  case 10:
156  break;
157 
158  case 12:
163  break;
164 
165  case 15:
170  break;
171 
172  case 30:
177  break;
178 
179  default:
181  pRfTrim->configSynth = HWREG(FCFG1_BASE + FCFG1_O_CONFIG_SYNTH);
182  // Make sure configMiscAdc is not 0 by setting an unused bit to 1
185  break;
186  }
187 }
188 
189 
190 
191 //*****************************************************************************
192 //
193 // Write preloaded RF trim values to CM0
194 //
195 //*****************************************************************************
196 void RFCRfTrimSet(rfTrim_t* pRfTrim)
197 {
198  memcpy((void*)&HWREG(0x21000018), (void*)pRfTrim, sizeof(rfTrim_t));
199 }
200 
201 
202 //*****************************************************************************
203 //
204 // Handle support for DriverLib in ROM:
205 // This section will undo prototype renaming made in the header file
206 //
207 //*****************************************************************************
208 #if !defined(DOXYGEN)
209  #undef RFCCpeIntGetAndClear
210  #define RFCCpeIntGetAndClear NOROM_RFCCpeIntGetAndClear
211  #undef RFCDoorbellSendTo
212  #define RFCDoorbellSendTo NOROM_RFCDoorbellSendTo
213  #undef RFCSynthPowerDown
214  #define RFCSynthPowerDown NOROM_RFCSynthPowerDown
215  #undef RFCRfTrimRead
216  #define RFCRfTrimRead NOROM_RFCRfTrimRead
217  #undef RFCRfTrimSet
218  #define RFCRfTrimSet NOROM_RFCRfTrimSet
219 #endif
220 
221 // See rfc.h for implementation
#define RFC_RESERVED0
Definition: rfc.c:41
uint32_t configSynth
Definition: rfc.h:73
struct __RFC_STRUCT rfc_CMD_PROP_RADIO_DIV_SETUP_s rfc_CMD_PROP_RADIO_DIV_SETUP_t
Definition: rf_prop_cmd.h:67
struct __RFC_STRUCT rfc_CMD_RADIO_SETUP_s rfc_CMD_RADIO_SETUP_t
Definition: rf_common_cmd.h:62
#define CMD_PROP_RADIO_DIV_SETUP
Definition: rf_prop_cmd.h:524
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:196
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
#define CMD_RADIO_SETUP
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