]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/TARGET_KPSDK_CODE/hal/pmc/fsl_pmc_hal.h
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / hal / TARGET_Freescale / TARGET_KPSDK_MCUS / TARGET_KPSDK_CODE / hal / pmc / fsl_pmc_hal.h
1 /*
2  * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  *   of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  *   list of conditions and the following disclaimer in the documentation and/or
13  *   other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  *   contributors may be used to endorse or promote products derived from this
17  *   software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 #if !defined(__FSL_PMC_HAL_H__)
31 #define __FSL_PMC_HAL_H__
32
33 #include <stdint.h>
34 #include <stdbool.h>
35 #include <assert.h>
36 #include "fsl_device_registers.h"
37 #include "fsl_pmc_features.h"
38
39 /*! @addtogroup pmc_hal*/
40 /*! @{*/
41
42 /*! @file fsl_pmc_hal.h */
43
44 /*******************************************************************************
45  * Definitions
46  ******************************************************************************/
47
48 /*! @brief Low-Voltage Warning Voltage Select*/
49 typedef enum _pmc_low_volt_warn_volt_select {
50     kPmcLowVoltWarnVoltLowTrip,             /*!< Low trip point selected (VLVW = VLVW1)*/
51     kPmcLowVoltWarnVoltMid1Trip,            /*!< Mid 1 trip point selected (VLVW = VLVW2)*/
52     kPmcLowVoltWarnVoltMid2Trip,            /*!< Mid 2 trip point selected (VLVW = VLVW3)*/
53     kPmcLowVoltWarnVoltHighTrip             /*!< High trip point selected (VLVW = VLVW4)*/
54 } pmc_low_volt_warn_volt_select_t;
55
56 /*! @brief Low-Voltage Detect Voltage Select*/
57 typedef enum _pmc_low_volt_detect_volt_select {
58     kPmcLowVoltDetectVoltLowTrip,           /*!< Low trip point selected (V LVD = V LVDL )*/
59     kPmcLowVoltDetectVoltHighTrip,          /*!< High trip point selected (V LVD = V LVDH )*/
60 } pmc_low_volt_detect_volt_select_t;
61
62 /*! @brief interrupt control*/
63 typedef enum _pmc_int_select {
64     kPmcIntLowVoltDetect,                   /*!< Low Voltage Detect Interrupt */
65     kPmcIntLowVoltWarn,                     /*!< Low Voltage Warning Interrupt */
66 } pmc_int_select_t;
67
68 /*******************************************************************************
69  * API
70  ******************************************************************************/
71
72 #if defined(__cplusplus)
73 extern "C" {
74 #endif /* __cplusplus*/
75
76 /*! @name Power Management Controller Control APIs*/
77 /*@{*/
78
79
80 /*!
81  * @brief Enables/Disables low voltage-related interrupts.
82  *
83  * This function  enables  the interrupt for the low voltage detection, warning, 
84  * etc. When enabled, if the LVDF (Low Voltage Detect Flag) is set, a hardware 
85  * interrupt occurs.
86  *
87  * @param baseAddr  Base address for current PMC instance.
88  * @param intSelect interrut select
89  * @param enable    enable/disable the interrupt
90  */
91 void PMC_HAL_SetLowVoltIntCmd(uint32_t baseAddr, pmc_int_select_t intSelect, bool enable);
92
93 /*!
94  * @brief Low-Voltage Detect Hardware Reset Enable/Disable (write once)
95  *
96  * This function enables/disables the  hardware reset for the low voltage 
97  * detection. When enabled, if the LVDF (Low Voltage Detect Flag) is set, a 
98  * hardware reset occurs. This setting is a write-once-only. Any additional writes 
99  * are ignored.
100  *
101  * @param baseAddr  Base address for current PMC instance.
102  * @param enable    enable/disable the LVD hardware reset
103  */
104 static inline void PMC_HAL_SetLowVoltDetectResetCmd(uint32_t baseAddr, bool enable)
105 {
106     BW_PMC_LVDSC1_LVDRE(baseAddr, (uint8_t)enable);
107 }
108
109 /*!
110  * @brief Low-Voltage Detect Acknowledge
111  *
112  * This function acknowledges the low voltage detection errors (write 1 to
113  * clear LVDF).
114  *
115  * @param baseAddr  Base address for current PMC instance.
116  */
117 static inline void PMC_HAL_SetLowVoltDetectAck(uint32_t baseAddr)
118 {
119     BW_PMC_LVDSC1_LVDACK(baseAddr, 1);
120 }
121
122 /*!
123  * @brief Low-Voltage Detect Flag Read
124  *
125  * This function  reads the current LVDF status. If it returns 1, a low
126  * voltage event is detected.
127  *
128  * @param baseAddr  Base address for current PMC instance.
129  * @return status Current low voltage detect flag
130  *                - true: Low-Voltage detected
131  *                - false: Low-Voltage not detected
132  */
133 static inline bool PMC_HAL_GetLowVoltDetectFlag(uint32_t baseAddr)
134 {
135     return BR_PMC_LVDSC1_LVDF(baseAddr);
136 }
137
138 /*!
139  * @brief Sets the Low-Voltage Detect Voltage Mode
140  *
141  * This function  sets the low voltage detect voltage select. It  sets
142  * the low voltage detect trip point voltage (Vlvd). An application can select
143  * either a low-trip or a high-trip point. See a chip reference manual for details.
144  *
145  * @param baseAddr  Base address for current PMC instance.
146  * @param select Voltage select setting defined in pmc_lvdv_select_t
147  */
148 static inline void PMC_HAL_SetLowVoltDetectVoltMode(uint32_t baseAddr, pmc_low_volt_detect_volt_select_t select)
149 {
150     BW_PMC_LVDSC1_LVDV(baseAddr, select);
151 }
152
153 /*!
154  * @brief Gets the Low-Voltage Detect Voltage Mode
155  *
156  * This function  gets the low voltage detect voltage select. It  gets 
157  * the low voltage detect trip point voltage (Vlvd). An application can select
158  * either a low-trip or a high-trip point. See a chip reference manual for details.
159  *
160  * @param baseAddr  Base address for current PMC instance.
161  * @return select Current voltage select setting
162  */
163 static inline pmc_low_volt_detect_volt_select_t PMC_HAL_GetLowVoltDetectVoltMode(uint32_t baseAddr)
164 {
165     return (pmc_low_volt_detect_volt_select_t)BR_PMC_LVDSC1_LVDV(baseAddr);
166 }
167
168 /*!
169  * @brief Low-Voltage Warning Acknowledge
170  * 
171  * This function acknowledges the low voltage warning errors (write 1 to
172  * clear LVWF).
173  *
174  * @param baseAddr  Base address for current PMC instance.
175  */
176 static inline void PMC_HAL_SetLowVoltWarnAck(uint32_t baseAddr)
177 {
178     BW_PMC_LVDSC2_LVWACK(baseAddr, 1);
179 }
180
181 /*!
182  * @brief Low-Voltage Warning Flag Read
183  *
184  * This function polls the current LVWF status. When 1 is returned, it 
185  * indicates a low-voltage warning event. LVWF is set when V Supply transitions
186  * below the trip point or after reset and V Supply is already below the V LVW.
187  *
188  * @param baseAddr  Base address for current PMC instance.
189  * @return status Current LVWF status
190  *                  - true: Low-Voltage Warning Flag is set.
191  *                  - false: the  Low-Voltage Warning does not happen.
192  */
193 static inline bool PMC_HAL_GetLowVoltWarnFlag(uint32_t baseAddr)
194 {
195     return BR_PMC_LVDSC2_LVWF(baseAddr);
196 }
197
198 /*!
199  * @brief Sets the Low-Voltage Warning Voltage Mode.
200  *
201  * This function  sets the low voltage warning voltage select. It  sets
202  * the low voltage warning trip point voltage (Vlvw). An application can select
203  * either a low, mid1, mid2 and a high-trip point. See a chip reference manual for 
204  * details and the  pmc_lvwv_select_t for supported settings.
205  * 
206  * @param baseAddr  Base address for current PMC instance.
207  * @param select Low voltage warning select setting
208  */
209 static inline void PMC_HAL_SetLowVoltWarnVoltMode(uint32_t baseAddr, pmc_low_volt_warn_volt_select_t select)
210 {
211     BW_PMC_LVDSC2_LVWV(baseAddr, select);
212 }
213
214 /*!
215  * @brief Gets the Low-Voltage Warning Voltage Mode.
216  *
217  * This function  gets the low voltage warning voltage select. It  gets
218  * the low voltage warning trip point voltage (Vlvw). See the pmc_lvwv_select_t
219  * for  supported settings.
220  *
221  * @param baseAddr  Base address for current PMC instance.
222  * @return select Current low voltage warning select setting
223  */
224 static inline pmc_low_volt_warn_volt_select_t PMC_HAL_GetLowVoltWarnVoltMode(uint32_t baseAddr)
225 {
226     return (pmc_low_volt_warn_volt_select_t)BR_PMC_LVDSC2_LVWV(baseAddr);
227 }
228
229 #if FSL_FEATURE_PMC_HAS_BGEN
230 /*!
231  * @brief Enables the Bandgap in the VLPx Operation.
232  *
233  * This function enables/disables the bandgap in lower power modes
234  * (VLPx, * LLS, and VLLSx). When on-chip peripherals require the bandgap voltage 
235  * reference in low power modes, set the BGEN to continue to enable
236  * the bandgap operation.
237  *
238  * @param baseAddr  Base address for current PMC instance.
239  * @param enable    enable/disable the Bangap.
240  */
241 static inline void PMC_HAL_SetBandgapInLowPowerModeCmd(uint32_t baseAddr, bool enable)
242 {
243     BW_PMC_REGSC_BGEN(baseAddr, enable);
244 }
245 #endif
246
247 /*!
248  * @brief Enables/Disables the Bandgap Buffer.
249  *
250  * This function  enables/disables the Bandgap buffer.
251  *
252  * @param baseAddr  Base address for current PMC instance.
253  * @param enable    enable/disable the Bangap Buffer.
254  */
255 static inline void PMC_HAL_SetBandgapBufferCmd(uint32_t baseAddr, bool enable)
256 {
257     BW_PMC_REGSC_BGBE(baseAddr, enable);
258 }
259
260 /*!
261  * @brief Gets the acknowledge isolation value.
262  *
263  * This function  reads the Acknowledge Isolation setting that indicates 
264  * whether certain peripherals and the I/O pads are in a latched state as 
265  * a result of having been in the VLLS mode. 
266  *
267  * @param baseAddr  Base address for current PMC instance.
268  * @return value ACK isolation
269  *               0 - Peripherals and I/O pads are in a normal run state.
270  *               1 - Certain peripherals and I/O pads are in an isolated and
271  *                   latched state.
272  */
273 static inline uint8_t PMC_HAL_GetAckIsolation(uint32_t baseAddr)
274 {
275     return BR_PMC_REGSC_ACKISO(baseAddr);
276 }
277
278 /*!
279  * @brief Clears an acknowledge isolation.
280  *
281  * This function  clears the ACK Isolation flag. Writing one to this setting
282  * when it is set releases the I/O pads and certain peripherals to their normal
283  * run mode state.
284  *
285  * @param baseAddr  Base address for current PMC instance.
286  */
287 static inline void PMC_HAL_SetClearAckIsolation(uint32_t baseAddr)
288 {
289     BW_PMC_REGSC_ACKISO(baseAddr, 1);
290 }
291
292 /*!
293  * @brief Gets the Regulator regulation status.
294  *
295  * This function  returns the regulator to a run regulation status. It provides
296  * the current status of the internal voltage regulator.
297  *
298  * @param baseAddr  Base address for current PMC instance.
299  * @return value Regulation status
300  *               0 - Regulator is in a stop regulation or in transition to/from it.
301  *               1 - Regulator is in a run regulation.
302  *
303  */
304 static inline uint8_t PMC_HAL_GetRegulatorStatus(uint32_t baseAddr)
305 {
306     return BR_PMC_REGSC_REGONS(baseAddr);
307 }
308
309 /*@}*/
310
311 #if defined(__cplusplus)
312 }
313 #endif /* __cplusplus*/
314
315 /*! @}*/
316
317 #endif /* __FSL_PMC_HAL_H__*/
318 /*******************************************************************************
319  * EOF
320  ******************************************************************************/
321