2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
5 * Redistribution and use in source and binary forms, with or without modification,
6 * are permitted provided that the following conditions are met:
8 * o Redistributions of source code must retain the above copyright notice, this list
9 * of conditions and the following disclaimer.
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.
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.
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.
31 #if !defined(__FSL_SMC_HAL_H__)
32 #define __FSL_SMC_HAL_H__
37 #include "fsl_device_registers.h"
38 #include "fsl_smc_features.h"
40 /*! @addtogroup smc_hal*/
43 /*! @file fsl_smc_hal.h */
45 /*******************************************************************************
47 ******************************************************************************/
48 /*! @brief Power Modes */
49 typedef enum _power_modes
{
63 * @brief Error code definition for the system mode controller manager APIs.
65 typedef enum _smc_hal_error_code
{
66 kSmcHalSuccess
, /*!< Success */
67 kSmcHalNoSuchModeName
, /*!< Cannot find the mode name specified*/
68 kSmcHalAlreadyInTheState
, /*!< Already in the required state*/
69 kSmcHalFailed
/*!< Unknown error, operation failed*/
70 } smc_hal_error_code_t
;
72 /*! @brief Power Modes in PMSTAT*/
73 typedef enum _power_mode_stat
{
74 kStatRun
= 0x01, /*!< 0000_0001 - Current power mode is RUN*/
75 kStatStop
= 0x02, /*!< 0000_0010 - Current power mode is STOP*/
76 kStatVlpr
= 0x04, /*!< 0000_0100 - Current power mode is VLPR*/
77 kStatVlpw
= 0x08, /*!< 0000_1000 - Current power mode is VLPW*/
78 kStatVlps
= 0x10, /*!< 0001_0000 - Current power mode is VLPS*/
79 kStatLls
= 0x20, /*!< 0010_0000 - Current power mode is LLS*/
80 kStatVlls
= 0x40, /*!< 0100_0000 - Current power mode is VLLS*/
81 kStatHsrun
= 0x80 /*!< 1000_0000 - Current power mode is HSRUN*/
84 /*! @brief Power Modes Protection*/
85 typedef enum _power_modes_protect
{
86 kAllowHsrun
, /*!< Allow High Speed Run mode*/
87 kAllowVlp
, /*!< Allow Very-Low-Power Modes*/
88 kAllowLls
, /*!< Allow Low-Leakage Stop Mode*/
89 kAllowVlls
, /*!< Allow Very-Low-Leakage Stop Mode*/
91 } power_modes_protect_t
;
94 * @brief Run mode definition
96 typedef enum _smc_run_mode
{
97 kSmcRun
, /*!< normal RUN mode*/
99 kSmcVlpr
, /*!< Very-Low-Power RUN mode*/
100 kSmcHsrun
/*!< High Speed Run mode (HSRUN)*/
104 * @brief Stop mode definition
106 typedef enum _smc_stop_mode
{
107 kSmcStop
, /*!< Normal STOP mode*/
108 kSmcReservedStop1
, /*!< Reserved*/
109 kSmcVlps
, /*!< Very-Low-Power STOP mode*/
110 kSmcLls
, /*!< Low-Leakage Stop mode*/
111 kSmcVlls
/*!< Very-Low-Leakage Stop mode*/
115 * @brief VLLS/LLS stop sub mode definition
117 typedef enum _smc_stop_submode
{
122 } smc_stop_submode_t
;
124 /*! @brief Low Power Wake Up on Interrupt option*/
125 typedef enum _smc_lpwui_option
{
126 kSmcLpwuiEnabled
, /*!< Low Power Wake Up on Interrupt enabled*/
127 kSmcLpwuiDisabled
/*!< Low Power Wake Up on Interrupt disabled*/
128 } smc_lpwui_option_t
;
130 /*! @brief Partial STOP option*/
131 typedef enum _smc_pstop_option
{
132 kSmcPstopStop
, /*!< STOP - Normal Stop mode*/
133 kSmcPstopStop1
, /*!< Partial Stop with both system and bus clocks disabled*/
134 kSmcPstopStop2
, /*!< Partial Stop with system clock disabled and bus clock enabled*/
136 } smc_pstop_option_t
;
138 /*! @brief POR option*/
139 typedef enum _smc_por_option
{
140 kSmcPorEnabled
, /*!< POR detect circuit is enabled in VLLS0*/
141 kSmcPorDisabled
/*!< POR detect circuit is disabled in VLLS0*/
144 /*! @brief LPO power option*/
145 typedef enum _smc_lpo_option
{
146 kSmcLpoEnabled
, /*!< LPO clock is enabled in LLS/VLLSx*/
147 kSmcLpoDisabled
/*!< LPO clock is disabled in LLS/VLLSx*/
150 /*! @brief Power mode control options*/
151 typedef enum _smc_power_options
{
152 kSmcOptionLpwui
, /*!< Low Power Wake Up on Interrupt*/
153 kSmcOptionPropo
/*!< POR option*/
154 } smc_power_options_t
;
156 /*! @brief Power mode protection configuration*/
157 typedef struct _smc_power_mode_protection_config
{
158 bool vlpProt
; /*!< VLP protect*/
159 bool llsProt
; /*!< LLS protect */
160 bool vllsProt
; /*!< VLLS protect*/
161 #if FSL_FEATURE_SMC_HAS_HIGH_SPEED_RUN_MODE
162 bool hsrunProt
; /*!< HSRUN protect */
164 } smc_power_mode_protection_config_t
;
166 /*! @brief Power mode control configuration used for calling the SMC_SYS_SetPowerMode API. */
167 typedef struct _smc_power_mode_config
{
168 power_modes_t powerModeName
; /*!< Power mode(enum), see power_modes_t */
169 smc_stop_submode_t stopSubMode
; /*!< Stop submode(enum), see smc_stop_submode_t */
170 #if FSL_FEATURE_SMC_HAS_LPWUI
171 bool lpwuiOption
; /*!< If LPWUI option is needed */
172 smc_lpwui_option_t lpwuiOptionValue
; /*!< LPWUI option(enum), see smc_lpwui_option_t */
174 #if FSL_FEATURE_SMC_HAS_PORPO
175 bool porOption
; /*!< If POR option is needed */
176 smc_por_option_t porOptionValue
; /*!< POR option(enum), see smc_por_option_t */
178 #if FSL_FEATURE_SMC_HAS_PSTOPO
179 bool pstopOption
; /*!< If PSTOPO option is needed */
180 smc_pstop_option_t pstopOptionValue
; /*!< PSTOPO option(enum), see smc_por_option_t */
182 } smc_power_mode_config_t
;
184 /*******************************************************************************
186 ******************************************************************************/
188 #if defined(__cplusplus)
190 #endif /* __cplusplus*/
192 /*! @name System mode controller APIs*/
196 * @brief Configures the power mode.
198 * This function configures the power mode control for both run, stop, and
199 * stop sub mode if needed. Also it configures the power options for a specific
200 * power mode. An application should follow the proper procedure to configure and
201 * switch power modes between different run and stop modes. For proper procedures
202 * and supported power modes, see an appropriate chip reference
203 * manual. See the smc_power_mode_config_t for required
204 * parameters to configure the power mode and the supported options. Other options
205 * may need to be individually configured through the HAL driver. See the HAL driver
206 * header file for details.
208 * @param baseAddr Base address for current SMC instance.
209 * @param powerModeConfig Power mode configuration structure smc_power_mode_config_t
210 * @return errorCode SMC error code
212 smc_hal_error_code_t
SMC_HAL_SetMode(uint32_t baseAddr
,
213 const smc_power_mode_config_t
*powerModeConfig
);
216 * @brief Configures all power mode protection settings.
218 * This function configures the power mode protection settings for
219 * supported power modes in the specified chip family. The available power modes
220 * are defined in the smc_power_mode_protection_config_t. An application should provide
221 * the protect settings for all supported power modes on the chip. This
222 * should be done at an early system level initialization stage. See the reference manual
223 * for details. This register can only write once after the power reset. If the user has
224 * only a single option to set,
225 * either use this function or use the individual set function.
228 * @param baseAddr Base address for current SMC instance.
229 * @param protectConfig Configurations for the supported power mode protect settings
230 * - See smc_power_mode_protection_config_t for details.
232 void SMC_HAL_SetProtection(uint32_t baseAddr
, smc_power_mode_protection_config_t
*protectConfig
);
235 * @brief Configures the individual power mode protection settings.
237 * This function only configures the power mode protection settings for
238 * a specified power mode on the specified chip family. The available power modes
239 * are defined in the smc_power_mode_protection_config_t. See the reference manual
240 * for details. This register can only write once after the power reset.
242 * @param baseAddr Base address for current SMC instance.
243 * @param protect Power mode to set for protection
244 * @param allow Allow or not allow the power mode protection
246 void SMC_HAL_SetProtectionMode(uint32_t baseAddr
, power_modes_protect_t protect
, bool allow
);
249 * @brief Gets the the current power mode protection setting.
251 * This function gets the current power mode protection settings for
252 * a specified power mode.
254 * @param baseAddr Base address for current SMC instance.
255 * @param protect Power mode to set for protection
256 * @return state Status of the protection setting
258 * - false: Not allowed
260 bool SMC_HAL_GetProtectionMode(uint32_t baseAddr
, power_modes_protect_t protect
);
263 * @brief Configures the the RUN mode control setting.
265 * This function sets the run mode settings, for example, normal run mode,
266 * very lower power run mode, etc. See the smc_run_mode_t for supported run
267 * mode on the chip family and the reference manual for details about the
270 * @param baseAddr Base address for current SMC instance.
271 * @param runMode Run mode setting defined in smc_run_mode_t
273 void SMC_HAL_SetRunMode(uint32_t baseAddr
, smc_run_mode_t runMode
);
276 * @brief Gets the current RUN mode configuration setting.
278 * This function gets the run mode settings. See the smc_run_mode_t
279 * for a supported run mode on the chip family and the reference manual for
280 * details about the run mode.
282 * @param baseAddr Base address for current SMC instance.
283 * @return setting Run mode configuration setting
285 smc_run_mode_t
SMC_HAL_GetRunMode(uint32_t baseAddr
);
288 * @brief Configures the STOP mode control setting.
290 * This function sets the stop mode settings, for example, normal stop mode,
291 * very lower power stop mode, etc. See the smc_stop_mode_t for supported stop
292 * mode on the chip family and the reference manual for details about the
295 * @param baseAddr Base address for current SMC instance.
296 * @param stopMode Stop mode defined in smc_stop_mode_t
298 void SMC_HAL_SetStopMode(uint32_t baseAddr
, smc_stop_mode_t stopMode
);
301 * @brief Gets the current STOP mode control settings.
303 * This function gets the stop mode settings, for example, normal stop mode,
304 * very lower power stop mode, etc. See the smc_stop_mode_t for supported stop
305 * mode on the chip family and the reference manual for details about the
308 * @param baseAddr Base address for current SMC instance.
309 * @return setting Current stop mode configuration setting
311 smc_stop_mode_t
SMC_HAL_GetStopMode(uint32_t baseAddr
);
314 * @brief Configures the stop sub mode control setting.
316 * This function sets the stop submode settings. Some of the stop mode
317 * further supports submodes. See the smc_stop_submode_t for supported
318 * stop submodes and the reference manual for details about the submodes
319 * for a specific stop mode.
321 * @param baseAddr Base address for current SMC instance.
322 * @param stopSubMode Stop submode setting defined in smc_stop_submode_t
324 void SMC_HAL_SetStopSubMode(uint32_t baseAddr
, smc_stop_submode_t stopSubMode
);
327 * @brief Gets the current stop submode configuration settings.
329 * This function gets the stop submode settings. Some of the stop mode
330 * further support submodes. See the smc_stop_submode_t for supported
331 * stop submodes and the reference manual for details about the submode
332 * for a specific stop mode.
334 * @param baseAddr Base address for current SMC instance.
335 * @return setting Current stop submode setting
337 smc_stop_submode_t
SMC_HAL_GetStopSubMode(uint32_t baseAddr
);
339 #if FSL_FEATURE_SMC_HAS_PORPO
341 * @brief Configures the POR (power-on-reset) option.
343 * This function sets the POR power option setting. It controls whether the
344 * POR detect circuit (for brown-out detection) is enabled in a certain stop mode.
345 * The setting either enables or disables the above feature when the POR
346 * occurs. See the reference manual for details.
348 * @param baseAddr Base address for current SMC instance.
349 * @param option POR option setting refer to smc_por_option_t
351 void SMC_HAL_SetPorMode(uint32_t baseAddr
, smc_por_option_t option
);
354 * @brief Gets the configuration settings for the POR option.
356 * This function sets the POR power option setting. See the configuration function
357 * header for details.
359 * @param baseAddr Base address for current SMC instance.
360 * @return option Current POR option setting
362 smc_por_option_t
SMC_HAL_GetPorMode(uint32_t baseAddr
);
365 #if FSL_FEATURE_SMC_HAS_PSTOPO
367 * @brief Configures the PSTOPO (Partial Stop Option).
369 * This function sets the PSTOPO option. It controls whether a Partial
370 * Stop mode is entered when the STOPM=STOP. When entering a Partial Stop mode from the
371 * RUN mode, the PMC, MCG and Flash remain fully powered allowing the device
372 * to wakeup almost instantaneously at the expense of a higher power consumption.
373 * In PSTOP2, only the system clocks are gated, which allows the peripherals running on bus
374 * clock to remain fully functional. In PSTOP1, both system and bus clocks are
375 * gated. Refer to the smc_pstop_option_t for supported options. See the reference
376 * manual for details.
378 * @param baseAddr Base address for current SMC instance.
379 * @param option PSTOPO option setting defined in smc_pstop_option_t
381 void SMC_HAL_SetPstopMode(uint32_t baseAddr
, smc_pstop_option_t option
);
384 * @brief Gets the configuration of the PSTOPO option.
386 * This function gets the current PSTOPO option setting. See the configuration
387 * function for more details.
389 * @param baseAddr Base address for current SMC instance.
390 * @return option Current PSTOPO option setting
392 smc_pstop_option_t
SMC_HAL_GetPstopMode(uint32_t baseAddr
);
395 #if FSL_FEATURE_SMC_HAS_LPOPO
397 * @brief Configures the LPO option setting.
399 * This function sets the LPO option setting. It controls whether the 1 kHZ
400 * LPO clock is enabled in a certain lower power stop modes. See the
401 * smc_lpo_option_t for supported options and the reference manual for
402 * details about this option.
404 * @param baseAddr Base address for current SMC instance.
405 * @param option LPO option setting defined in smc_lpo_option_t
407 void SMC_HAL_SetLpoMode(uint32_t baseAddr
, smc_lpo_option_t option
);
410 * @brief Gets the settings of the LPO option.
412 * This function gets the current LPO option setting. See the configuration
413 * function for details.
415 * @param baseAddr Base address for current SMC instance.
416 * @return option Current LPO option setting
418 smc_por_option_t
SMC_HAL_GetLpoMode(uint32_t baseAddr
);
421 #if FSL_FEATURE_SMC_HAS_LPWUI
423 * @brief Configures the LPWUI (Low Power Wake Up on interrupt) option.
425 * This function sets the LPWUI option and cause the system to exit
426 * to normal RUN mode when any active interrupt occurs while in a specific lower
427 * power mode. See the smc_lpwui_option_t for supported options and the
428 * reference manual for more details about this option.
430 * @param baseAddr Base address for current SMC instance.
431 * @param option LPWUI option setting defined in smc_lpwui_option_t
433 void SMC_HAL_SetLpwuiMode(uint32_t baseAddr
, smc_lpwui_option_t option
);
436 * @brief Gets the current LPWUI option.
438 * This function gets the LPWUI option. See the configuration function for more
441 * @param baseAddr Base address for current SMC instance.
442 * @return setting Current LPWAUI option setting
444 smc_lpwui_option_t
SMC_HAL_GetLpwuiMode(uint32_t baseAddr
);
448 * @brief Gets the current power mode stat.
450 * This function returns the current power mode stat. Once application
451 * switches the power mode, it should always check the stat to check whether it
452 * runs into the specified mode or not. An application should check
453 * this mode before switching to a different mode. The system requires that
454 * only certain modes can switch to other specific modes. See the
455 * reference manual for details and the _power_mode_stat for information about
458 * @param baseAddr Base address for current SMC instance.
459 * @return stat Current power mode stat
461 uint8_t SMC_HAL_GetStat(uint32_t baseAddr
);
465 #if defined(__cplusplus)
467 #endif /* __cplusplus*/
471 #endif /* __FSL_SMC_HAL_H__*/
472 /*******************************************************************************
474 ******************************************************************************/