1 /******************************************************************************
2 *  Filename:       pwr_ctrl.h
3 *  Revised:        2020-02-14 11:30:20 +0100 (Fri, 14 Feb 2020)
4 *  Revision:       56760
5 *
6 *  Description:    Defines and prototypes for the System Power Control.
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 system_control_group
42 //! @{
43 //! \addtogroup pwrctrl_api
44 //! @{
45 //
46 //*****************************************************************************
47 
48 #ifndef __PWR_CTRL_H__
49 #define __PWR_CTRL_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_ints.h"
67 #include "../inc/hw_aon_pmctl.h"
68 #include "../inc/hw_aon_rtc.h"
69 #include "../inc/hw_adi_2_refsys.h"
70 #include "debug.h"
71 #include "interrupt.h"
72 #include "osc.h"
73 #include "cpu.h"
74 #include "prcm.h"
75 #include "aon_ioc.h"
76 #include "adi.h"
77 
78 //*****************************************************************************
79 //
80 // Support for DriverLib in ROM:
81 // This section renames all functions that are not "static inline", so that
82 // calling these functions will default to implementation in flash. At the end
83 // of this file a second renaming will change the defaults to implementation in
84 // ROM for available functions.
85 //
86 // To force use of the implementation in flash, e.g. for debugging:
87 // - Globally: Define DRIVERLIB_NOROM at project level
88 // - Per function: Use prefix "NOROM_" when calling the function
89 //
90 //*****************************************************************************
91 #if !defined(DOXYGEN)
92     #define PowerCtrlSourceSet              NOROM_PowerCtrlSourceSet
93 #endif
94 
95 //*****************************************************************************
96 //
97 // Defines for the system power states
98 //
99 //*****************************************************************************
100 #define PWRCTRL_ACTIVE          0x00000001
101 #define PWRCTRL_STANDBY         0x00000002
102 #define PWRCTRL_POWER_DOWN      0x00000004
103 #define PWRCTRL_SHUTDOWN        0x00000008
104 
105 //*****************************************************************************
106 //
107 // Defines for the power configuration in the AON System Control 1.2 V
108 //
109 //*****************************************************************************
110 #define PWRCTRL_IOSEG3_ENABLE   0x00000800
111 #define PWRCTRL_IOSEG2_ENABLE   0x00000400
112 #define PWRCTRL_IOSEG3_DISABLE  0x00000200
113 #define PWRCTRL_IOSEG2_DISABLE  0x00000100
114 #define PWRCTRL_PWRSRC_DCDC     0x00000001
115 #define PWRCTRL_PWRSRC_GLDO     0x00000000
116 #define PWRCTRL_PWRSRC_ULDO     0x00000002
117 
118 //*****************************************************************************
119 //
120 // The following are defines for the various reset source for the device.
121 //
122 //*****************************************************************************
123 #define PWRCTRL_RST_POWER_ON    0x00000000  // Reset by power on
124 #define PWRCTRL_RST_PIN         0x00000001  // Pin reset
125 #define PWRCTRL_RST_VDDS_BOD    0x00000002  // VDDS Brown Out Detect
126 #define PWRCTRL_RST_VDD_BOD     0x00000003  // VDD Brown Out Detect
127 #define PWRCTRL_RST_VDDR_BOD    0x00000004  // VDDR Brown Out Detect
128 #define PWRCTRL_RST_CLK_LOSS    0x00000005  // Clock loss Reset
129 #define PWRCTRL_RST_SW_PIN      0x00000006  // SYSRESET or pin reset
130 #define PWRCTRL_RST_WARM        0x00000007  // Reset via PRCM warm reset request
131 
132 //*****************************************************************************
133 //
134 // API Functions and prototypes
135 //
136 //*****************************************************************************
137 
138 //*****************************************************************************
139 //
140 //! \brief Set (Request) the main power source.
141 //!
142 //! \note The system will never allow a switch to the \ref PWRCTRL_PWRSRC_ULDO
143 //! when in active mode. This is only allowed when the system is in lower power
144 //! mode where no code is executing and no peripherals are active.
145 //! Assuming that there is an external capacitor available for the
146 //! \ref PWRCTRL_PWRSRC_DCDC the system can dynamically switch back and forth
147 //! between the two when in active mode.
148 //!
149 //! \note The system will automatically switch to the GLDO / DCDC when waking
150 //! up from a low power mode.
151 //!
152 //! \param ui32PowerConfig is a bitmask indicating the target power source.
153 //! - \ref PWRCTRL_PWRSRC_DCDC
154 //! - \ref PWRCTRL_PWRSRC_GLDO
155 //! - \ref PWRCTRL_PWRSRC_ULDO
156 //!
157 //! \return None
158 //
159 //*****************************************************************************
160 extern void PowerCtrlSourceSet(uint32_t ui32PowerConfig);
161 
162 //*****************************************************************************
163 //
164 //! \brief Get the main power source.
165 //!
166 //! Use this function to retrieve the current active power source.
167 //!
168 //! When the System CPU is active it can never be powered by uLDO as this
169 //! is too weak a power source.
170 //!
171 //! \note Using the DCDC power supply requires an external inductor.
172 //!
173 //! \return Returns the main power source.
174 //! - \ref PWRCTRL_PWRSRC_DCDC
175 //! - \ref PWRCTRL_PWRSRC_GLDO
176 //
177 //*****************************************************************************
178 __STATIC_INLINE uint32_t
PowerCtrlSourceGet(void)179 PowerCtrlSourceGet(void)
180 {
181     uint32_t ui32PowerConfig;
182 
183     // Return the current power source
184     ui32PowerConfig = HWREG(AON_PMCTL_BASE + AON_PMCTL_O_PWRCTL);
185     if(ui32PowerConfig & AON_PMCTL_PWRCTL_DCDC_ACTIVE)
186     {
187         return (PWRCTRL_PWRSRC_DCDC);
188     }
189     else
190     {
191         return (PWRCTRL_PWRSRC_GLDO);
192     }
193 }
194 
195 //*****************************************************************************
196 //
197 //! \brief OBSOLETE: Get the last known reset source of the system.
198 //!
199 //! \deprecated This function will be removed in a future release.
200 //! Use \ref SysCtrlResetSourceGet() instead.
201 //!
202 //! This function returns reset source but does not cover if waking up from shutdown.
203 //! This function can be seen as a subset of function \ref SysCtrlResetSourceGet()
204 //! and will be removed in a future release.
205 //!
206 //! \return Returns one of the known reset values.
207 //! The possible reset sources are:
208 //! - \ref PWRCTRL_RST_POWER_ON
209 //! - \ref PWRCTRL_RST_PIN
210 //! - \ref PWRCTRL_RST_VDDS_BOD
211 //! - \ref PWRCTRL_RST_VDD_BOD
212 //! - \ref PWRCTRL_RST_VDDR_BOD
213 //! - \ref PWRCTRL_RST_CLK_LOSS
214 //! - \ref PWRCTRL_RST_SW_PIN
215 //! - \ref PWRCTRL_RST_WARM
216 //!
217 //! \sa \ref SysCtrlResetSourceGet()
218 //
219 //*****************************************************************************
220 __STATIC_INLINE uint32_t
PowerCtrlResetSourceGet(void)221 PowerCtrlResetSourceGet(void)
222 {
223     //  Get the reset source.
224     return (( HWREG( AON_PMCTL_BASE + AON_PMCTL_O_RESETCTL ) &
225         AON_PMCTL_RESETCTL_RESET_SRC_M ) >>
226         AON_PMCTL_RESETCTL_RESET_SRC_S ) ;
227 }
228 
229 //*****************************************************************************
230 //
231 //! \brief Enables pad sleep in order to latch device outputs before shutdown.
232 //!
233 //! See \ref SysCtrlShutdown() for more information about how to enter
234 //! shutdown and how to wake up from shutdown.
235 //!
236 //! \return None
237 //!
238 //! \sa \ref PowerCtrlPadSleepDisable()
239 //
240 //*****************************************************************************
241 __STATIC_INLINE void
PowerCtrlPadSleepEnable(void)242 PowerCtrlPadSleepEnable(void)
243 {
244     HWREG(AON_PMCTL_BASE + AON_PMCTL_O_SLEEPCTL) = 0;
245     HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
246 }
247 
248 //*****************************************************************************
249 //
250 //! \brief Disables pad sleep in order to unlatch device outputs after wakeup from shutdown.
251 //!
252 //! This function must be called by the application after the device wakes up
253 //! from shutdown.
254 //!
255 //! See \ref SysCtrlShutdown() for more information about how to enter
256 //! shutdown and how to wake up from shutdown.
257 //!
258 //! \return None
259 //!
260 //! \sa \ref PowerCtrlPadSleepEnable()
261 //
262 //*****************************************************************************
263 __STATIC_INLINE void
PowerCtrlPadSleepDisable(void)264 PowerCtrlPadSleepDisable(void)
265 {
266     HWREG(AON_PMCTL_BASE + AON_PMCTL_O_SLEEPCTL) = 1;
267     HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
268 }
269 
270 //*****************************************************************************
271 //
272 // Support for DriverLib in ROM:
273 // Redirect to implementation in ROM when available.
274 //
275 //*****************************************************************************
276 #if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
277     #include "../driverlib/rom.h"
278     #ifdef ROM_PowerCtrlSourceSet
279         #undef  PowerCtrlSourceSet
280         #define PowerCtrlSourceSet              ROM_PowerCtrlSourceSet
281     #endif
282 #endif
283 
284 //*****************************************************************************
285 //
286 // Mark the end of the C bindings section for C++ compilers.
287 //
288 //*****************************************************************************
289 #ifdef __cplusplus
290 }
291 #endif
292 
293 #endif // __PWR_CTRL_H__
294 
295 //*****************************************************************************
296 //
297 //! Close the Doxygen group.
298 //! @}
299 //! @}
300 //
301 //*****************************************************************************
302