1 /******************************************************************************
2 * Filename: aon_wuc.c
3 * Revised: 2015-04-28 11:13:22 +0200 (Tue, 28 Apr 2015)
4 * Revision: 43340
5 *
6 * Description: Driver for the AON Wake-Up Controller.
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/aon_wuc.h>
40
41 //*****************************************************************************
42 //
43 // Handle support for DriverLib in ROM:
44 // This section will undo prototype renaming made in the header file
45 //
46 //*****************************************************************************
47 #if !defined(DOXYGEN)
48 #undef AONWUCAuxReset
49 #define AONWUCAuxReset NOROM_AONWUCAuxReset
50 #undef AONWUCRechargeCtrlConfigSet
51 #define AONWUCRechargeCtrlConfigSet NOROM_AONWUCRechargeCtrlConfigSet
52 #undef AONWUCOscConfig
53 #define AONWUCOscConfig NOROM_AONWUCOscConfig
54 #endif
55
56
57 //*****************************************************************************
58 //
59 //! Reset the AUX domain
60 //
61 //*****************************************************************************
62 void
AONWUCAuxReset(void)63 AONWUCAuxReset(void)
64 {
65 // Reset the AUX domain.
66 // HWREG(AON_WUC_BASE + AON_WUC_O_AUXCTL) |= AON_WUC_AUXCTL_RESET_REQ; // ROM version
67 HWREGBITW(AON_WUC_BASE + AON_WUC_O_AUXCTL, AON_WUC_AUXCTL_RESET_REQ_BITN) = 1;
68
69 // Wait for AON interface to be in sync.
70 HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
71
72 // De-assert reset on the AUX domain.
73 // HWREG(AON_WUC_BASE + AON_WUC_O_AUXCTL) &= ~AON_WUC_AUXCTL_RESET_REQ; // ROM version
74 HWREGBITW(AON_WUC_BASE + AON_WUC_O_AUXCTL, AON_WUC_AUXCTL_RESET_REQ_BITN) = 0;
75
76 // Wait for AON interface to be in sync.
77 HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
78 }
79
80 //*****************************************************************************
81 //
82 //! Configure the recharge controller
83 //
84 //*****************************************************************************
85 void
AONWUCRechargeCtrlConfigSet(bool bAdaptEnable,uint32_t ui32AdaptRate,uint32_t ui32Period,uint32_t ui32MaxPeriod)86 AONWUCRechargeCtrlConfigSet(bool bAdaptEnable, uint32_t ui32AdaptRate,
87 uint32_t ui32Period, uint32_t ui32MaxPeriod)
88 {
89 uint32_t ui32Shift;
90 uint32_t ui32C1;
91 uint32_t ui32C2;
92 uint32_t ui32Reg;
93 uint32_t ui32Exponent;
94 uint32_t ui32MaxExponent;
95 uint32_t ui32Mantissa;
96 uint32_t ui32MaxMantissa;
97
98 //
99 // Check the arguments.
100 //
101 ASSERT((ui32AdaptRate >= RC_RATE_MIN) ||
102 (ui32AdaptRate <= RC_RATE_MAX));
103
104 ui32C1 = 0;
105 ui32C2 = 0;
106 ui32Shift = 9;
107
108 //
109 // Clear the previous values.
110 //
111 ui32Reg = HWREG(AON_WUC_BASE + AON_WUC_O_RECHARGECFG);
112 ui32Reg &= ~(AON_WUC_RECHARGECFG_MAX_PER_M_M | AON_WUC_RECHARGECFG_MAX_PER_E_M |
113 AON_WUC_RECHARGECFG_ADAPTIVE_EN_M | AON_WUC_RECHARGECFG_PER_M_M |
114 AON_WUC_RECHARGECFG_PER_E_M | AON_WUC_RECHARGECFG_C1_M |
115 AON_WUC_RECHARGECFG_C2_M);
116
117 //
118 // Check if the recharge controller adaptation algorithm should be active.
119 //
120 if(bAdaptEnable)
121 {
122 //
123 // Calculate adaptation parameters.
124 //
125 while(ui32AdaptRate)
126 {
127 if(ui32AdaptRate & (1 << ui32Shift))
128 {
129 if(!ui32C1)
130 {
131 ui32C1 = ui32Shift;
132 }
133 else if(!ui32C2)
134 {
135 if((2 * ui32AdaptRate) > ((uint32_t)(3 << ui32Shift)))
136 {
137 ui32C2 = ui32Shift + 1;
138 }
139 else
140 {
141 ui32C2 = ui32Shift;
142 }
143 }
144 else
145 {
146 break;
147 }
148 ui32AdaptRate &= ~(1 << ui32Shift);
149 }
150 ui32Shift--;
151 }
152 if(!ui32C2)
153 {
154 ui32C2 = ui32C1 = ui32C1 - 1;
155 }
156
157 ui32C1 = 10 - ui32C1;
158 ui32C2 = 10 - ui32C2;
159
160 //
161 // Update the recharge rate parameters.
162 //
163 ui32Reg &= ~(AON_WUC_RECHARGECFG_C1_M | AON_WUC_RECHARGECFG_C2_M);
164 ui32Reg |= (ui32C1 << AON_WUC_RECHARGECFG_C1_S) |
165 (ui32C2 << AON_WUC_RECHARGECFG_C2_S) |
166 AON_WUC_RECHARGECFG_ADAPTIVE_EN_M;
167 }
168
169 //
170 // Resolve the period into an exponent and mantissa.
171 //
172 ui32Period = (ui32Period >> 4);
173 ui32Exponent = 0;
174 while(ui32Period > (AON_WUC_RECHARGECFG_PER_M_M >> AON_WUC_RECHARGECFG_PER_M_S))
175 {
176 ui32Period >>= 1;
177 ui32Exponent++;
178 }
179 ui32Mantissa = ui32Period;
180
181 //
182 // Resolve the max period into an exponent and mantissa.
183 //
184 ui32MaxPeriod = (ui32MaxPeriod >> 4);
185 ui32MaxExponent = 0;
186 while(ui32MaxPeriod > (AON_WUC_RECHARGECFG_MAX_PER_M_M >> AON_WUC_RECHARGECFG_MAX_PER_M_S))
187 {
188 ui32MaxPeriod >>= 1;
189 ui32MaxExponent++;
190 }
191 ui32MaxMantissa = ui32MaxPeriod;
192
193 //
194 // Configure the controller.
195 //
196 ui32Reg |= ((ui32MaxMantissa << AON_WUC_RECHARGECFG_MAX_PER_M_S) |
197 (ui32MaxExponent << AON_WUC_RECHARGECFG_MAX_PER_E_S) |
198 (ui32Mantissa << AON_WUC_RECHARGECFG_PER_M_S) |
199 (ui32Exponent << AON_WUC_RECHARGECFG_PER_E_S));
200 HWREG(AON_WUC_BASE + AON_WUC_O_RECHARGECFG) = ui32Reg;
201
202 }
203
204 //*****************************************************************************
205 //
206 //! Configure the interval for oscillator amplitude calibration
207 //
208 //*****************************************************************************
209 void
AONWUCOscConfig(uint32_t ui32Period)210 AONWUCOscConfig(uint32_t ui32Period)
211 {
212 uint32_t ui32Mantissa;
213 uint32_t ui32Exponent;
214 uint32_t ui32Reg;
215
216 //
217 // Resolve the period into a exponent and mantissa.
218 //
219 ui32Period = (ui32Period >> 4);
220 ui32Exponent = 0;
221 while(ui32Period > (AON_WUC_OSCCFG_PER_M_M >> AON_WUC_OSCCFG_PER_M_S))
222 {
223 ui32Period >>= 1;
224 ui32Exponent++;
225 }
226 ui32Mantissa = ui32Period;
227
228 //
229 // Update the period for the oscillator amplitude calibration.
230 //
231 HWREG(AON_WUC_BASE + AON_WUC_O_OSCCFG) =
232 (ui32Mantissa << AON_WUC_OSCCFG_PER_M_S) |
233 (ui32Exponent << AON_WUC_OSCCFG_PER_E_S);
234
235 //
236 // Set the maximum recharge period equal to the oscillator amplitude
237 // calibration period.
238 //
239 ui32Reg = HWREG(AON_WUC_BASE + AON_WUC_O_RECHARGECFG);
240 ui32Reg &= ~(AON_WUC_RECHARGECFG_MAX_PER_M_M | AON_WUC_RECHARGECFG_MAX_PER_E_M);
241 ui32Reg |= ((ui32Mantissa << AON_WUC_RECHARGECFG_MAX_PER_M_S) |
242 (ui32Exponent << AON_WUC_RECHARGECFG_MAX_PER_E_S));
243
244 //
245 // Write the configuration.
246 //
247 HWREG(AON_WUC_BASE + AON_WUC_O_RECHARGECFG) = ui32Reg;
248 }
249