-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpwr_ctrl.h
296 lines (277 loc) · 10.5 KB
/
pwr_ctrl.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/******************************************************************************
* Filename: pwr_ctrl.h
* Revised: 2017-11-02 15:41:14 +0100 (Thu, 02 Nov 2017)
* Revision: 50165
*
* Description: Defines and prototypes for the System Power Control.
*
* Copyright (c) 2015 - 2017, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1) Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2) Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3) Neither the name of the ORGANIZATION nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
//*****************************************************************************
//
//! \addtogroup system_control_group
//! @{
//! \addtogroup pwrctrl_api
//! @{
//
//*****************************************************************************
#ifndef __PWR_CTRL_H__
#define __PWR_CTRL_H__
//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdbool.h>
#include <stdint.h>
#include "../inc/hw_types.h"
#include "../inc/hw_memmap.h"
#include "../inc/hw_ints.h"
#include "../inc/hw_aon_wuc.h"
#include "../inc/hw_aon_sysctl.h"
#include "../inc/hw_aon_rtc.h"
#include "../inc/hw_adi_2_refsys.h"
#include "debug.h"
#include "interrupt.h"
#include "osc.h"
#include "cpu.h"
#include "prcm.h"
#include "aon_ioc.h"
#include "adi.h"
//*****************************************************************************
//
// Support for DriverLib in ROM:
// This section renames all functions that are not "static inline", so that
// calling these functions will default to implementation in flash. At the end
// of this file a second renaming will change the defaults to implementation in
// ROM for available functions.
//
// To force use of the implementation in flash, e.g. for debugging:
// - Globally: Define DRIVERLIB_NOROM at project level
// - Per function: Use prefix "NOROM_" when calling the function
//
//*****************************************************************************
#if !defined(DOXYGEN)
#define PowerCtrlSourceSet NOROM_PowerCtrlSourceSet
#endif
//*****************************************************************************
//
// Defines for the system power states
//
//*****************************************************************************
#define PWRCTRL_ACTIVE 0x00000001
#define PWRCTRL_STANDBY 0x00000002
#define PWRCTRL_POWER_DOWN 0x00000004
#define PWRCTRL_SHUTDOWN 0x00000008
//*****************************************************************************
//
// Defines for the power configuration in the AON System Control 1.2 V
//
//*****************************************************************************
#define PWRCTRL_IOSEG3_ENABLE 0x00000800
#define PWRCTRL_IOSEG2_ENABLE 0x00000400
#define PWRCTRL_IOSEG3_DISABLE 0x00000200
#define PWRCTRL_IOSEG2_DISABLE 0x00000100
#define PWRCTRL_PWRSRC_DCDC 0x00000001
#define PWRCTRL_PWRSRC_GLDO 0x00000000
#define PWRCTRL_PWRSRC_ULDO 0x00000002
//*****************************************************************************
//
// The following are defines for the various reset source for the device.
//
//*****************************************************************************
#define PWRCTRL_RST_POWER_ON 0x00000000 // Reset by power on
#define PWRCTRL_RST_PIN 0x00000001 // Pin reset
#define PWRCTRL_RST_VDDS_BOD 0x00000002 // VDDS Brown Out Detect
#define PWRCTRL_RST_VDD_BOD 0x00000003 // VDD Brown Out Detect
#define PWRCTRL_RST_VDDR_BOD 0x00000004 // VDDR Brown Out Detect
#define PWRCTRL_RST_CLK_LOSS 0x00000005 // Clock loss Reset
#define PWRCTRL_RST_SW_PIN 0x00000006 // SYSRESET or pin reset
#define PWRCTRL_RST_WARM 0x00000007 // Reset via PRCM warm reset request
//*****************************************************************************
//
// API Functions and prototypes
//
//*****************************************************************************
//*****************************************************************************
//
//! \brief Set (Request) the main power source.
//!
//! \note The system will never allow a switch to the \ref PWRCTRL_PWRSRC_ULDO
//! when in active mode. This is only allowed when the system is in lower power
//! mode where no code is executing and no peripherals are active.
//! Assuming that there is an external capacitor available for the
//! \ref PWRCTRL_PWRSRC_DCDC the system can dynamically switch back and forth
//! between the two when in active mode.
//!
//! \note The system will automatically switch to the GLDO / DCDC when waking
//! up from a low power mode.
//!
//! \param ui32PowerConfig is a bitmask indicating the target power source.
//! - \ref PWRCTRL_PWRSRC_DCDC
//! - \ref PWRCTRL_PWRSRC_GLDO
//! - \ref PWRCTRL_PWRSRC_ULDO
//!
//! \return None
//
//*****************************************************************************
extern void PowerCtrlSourceSet(uint32_t ui32PowerConfig);
//*****************************************************************************
//
//! \brief Get the main power source.
//!
//! Use this function to retrieve the current active power source.
//!
//! When the System CPU is active it can never be powered by uLDO as this
//! is too weak a power source.
//!
//! \note Using the DCDC power supply requires an external inductor.
//!
//! \return Returns the main power source.
//! - \ref PWRCTRL_PWRSRC_DCDC
//! - \ref PWRCTRL_PWRSRC_GLDO
//
//*****************************************************************************
__STATIC_INLINE uint32_t
PowerCtrlSourceGet(void)
{
uint32_t ui32PowerConfig;
// Return the current power source
ui32PowerConfig = HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_PWRCTL);
if(ui32PowerConfig & AON_SYSCTL_PWRCTL_DCDC_ACTIVE)
{
return (PWRCTRL_PWRSRC_DCDC);
}
else
{
return (PWRCTRL_PWRSRC_GLDO);
}
}
//*****************************************************************************
//
//! \brief OBSOLETE: Get the last known reset source of the system.
//!
//! \deprecated This function will be removed in a future release.
//! Use \ref SysCtrlResetSourceGet() instead.
//!
//! This function returns reset source but does not cover if waking up from shutdown.
//! This function can be seen as a subset of function \ref SysCtrlResetSourceGet()
//! and will be removed in a future release.
//!
//! \return Returns one of the known reset values.
//! The possible reset sources are:
//! - \ref PWRCTRL_RST_POWER_ON
//! - \ref PWRCTRL_RST_PIN
//! - \ref PWRCTRL_RST_VDDS_BOD
//! - \ref PWRCTRL_RST_VDD_BOD
//! - \ref PWRCTRL_RST_VDDR_BOD
//! - \ref PWRCTRL_RST_CLK_LOSS
//! - \ref PWRCTRL_RST_SW_PIN
//! - \ref PWRCTRL_RST_WARM
//!
//! \sa \ref SysCtrlResetSourceGet()
//
//*****************************************************************************
__STATIC_INLINE uint32_t
PowerCtrlResetSourceGet(void)
{
// Get the reset source.
return (( HWREG( AON_SYSCTL_BASE + AON_SYSCTL_O_RESETCTL ) &
AON_SYSCTL_RESETCTL_RESET_SRC_M ) >>
AON_SYSCTL_RESETCTL_RESET_SRC_S ) ;
}
//*****************************************************************************
//
//! \brief Enables pad sleep in order to latch device outputs before shutdown.
//!
//! \return None
//!
//! \sa \ref PowerCtrlPadSleepDisable()
//
//*****************************************************************************
__STATIC_INLINE void
PowerCtrlPadSleepEnable(void)
{
HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 0;
HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
}
//*****************************************************************************
//
//! \brief Disables pad sleep in order to unlatch device outputs after wakeup from shutdown.
//!
//! This function must be called by the application after the device wakes up
//! from shutdown.
//!
//! \return None
//!
//! \sa \ref PowerCtrlPadSleepEnable()
//
//*****************************************************************************
__STATIC_INLINE void
PowerCtrlPadSleepDisable(void)
{
HWREG(AON_SYSCTL_BASE + AON_SYSCTL_O_SLEEPCTL) = 1;
HWREG(AON_RTC_BASE + AON_RTC_O_SYNC);
}
//*****************************************************************************
//
// Support for DriverLib in ROM:
// Redirect to implementation in ROM when available.
//
//*****************************************************************************
#if !defined(DRIVERLIB_NOROM) && !defined(DOXYGEN)
#include "../driverlib/rom.h"
#ifdef ROM_PowerCtrlSourceSet
#undef PowerCtrlSourceSet
#define PowerCtrlSourceSet ROM_PowerCtrlSourceSet
#endif
#endif
//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif
#endif // __PWR_CTRL_H__
//*****************************************************************************
//
//! Close the Doxygen group.
//! @}
//! @}
//
//*****************************************************************************