1 /******************************************************************************
2 *  Filename:       aon_wuc.h
3 *  Revised:        2015-07-16 12:12:04 +0200 (Thu, 16 Jul 2015)
4 *  Revision:       44151
5 *
6 *  Description:    Defines and prototypes for the AUX Wakeup 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 //****************************************************************************
40 //
41 //! \addtogroup aux_group
42 //! @{
43 //! \addtogroup auxwuc_api
44 //! @{
45 //
46 //****************************************************************************
47 
48 #ifndef __AUX_WUC_H__
49 #define __AUX_WUC_H__
50 
51 //*****************************************************************************
52 //
53 // If building with a C++ compiler, make all of the definitions in this header
54 // have a C binding.
55 //
56 //*****************************************************************************
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61 
62 #include <stdbool.h>
63 #include <stdint.h>
64 #include <inc/hw_types.h>
65 #include <inc/hw_memmap.h>
66 #include <inc/hw_aux_wuc.h>
67 #include <driverlib/debug.h>
68 
69 //*****************************************************************************
70 //
71 // Support for DriverLib in ROM:
72 // This section renames all functions that are not "static inline", so that
73 // calling these functions will default to implementation in flash. At the end
74 // of this file a second renaming will change the defaults to implementation in
75 // ROM for available functions.
76 //
77 // To force use of the implementation in flash, e.g. for debugging:
78 // - Globally: Define DRIVERLIB_NOROM at project level
79 // - Per function: Use prefix "NOROM_" when calling the function
80 //
81 //*****************************************************************************
82 #if !defined(DOXYGEN)
83     #define AUXWUCClockEnable               NOROM_AUXWUCClockEnable
84     #define AUXWUCClockDisable              NOROM_AUXWUCClockDisable
85     #define AUXWUCClockStatus               NOROM_AUXWUCClockStatus
86     #define AUXWUCPowerCtrl                 NOROM_AUXWUCPowerCtrl
87 #endif
88 
89 //*****************************************************************************
90 //
91 // Defines for the AUX power control.
92 //
93 //*****************************************************************************
94 #define AUX_WUC_POWER_OFF       0x00000001
95 #define AUX_WUC_POWER_DOWN      0x00000002
96 #define AUX_WUC_POWER_ACTIVE    0x00000004
97 
98 //*****************************************************************************
99 //
100 // Defines for the AUX peripherals clock control.
101 //
102 //*****************************************************************************
103 #define AUX_WUC_SMPH_CLOCK      (AUX_WUC_MODCLKEN0_SMPH_EN)
104 #define AUX_WUC_AIODIO0_CLOCK   (AUX_WUC_MODCLKEN0_AIODIO0_EN)
105 #define AUX_WUC_AIODIO1_CLOCK   (AUX_WUC_MODCLKEN0_AIODIO1_EN)
106 #define AUX_WUC_TIMER_CLOCK     (AUX_WUC_MODCLKEN0_TIMER_EN)
107 #define AUX_WUC_ANAIF_CLOCK     (AUX_WUC_MODCLKEN0_ANAIF_EN)
108 #define AUX_WUC_TDCIF_CLOCK     (AUX_WUC_MODCLKEN0_TDC_EN)
109 #define AUX_WUC_OSCCTRL_CLOCK   (AUX_WUC_MODCLKEN0_AUX_DDI0_OSC_EN)
110 #define AUX_WUC_ADI_CLOCK       (AUX_WUC_MODCLKEN0_AUX_ADI4_EN)
111 #define AUX_WUC_MODCLK_MASK     0x000000FF
112 
113 #define AUX_WUC_TDC_CLOCK       0x00000100
114 #define AUX_WUC_ADC_CLOCK       0x00000200
115 #define AUX_WUC_REF_CLOCK       0x00000400
116 
117 #define AUX_WUC_CLOCK_OFF       0x00000000
118 #define AUX_WUC_CLOCK_UNSTABLE  0x00000001
119 #define AUX_WUC_CLOCK_READY     0x00000011
120 
121 #define AUX_WUC_CLOCK_HIFREQ    0x00000000
122 #define AUX_WUC_CLOCK_LOFREQ    0x00000001
123 
124 //*****************************************************************************
125 //
126 // API Functions and prototypes
127 //
128 //*****************************************************************************
129 
130 //****************************************************************************
131 //
132 //! \brief Enable clocks for peripherals in the AUX domain.
133 //!
134 //! Use this function to enable specific clocks in the AUX domain.
135 //!
136 //! \param ui32Clocks is a bitmap of clocks to enable.
137 //! Use a bitwise OR combination of the following values:
138 //! - \ref AUX_WUC_ADI_CLOCK
139 //! - \ref AUX_WUC_OSCCTRL_CLOCK
140 //! - \ref AUX_WUC_TDCIF_CLOCK
141 //! - \ref AUX_WUC_ANAIF_CLOCK
142 //! - \ref AUX_WUC_TIMER_CLOCK
143 //! - \ref AUX_WUC_AIODIO0_CLOCK
144 //! - \ref AUX_WUC_AIODIO1_CLOCK
145 //! - \ref AUX_WUC_SMPH_CLOCK
146 //! - \ref AUX_WUC_TDC_CLOCK
147 //! - \ref AUX_WUC_ADC_CLOCK
148 //! - \ref AUX_WUC_REF_CLOCK
149 //!
150 //! \return None
151 //!
152 //! \sa \ref AUXWUCClockDisable()
153 //
154 //****************************************************************************
155 extern void AUXWUCClockEnable(uint32_t ui32Clocks);
156 
157 //****************************************************************************
158 //
159 //! \brief Disable clocks for peripherals in the AUX domain.
160 //!
161 //! Use this function to enable specific clocks in the AUX domain.
162 //!
163 //! \param ui32Clocks a bitmap of clocks to disable.
164 //! Use a bitwise OR combination of the following values:
165 //! - \ref AUX_WUC_ADI_CLOCK
166 //! - \ref AUX_WUC_OSCCTRL_CLOCK
167 //! - \ref AUX_WUC_TDCIF_CLOCK
168 //! - \ref AUX_WUC_ANAIF_CLOCK
169 //! - \ref AUX_WUC_TIMER_CLOCK
170 //! - \ref AUX_WUC_AIODIO0_CLOCK
171 //! - \ref AUX_WUC_AIODIO1_CLOCK
172 //! - \ref AUX_WUC_SMPH_CLOCK
173 //! - \ref AUX_WUC_TDC_CLOCK
174 //! - \ref AUX_WUC_ADC_CLOCK
175 //! - \ref AUX_WUC_REF_CLOCK
176 //!
177 //! \return None
178 //!
179 //! \sa \ref AUXWUCClockEnable()
180 //
181 //****************************************************************************
182 extern void AUXWUCClockDisable(uint32_t ui32Clocks);
183 
184 //****************************************************************************
185 //
186 //! \brief Get the status of a clock.
187 //!
188 //! Use this function to poll the status of a specific clock in the AUX
189 //! domain.
190 //!
191 //! \param ui32Clocks is the clock for which to return status.
192 //! - \ref AUX_WUC_ADI_CLOCK
193 //! - \ref AUX_WUC_OSCCTRL_CLOCK
194 //! - \ref AUX_WUC_TDCIF_CLOCK
195 //! - \ref AUX_WUC_ANAIF_CLOCK
196 //! - \ref AUX_WUC_TIMER_CLOCK
197 //! - \ref AUX_WUC_AIODIO0_CLOCK
198 //! - \ref AUX_WUC_AIODIO1_CLOCK
199 //! - \ref AUX_WUC_SMPH_CLOCK
200 //! - \ref AUX_WUC_TDC_CLOCK
201 //! - \ref AUX_WUC_ADC_CLOCK
202 //! - \ref AUX_WUC_REF_CLOCK
203 //!
204 //! \return Returns the status of the clock as one of two states:
205 //! - \ref AUX_WUC_CLOCK_OFF
206 //! - \ref AUX_WUC_CLOCK_READY
207 //
208 //****************************************************************************
209 extern uint32_t AUXWUCClockStatus(uint32_t ui32Clocks);
210 
211 //****************************************************************************
212 //
213 //! \brief Request a high or low frequency clock source.
214 //!
215 //! Using this function it is possible to make a request to the System
216 //! Control to use a high or low frequency clock as clock source for the AUX
217 //! domain.
218 //!
219 //! \note A low frequency clock is always 32 kHz, while a high frequency clock
220 //! is really a large span of frequencies determined by the clock source (High
221 //! Frequency or Medium Frequency) and the setting for the clock divider for
222 //! the AUX domain in the System Control.
223 //!
224 //! \param ui32ClockFreq determines the clock source frequency.
225 //! - \ref AUX_WUC_CLOCK_LOFREQ : Request low frequency clock source for AUX domain.
226 //! - \ref AUX_WUC_CLOCK_HIFREQ : Request high frequency clock source for AUX domain.
227 //!
228 //! \return
229 //
230 //****************************************************************************
231 __STATIC_INLINE void
AUXWUCClockFreqReq(uint32_t ui32ClockFreq)232 AUXWUCClockFreqReq(uint32_t ui32ClockFreq)
233 {
234     //
235     // Check the arguments.
236     //
237     ASSERT((ui32ClockFreq == AUX_WUC_CLOCK_HIFREQ) ||
238            (ui32ClockFreq == AUX_WUC_CLOCK_LOFREQ));
239 
240     //
241     // Set the request
242     //
243     HWREG(AUX_WUC_BASE + AUX_WUC_O_CLKLFREQ) = ui32ClockFreq;
244 }
245 
246 //****************************************************************************
247 //
248 //! \brief Control the power to the AUX domain.
249 //!
250 //! Use this function to set the power mode of the entire AUX domain.
251 //!
252 //! \param ui32PowerMode control the desired power mode for the AUX domain.
253 //! The domain has three different power modes:
254 //! - \ref AUX_WUC_POWER_OFF
255 //! - \ref AUX_WUC_POWER_DOWN
256 //! - \ref AUX_WUC_POWER_ACTIVE
257 //!
258 //! \return None
259 //
260 //****************************************************************************
261 extern void AUXWUCPowerCtrl(uint32_t ui32PowerMode);
262 
263 //*****************************************************************************
264 //
265 //! \brief Freeze the AUX IOs.
266 //!
267 //! To retain the values of the output IOs during a powerdown of the AUX domain
268 //! all IO latches in the AUX domain should be frozen in their current state.
269 //! This ensures that software can regain control of the IOs after a powerdown
270 //! without the IOs first falling back to the default values (i.e. input and
271 //! pull-up).
272 //!
273 //! \return None
274 //!
275 //! \sa AUXWUCFreezeDisable()
276 //
277 //*****************************************************************************
278 __STATIC_INLINE void
AUXWUCFreezeEnable(void)279 AUXWUCFreezeEnable(void)
280 {
281     //
282     // Set the AUX WUC latches as static.
283     //
284     HWREG(AUX_WUC_BASE + AUX_WUC_O_AUXIOLATCH) = 0x0;
285 }
286 
287 //*****************************************************************************
288 //
289 //! \brief Unfreeze the AUX IOs.
290 //!
291 //! When restarting the AUX domain after it has entered powerdown mode, the
292 //! software can regain control of the IOs by setting the IO latches as
293 //! transparent.
294 //!
295 //! \note The IOs should not be unfrozen before software has restored
296 //! the functionality of the IO.
297 //!
298 //! \return None
299 //!
300 //! \sa AUXWUCFreezeEnable()
301 //
302 //*****************************************************************************
303 __STATIC_INLINE void
AUXWUCFreezeDisable(void)304 AUXWUCFreezeDisable(void)
305 {
306     //
307     // Set the AUX WUC latches as transparent.
308     //
309     HWREG(AUX_WUC_BASE + AUX_WUC_O_AUXIOLATCH) = AUX_WUC_AUXIOLATCH_EN;
310 }
311 
312 //*****************************************************************************
313 //
314 // Support for DriverLib in ROM:
315 // Redirect to implementation in ROM when available.
316 //
317 //*****************************************************************************
318 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
319     #include <driverlib/rom.h>
320     #ifdef ROM_AUXWUCClockEnable
321         #undef  AUXWUCClockEnable
322         #define AUXWUCClockEnable               ROM_AUXWUCClockEnable
323     #endif
324     #ifdef ROM_AUXWUCClockDisable
325         #undef  AUXWUCClockDisable
326         #define AUXWUCClockDisable              ROM_AUXWUCClockDisable
327     #endif
328     #ifdef ROM_AUXWUCClockStatus
329         #undef  AUXWUCClockStatus
330         #define AUXWUCClockStatus               ROM_AUXWUCClockStatus
331     #endif
332     #ifdef ROM_AUXWUCPowerCtrl
333         #undef  AUXWUCPowerCtrl
334         #define AUXWUCPowerCtrl                 ROM_AUXWUCPowerCtrl
335     #endif
336 #endif
337 
338 //*****************************************************************************
339 //
340 // Mark the end of the C bindings section for C++ compilers.
341 //
342 //*****************************************************************************
343 #ifdef __cplusplus
344 }
345 #endif
346 
347 #endif //  __AUX_WUC_H__
348 
349 //****************************************************************************
350 //
351 //! Close the Doxygen group.
352 //! @}
353 //! @}
354 //
355 //****************************************************************************
356