1 /*
2 * Copyright 2022-2024 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8 #ifndef FSL_SPC_H_
9 #define FSL_SPC_H_
10 #include "fsl_common.h"
11
12 /*!
13 * @addtogroup mcx_spc
14 * @{
15 */
16
17 /*******************************************************************************
18 * Definitions
19 ******************************************************************************/
20
21 /*! @name Driver version */
22 /*! @{ */
23 /*! @brief SPC driver version 2.4.2. */
24 #define FSL_SPC_DRIVER_VERSION (MAKE_VERSION(2, 4, 2))
25 /*! @} */
26
27 #define SPC_EVD_CFG_REG_EVDISO_SHIFT 0UL
28 #define SPC_EVD_CFG_REG_EVDLPISO_SHIFT 8UL
29 #define SPC_EVD_CFG_REG_EVDSTAT_SHIFT 16UL
30
31 #define SPC_EVD_CFG_REG_EVDISO(x) ((uint32_t)(x) << SPC_EVD_CFG_REG_EVDISO_SHIFT)
32 #define SPC_EVD_CFG_REG_EVDLPISO(x) ((uint32_t)(x) << SPC_EVD_CFG_REG_EVDLPISO_SHIFT)
33 #define SPC_EVD_CFG_REG_EVDSTAT(x) ((uint32_t)(x) << SPC_EVD_CFG_REG_EVDSTAT_SHIFT)
34
35 #if (defined(SPC_GLITCH_DETECT_SC_CNT_SELECT_MASK))
36 #define VDD_CORE_GLITCH_DETECT_SC GLITCH_DETECT_SC
37 #define SPC_VDD_CORE_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG_MASK SPC_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG_MASK
38 #define SPC_VDD_CORE_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG SPC_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG
39 #define SPC_VDD_CORE_GLITCH_DETECT_SC_LOCK_MASK SPC_GLITCH_DETECT_SC_LOCK_MASK
40 #define SPC_VDD_CORE_GLITCH_DETECT_SC_CNT_SELECT_MASK SPC_GLITCH_DETECT_SC_CNT_SELECT_MASK
41 #define SPC_VDD_CORE_GLITCH_DETECT_SC_CNT_SELECT SPC_GLITCH_DETECT_SC_CNT_SELECT
42 #define SPC_VDD_CORE_GLITCH_DETECT_SC_RE_MASK SPC_GLITCH_DETECT_SC_RE_MASK
43 #define SPC_VDD_CORE_GLITCH_DETECT_SC_RE SPC_GLITCH_DETECT_SC_RE
44 #define SPC_VDD_CORE_GLITCH_DETECT_SC_TIMEOUT_MASK SPC_GLITCH_DETECT_SC_TIMEOUT_MASK
45 #define SPC_VDD_CORE_GLITCH_DETECT_SC_TIMEOUT SPC_GLITCH_DETECT_SC_TIMEOUT
46 #define SPC_VDD_CORE_GLITCH_DETECT_SC_IE_MASK SPC_GLITCH_DETECT_SC_IE_MASK
47 #define SPC_VDD_CORE_GLITCH_DETECT_SC_IE SPC_GLITCH_DETECT_SC_IE
48 #endif
49
50 /*!
51 * @brief SPC status enumeration.
52 *
53 * @note Some device(such as MCXA family) do not equip DCDC or System LDO, please refer to the reference manual
54 * to check.
55 */
56 enum
57 {
58 kStatus_SPC_Busy = MAKE_STATUS(kStatusGroup_SPC, 0U), /*!< The SPC instance is busy executing any
59 type of power mode transition. */
60 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
61 kStatus_SPC_DCDCLowDriveStrengthIgnore = MAKE_STATUS(kStatusGroup_SPC, 1U), /*!< DCDC Low drive strength setting be
62 ignored for LVD/HVD enabled. */
63 kStatus_SPC_DCDCPulseRefreshModeIgnore = MAKE_STATUS(kStatusGroup_SPC, 2U), /*!< DCDC Pulse Refresh Mode drive
64 strength setting be ignored for LVD/HVD enabled. */
65 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
66 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
67 kStatus_SPC_SYSLDOOverDriveVoltageFail = MAKE_STATUS(kStatusGroup_SPC, 3U), /*!< SYS LDO regulate to Over drive
68 voltage failed for SYS LDO HVD must be disabled. */
69 kStatus_SPC_SYSLDOLowDriveStrengthIgnore = MAKE_STATUS(kStatusGroup_SPC, 4U), /*!< SYS LDO Low driver strength
70 setting be ignored for LDO LVD/HVD enabled. */
71 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
72 kStatus_SPC_CORELDOLowDriveStrengthIgnore = MAKE_STATUS(kStatusGroup_SPC, 5U), /*!< CORE LDO Low driver strength
73 setting be ignored for LDO LVD/HVD enabled. */
74 kStatus_SPC_CORELDOVoltageWrong = MAKE_STATUS(kStatusGroup_SPC, 7U), /*!< Core LDO voltage is wrong. */
75 kStatus_SPC_CORELDOVoltageSetFail = MAKE_STATUS(kStatusGroup_SPC, 8U), /*!< Core LDO voltage set fail. */
76 kStatus_SPC_BandgapModeWrong = MAKE_STATUS(kStatusGroup_SPC, 6U), /*!< Selected Bandgap Mode wrong. */
77 };
78
79 /*!
80 * @brief Voltage Detect Status Flags.
81 */
82 enum _spc_voltage_detect_flags
83 {
84 #if (defined(FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD) && FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD)
85 kSPC_IOVDDHighVoltageDetectFlag = SPC_VD_STAT_IOVDD_HVDF_MASK, /*!< IO VDD High-Voltage detect flag. */
86 kSPC_IOVDDLowVoltageDetectFlag = SPC_VD_STAT_IOVDD_LVDF_MASK, /*!< IO VDD Low-Voltage detect flag. */
87 #endif /* FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD */
88 kSPC_SystemVDDHighVoltageDetectFlag = SPC_VD_STAT_SYSVDD_HVDF_MASK, /*!< System VDD High-Voltage detect flag. */
89 kSPC_SystemVDDLowVoltageDetectFlag = SPC_VD_STAT_SYSVDD_LVDF_MASK, /*!< System VDD Low-Voltage detect flag. */
90 #if (defined(FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD) && FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD)
91 kSPC_CoreVDDHighVoltageDetectFlag = SPC_VD_STAT_COREVDD_HVDF_MASK, /*!< Core VDD High-Voltage detect flag. */
92 #endif /* FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD */
93 kSPC_CoreVDDLowVoltageDetectFlag = SPC_VD_STAT_COREVDD_LVDF_MASK, /*!< Core VDD Low-Voltage detect flag. */
94 };
95
96 /*!
97 * @brief SPC power domain isolation status.
98 * @note Some devices(such as MCXA family) do not contain WAKE Power Domain, please refer to the reference manual to
99 * check.
100 */
101 enum _spc_power_domains
102 {
103 kSPC_MAINPowerDomainRetain = 1UL << 16U, /*!< Peripherals and IO pads retain in MAIN Power Domain. */
104 kSPC_WAKEPowerDomainRetain = 1UL << 17U, /*!< Peripherals and IO pads retain in WAKE Power Domain. */
105 };
106
107 /*!
108 * @brief The enumeration of all analog module that can be controlled by SPC in active or low-power modes.
109 * @anchor spc_analog_module_control
110 */
111 enum _spc_analog_module_control
112 {
113 kSPC_controlVref = 1UL << 0UL, /*!< Enable/disable VREF in active or low-power modes. */
114 kSPC_controlUsb3vDet = 1UL << 1UL, /*!< Enable/disable USB3V_Det in active or low-power modes. */
115 kSPC_controlDac0 = 1UL << 4UL, /*!< Enable/disable DAC0 in active or low-power modes. */
116 kSPC_controlDac1 = 1UL << 5UL, /*!< Enable/disable DAC1 in active or low-power modes. */
117 kSPC_controlDac2 = 1UL << 6UL, /*!< Enable/disable DAC2 in active or low-power modes. */
118 kSPC_controlOpamp0 = 1UL << 8UL, /*!< Enable/disable OPAMP0 in active or low-power modes. */
119 kSPC_controlOpamp1 = 1UL << 9UL, /*!< Enable/disable OPAMP1 in active or low-power modes. */
120 kSPC_controlOpamp2 = 1UL << 10UL, /*!< Enable/disable OPAMP2 in active or low-power modes. */
121 kSPC_controlCmp0 = 1UL << 16UL, /*!< Enable/disable CMP0 in active or low-power modes. */
122 kSPC_controlCmp1 = 1UL << 17UL, /*!< Enable/disable CMP1 in active or low-power modes. */
123 kSPC_controlCmp2 = 1UL << 18UL, /*!< Enable/disable CMP2 in active or low-power modes. */
124 kSPC_controlCmp0Dac = 1UL << 20UL, /*!< Enable/disable CMP0_DAC in active or low-power modes. */
125 kSPC_controlCmp1Dac = 1UL << 21UL, /*!< Enable/disable CMP1_DAC in active or low-power modes. */
126 kSPC_controlCmp2Dac = 1UL << 22UL, /*!< Enable/disable CMP2_DAC in active or low-power modes. */
127 kSPC_controlAllModules = 0x770773UL, /*!< Enable/disable all modules in active or low-power modes. */
128 };
129
130 /*!
131 * @brief The enumeration of spc power domain, the connected power domain is chip specfic, please refer to chip's RM
132 * for details.
133 */
134 typedef enum _spc_power_domain_id
135 {
136 kSPC_PowerDomain0 = 0U, /*!< Power domain0, the connected power domain is chip specific. */
137 kSPC_PowerDomain1 = 1U, /*!< Power domain1, the connected power domain is chip specific. */
138 } spc_power_domain_id_t;
139
140 /*!
141 * @brief The enumeration of Power domain's low power mode.
142 */
143 typedef enum _spc_power_domain_low_power_mode
144 {
145 kSPC_SleepWithSYSClockRunning = 0U, /*!< Power domain request SLEEP mode with SYS clock running. */
146 kSPC_DeepSleepWithSysClockOff = 1U, /*!< Power domain request deep sleep mode with system clock off. */
147 kSPC_PowerDownWithSysClockOff = 2U, /*!< Power domain request power down mode with system clock off. */
148 kSPC_DeepPowerDownWithSysClockOff = 4U, /*!< Power domain request deep power down mode with system clock off. */
149 } spc_power_domain_low_power_mode_t;
150
151 /*!
152 * @brief SPC low power request output pin polarity.
153 */
154 typedef enum _spc_lowPower_request_pin_polarity
155 {
156 kSPC_HighTruePolarity = 0x0U, /*!< Control the High Polarity of the Low Power Reqest Pin. */
157 kSPC_LowTruePolarity = 0x1U, /*!< Control the Low Polarity of the Low Power Reqest Pin. */
158 } spc_lowpower_request_pin_polarity_t;
159
160 /*!
161 * @brief SPC low power request output override.
162 */
163 typedef enum _spc_lowPower_request_output_override
164 {
165 kSPC_LowPowerRequestNotForced = 0x0U, /*!< Not Forced. */
166 kSPC_LowPowerRequestReserved = 0x1U, /*!< Reserved. */
167 kSPC_LowPowerRequestForcedLow = 0x2U, /*!< Forced Low (Ignore LowPower request output polarity setting.) */
168 kSPC_LowPowerRequestForcedHigh = 0x3U, /*!< Forced High (Ignore LowPower request output polarity setting.) */
169 } spc_lowpower_request_output_override_t;
170
171 /*!
172 * @brief SPC Bandgap mode enumeration in Active mode or Low Power mode.
173 */
174 typedef enum _spc_bandgap_mode
175 {
176 kSPC_BandgapDisabled = 0x0U, /*!< Bandgap disabled. */
177 kSPC_BandgapEnabledBufferDisabled = 0x1U, /*!< Bandgap enabled with Buffer disabled. */
178 kSPC_BandgapEnabledBufferEnabled = 0x2U, /*!< Bandgap enabled with Buffer enabled. */
179 kSPC_BandgapReserved = 0x3U, /*!< Reserved. */
180 } spc_bandgap_mode_t;
181
182 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
183 /*!
184 * @brief DCDC regulator voltage level enumeration in Active mode or Low Power Mode.
185 *
186 * @note #kSPC_DCDC_RetentionVoltage not supported for all power modes.
187 */
188 typedef enum _spc_dcdc_voltage_level
189 {
190 kSPC_DCDC_RetentionVoltage = 0x0U, /*!< DCDC_CORE Regulator regulate to retention
191 Voltage(Only supportedin low power modes) */
192 kSPC_DCDC_MidVoltage = 0x1U, /*!< DCDC_CORE Regulator regulate to Mid Voltage(1.0V). */
193 kSPC_DCDC_NormalVoltage = 0x2U, /*!< DCDC_CORE Regulator regulate to Normal Voltage(1.1V). */
194 kSPC_DCDC_OverdriveVoltage = 0x3U, /*!< DCDC_CORE Regulator regulate to Safe-Mode Voltage(1.2V). */
195 } spc_dcdc_voltage_level_t;
196
197 /*!
198 * @brief DCDC regulator Drive Strength enumeration in Active mode or Low Power Mode.
199 *
200 * @note Different drive strength differ in these DCDC characterstics:
201 * Maximum load current
202 * Quiescent current
203 * Transient response.
204 */
205 typedef enum _spc_dcdc_drive_strength
206 {
207 kSPC_DCDC_PulseRefreshMode = 0x0U, /*!< DCDC_CORE Regulator Drive Strength set to Pulse Refresh Mode,
208 * This enum member is only useful for Low Power Mode config, please
209 * note that pluse refresh mode is invalid in SLEEP mode.
210 */
211 kSPC_DCDC_LowDriveStrength = 0x1U, /*!< DCDC_CORE regulator Drive Strength set to low. */
212 kSPC_DCDC_NormalDriveStrength = 0x2U, /*!< DCDC_CORE regulator Drive Strength set to Normal. */
213 } spc_dcdc_drive_strength_t;
214 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
215
216 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
217 /*!
218 * @brief SYS LDO regulator voltage level enumeration in Active mode.
219 */
220 typedef enum _spc_sys_ldo_voltage_level
221 {
222 kSPC_SysLDO_NormalVoltage = 0x0U, /*!< SYS LDO VDD Regulator regulate to Normal Voltage(1.8V). */
223 kSPC_SysLDO_OverDriveVoltage = 0x1U, /*!< SYS LDO VDD Regulator regulate to Over Drive Voltage(2.5V). */
224 } spc_sys_ldo_voltage_level_t;
225
226 /*!
227 * @brief SYS LDO regulator Drive Strength enumeration in Active mode or Low Power mode.
228 */
229 typedef enum _spc_sys_ldo_drive_strength
230 {
231 kSPC_SysLDO_LowDriveStrength = 0x0U, /*!< SYS LDO VDD regulator Drive Strength set to low. */
232 kSPC_SysLDO_NormalDriveStrength = 0x1U, /*!< SYS LDO VDD regulator Drive Strength set to Normal. */
233 } spc_sys_ldo_drive_strength_t;
234 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
235
236 /*!
237 * @brief Core LDO regulator voltage level enumeration in Active mode or Low Power mode.
238 */
239 typedef enum _spc_core_ldo_voltage_level
240 {
241 kSPC_CoreLDO_UnderDriveVoltage = 0x0U, /*!< @deprecated, to align with description of latest RM, please use
242 #kSPC_Core_LDO_RetentionVoltage as instead. */
243 kSPC_Core_LDO_RetentionVoltage = 0x0U, /*!< Core LDO VDD regulator regulate to retention voltage, please note that
244 only useful in low power modes and not all devices support this options
245 please refer to devices' RM for details. */
246 kSPC_CoreLDO_MidDriveVoltage = 0x1U, /*!< Core LDO VDD regulator regulate to Mid Drive Voltage. */
247 kSPC_CoreLDO_NormalVoltage = 0x2U, /*!< Core LDO VDD regulator regulate to Normal Voltage. */
248 kSPC_CoreLDO_OverDriveVoltage = 0x3U, /*!< Core LDO VDD regulator regulate to overdrive Voltage. */
249 } spc_core_ldo_voltage_level_t;
250
251 /*!
252 * @brief CORE LDO VDD regulator Drive Strength enumeration in Low Power mode.
253 */
254 typedef enum _spc_core_ldo_drive_strength
255 {
256 kSPC_CoreLDO_LowDriveStrength = 0x0U, /*!< Core LDO VDD regulator Drive Strength set to low. */
257 kSPC_CoreLDO_NormalDriveStrength = 0x1U, /*!< Core LDO VDD regulator Drive Strength set to Normal. */
258 } spc_core_ldo_drive_strength_t;
259
260 /*!
261 * @brief IO VDD Low-Voltage Level Select.
262 */
263 typedef enum _spc_low_voltage_level_select
264 {
265 kSPC_LowVoltageNormalLevel = 0x0U, /*!< @deprecated, please use kSPC_LowVoltageHighRange as instead. */
266 kSPC_LowVoltageSafeLevel = 0x1U, /*!< @deprecated, please use kSPC_LowVoltageLowRange as instead. */
267
268 kSPC_LowVoltageHighRange = 0x0U, /*!< High range LVD threshold. */
269 kSPC_LowVoltageLowRange = 0x1U, /*!< Low range LVD threshold. */
270 } spc_low_voltage_level_select_t;
271
272 #if !(defined(FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT) && FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT)
273 /*!
274 * @brief Used to select output of 4-bit ripple counter is used to monitor a glitch on VDD core.
275 */
276 typedef enum _spc_vdd_core_glitch_ripple_counter_select
277 {
278 kSPC_selectBit0Of4bitRippleCounter = 0x0U, /*!< Select bit-0 of 4-bit Ripple Counter
279 to detect glitch on VDD Core. */
280 kSPC_selectBit1Of4bitRippleCounter = 0x1U, /*!< Select bit-1 of 4-bit Ripple Counter
281 to detect glitch on VDD Core. */
282 kSPC_selectBit2Of4bitRippleCounter = 0x2U, /*!< Select bit-2 of 4-bit Ripple Counter
283 to detect glitch on VDD Core. */
284 kSPC_selectBit3Of4bitRippleCounter = 0x3U, /*!< Select bit-3 of 4-bit Ripple Counter
285 to detect glitch on VDD Core. */
286 } spc_vdd_core_glitch_ripple_counter_select_t;
287 #endif
288
289 /*!
290 * @brief The list of the operating voltage for the SRAM's read/write timing margin.
291 */
292 typedef enum _spc_sram_operate_voltage
293 {
294 kSPC_sramOperateAt1P0V = 0x1U, /*!< SRAM configured for 1.0V operation. */
295 kSPC_sramOperateAt1P1V = 0x2U, /*!< SRAM configured for 1.1V operation. */
296 kSPC_sramOperateAt1P2V = 0x3U, /*!< SRAM configured for 1.2V operation. */
297 } spc_sram_operate_voltage_t;
298
299 #if !(defined(FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT) && FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT)
300 /*!
301 * @brief The configuration of VDD Core glitch detector.
302 */
303 typedef struct _spc_vdd_core_glitch_detector_config
304 {
305 spc_vdd_core_glitch_ripple_counter_select_t rippleCounterSelect; /*!< Used to set ripple counter. */
306 uint8_t resetTimeoutValue; /*!< The timeout value used to reset glitch detect/compare logic after an initial
307 glitch is detected. */
308 bool enableReset; /*!< Used to enable/disable POR/LVD reset that caused by CORE VDD glitch detect error. */
309 bool enableInterrupt; /*!< Used to enable/disable hardware interrupt if CORE VDD glitch detect error. */
310 } spc_vdd_core_glitch_detector_config_t;
311 #endif
312
313 typedef struct _spc_sram_voltage_config
314 {
315 spc_sram_operate_voltage_t operateVoltage; /*!< Specifies the operating voltage for the SRAM's
316 read/write timing margin. */
317 bool requestVoltageUpdate; /*!< Used to control whether request an SRAM trim value change. */
318 } spc_sram_voltage_config_t;
319
320 /*!
321 * @brief Low Power Request output pin configuration.
322 */
323 typedef struct _spc_lowpower_request_config
324 {
325 bool enable; /*!< Low Power Request Output enable. */
326 spc_lowpower_request_pin_polarity_t polarity; /*!< Low Power Request Output pin polarity select. */
327 spc_lowpower_request_output_override_t override; /*!< Low Power Request Output Override. */
328 } spc_lowpower_request_config_t;
329
330 /*!
331 * @brief Core LDO regulator options in Active mode.
332 */
333 typedef struct _spc_active_mode_core_ldo_option
334 {
335 spc_core_ldo_voltage_level_t CoreLDOVoltage; /*!< Core LDO Regulator Voltage Level selection in Active mode. */
336 #if defined(FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS) && FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS
337 spc_core_ldo_drive_strength_t CoreLDODriveStrength; /*!< Core LDO Regulator Drive Strength
338 selection in Active mode */
339 #endif /* FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS */
340 } spc_active_mode_core_ldo_option_t;
341
342 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
343 /*!
344 * @brief System LDO regulator options in Active mode.
345 */
346 typedef struct _spc_active_mode_sys_ldo_option
347 {
348 spc_sys_ldo_voltage_level_t SysLDOVoltage; /*!< System LDO Regulator Voltage Level selection in Active mode. */
349 spc_sys_ldo_drive_strength_t SysLDODriveStrength; /*!< System LDO Regulator Drive Strength
350 selection in Active mode. */
351 } spc_active_mode_sys_ldo_option_t;
352 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
353
354 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
355 /*!
356 * @brief DCDC regulator options in Active mode.
357 */
358 typedef struct _spc_active_mode_dcdc_option
359 {
360 spc_dcdc_voltage_level_t DCDCVoltage; /*!< DCDC Regulator Voltage Level selection in Active mode. */
361 spc_dcdc_drive_strength_t DCDCDriveStrength; /*!< DCDC_CORE Regulator Drive Strength selection in Active mode. */
362 } spc_active_mode_dcdc_option_t;
363 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
364
365 /*!
366 * @brief Core LDO regulator options in Low Power mode.
367 */
368 typedef struct _spc_lowpower_mode_core_ldo_option
369 {
370 spc_core_ldo_voltage_level_t CoreLDOVoltage; /*!< Core LDO Regulator Voltage Level selection in Low Power mode. */
371 spc_core_ldo_drive_strength_t CoreLDODriveStrength; /*!< Core LDO Regulator Drive Strength
372 selection in Low Power mode */
373 } spc_lowpower_mode_core_ldo_option_t;
374
375 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
376 /*!
377 * @brief System LDO regulator options in Low Power mode.
378 */
379 typedef struct _spc_lowpower_mode_sys_ldo_option
380 {
381 spc_sys_ldo_drive_strength_t SysLDODriveStrength; /*!< System LDO Regulator Drive Strength
382 selection in Low Power mode. */
383 } spc_lowpower_mode_sys_ldo_option_t;
384 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
385
386 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
387 /*!
388 * @brief DCDC regulator options in Low Power mode.
389 */
390 typedef struct _spc_lowpower_mode_dcdc_option
391 {
392 spc_dcdc_voltage_level_t DCDCVoltage; /*!< DCDC Regulator Voltage Level selection in Low Power mode. */
393 spc_dcdc_drive_strength_t DCDCDriveStrength; /*!< DCDC_CORE Regulator Drive Strength selection in Low Power mode. */
394 } spc_lowpower_mode_dcdc_option_t;
395
396 /*!
397 * @brief DCDC Burst configuration.
398 * @deprecated Do not recommend to use this structure.
399 */
400 typedef struct _spc_dcdc_burst_config
401 {
402 bool sofwareBurstRequest; /*!< Enable/Disable DCDC Software Burst Request. */
403 bool externalBurstRequest; /*!< Enable/Disable DCDC External Burst Request. */
404 bool stabilizeBurstFreq; /*!< Enable/Disable DCDC frequency stabilization. */
405 uint8_t freq; /*!< The frequency of the current burst. */
406 } spc_dcdc_burst_config_t;
407 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
408
409 /*!
410 * @brief CORE/SYS/IO VDD Voltage Detect options.
411 */
412 typedef struct _spc_voltage_detect_option
413 {
414 bool HVDInterruptEnable; /*!< CORE/SYS/IO VDD High Voltage Detect interrupt enable. */
415 bool HVDResetEnable; /*!< CORE/SYS/IO VDD High Voltage Detect reset enable. */
416 bool LVDInterruptEnable; /*!< CORE/SYS/IO VDD Low Voltage Detect interrupt enable. */
417 bool LVDResetEnable; /*!< CORE/SYS/IO VDD Low Voltage Detect reset enable. */
418 } spc_voltage_detect_option_t;
419
420 /*!
421 * @brief Core Voltage Detect configuration.
422 */
423 typedef struct _spc_core_voltage_detect_config
424 {
425 spc_voltage_detect_option_t option; /*!< Core VDD Voltage Detect option. */
426 } spc_core_voltage_detect_config_t;
427
428 /*!
429 * @brief System Voltage Detect Configuration.
430 */
431 typedef struct _spc_system_voltage_detect_config
432 {
433 spc_voltage_detect_option_t option; /*!< System VDD Voltage Detect option. */
434 spc_low_voltage_level_select_t level; /*!< @deprecated, reserved for all devices, will removed in next release. */
435 } spc_system_voltage_detect_config_t;
436
437 #if (defined(FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD) && FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD)
438 /*!
439 * @brief IO Voltage Detect Configuration.
440 */
441 typedef struct _spc_io_voltage_detect_config
442 {
443 spc_voltage_detect_option_t option; /*!< IO VDD Voltage Detect option. */
444 spc_low_voltage_level_select_t level; /*!< IO VDD Low-voltage level selection. */
445 } spc_io_voltage_detect_config_t;
446 #endif /* FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD */
447
448 /*!
449 * @brief Active mode configuration.
450 */
451 typedef struct _spc_active_mode_regulators_config
452 {
453 spc_bandgap_mode_t bandgapMode; /*!< Specify bandgap mode in active mode. */
454
455 #if (defined(FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT) && FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT)
456 bool lpBuff; /*!< Enable/disable CMP bandgap buffer. */
457 #endif /* FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT */
458
459 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
460 spc_active_mode_dcdc_option_t DCDCOption; /*!< Specify DCDC configurations in active mode. */
461 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
462
463 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
464 spc_active_mode_sys_ldo_option_t SysLDOOption; /*!< Specify System LDO configurations in active mode. */
465 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
466
467 spc_active_mode_core_ldo_option_t CoreLDOOption; /*!< Specify Core LDO configurations in active mode. */
468 } spc_active_mode_regulators_config_t;
469
470 /*!
471 * @brief Low Power Mode configuration.
472 */
473 typedef struct _spc_lowpower_mode_regulators_config
474 {
475 bool lpIREF; /*!< Enable/disable low power IREF in low power modes. */
476 spc_bandgap_mode_t bandgapMode; /*!< Specify bandgap mode in low power modes. */
477
478 #if (defined(FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT) && FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT)
479 bool lpBuff; /*!< Enable/disable CMP bandgap buffer in low power modes. */
480 #endif /* FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT */
481
482 #if (defined(FSL_FEATURE_MCX_SPC_HAS_COREVDD_IVS_EN_BIT) && FSL_FEATURE_MCX_SPC_HAS_COREVDD_IVS_EN_BIT)
483 bool CoreIVS; /*!< Enable/disable CORE VDD internal voltage scaling. */
484 #endif /* FSL_FEATURE_MCX_SPC_HAS_COREVDD_IVS_EN_BIT */
485
486 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
487 spc_lowpower_mode_dcdc_option_t DCDCOption; /*!< Specify DCDC configurations in low power modes. */
488 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
489
490 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
491 spc_lowpower_mode_sys_ldo_option_t SysLDOOption; /*!< Specify system LDO configurations in low power modes. */
492 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
493
494 spc_lowpower_mode_core_ldo_option_t CoreLDOOption; /*!< Specify core LDO configurations in low power modes. */
495 } spc_lowpower_mode_regulators_config_t;
496
497 /*******************************************************************************
498 * API
499 ******************************************************************************/
500 #if defined(__cplusplus)
501 extern "C" {
502 #endif /* __cplusplus */
503
504 /*!
505 * @name SPC Status
506 * @{
507 */
508 /*!
509 * @brief Gets Isolation status for each power domains.
510 *
511 * This function gets the status which indicates whether certain
512 * peripheral and the IO pads are in a latched state as a result
513 * of having been in POWERDOWN mode.
514 *
515 * @param base SPC peripheral base address.
516 * @return Current isolation status for each power domains. See @ref _spc_power_domains for details.
517 */
518 uint8_t SPC_GetPeriphIOIsolationStatus(SPC_Type *base);
519
520 /*!
521 * @brief Clears peripherals and I/O pads isolation flags for each power domains.
522 *
523 * This function clears peripherals and I/O pads isolation flags for each power domains.
524 * After recovering from the POWERDOWN mode, user must invoke this function to release the
525 * I/O pads and certain peripherals to their normal run mode state. Before invoking this
526 * function, user must restore chip configuration in particular pin configuration for enabled
527 * WUU wakeup pins.
528 *
529 * @param base SPC peripheral base address.
530 */
SPC_ClearPeriphIOIsolationFlag(SPC_Type * base)531 static inline void SPC_ClearPeriphIOIsolationFlag(SPC_Type *base)
532 {
533 base->SC |= SPC_SC_ISO_CLR_MASK;
534 }
535
536 /*!
537 * @brief Gets SPC busy status flag.
538 *
539 * This function gets SPC busy status flag. When SPC executing any type of power mode
540 * transition in ACTIVE mode or any of the SOC low power mode, the SPC busy status flag is set
541 * and this function returns true. When changing CORE LDO voltage level and DCDC voltage level
542 * in ACTIVE mode, the SPC busy status flag is set and this function return true.
543 *
544 * @param base SPC peripheral base address.
545 * @return Ack busy flag.
546 * true - SPC is busy.
547 * false - SPC is not busy.
548 */
SPC_GetBusyStatusFlag(SPC_Type * base)549 static inline bool SPC_GetBusyStatusFlag(SPC_Type *base)
550 {
551 return ((base->SC & SPC_SC_BUSY_MASK) != 0UL);
552 }
553
554 /*!
555 * @brief Checks system low power request.
556 *
557 * @note Only when all power domains request low power mode entry, the result of this function is true. That means when
558 * all power domains request low power mode entry, the SPC regulators will be controlled by LP_CFG register.
559 *
560 * @param base SPC peripheral base address.
561 * @return The system low power request check result.
562 * - \b true All power domains have requested low power mode and SPC has entered a low power state and power mode
563 * configuration are based on the LP_CFG configuration register.
564 * - \b false SPC in active mode and ACTIVE_CFG register control system power supply.
565 */
SPC_CheckLowPowerReqest(SPC_Type * base)566 static inline bool SPC_CheckLowPowerReqest(SPC_Type *base)
567 {
568 return ((base->SC & SPC_SC_SPC_LP_REQ_MASK) == SPC_SC_SPC_LP_REQ_MASK);
569 }
570
571 /*!
572 * @brief Clears system low power request, set SPC in active mode.
573 *
574 * @param base SPC peripheral base address.
575 */
SPC_ClearLowPowerRequest(SPC_Type * base)576 static inline void SPC_ClearLowPowerRequest(SPC_Type *base)
577 {
578 base->SC |= SPC_SC_SPC_LP_REQ_MASK;
579 }
580
581 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SWITCH_STATE_BIT) && FSL_FEATURE_MCX_SPC_HAS_SWITCH_STATE_BIT)
582 /*!
583 * @brief Checks whether the power switch is on.
584 *
585 * @param base SPC peripheral base address.
586 *
587 * @retval true The power switch is on.
588 * @retval false The power switch is off.
589 */
SPC_CheckSwitchState(SPC_Type * base)590 static inline bool SPC_CheckSwitchState(SPC_Type *base)
591 {
592 return ((base->SC & SPC_SC_SWITCH_STATE_MASK) != 0UL);
593 }
594 #endif /* FSL_FEATURE_MCX_SPC_HAS_SWITCH_STATE_BIT */
595
596 /*!
597 * @brief Gets selected power domain's requested low power mode.
598 *
599 * @param base SPC peripheral base address.
600 * @param powerDomainId Power Domain Id, please refer to @ref spc_power_domain_id_t.
601 *
602 * @return The selected power domain's requested low power mode, please refer to @ref spc_power_domain_low_power_mode_t.
603 */
604 spc_power_domain_low_power_mode_t SPC_GetPowerDomainLowPowerMode(SPC_Type *base, spc_power_domain_id_t powerDomainId);
605
606 /*!
607 * @brief Checks power domain's low power request.
608 *
609 * @param base SPC peripheral base address.
610 * @param powerDomainId Power Domain Id, please refer to @ref spc_power_domain_id_t.
611 * @return The result of power domain's low power request.
612 * - \b true The selected power domain requests low power mode entry.
613 * - \b false The selected power domain does not request low power mode entry.
614 */
SPC_CheckPowerDomainLowPowerRequest(SPC_Type * base,spc_power_domain_id_t powerDomainId)615 static inline bool SPC_CheckPowerDomainLowPowerRequest(SPC_Type *base, spc_power_domain_id_t powerDomainId)
616 {
617 assert((uint8_t)powerDomainId < SPC_PD_STATUS_COUNT);
618 return ((base->PD_STATUS[(uint8_t)powerDomainId] & SPC_PD_STATUS_PWR_REQ_STATUS_MASK) ==
619 SPC_PD_STATUS_PWR_REQ_STATUS_MASK);
620 }
621
622 /*!
623 * @brief Clears selected power domain's low power request flag.
624 *
625 * @param base SPC peripheral base address.
626 * @param powerDomainId Power Domain Id, please refer to @ref spc_power_domain_id_t.
627 */
SPC_ClearPowerDomainLowPowerRequestFlag(SPC_Type * base,spc_power_domain_id_t powerDomainId)628 static inline void SPC_ClearPowerDomainLowPowerRequestFlag(SPC_Type *base, spc_power_domain_id_t powerDomainId)
629 {
630 assert((uint8_t)powerDomainId < SPC_PD_STATUS_COUNT);
631 base->PD_STATUS[(uint8_t)powerDomainId] |= SPC_PD_STATUS_PD_LP_REQ_MASK;
632 }
633
634 /*! @} */
635
636 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SRAMRETLDO_REG) && FSL_FEATURE_MCX_SPC_HAS_SRAMRETLDO_REG)
637 /*!
638 * @name SRAM Retention LDO Control APIs
639 * @{
640 */
641
642 /*!
643 * @brief Trims SRAM retention regulator reference voltage, trim step is 12 mV, range is around 0.48V to 0.85V.
644 *
645 * @param base SPC peripheral base address.
646 * @param trimValue Reference voltage trim value.
647 */
SPC_TrimSRAMLdoRefVoltage(SPC_Type * base,uint8_t trimValue)648 static inline void SPC_TrimSRAMLdoRefVoltage(SPC_Type *base, uint8_t trimValue)
649 {
650 base->SRAMRETLDO_REFTRIM =
651 ((base->SRAMRETLDO_REFTRIM & ~SPC_SRAMRETLDO_REFTRIM_REFTRIM_MASK) | SPC_SRAMRETLDO_REFTRIM_REFTRIM(trimValue));
652 }
653
654 /*!
655 * @brief Enables/disables SRAM retention LDO.
656 *
657 * @param base SPC peripheral base address.
658 * @param enable Used to enable/disable SRAM LDO :
659 * - \b true Enable SRAM LDO;
660 * - \b false Disable SRAM LDO.
661 */
SPC_EnableSRAMLdo(SPC_Type * base,bool enable)662 static inline void SPC_EnableSRAMLdo(SPC_Type *base, bool enable)
663 {
664 if (enable)
665 {
666 base->SRAMRETLDO_CNTRL |= SPC_SRAMRETLDO_CNTRL_SRAMLDO_ON_MASK;
667 }
668 else
669 {
670 base->SRAMRETLDO_CNTRL &= ~SPC_SRAMRETLDO_CNTRL_SRAMLDO_ON_MASK;
671 }
672 }
673
674 /*!
675 * @brief
676 *
677 * @todo Need to check.
678 *
679 * @param base SPC peripheral base address.
680 * @param mask The OR'ed value of SRAM Array.
681 */
SPC_RetainSRAMArray(SPC_Type * base,uint8_t mask)682 static inline void SPC_RetainSRAMArray(SPC_Type *base, uint8_t mask)
683 {
684 base->SRAMRETLDO_CNTRL |= SPC_SRAMRETLDO_CNTRL_SRAM_RET_EN(mask);
685 }
686
687 /*! @} */
688 #endif /* FSL_FEATURE_MCX_SPC_HAS_SRAMRETLDO_REG */
689
690 /*!
691 * @name Low Power Request configuration
692 * @{
693 */
694 /*!
695 * @brief Configs Low power request output pin.
696 *
697 * This function config the low power request output pin
698 *
699 * @param base SPC peripheral base address.
700 * @param config Pointer the @ref spc_lowpower_request_config_t structure.
701 */
702 void SPC_SetLowPowerRequestConfig(SPC_Type *base, const spc_lowpower_request_config_t *config);
703
704 /*! @} */
705
706 #if (defined(FSL_FEATURE_MCX_SPC_HAS_CFG_REG) && FSL_FEATURE_MCX_SPC_HAS_CFG_REG)
707 /*!
708 * @name Integrated Power Switch Control APIs
709 * @{
710 */
711
712 /*!
713 * @brief Enables/disables the integrated power switch manually.
714 *
715 * @param base SPC peripheral base address.
716 * @param enable Used to enable/disable the integrated power switch:
717 * - \b true Enable the integrated power switch;
718 * - \b false Disable the integrated power switch.
719 */
SPC_EnableIntegratedPowerSwitchManually(SPC_Type * base,bool enable)720 static inline void SPC_EnableIntegratedPowerSwitchManually(SPC_Type *base, bool enable)
721 {
722 if (enable)
723 {
724 base->CFG |= (SPC_CFG_INTG_PWSWTCH_SLEEP_ACTIVE_EN_MASK | SPC_CFG_INTG_PWSWTCH_WKUP_ACTIVE_EN_MASK);
725 }
726 else
727 {
728 base->CFG &= ~(SPC_CFG_INTG_PWSWTCH_SLEEP_ACTIVE_EN_MASK | SPC_CFG_INTG_PWSWTCH_WKUP_ACTIVE_EN_MASK);
729 }
730 }
731
732 /*!
733 * @brief Enables/disables the integrated power switch automatically.
734 *
735 * To gate the integrated power switch when chip enter low power modes, and ungate the switch after wake-up from low
736 * power modes:
737 * @code
738 * SPC_EnableIntegratedPowerSwitchAutomatically(SPC, true, true);
739 * @endcode
740 *
741 * @param base SPC peripheral base address.
742 * @param sleepGate Enable the integrated power switch when chip enter low power modes:
743 * - \b true SPC asserts an output pin at low-power entry to power-gate the switch;
744 * - \b false SPC does not assert an output pin at low-power entry to power-gate the switch.
745 * @param wakeupUngate Enables the switch after wake-up from low power modes:
746 * - \b true SPC asserts an output pin at low-power exit to power-ungate the switch;
747 * - \b false SPC does not assert an output pin at low-power exit to power-ungate the switch.
748 */
SPC_EnableIntegratedPowerSwitchAutomatically(SPC_Type * base,bool sleepGate,bool wakeupUngate)749 static inline void SPC_EnableIntegratedPowerSwitchAutomatically(SPC_Type *base, bool sleepGate, bool wakeupUngate)
750 {
751 uint32_t tmp32 = ((base->CFG) & ~(SPC_CFG_INTG_PWSWTCH_SLEEP_EN_MASK | SPC_CFG_INTG_PWSWTCH_WKUP_EN_MASK));
752
753 tmp32 |= SPC_CFG_INTG_PWSWTCH_SLEEP_EN(sleepGate) | SPC_CFG_INTG_PWSWTCH_WKUP_EN(wakeupUngate);
754
755 base->CFG = tmp32;
756 }
757
758 /*! @} */
759 #endif /* FSL_FEATURE_MCX_SPC_HAS_CFG_REG */
760
761 #if !(defined(FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT) && FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT)
762 /*!
763 * @name VDD Core Glitch Detector Control APIs
764 * @{
765 */
766
767 /*!
768 * @brief Configures VDD Core Glitch detector, including ripple counter selection, timeout value and so on.
769 *
770 * @param base SPC peripheral base address.
771 * @param config Pointer to the structure in type of @ref spc_vdd_core_glitch_detector_config_t.
772 */
773 void SPC_ConfigVddCoreGlitchDetector(SPC_Type *base, const spc_vdd_core_glitch_detector_config_t *config);
774
775 /*!
776 * @brief Checks selected 4-bit glitch ripple counter's output.
777 *
778 * @param base SPC peripheral base address.
779 * @param rippleCounter The ripple counter to check, please refer to @ref spc_vdd_core_glitch_ripple_counter_select_t.
780 *
781 * @retval true The selected ripple counter output is 1, will generate interrupt or reset based on settings.
782 * @retval false The selected ripple counter output is 0.
783 */
784
SPC_CheckGlitchRippleCounterOutput(SPC_Type * base,spc_vdd_core_glitch_ripple_counter_select_t rippleCounter)785 static inline bool SPC_CheckGlitchRippleCounterOutput(SPC_Type *base,
786 spc_vdd_core_glitch_ripple_counter_select_t rippleCounter)
787 {
788 return ((base->VDD_CORE_GLITCH_DETECT_SC & SPC_VDD_CORE_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG_MASK) ==
789 SPC_VDD_CORE_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG(1UL << (uint32_t)(rippleCounter)));
790 }
791
792 /*!
793 * @brief Clears output of selected glitch ripple counter.
794 *
795 * @param base SPC peripheral base address.
796 * @param rippleCounter The ripple counter to check, please refer to @ref spc_vdd_core_glitch_ripple_counter_select_t.
797 */
SPC_ClearGlitchRippleCounterOutput(SPC_Type * base,spc_vdd_core_glitch_ripple_counter_select_t rippleCounter)798 static inline void SPC_ClearGlitchRippleCounterOutput(SPC_Type *base,
799 spc_vdd_core_glitch_ripple_counter_select_t rippleCounter)
800 {
801 base->VDD_CORE_GLITCH_DETECT_SC |=
802 SPC_VDD_CORE_GLITCH_DETECT_SC_GLITCH_DETECT_FLAG(1UL << (uint32_t)(rippleCounter));
803 }
804
805 /*!
806 * @brief After invoking this function, writes to SPC_VDD_CORE_GLITCH_DETECT_SC[RE] register are ignored.
807 *
808 * @param base SPC peripheral base address.
809 */
SPC_LockVddCoreVoltageGlitchDetectResetControl(SPC_Type * base)810 static inline void SPC_LockVddCoreVoltageGlitchDetectResetControl(SPC_Type *base)
811 {
812 base->VDD_CORE_GLITCH_DETECT_SC |= SPC_VDD_CORE_GLITCH_DETECT_SC_LOCK_MASK;
813 }
814
815 /*!
816 * @brief After invoking this function, writes to SPC_VDD_CORE_GLITCH_DETECT_SC[RE] register are allowed.
817 *
818 * @param base SPC peripheral base address.
819 */
SPC_UnlockVddCoreVoltageGlitchDetectResetControl(SPC_Type * base)820 static inline void SPC_UnlockVddCoreVoltageGlitchDetectResetControl(SPC_Type *base)
821 {
822 base->VDD_CORE_GLITCH_DETECT_SC &= ~SPC_VDD_CORE_GLITCH_DETECT_SC_LOCK_MASK;
823 }
824
825 /*!
826 * @brief Checks if SPC_VDD_CORE_GLITCH_DETECT_SC[RE] register is writable.
827 *
828 * @param base SPC peripheral base address.
829 *
830 * @retval true SPC_VDD_CORE_GLITCH_DETECT_SC[RE] register is writable.
831 * @retval false SPC_VDD_CORE_GLITCH_DETECT_SC[RE] register is not writable.
832 */
SPC_CheckVddCoreVoltageGlitchResetControlState(SPC_Type * base)833 static inline bool SPC_CheckVddCoreVoltageGlitchResetControlState(SPC_Type *base)
834 {
835 return ((base->VDD_CORE_GLITCH_DETECT_SC & SPC_VDD_CORE_GLITCH_DETECT_SC_LOCK_MASK) != 0UL);
836 }
837
838 /*! @} */
839 #endif
840
841 /*!
842 * @name SRAM Control APIs
843 * @{
844 */
845
846 /*!
847 * @brief Set SRAM operate voltage.
848 *
849 * @param base SPC peripheral base address.
850 * @param config The pointer to @ref spc_sram_voltage_config_t, specifies the configuration of sram voltage.
851 */
852 void SPC_SetSRAMOperateVoltage(SPC_Type *base, const spc_sram_voltage_config_t *config);
853
854 /*! @} */
855
856 /*!
857 * @name Active Mode configuration
858 * @{
859 */
860
861 /*!
862 * @brief Gets the Bandgap mode in Active mode.
863 *
864 * @param base SPC peripheral base address.
865 * @return Bandgap mode in the type of @ref spc_bandgap_mode_t enumeration.
866 */
SPC_GetActiveModeBandgapMode(SPC_Type * base)867 static inline spc_bandgap_mode_t SPC_GetActiveModeBandgapMode(SPC_Type *base)
868 {
869 return (spc_bandgap_mode_t)(uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_BGMODE_MASK) >>
870 SPC_ACTIVE_CFG_BGMODE_SHIFT);
871 }
872
873 /*!
874 * @brief Gets all voltage detectors status in Active mode.
875 *
876 * @param base SPC peripheral base address.
877 * @return All voltage detectors status in Active mode.
878 */
SPC_GetActiveModeVoltageDetectStatus(SPC_Type * base)879 static inline uint32_t SPC_GetActiveModeVoltageDetectStatus(SPC_Type *base)
880 {
881 uint32_t state;
882 state = base->ACTIVE_CFG &
883 (
884 #if (defined(FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD) && FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD)
885 SPC_ACTIVE_CFG_IO_HVDE_MASK | SPC_ACTIVE_CFG_IO_LVDE_MASK |
886
887 #endif /* FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD */
888 SPC_ACTIVE_CFG_SYS_HVDE_MASK | SPC_ACTIVE_CFG_SYS_LVDE_MASK | SPC_ACTIVE_CFG_CORE_LVDE_MASK
889
890 #if (defined(FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD) && FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD)
891 | SPC_ACTIVE_CFG_CORE_HVDE_MASK
892
893 #endif /* FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD */
894 );
895 return state;
896 }
897
898 /*!
899 * @brief Configs Bandgap mode in Active mode.
900 *
901 * @note To disable bandgap in Active mode:
902 * 1. Disable all LVD's and HVD's in active mode;
903 * 2. Disable Glitch detect;
904 * 3. Configrue LDO's and DCDC to low drive strength in active mode;
905 * 4. Invoke this function to disable bandgap in active mode;
906 * otherwise the error status will be reported.
907 *
908 * @note Some other system resources(such as PLL, CMP) require bandgap to be enabled, to disable bandgap please
909 * take care of other system resources.
910 *
911 * @param base SPC peripheral base address.
912 * @param mode The Bandgap mode be selected.
913 *
914 * @retval #kStatus_SPC_BandgapModeWrong The Bandgap can not be disabled in active mode.
915 * @retval #kStatus_Success Config Bandgap mode in Active power mode successful.
916 */
917 status_t SPC_SetActiveModeBandgapModeConfig(SPC_Type *base, spc_bandgap_mode_t mode);
918
919 #if (defined(FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT) && FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT)
920 /*!
921 * @brief Enables/Disable the CMP Bandgap Buffer in Active mode.
922 *
923 * @param base SPC peripheral base address.
924 * @param enable Enable/Disable CMP Bandgap buffer.
925 * true - Enable Buffer Stored Reference voltage to CMP.
926 * false - Disable Buffer Stored Reference voltage to CMP.
927 */
SPC_EnableActiveModeCMPBandgapBuffer(SPC_Type * base,bool enable)928 static inline void SPC_EnableActiveModeCMPBandgapBuffer(SPC_Type *base, bool enable)
929 {
930 if (enable)
931 {
932 base->ACTIVE_CFG |= SPC_ACTIVE_CFG_LPBUFF_EN_MASK;
933 }
934 else
935 {
936 base->ACTIVE_CFG &= ~SPC_ACTIVE_CFG_LPBUFF_EN_MASK;
937 }
938 }
939 #endif /* FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT */
940
941 /*!
942 * @brief Sets the delay when the regulators change voltage level in Active mode.
943 *
944 * @param base SPC peripheral base address.
945 * @param delay The number of SPC timer clock cycles.
946 */
SPC_SetActiveModeVoltageTrimDelay(SPC_Type * base,uint16_t delay)947 static inline void SPC_SetActiveModeVoltageTrimDelay(SPC_Type *base, uint16_t delay)
948 {
949 base->ACTIVE_VDELAY = SPC_ACTIVE_VDELAY_ACTIVE_VDELAY(delay);
950 }
951
952 /*!
953 * @brief Configs all settings of regulators in Active mode at a time.
954 *
955 * @note This function is used to overwrite all settings of regulators(including bandgap mode, regulators'
956 * drive strength and voltage level) in active mode at a time.
957 *
958 * @note Enable/disable LVDs/HVDs before invoking this function.
959 *
960 * @note This function will check input parameters based on hardware restrictions before setting registers, if input
961 * parameters do not satisfy hardware restrictions the specific error will be reported.
962 *
963 *
964 * @note Some hardware restrictions not covered, application should be aware of this and follow this hardware
965 * restrictions otherwise some unkown issue may occur:
966 * 1. If Core LDO's drive strength are set to same value in both Active mode and low power mode,
967 * the voltage level should also set to same value.
968 * 2. When switching Core LDO's drive strength from low to normal, ensure the LDO_CORE high voltage level is set
969 * to same level that was set prior to switching to the LDO_CORE drive strength. Otherwise, if the LVDs are
970 * enabled, an unexpected LVD can occur.
971 *
972 * @note If this function can not satisfy some tricky settings, please invoke other APIs in low-level function group.
973 *
974 * @param base SPC peripheral base address.
975 * @param config Pointer to spc_active_mode_regulators_config_t structure.
976 *
977 * @retval #kStatus_Success Config regulators in Active power mode successful.
978 * @retval #kStatus_SPC_BandgapModeWrong Based on input setting, bandgap can not be disabled.
979 * @retval #kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
980 * @retval #kStatus_SPC_CORELDOLowDriveStrengthIgnore Any of LVDs/HVDs kept enabled before invoking this function.
981 * @retval #kStatus_SPC_SYSLDOOverDriveVoltageFail Fail to regulator to Over Drive Voltage due to
982 * System VDD HVD is not disabled.
983 * @retval #kStatus_SPC_SYSLDOLowDriveStrengthIgnore Any of LVDs/HVDs kept enabled before invoking this function.
984 * @retval #kStatus_SPC_CORELDOVoltageWrong Core LDO and System LDO do not have same voltage level.
985 */
986 status_t SPC_SetActiveModeRegulatorsConfig(SPC_Type *base, const spc_active_mode_regulators_config_t *config);
987
988 #if !(defined(FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT) && FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT)
989 /*!
990 * @brief Disables/Enables VDD Core Glitch Detect in Active mode.
991 *
992 * @note State of glitch detect disable feature will be ignored if bandgap is disabled and
993 * glitch detect hardware will be forced to OFF state.
994 *
995 * @param base SPC peripheral base address.
996 * @param disable Used to disable/enable VDD Core Glitch detect feature.
997 * - \b true Disable VDD Core Low Voltage detect;
998 * - \b false Enable VDD Core Low Voltage detect.
999 */
SPC_DisableActiveModeVddCoreGlitchDetect(SPC_Type * base,bool disable)1000 static inline void SPC_DisableActiveModeVddCoreGlitchDetect(SPC_Type *base, bool disable)
1001 {
1002 if (disable)
1003 {
1004 base->ACTIVE_CFG |= SPC_ACTIVE_CFG_GLITCH_DETECT_DISABLE_MASK;
1005 }
1006 else
1007 {
1008 base->ACTIVE_CFG &= ~SPC_ACTIVE_CFG_GLITCH_DETECT_DISABLE_MASK;
1009 }
1010 }
1011
1012 /*!
1013 * @brief Check if Glitch detect hardware is enabled in active mode.
1014 *
1015 * @param base SPC peripheral base address.
1016 * @return Indicate if Glitch detector is enabled.
1017 */
SPC_CheckActiveModeVddCoreGlitchDetectEnabled(SPC_Type * base)1018 static inline bool SPC_CheckActiveModeVddCoreGlitchDetectEnabled(SPC_Type *base)
1019 {
1020 if ((base->ACTIVE_CFG & SPC_ACTIVE_CFG_GLITCH_DETECT_DISABLE_MASK) == 0UL)
1021 {
1022 return true;
1023 }
1024 else
1025 {
1026 return false;
1027 }
1028 }
1029
1030 #endif /* FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT */
1031
1032 /*!
1033 * @brief Enables analog modules in active mode.
1034 *
1035 * @param base SPC peripheral base address.
1036 * @param maskValue The mask of analog modules to enable in active mode, should be the OR'ed value
1037 * of @ref spc_analog_module_control.
1038 */
SPC_EnableActiveModeAnalogModules(SPC_Type * base,uint32_t maskValue)1039 static inline void SPC_EnableActiveModeAnalogModules(SPC_Type *base, uint32_t maskValue)
1040 {
1041 base->ACTIVE_CFG1 |= SPC_ACTIVE_CFG1_SOC_CNTRL(maskValue);
1042 }
1043
1044 /*!
1045 * @brief Disables analog modules in active mode.
1046 *
1047 * @param base SPC peripheral base address.
1048 * @param maskValue The mask of analog modules to disable in active mode, should be the OR'ed value
1049 * of @ref spc_analog_module_control.
1050 */
SPC_DisableActiveModeAnalogModules(SPC_Type * base,uint32_t maskValue)1051 static inline void SPC_DisableActiveModeAnalogModules(SPC_Type *base, uint32_t maskValue)
1052 {
1053 base->ACTIVE_CFG1 &= ~SPC_ACTIVE_CFG1_SOC_CNTRL(maskValue);
1054 }
1055
1056 /*!
1057 * @brief Gets enabled analog modules that enabled in active mode.
1058 *
1059 * @param base SPC peripheral base address.
1060 *
1061 * @return The mask of enabled analog modules that enabled in active mode.
1062 */
SPC_GetActiveModeEnabledAnalogModules(SPC_Type * base)1063 static inline uint32_t SPC_GetActiveModeEnabledAnalogModules(SPC_Type *base)
1064 {
1065 return base->ACTIVE_CFG1;
1066 }
1067
1068 /*! @} */
1069
1070 /*!
1071 * @name Low Power mode configuration
1072 * @{
1073 */
1074
1075 /*!
1076 * @brief Gets the Bandgap mode in Low Power mode.
1077 *
1078 * @param base SPC peripheral base address.
1079 * @return Bandgap mode in the type of @ref spc_bandgap_mode_t enumeration.
1080 */
SPC_GetLowPowerModeBandgapMode(SPC_Type * base)1081 static inline spc_bandgap_mode_t SPC_GetLowPowerModeBandgapMode(SPC_Type *base)
1082 {
1083 return (spc_bandgap_mode_t)(uint32_t)((base->LP_CFG & SPC_LP_CFG_BGMODE_MASK) >> SPC_LP_CFG_BGMODE_SHIFT);
1084 }
1085
1086 /*!
1087 * @brief Gets the status of all voltage detectors in Low Power mode.
1088 *
1089 * @param base SPC peripheral base address.
1090 * @return The status of all voltage detectors in low power mode.
1091 */
SPC_GetLowPowerModeVoltageDetectStatus(SPC_Type * base)1092 static inline uint32_t SPC_GetLowPowerModeVoltageDetectStatus(SPC_Type *base)
1093 {
1094 uint32_t state;
1095 state = base->LP_CFG & (
1096 #if (defined(FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD) && FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD)
1097 SPC_LP_CFG_IO_HVDE_MASK | SPC_LP_CFG_IO_LVDE_MASK |
1098
1099 #endif /* FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD */
1100 SPC_LP_CFG_SYS_HVDE_MASK | SPC_LP_CFG_SYS_LVDE_MASK | SPC_LP_CFG_CORE_LVDE_MASK
1101
1102 #if (defined(FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD) && FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD)
1103 | SPC_LP_CFG_CORE_HVDE_MASK
1104
1105 #endif /* FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD */
1106 );
1107 return state;
1108 }
1109
1110 /*!
1111 * @brief Enables/Disables Low Power IREF in low power modes.
1112 *
1113 * This function enables/disables Low Power IREF. Low Power IREF can only get
1114 * disabled in Deep power down mode. In other low power modes, the Low Power IREF
1115 * is always enabled.
1116 *
1117 * @param base SPC peripheral base address.
1118 * @param enable Enable/Disable Low Power IREF.
1119 * true - Enable Low Power IREF for Low Power modes.
1120 * false - Disable Low Power IREF for Deep Power Down mode.
1121 */
SPC_EnableLowPowerModeLowPowerIREF(SPC_Type * base,bool enable)1122 static inline void SPC_EnableLowPowerModeLowPowerIREF(SPC_Type *base, bool enable)
1123 {
1124 if (enable)
1125 {
1126 base->LP_CFG |= SPC_LP_CFG_LP_IREFEN_MASK;
1127 }
1128 else
1129 {
1130 base->LP_CFG &= ~SPC_LP_CFG_LP_IREFEN_MASK;
1131 }
1132 }
1133
1134 /*!
1135 * @brief Configs Bandgap mode in Low Power mode.
1136 *
1137 * @note To disable Bandgap in Low-power mode:
1138 * 1. Disable all LVD's ad HVD's in low power mode;
1139 * 2. Disable Glitch detect in low power mode;
1140 * 3. Configure LDO's and DCDC to low drive strength in low power mode;
1141 * 4. Disable bandgap in low power mode;
1142 * Otherwise, the error status will be reported.
1143 *
1144 * @note Some other system resources(such as PLL, CMP) require bandgap to be enabled, to disable bandgap please
1145 * take care of other system resources.
1146 *
1147 * @param base SPC peripheral base address.
1148 * @param mode The Bandgap mode be selected.
1149 *
1150 * @retval #kStatus_SPC_BandgapModeWrong The bandgap mode setting in Low Power mode is wrong.
1151 * @retval #kStatus_Success Config Bandgap mode in Low Power power mode successful.
1152 */
1153 status_t SPC_SetLowPowerModeBandgapmodeConfig(SPC_Type *base, spc_bandgap_mode_t mode);
1154
1155 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SRAMLDO_DPD_ON_BIT) && FSL_FEATURE_MCX_SPC_HAS_SRAMLDO_DPD_ON_BIT)
1156 /*!
1157 * @brief Enables/disables SRAM_LDO deep power low power IREF.
1158 *
1159 * @param base SPC peripheral base address.
1160 * @param enable Used to enable/disable low power IREF :
1161 * - \b true: Low Power IREF is enabled ;
1162 * - \b false: Low Power IREF is disabled for power saving.
1163 */
SPC_EnableSRAMLdOLowPowerModeIREF(SPC_Type * base,bool enable)1164 static inline void SPC_EnableSRAMLdOLowPowerModeIREF(SPC_Type *base, bool enable)
1165 {
1166 if (enable)
1167 {
1168 base->LP_CFG |= SPC_LP_CFG_SRAMLDO_DPD_ON_MASK;
1169 }
1170 else
1171 {
1172 base->LP_CFG &= ~SPC_LP_CFG_SRAMLDO_DPD_ON_MASK;
1173 }
1174 }
1175 #endif /* FSL_FEATURE_MCX_SPC_HAS_SRAMLDO_DPD_ON_BIT */
1176
1177 #if (defined(FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT) && FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT)
1178 /*!
1179 * @brief Enables/Disables CMP Bandgap Buffer.
1180 *
1181 * This function gates CMP bandgap buffer. CMP bandgap buffer is automatically disabled and turned off
1182 * in Deep Power Down mode.
1183 *
1184 * @deprecated No longer used, please use SPC_EnableLowPowerModeCMPBandgapBuffer as instead.
1185 *
1186 * @param base SPC peripheral base address.
1187 * @param enable Enable/Disable CMP Bandgap buffer.
1188 * true - Enable Buffer Stored Reference Voltage to CMP.
1189 * false - Disable Buffer Stored Reference Voltage to CMP.
1190 */
SPC_EnableLowPowerModeCMPBandgapBufferMode(SPC_Type * base,bool enable)1191 static inline void SPC_EnableLowPowerModeCMPBandgapBufferMode(SPC_Type *base, bool enable)
1192 {
1193 if (enable)
1194 {
1195 base->LP_CFG |= SPC_LP_CFG_LPBUFF_EN_MASK;
1196 }
1197 else
1198 {
1199 base->LP_CFG &= ~SPC_LP_CFG_LPBUFF_EN_MASK;
1200 }
1201 }
1202
1203 /*!
1204 * @brief Enables/Disables CMP Bandgap Buffer.
1205 *
1206 * This function gates CMP bandgap buffer. CMP bandgap buffer is automatically disabled and turned off
1207 * in Deep Power Down mode.
1208 *
1209 * @deprecated No longer used.
1210 *
1211 * @param base SPC peripheral base address.
1212 * @param enable Enable/Disable CMP Bandgap buffer.
1213 * true - Enable Buffer Stored Reference Voltage to CMP.
1214 * false - Disable Buffer Stored Reference Voltage to CMP.
1215 */
SPC_EnableLowPowerModeCMPBandgapBuffer(SPC_Type * base,bool enable)1216 static inline void SPC_EnableLowPowerModeCMPBandgapBuffer(SPC_Type *base, bool enable)
1217 {
1218 if (enable)
1219 {
1220 base->LP_CFG |= SPC_LP_CFG_LPBUFF_EN_MASK;
1221 }
1222 else
1223 {
1224 base->LP_CFG &= ~SPC_LP_CFG_LPBUFF_EN_MASK;
1225 }
1226 }
1227 #endif /* FSL_FEATURE_MCX_SPC_HAS_LPBUFF_EN_BIT */
1228
1229 #if (defined(FSL_FEATURE_MCX_SPC_HAS_COREVDD_IVS_EN_BIT) && FSL_FEATURE_MCX_SPC_HAS_COREVDD_IVS_EN_BIT)
1230 /*!
1231 * @brief Enables/Disables CORE VDD IVS(Internal Voltage Scaling) in power down modes.
1232 *
1233 * This function gates CORE VDD IVS. When enabled, the IVS regulator will scale the
1234 * external input CORE VDD to a lower voltage level to reduce internal leakage.
1235 * IVS is invalid in Sleep or Deep power down mode.
1236 *
1237 * @param base SPC peripheral base address.
1238 * @param enable Enable/Disable IVS.
1239 * true - enable CORE VDD IVS in Power Down mode.
1240 * false - disable CORE VDD IVS in Power Down mode.
1241 */
SPC_EnableLowPowerModeCoreVDDInternalVoltageScaling(SPC_Type * base,bool enable)1242 static inline void SPC_EnableLowPowerModeCoreVDDInternalVoltageScaling(SPC_Type *base, bool enable)
1243 {
1244 if (enable)
1245 {
1246 base->LP_CFG |= SPC_LP_CFG_COREVDD_IVS_EN_MASK;
1247 }
1248 else
1249 {
1250 base->LP_CFG &= ~SPC_LP_CFG_COREVDD_IVS_EN_MASK;
1251 }
1252 }
1253 #endif /* FSL_FEATURE_MCX_SPC_HAS_COREVDD_IVS_EN_BIT */
1254
1255 /*!
1256 * @brief Sets the delay when exit the low power modes.
1257 *
1258 * @param base SPC peripheral base address.
1259 * @param delay The number of SPC timer clock cycles that the SPC waits on exit from low power modes.
1260 */
SPC_SetLowPowerWakeUpDelay(SPC_Type * base,uint16_t delay)1261 static inline void SPC_SetLowPowerWakeUpDelay(SPC_Type *base, uint16_t delay)
1262 {
1263 base->LPWKUP_DELAY = SPC_LPWKUP_DELAY_LPWKUP_DELAY(delay);
1264 }
1265
1266 /*!
1267 * @brief Configs all settings of regulators in Low power mode at a time.
1268 *
1269 * @note This function is used to overwrite all settings of regulators(including bandgap mode, regulators'
1270 * drive strength and voltage level) in low power mode at a time.
1271 *
1272 * @note Enable/disable LVDs/HVDs before invoking this function.
1273 *
1274 * @note This function will check input parameters based on hardware restrictions before setting registers, if input
1275 * parameters do not satisfy hardware restrictions the specific error will be reported.
1276 *
1277 * @note Some hardware restrictions not covered, application should be aware of this and follow this hardware
1278 * restrictions otherwise some unkown issue may occur:
1279 * 1. If Core LDO's drive strength are set to same value in both Active mode and low power mode,
1280 * the voltage level should also set to same value.
1281 * 2. When switching Core LDO's drive strength from low to normal, ensure the LDO_CORE high voltage level is set
1282 * to same level that was set prior to switching to the LDO_CORE drive strength. Otherwise, if the LVDs are
1283 * enabled, an unexpected LVD can occur.
1284 *
1285 * @note If this function can not satisfy some tricky settings, please invoke other APIs in low-level function group.
1286 *
1287 * @param base SPC peripheral base address.
1288 * @param config Pointer to spc_lowpower_mode_regulators_config_t structure.
1289 * @retval #kStatus_Success Config regulators in Low power mode successful.
1290 * @retval #kStatus_SPC_BandgapModeWrong The bandgap should not be disabled based on input settings.
1291 * @retval #kStatus_SPC_CORELDOLowDriveStrengthIgnore Set driver strength to low will be ignored.
1292 * @retval #kStatus_SPC_SYSLDOLowDriveStrengthIgnore Set driver strength to low will be ignored.
1293 * @retval #kStatus_SPC_CORELDOVoltageWrong Core LDO and System LDO do not have same voltage level.
1294 */
1295 status_t SPC_SetLowPowerModeRegulatorsConfig(SPC_Type *base, const spc_lowpower_mode_regulators_config_t *config);
1296
1297 #if !(defined(FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT) && FSL_FEATURE_MCX_SPC_HAS_NO_GLITCH_DETECT)
1298 /*!
1299 * @brief Disable/Enable VDD Core Glitch Detect in low power mode.
1300 *
1301 * @note State of glitch detect disable feature will be ignored if bandgap is disabled and
1302 * glitch detect hardware will be forced to OFF state.
1303 *
1304 * @param base SPC peripheral base address.
1305 * @param disable Used to disable/enable VDD Core Glitch detect feature.
1306 * - \b true Disable VDD Core Low Voltage detect;
1307 * - \b false Enable VDD Core Low Voltage detect.
1308 */
SPC_DisableLowPowerModeVddCoreGlitchDetect(SPC_Type * base,bool disable)1309 static inline void SPC_DisableLowPowerModeVddCoreGlitchDetect(SPC_Type *base, bool disable)
1310 {
1311 if (disable)
1312 {
1313 base->LP_CFG |= SPC_LP_CFG_GLITCH_DETECT_DISABLE_MASK;
1314 }
1315 else
1316 {
1317 base->LP_CFG &= ~SPC_LP_CFG_GLITCH_DETECT_DISABLE_MASK;
1318 }
1319 }
1320
1321 /*!
1322 * @brief Check if Glitch detect hardware is enabled in low power mode.
1323 *
1324 * @param base SPC peripheral base address.
1325 * @return Indicate if Glitch detector is enabled.
1326 */
SPC_CheckLowPowerModeVddCoreGlitchDetectEnabled(SPC_Type * base)1327 static inline bool SPC_CheckLowPowerModeVddCoreGlitchDetectEnabled(SPC_Type *base)
1328 {
1329 if ((base->LP_CFG & SPC_LP_CFG_GLITCH_DETECT_DISABLE_MASK) == 0UL)
1330 {
1331 return true;
1332 }
1333 else
1334 {
1335 return false;
1336 }
1337 }
1338 #endif
1339
1340 /*!
1341 * @brief Enables analog modules in low power modes.
1342 *
1343 * @param base SPC peripheral base address.
1344 * @param maskValue The mask of analog modules to enable in low power modes, should be OR'ed value
1345 of @ref spc_analog_module_control.
1346 */
SPC_EnableLowPowerModeAnalogModules(SPC_Type * base,uint32_t maskValue)1347 static inline void SPC_EnableLowPowerModeAnalogModules(SPC_Type *base, uint32_t maskValue)
1348 {
1349 base->LP_CFG1 |= SPC_LP_CFG1_SOC_CNTRL(maskValue);
1350 }
1351
1352 /*!
1353 * @brief Disables analog modules in low power modes.
1354 *
1355 * @param base SPC peripheral base address.
1356 * @param maskValue The mask of analog modules to disable in low power modes, should be OR'ed value
1357 of @ref spc_analog_module_control.
1358 */
SPC_DisableLowPowerModeAnalogModules(SPC_Type * base,uint32_t maskValue)1359 static inline void SPC_DisableLowPowerModeAnalogModules(SPC_Type *base, uint32_t maskValue)
1360 {
1361 base->LP_CFG1 &= ~SPC_LP_CFG1_SOC_CNTRL(maskValue);
1362 }
1363
1364 /*!
1365 * @brief Gets enabled analog modules that enabled in low power modes.
1366 *
1367 * @param base SPC peripheral base address.
1368 *
1369 * @return The mask of enabled analog modules that enabled in low power modes.
1370 */
SPC_GetLowPowerModeEnabledAnalogModules(SPC_Type * base)1371 static inline uint32_t SPC_GetLowPowerModeEnabledAnalogModules(SPC_Type *base)
1372 {
1373 return base->LP_CFG1;
1374 }
1375
1376 /*! @} */
1377
1378 /*!
1379 * @name Voltage Detect Status
1380 * @{
1381 */
1382 /*!
1383 * @brief Get Voltage Detect Status Flags.
1384 *
1385 * @param base SPC peripheral base address.
1386 * @return Voltage Detect Status Flags. See @ref _spc_voltage_detect_flags for details.
1387 */
SPC_GetVoltageDetectStatusFlag(SPC_Type * base)1388 static inline uint8_t SPC_GetVoltageDetectStatusFlag(SPC_Type *base)
1389 {
1390 return (uint8_t)(base->VD_STAT);
1391 }
1392
1393 /*!
1394 * @brief Clear Voltage Detect Status Flags.
1395 *
1396 * @param base SPC peripheral base address.
1397 * @param mask The mask of the voltage detect status flags. See @ref _spc_voltage_detect_flags for details.
1398 */
SPC_ClearVoltageDetectStatusFlag(SPC_Type * base,uint8_t mask)1399 static inline void SPC_ClearVoltageDetectStatusFlag(SPC_Type *base, uint8_t mask)
1400 {
1401 base->VD_STAT |= mask;
1402 }
1403
1404 /*! @} */
1405
1406 /*!
1407 * @name Voltage Detect configuration for Core voltage domain.
1408 * @{
1409 */
1410
1411 /*!
1412 * @brief Configs CORE voltage detect options.
1413 *
1414 * @note: Setting both the voltage detect interrupt and reset
1415 * enable will cause interrupt to be generated on exit from reset.
1416 * If those conditioned is not desired, interrupt/reset so only one is enabled.
1417 *
1418 * @param base SPC peripheral base address.
1419 * @param config Pointer to spc_core_voltage_detect_config_t structure.
1420 */
1421 void SPC_SetCoreVoltageDetectConfig(SPC_Type *base, const spc_core_voltage_detect_config_t *config);
1422
1423 /*!
1424 * @brief Locks Core voltage detect reset setting.
1425 *
1426 * This function locks core voltage detect reset setting. After invoking this function
1427 * any configuration of Core voltage detect reset will be ignored.
1428 *
1429 * @param base SPC peripheral base address.
1430 */
SPC_LockCoreVoltageDetectResetSetting(SPC_Type * base)1431 static inline void SPC_LockCoreVoltageDetectResetSetting(SPC_Type *base)
1432 {
1433 base->VD_CORE_CFG |= SPC_VD_CORE_CFG_LOCK_MASK;
1434 }
1435
1436 /*!
1437 * @brief Unlocks Core voltage detect reset setting.
1438 *
1439 * This function unlocks core voltage detect reset setting. If locks the Core
1440 * voltage detect reset setting, invoking this function to unlock.
1441 *
1442 * @param base SPC peripheral base address.
1443 */
SPC_UnlockCoreVoltageDetectResetSetting(SPC_Type * base)1444 static inline void SPC_UnlockCoreVoltageDetectResetSetting(SPC_Type *base)
1445 {
1446 base->VD_CORE_CFG &= ~SPC_VD_CORE_CFG_LOCK_MASK;
1447 }
1448
1449 /*!
1450 * @brief Enables/Disables the Core Low Voltage Detector in Active mode.
1451 *
1452 * @note If the CORE_LDO low voltage detect is enabled in Active mode, please note that the bandgap must be enabled
1453 * and the drive strength of each regulator must not set to low.
1454 *
1455 * @param base SPC peripheral base address.
1456 * @param enable Enable/Disable Core LVD.
1457 * true - Enable Core Low voltage detector in active mode.
1458 * false - Disable Core Low voltage detector in active mode.
1459 *
1460 * @retval #kStatus_Success Enable/Disable Core Low Voltage Detect successfully.
1461 */
1462 status_t SPC_EnableActiveModeCoreLowVoltageDetect(SPC_Type *base, bool enable);
1463
1464 /*!
1465 * @brief Enables/Disables the Core Low Voltage Detector in Low Power mode.
1466 *
1467 * This function enables/disables the Core Low Voltage Detector.
1468 * If enabled the Core Low Voltage detector. The Bandgap mode in
1469 * low power mode must be programmed so that Bandgap is enabled.
1470 *
1471 * @note If the CORE_LDO low voltage detect is enabled in Low Power mode, please note that the bandgap must be enabled
1472 * and the drive strength of each regulator must not set to low in Low Power mode.
1473 *
1474 * @param base SPC peripheral base address.
1475 * @param enable Enable/Disable Core HVD.
1476 * true - Enable Core Low voltage detector in low power mode.
1477 * false - Disable Core Low voltage detector in low power mode.
1478 *
1479 * @retval #kStatus_Success Enable/Disable Core Low Voltage Detect in low power mode successfully.
1480 */
1481 status_t SPC_EnableLowPowerModeCoreLowVoltageDetect(SPC_Type *base, bool enable);
1482
1483 #if (defined(FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD) && FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD)
1484 /*!
1485 * @brief Enables/Disables the Core High Voltage Detector in Active mode.
1486 *
1487 * @note If the CORE_LDO high voltage detect is enabled in Active mode, please note that the bandgap must be enabled
1488 * and the drive strength of each regulator must not set to low.
1489 *
1490 * @param base SPC peripheral base address.
1491 * @param enable Enable/Disable Core HVD.
1492 * true - Enable Core High voltage detector in active mode.
1493 * false - Disable Core High voltage detector in active mode.
1494 *
1495 * @retval #kStatus_Success Enable/Disable Core High Voltage Detect successfully.
1496 */
1497 status_t SPC_EnableActiveModeCoreHighVoltageDetect(SPC_Type *base, bool enable);
1498
1499 /*!
1500 * @brief Enables/Disables the Core High Voltage Detector in Low Power mode.
1501 *
1502 * This function enables/disables the Core High Voltage Detector.
1503 * If enabled the Core High Voltage detector. The Bandgap mode in
1504 * low power mode must be programmed so that Bandgap is enabled.
1505 *
1506 * @note If the CORE_LDO high voltage detect is enabled in Low Power mode, please note that the bandgap must be enabled
1507 * and the drive strength of each regulator must not set to low in low power mode.
1508 *
1509 * @param base SPC peripheral base address.
1510 * @param enable Enable/Disable Core HVD.
1511 * true - Enable Core High voltage detector in low power mode.
1512 * false - Disable Core High voltage detector in low power mode.
1513 *
1514 * @retval #kStatus_Success Enable/Disable Core High Voltage Detect in low power mode successfully.
1515 */
1516 status_t SPC_EnableLowPowerModeCoreHighVoltageDetect(SPC_Type *base, bool enable);
1517 #endif /* FSL_FEATURE_MCX_SPC_HAS_COREVDD_HVD */
1518
1519 /*! @} */
1520
1521 /*!
1522 * @name Voltage detect configuration for System Voltage domain
1523 * @{
1524 */
1525 /*!
1526 * @brief Set system VDD Low-voltage level selection.
1527 *
1528 * This function selects the system VDD low-voltage level. Changing system VDD low-voltage level
1529 * must be done after disabling the System VDD low voltage reset and interrupt.
1530 *
1531 * @deprecated In latest RM, reserved for all devices, will removed in next release.
1532 *
1533 * @param base SPC peripheral base address.
1534 * @param level System VDD Low-Voltage level selection.
1535 */
1536 void SPC_SetSystemVDDLowVoltageLevel(SPC_Type *base, spc_low_voltage_level_select_t level);
1537
1538 /*!
1539 * @brief Configs SYS voltage detect options.
1540 *
1541 * This function config SYS voltage detect options.
1542 * @note: Setting both the voltage detect interrupt and reset
1543 * enable will cause interrupt to be generated on exit from reset.
1544 * If those conditioned is not desired, interrupt/reset so only one is enabled.
1545 *
1546 * @param base SPC peripheral base address.
1547 * @param config Pointer to spc_system_voltage_detect_config_t structure.
1548 */
1549 void SPC_SetSystemVoltageDetectConfig(SPC_Type *base, const spc_system_voltage_detect_config_t *config);
1550
1551 /*!
1552 * @brief Lock System voltage detect reset setting.
1553 *
1554 * This function locks system voltage detect reset setting. After invoking this function
1555 * any configuration of System Voltage detect reset will be ignored.
1556 *
1557 * @param base SPC peripheral base address.
1558 */
SPC_LockSystemVoltageDetectResetSetting(SPC_Type * base)1559 static inline void SPC_LockSystemVoltageDetectResetSetting(SPC_Type *base)
1560 {
1561 base->VD_SYS_CFG |= SPC_VD_SYS_CFG_LOCK_MASK;
1562 }
1563
1564 /*!
1565 * @brief Unlock System voltage detect reset setting.
1566 *
1567 * This function unlocks system voltage detect reset setting. If locks the System
1568 * voltage detect reset setting, invoking this function to unlock.
1569 *
1570 * @param base SPC peripheral base address.
1571 */
SPC_UnlockSystemVoltageDetectResetSetting(SPC_Type * base)1572 static inline void SPC_UnlockSystemVoltageDetectResetSetting(SPC_Type *base)
1573 {
1574 base->VD_SYS_CFG &= ~SPC_VD_SYS_CFG_LOCK_MASK;
1575 }
1576
1577 /*!
1578 * @brief Enables/Disables the System High Voltage Detector in Active mode.
1579 *
1580 * @note If the System_LDO high voltage detect is enabled in Active mode, please note that the bandgap must be enabled
1581 * and the drive strength of each regulator must not set to low in Active mode.
1582 *
1583 * @param base SPC peripheral base address.
1584 * @param enable Enable/Disable System HVD.
1585 * true - Enable System High voltage detector in active mode.
1586 * false - Disable System High voltage detector in active mode.
1587 *
1588 * @retval #kStatus_Success Enable/Disable System High Voltage Detect successfully.
1589 */
1590 status_t SPC_EnableActiveModeSystemHighVoltageDetect(SPC_Type *base, bool enable);
1591
1592 /*!
1593 * @brief Enables/Disable the System Low Voltage Detector in Active mode.
1594 *
1595 * @note If the System_LDO low voltage detect is enabled in Active mode,
1596 * please note that the bandgap must be enabled and the drive strength of each
1597 * regulator must not set to low in Active mode.
1598 *
1599 * @param base SPC peripheral base address.
1600 * @param enable Enable/Disable System LVD.
1601 * true - Enable System Low voltage detector in active mode.
1602 * false - Disable System Low voltage detector in active mode.
1603 *
1604 * @retval #kStatus_Success Enable/Disable the System Low Voltage Detect successfully.
1605 */
1606 status_t SPC_EnableActiveModeSystemLowVoltageDetect(SPC_Type *base, bool enable);
1607
1608 /*!
1609 * @brief Enables/Disables the System High Voltage Detector in Low Power mode.
1610 *
1611 * @note If the System_LDO high voltage detect is enabled in Low Power mode, please note
1612 * that the bandgap must be enabled and the drive strength of each regulator must
1613 * not set to low in Low Power mode.
1614 *
1615 * @param base SPC peripheral base address.
1616 * @param enable Enable/Disable System HVD.
1617 * true - Enable System High voltage detector in low power mode.
1618 * false - Disable System High voltage detector in low power mode.
1619 *
1620 * @retval #kStatus_Success Enable/Disable System High Voltage Detect in low power mode successfully.
1621 */
1622 status_t SPC_EnableLowPowerModeSystemHighVoltageDetect(SPC_Type *base, bool enable);
1623
1624 /*!
1625 * @brief Enables/Disables the System Low Voltage Detector in Low Power mode.
1626 *
1627 * @note If the System_LDO low voltage detect is enabled in Low Power mode,
1628 * please note that the bandgap must be enabled and the drive strength of each
1629 * regulator must not set to low in Low Power mode.
1630 *
1631 * @param base SPC peripheral base address.
1632 * @param enable Enable/Disable System HVD.
1633 * true - Enable System Low voltage detector in low power mode.
1634 * false - Disable System Low voltage detector in low power mode.
1635 *
1636 * @retval #kStatus_Success Enables System Low Voltage Detect in low power mode successfully.
1637 */
1638 status_t SPC_EnableLowPowerModeSystemLowVoltageDetect(SPC_Type *base, bool enable);
1639
1640 /*! @} */
1641
1642 #if (defined(FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD) && FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD)
1643 /*!
1644 * @name Voltage detect configuration for IO voltage domain
1645 * @{
1646 */
1647 /*!
1648 * @brief Set IO VDD Low-Voltage level selection.
1649 *
1650 * This function selects the IO VDD Low-voltage level. Changing IO VDD low-voltage level
1651 * must be done after disabling the IO VDD low voltage reset and interrupt.
1652 *
1653 * @param base SPC peripheral base address.
1654 * @param level IO VDD Low-voltage level selection.
1655 */
1656 void SPC_SetIOVDDLowVoltageLevel(SPC_Type *base, spc_low_voltage_level_select_t level);
1657
1658 /*!
1659 * @brief Configs IO voltage detect options.
1660 *
1661 * This function config IO voltage detect options.
1662 * @note: Setting both the voltage detect interrupt and reset
1663 * enable will cause interrupt to be generated on exit from reset.
1664 * If those conditioned is not desired, interrupt/reset so only one is enabled.
1665 *
1666 * @param base SPC peripheral base address.
1667 * @param config Pointer to spc_voltage_detect_config_t structure.
1668 */
1669 void SPC_SetIOVoltageDetectConfig(SPC_Type *base, const spc_io_voltage_detect_config_t *config);
1670
1671 /*!
1672 * @brief Lock IO Voltage detect reset setting.
1673 *
1674 * This function locks IO voltage detect reset setting. After invoking this function
1675 * any configuration of system voltage detect reset will be ignored.
1676 *
1677 * @param base SPC peripheral base address.
1678 */
SPC_LockIOVoltageDetectResetSetting(SPC_Type * base)1679 static inline void SPC_LockIOVoltageDetectResetSetting(SPC_Type *base)
1680 {
1681 base->VD_IO_CFG |= SPC_VD_IO_CFG_LOCK_MASK;
1682 }
1683
1684 /*!
1685 * @brief Unlock IO voltage detect reset setting.
1686 *
1687 * This function unlocks IO voltage detect reset setting. If locks the IO
1688 * voltage detect reset setting, invoking this function to unlock.
1689 *
1690 * @param base SPC peripheral base address.
1691 */
SPC_UnlockIOVoltageDetectResetSetting(SPC_Type * base)1692 static inline void SPC_UnlockIOVoltageDetectResetSetting(SPC_Type *base)
1693 {
1694 base->VD_IO_CFG &= ~SPC_VD_IO_CFG_LOCK_MASK;
1695 }
1696
1697 /*!
1698 * @brief Enables/Disables the IO High Voltage Detector in Active mode.
1699 *
1700 * @note If the IO high voltage detect is enabled in Active mode, please note that the bandgap must be enabled
1701 * and the drive strength of each regulator must not set to low in Active mode.
1702 *
1703 * @param base SPC peripheral base address.
1704 * @param enable Enable/Disable IO HVD.
1705 * true - Enable IO High voltage detector in active mode.
1706 * false - Disable IO High voltage detector in active mode.
1707 *
1708 * @retval #kStatus_Success Enable/Disable IO High Voltage Detect successfully.
1709 */
1710 status_t SPC_EnableActiveModeIOHighVoltageDetect(SPC_Type *base, bool enable);
1711
1712 /*!
1713 * @brief Enables/Disables the IO Low Voltage Detector in Active mode.
1714 *
1715 * @note If the IO low voltage detect is enabled in Active mode, please note that the bandgap must be enabled
1716 * and the drive strength of each regulator must not set to low in Active mode.
1717 *
1718 * @param base SPC peripheral base address.
1719 * @param enable Enable/Disable IO LVD.
1720 * true - Enable IO Low voltage detector in active mode.
1721 * false - Disable IO Low voltage detector in active mode.
1722 *
1723 * @retval #kStatus_Success Enable IO Low Voltage Detect successfully.
1724 */
1725 status_t SPC_EnableActiveModeIOLowVoltageDetect(SPC_Type *base, bool enable);
1726
1727 /*!
1728 * @brief Enables/Disables the IO High Voltage Detector in Low Power mode.
1729 *
1730 * @note If the IO high voltage detect is enabled in Low Power mode, please note that the bandgap must be enabled
1731 * and the drive strength of each regulator must not set to low in Low Power mode.
1732 *
1733 * @param base SPC peripheral base address.
1734 * @param enable Enable/Disable IO HVD.
1735 * true - Enable IO High voltage detector in low power mode.
1736 * false - Disable IO High voltage detector in low power mode.
1737 *
1738 * @retval #kStatus_Success Enable IO High Voltage Detect in low power mode successfully.
1739 */
1740 status_t SPC_EnableLowPowerModeIOHighVoltageDetect(SPC_Type *base, bool enable);
1741
1742 /*!
1743 * @brief Enables/Disables the IO Low Voltage Detector in Low Power mode.
1744 *
1745 * @note If the IO low voltage detect is enabled in Low Power mode, please note that the bandgap must be enabled
1746 * and the drive strength of each regulator must not set to low in Low Power mode.
1747 *
1748 * @param base SPC peripheral base address.
1749 * @param enable Enable/Disable IO LVD.
1750 * true - Enable IO Low voltage detector in low power mode.
1751 * false - Disable IO Low voltage detector in low power mode.
1752 *
1753 * @retval #kStatus_Success Enable/Disable IO Low Voltage Detect in low power mode successfully.
1754 */
1755 status_t SPC_EnableLowPowerModeIOLowVoltageDetect(SPC_Type *base, bool enable);
1756
1757 /*! @} */
1758
1759 #endif /* FSL_FEATURE_MCX_SPC_HAS_IOVDD_VD */
1760
1761 /*!
1762 * @name External Voltage domains configuration
1763 * @{
1764 */
1765 /*!
1766 * @brief Configs external voltage domains
1767 *
1768 * This function configs external voltage domains isolation.
1769 *
1770 * @param base SPC peripheral base address.
1771 * @param lowPowerIsoMask The mask of external domains isolate enable during low power mode. Please read the Reference
1772 * Manual for the Bitmap.
1773 * @param IsoMask The mask of external domains isolate. Please read the Reference Manual for the Bitmap.
1774 */
1775 void SPC_SetExternalVoltageDomainsConfig(SPC_Type *base, uint8_t lowPowerIsoMask, uint8_t IsoMask);
1776
1777 /*!
1778 * @brief Gets External Domains status.
1779 *
1780 * @param base SPC peripheral base address.
1781 * @return The status of each external domain.
1782 */
SPC_GetExternalDomainsStatus(SPC_Type * base)1783 static inline uint8_t SPC_GetExternalDomainsStatus(SPC_Type *base)
1784 {
1785 return (uint8_t)(base->EVD_CFG >> SPC_EVD_CFG_REG_EVDSTAT_SHIFT);
1786 }
1787
1788 /*! @} */
1789
1790 /*!
1791 * @name Low Level APIs To Set CORE LDO Regulator
1792 * @{
1793 */
1794
1795 #if (defined(FSL_FEATURE_MCX_SPC_HAS_CNTRL_REG) && FSL_FEATURE_MCX_SPC_HAS_CNTRL_REG)
1796 /*!
1797 * @brief Enable/Disable Core LDO regulator.
1798 *
1799 * @note The CORE LDO enable bit is write-once.
1800 *
1801 * @param base SPC peripheral base address.
1802 * @param enable Enable/Disable CORE LDO Regulator.
1803 * true - Enable CORE LDO Regulator.
1804 * false - Disable CORE LDO Regulator.
1805 */
SPC_EnableCoreLDORegulator(SPC_Type * base,bool enable)1806 static inline void SPC_EnableCoreLDORegulator(SPC_Type *base, bool enable)
1807 {
1808 if (enable)
1809 {
1810 base->CNTRL |= SPC_CNTRL_CORELDO_EN_MASK;
1811 }
1812 else
1813 {
1814 /*
1815 * $Branch Coverage Justification$
1816 * If CORE_LDO is disabled, all RAMs data will powered off.
1817 */
1818 base->CNTRL &= ~SPC_CNTRL_CORELDO_EN_MASK;
1819 }
1820 }
1821 #endif /* FSL_FEATURE_MCX_SPC_HAS_CNTRL_REG */
1822
1823 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DPDOWN_PULLDOWN_DISABLE_BIT) && \
1824 FSL_FEATURE_MCX_SPC_HAS_DPDOWN_PULLDOWN_DISABLE_BIT)
1825 /*!
1826 * @brief Enable/Disable the CORE LDO Regulator pull down in Deep Power Down.
1827 *
1828 * @note This function only useful when enabled the CORE LDO Regulator.
1829 *
1830 * @param base SPC peripheral base address.
1831 * @param pulldown Enable/Disable CORE LDO pulldown in Deep Power Down mode.
1832 * true - CORE LDO Regulator will discharge in Deep Power Down mode.
1833 * false - CORE LDO Regulator will not discharge in Deep Power Down mode.
1834 */
SPC_PullDownCoreLDORegulator(SPC_Type * base,bool pulldown)1835 static inline void SPC_PullDownCoreLDORegulator(SPC_Type *base, bool pulldown)
1836 {
1837 if (pulldown)
1838 {
1839 base->CORELDO_CFG &= ~SPC_CORELDO_CFG_DPDOWN_PULLDOWN_DISABLE_MASK;
1840 }
1841 else
1842 {
1843 base->CORELDO_CFG |= SPC_CORELDO_CFG_DPDOWN_PULLDOWN_DISABLE_MASK;
1844 }
1845 }
1846 #endif /* FSL_FEATURE_MCX_SPC_HAS_DPDOWN_PULLDOWN_DISABLE_BIT */
1847
1848 /*!
1849 * @brief Configs Core LDO Regulator in Active mode.
1850 *
1851 * @note The bandgap must be enabled before invoking this function.
1852 * @note To set Core LDO as low drive strength, all HVDs/LVDs must be disabled previously.
1853 *
1854 * @param base SPC peripheral base address.
1855 * @param option Pointer to the spc_active_mode_core_ldo_option_t structure.
1856 *
1857 * @retval kStatus_Success Config Core LDO regulator in Active power mode successful.
1858 * @retval kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
1859 * @retval kStatus_SPC_BandgapModeWrong Bandgap should be enabled before invoking this function.
1860 * @retval kStatus_SPC_CORELDOLowDriveStrengthIgnore To set Core LDO as low drive strength,
1861 * all LVDs/HVDs must be disabled before invoking this function.
1862 */
1863 status_t SPC_SetActiveModeCoreLDORegulatorConfig(SPC_Type *base, const spc_active_mode_core_ldo_option_t *option);
1864
1865 /*!
1866 * @brief Set Core LDO Regulator Voltage level in Active mode.
1867 *
1868 * @param base SPC peripheral base address.
1869 * @param voltageLevel Specify the voltage level of CORE LDO Regulator in Active mode, please
1870 refer to @ref spc_core_ldo_voltage_level_t.
1871 *
1872 * @note In active mode, the Core LDO voltage level should only be changed when the
1873 * Core LDO is in normal drive strength.
1874 *
1875 * @note Update Core LDO voltage level will set Busy flag,
1876 * this function return only when busy flag is cleared by hardware
1877 *
1878 * @retval kStatus_SPC_CORELDOVoltageSetFail The drive strength of Core LDO is not normal.
1879 * @retval kStatus_Success Set Core LDO regulator voltage level in Active power mode successful.
1880 */
1881 status_t SPC_SetActiveModeCoreLDORegulatorVoltageLevel(SPC_Type *base, spc_core_ldo_voltage_level_t voltageLevel);
1882
1883 /*!
1884 * @brief Gets CORE LDO Regulator Voltage level.
1885 *
1886 * This function returns the voltage level of CORE LDO Regulator in Active mode.
1887 *
1888 * @param base SPC peripheral base address.
1889 * @return Voltage level of CORE LDO in type of @ref spc_core_ldo_voltage_level_t enumeration.
1890 */
SPC_GetActiveModeCoreLDOVDDVoltageLevel(SPC_Type * base)1891 static inline spc_core_ldo_voltage_level_t SPC_GetActiveModeCoreLDOVDDVoltageLevel(SPC_Type *base)
1892 {
1893 return (spc_core_ldo_voltage_level_t)(uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_CORELDO_VDD_LVL_MASK) >>
1894 SPC_ACTIVE_CFG_CORELDO_VDD_LVL_SHIFT);
1895 }
1896
1897 #if (defined(FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS) && FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS)
1898 /*!
1899 * @brief Set Core LDO VDD Regulator Drive Strength in Active mode.
1900 *
1901 * @param base SPC peripheral base address.
1902 * @param driveStrength Specify the drive strength of CORE LDO Regulator in Active mode, please
1903 refer to @ref spc_core_ldo_drive_strength_t.
1904 *
1905 * @retval #kStatus_Success Set Core LDO regulator drive strength in Active power mode successful.
1906 * @retval #kStatus_SPC_CORELDOLowDriveStrengthIgnore If any voltage detect enabled,
1907 core_ldo's drive strength can not set to low.
1908 * @retval #kStatus_SPC_BandgapModeWrong The selected bandgap mode is not allowed.
1909 */
1910 status_t SPC_SetActiveModeCoreLDORegulatorDriveStrength(SPC_Type *base, spc_core_ldo_drive_strength_t driveStrength);
1911
1912 /*!
1913 * @brief Gets CORE LDO VDD Regulator Drive Strength in Active mode.
1914 *
1915 * @param base SPC peripheral base address.
1916 * @return Drive Strength of CORE LDO regulator in Active mode, please refer to @ref spc_core_ldo_drive_strength_t.
1917 */
SPC_GetActiveModeCoreLDODriveStrength(SPC_Type * base)1918 static inline spc_core_ldo_drive_strength_t SPC_GetActiveModeCoreLDODriveStrength(SPC_Type *base)
1919 {
1920 return (spc_core_ldo_drive_strength_t)(uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_CORELDO_VDD_DS_MASK) >>
1921 SPC_ACTIVE_CFG_CORELDO_VDD_DS_SHIFT);
1922 }
1923 #endif /* defined(FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS) && FSL_FEATURE_SPC_HAS_CORELDO_VDD_DS */
1924
1925 /*!
1926 * @brief Configs CORE LDO Regulator in low power mode
1927 *
1928 * This function configs CORE LDO Regulator in Low Power mode.
1929 * If CORE LDO VDD Drive Strength is set to Normal, the CORE LDO VDD regulator voltage
1930 * level in Active mode must be equal to the voltage level in Low power mode. And the Bandgap
1931 * must be programmed to select bandgap enabled.
1932 * Core VDD voltage levels for the Core LDO low power regulator can only be changed when the CORE
1933 * LDO Drive Strength set as Normal.
1934 *
1935 * @param base SPC peripheral base address.
1936 * @param option Pointer to the spc_lowpower_mode_core_ldo_option_t structure.
1937 *
1938 * @retval #kStatus_Success Config Core LDO regulator in power mode successfully.
1939 * @retval #kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
1940 * @retval #kStatus_SPC_CORELDOLowDriveStrengthIgnore Set driver strength to low will be ignored.
1941 * @retval #kStatus_SPC_CORELDOVoltageSetFail. Fail to change Core LDO voltage level.
1942 */
1943 status_t SPC_SetLowPowerModeCoreLDORegulatorConfig(SPC_Type *base, const spc_lowpower_mode_core_ldo_option_t *option);
1944
1945 /*!
1946 * @brief Set Core LDO VDD Regulator Voltage level in Low power mode.
1947 *
1948 * @note If CORE LDO's drive strength is set to Normal, the CORE LDO VDD regulator voltage in active mode and low power
1949 * mode must be same.
1950 * @note Voltage level for the CORE LDO in low power mode can only be changed when the CORE LDO Drive Strength set as
1951 * Normal.
1952 *
1953 * @param base SPC peripheral base address.
1954 * @param voltageLevel Voltage level of CORE LDO Regulator in Low power mode, please
1955 refer to @ref spc_core_ldo_voltage_level_t.
1956 *
1957 * @retval #kStatus_SPC_CORELDOVoltageWrong Voltage level in active mode and low power mode is not same.
1958 * @retval #kStatus_Success Set Core LDO regulator voltage level in Low power mode successful.
1959 * @retval #kStatus_SPC_CORELDOVoltageSetFail Fail to update voltage level because drive strength is incorrect.
1960 */
1961 status_t SPC_SetLowPowerModeCoreLDORegulatorVoltageLevel(SPC_Type *base, spc_core_ldo_voltage_level_t voltageLevel);
1962
1963 /*!
1964 * @brief Gets the CORE LDO VDD Regulator Voltage Level for Low Power modes.
1965 *
1966 * @param base SPC peripheral base address.
1967 * @return The CORE LDO VDD Regulator's voltage level.
1968 */
SPC_GetLowPowerCoreLDOVDDVoltageLevel(SPC_Type * base)1969 static inline spc_core_ldo_voltage_level_t SPC_GetLowPowerCoreLDOVDDVoltageLevel(SPC_Type *base)
1970 {
1971 return ((spc_core_ldo_voltage_level_t)(uint32_t)((base->LP_CFG & SPC_LP_CFG_CORELDO_VDD_LVL_MASK) >>
1972 SPC_LP_CFG_CORELDO_VDD_LVL_SHIFT));
1973 }
1974
1975 /*!
1976 * @brief Set Core LDO VDD Regulator Drive Strength in Low power mode.
1977 *
1978 * @param base SPC peripheral base address.
1979 * @param driveStrength Specify drive strength of CORE LDO in low power mode.
1980 *
1981 * @retval #kStatus_SPC_CORELDOLowDriveStrengthIgnore Some voltage detect enabled, CORE LDO's drive strength can not set
1982 * as low.
1983 * @retval #kStatus_Success Set Core LDO regulator drive strength in Low power mode successful.
1984 * @retval #kStatus_SPC_BandgapModeWrong Bandgap is disabled when attempt to set CORE LDO work as normal drive strength.
1985 */
1986 status_t SPC_SetLowPowerModeCoreLDORegulatorDriveStrength(SPC_Type *base, spc_core_ldo_drive_strength_t driveStrength);
1987
1988 /*!
1989 * @brief Gets CORE LDO VDD Drive Strength for Low Power modes.
1990 *
1991 * @param base SPC peripheral base address.
1992 * @return The CORE LDO's VDD Drive Strength.
1993 */
SPC_GetLowPowerCoreLDOVDDDriveStrength(SPC_Type * base)1994 static inline spc_core_ldo_drive_strength_t SPC_GetLowPowerCoreLDOVDDDriveStrength(SPC_Type *base)
1995 {
1996 return (spc_core_ldo_drive_strength_t)(uint32_t)((base->LP_CFG & SPC_LP_CFG_CORELDO_VDD_DS_MASK) >>
1997 SPC_LP_CFG_CORELDO_VDD_DS_SHIFT);
1998 }
1999
2000 #if (defined(FSL_FEATURE_MCX_SPC_HAS_SYS_LDO) && FSL_FEATURE_MCX_SPC_HAS_SYS_LDO)
2001 /*!
2002 * @name Low Level APIs To Set System LDO Regulator
2003 * @{
2004 */
2005
2006 /*!
2007 * @brief Enable/Disable System LDO regulator.
2008 *
2009 * @note The SYSTEM LDO enable bit is write-once.
2010 *
2011 * @param base SPC peripheral base address.
2012 * @param enable Enable/Disable System LDO Regulator.
2013 * true - Enable System LDO Regulator.
2014 * false - Disable System LDO Regulator.
2015 */
SPC_EnableSystemLDORegulator(SPC_Type * base,bool enable)2016 static inline void SPC_EnableSystemLDORegulator(SPC_Type *base, bool enable)
2017 {
2018 if (enable)
2019 {
2020 base->CNTRL |= SPC_CNTRL_SYSLDO_EN_MASK;
2021 }
2022 else
2023 {
2024 /*
2025 * $Branch Coverage Justification$
2026 * If SYSTEM_LDO is disabled, may cause some unexpected issues.
2027 */
2028 base->CNTRL &= ~SPC_CNTRL_SYSLDO_EN_MASK;
2029 }
2030 }
2031
2032 /*!
2033 * @brief Enable/Disable current sink feature of System LDO Regulator.
2034 *
2035 * @param base SPC peripheral base address.
2036 * @param sink Enable/Disable current sink feature.
2037 * true - Enable current sink feature of System LDO Regulator.
2038 * false - Disable current sink feature of System LDO Regulator.
2039 */
SPC_EnableSystemLDOSinkFeature(SPC_Type * base,bool sink)2040 static inline void SPC_EnableSystemLDOSinkFeature(SPC_Type *base, bool sink)
2041 {
2042 if (sink)
2043 {
2044 base->SYSLDO_CFG |= SPC_SYSLDO_CFG_ISINKEN_MASK;
2045 }
2046 else
2047 {
2048 base->SYSLDO_CFG &= ~SPC_SYSLDO_CFG_ISINKEN_MASK;
2049 }
2050 }
2051
2052 /*!
2053 * @brief Configs System LDO VDD Regulator in Active mode.
2054 *
2055 * @note If System LDO VDD Drive Strength is set to Normal, the Bandgap mode in Active mode must be programmed
2056 * to a value that enables the bandgap.
2057 * @note If any voltage detects are kept enabled, configuration to set System LDO VDD drive strength to low will
2058 * be ignored.
2059 * @note If select System LDO VDD Regulator voltage level to Over Drive Voltage, the Drive Strength of System LDO VDD
2060 * Regulator must be set to Normal otherwise the regulator Drive Strength will be forced to Normal.
2061 * @note If select System LDO VDD Regulator voltage level to Over Drive Voltage, the High voltage detect must be
2062 * disabled. Otherwise it will be fail to regulator to Over Drive Voltage.
2063 *
2064 * @param base SPC peripheral base address.
2065 * @param option Pointer to the spc_active_mode_sys_ldo_option_t structure.
2066 *
2067 * @retval #kStatus_Success Config System LDO regulator in Active power mode successful.
2068 * @retval #kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
2069 * @retval #kStatus_SPC_BandgapModeWrong The bandgap is not enabled before invoking this function.
2070 * @retval #kStatus_SPC_SYSLDOOverDriveVoltageFail HVD of System VDD is not disable before setting to Over Drive
2071 * voltage.
2072 * @retval kStatus_SPC_SYSLDOLowDriveStrengthIgnore Set System LDO VDD regulator's driver strength to Low will be
2073 * ignored.
2074 */
2075 status_t SPC_SetActiveModeSystemLDORegulatorConfig(SPC_Type *base, const spc_active_mode_sys_ldo_option_t *option);
2076
2077 /*!
2078 * @brief Set System LDO Regulator voltage level in Active mode.
2079 *
2080 * @note The system LDO regulator can only operate at the overdrive voltage level for a limited amount of time for the
2081 * life of chip.
2082 *
2083 * @param base SPC peripheral base address.
2084 * @param voltageLevel Specify the voltage level of System LDO Regulator in Active mode.
2085 *
2086 * @retval #kStatus_Success Set System LDO Regulator voltage level in Active mode successfully.
2087 * @retval #kStatus_SPC_SYSLDOOverDriveVoltageFail Must disable system LDO high voltage detector before specifing
2088 * overdrive voltage.
2089 */
2090 status_t SPC_SetActiveModeSystemLDORegulatorVoltageLevel(SPC_Type *base, spc_sys_ldo_voltage_level_t voltageLevel);
2091
2092 /*!
2093 * @brief Get System LDO Regulator voltage level in Active mode.
2094 *
2095 * @param base SPC peripheral base address.
2096 * @return System LDO Regulator voltage level in Active mode, please refer to @ref spc_sys_ldo_voltage_level_t.
2097 */
SPC_GetActiveModeSystemLDORegulatorVoltageLevel(SPC_Type * base)2098 static inline spc_sys_ldo_voltage_level_t SPC_GetActiveModeSystemLDORegulatorVoltageLevel(SPC_Type *base)
2099 {
2100 return (spc_sys_ldo_voltage_level_t)(uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_SYSLDO_VDD_LVL_MASK) >>
2101 SPC_ACTIVE_CFG_SYSLDO_VDD_LVL_SHIFT);
2102 }
2103
2104 /*!
2105 * @brief Set System LDO Regulator Drive Strength in Active mode.
2106 *
2107 * @param base SPC peripheral base address.
2108 * @param driveStrength Specify the drive strength of System LDO Regulator in Active mode.
2109 *
2110 * @retval #kStatus_Success Set System LDO Regulator drive strength in Active mode successfully.
2111 * @retval #kStatus_SPC_SYSLDOLowDriveStrengthIgnore Attempt to specify low drive strength is ignored due to any
2112 voltage detect feature is enabled in active mode.
2113 * @retval #kStatus_SPC_BandgapModeWrong Bandgap mode in Active mode must be programmed to a value that enables
2114 the bandgap if attempt to specify normal drive strength.
2115 */
2116 status_t SPC_SetActiveModeSystemLDORegulatorDriveStrength(SPC_Type *base, spc_sys_ldo_drive_strength_t driveStrength);
2117
2118 /*!
2119 * @brief Get System LDO Regulator Drive Strength in Active mode.
2120 *
2121 * @param base SPC peripheral base address.
2122 * @return System LDO regulator drive strength in Active mode, please refer to @ref spc_sys_ldo_drive_strength_t.
2123 */
SPC_GetActiveModeSystemLDORegulatorDriveStrength(SPC_Type * base)2124 static inline spc_sys_ldo_drive_strength_t SPC_GetActiveModeSystemLDORegulatorDriveStrength(SPC_Type *base)
2125 {
2126 return (spc_sys_ldo_drive_strength_t)(uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_SYSLDO_VDD_DS_MASK) >>
2127 SPC_ACTIVE_CFG_SYSLDO_VDD_DS_SHIFT);
2128 }
2129
2130 /*!
2131 * @brief Configs System LDO regulator in low power modes.
2132 *
2133 * This function configs System LDO regulator in low power modes.
2134 * If System LDO VDD Regulator Drive strength is set to normal, bandgap mode in low power
2135 * mode must be programmed to a value that enables the Bandgap.
2136 * If any High voltage detectors or Low Voltage detectors are kept enabled, configuration
2137 * to set System LDO Regulator drive strength as Low will be ignored.
2138 *
2139 * @param base SPC peripheral base address.
2140 * @param option Pointer to spc_lowpower_mode_sys_ldo_option_t structure.
2141 *
2142 * @retval #kStatus_Success Config System LDO regulator in Low Power Mode successfully.
2143 * @retval #kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
2144 * @retval #kStatus_SPC_SYSLDOLowDriveStrengthIgnore Set driver strength to low will be ignored.
2145 */
2146 status_t SPC_SetLowPowerModeSystemLDORegulatorConfig(SPC_Type *base, const spc_lowpower_mode_sys_ldo_option_t *option);
2147
2148 /*!
2149 * @brief Set System LDO Regulator drive strength in Low Power Mode.
2150 *
2151 * @param base SPC peripheral base address.
2152 * @param driveStrength Specify the drive strength of System LDO Regulator in Low Power Mode.
2153 *
2154 * @retval #kStatus_Success Set System LDO Regulator drive strength in Low Power Mode successfully.
2155 * @retval #kStatus_SPC_SYSLDOLowDriveStrengthIgnore Attempt to specify low drive strength is ignored due to any
2156 voltage detect feature is enabled in low power mode.
2157 * @retval #kStatus_SPC_BandgapModeWrong Bandgap mode in low power mode must be programmed to a value that enables
2158 the bandgap if attempt to specify normal drive strength.
2159 */
2160 status_t SPC_SetLowPowerModeSystemLDORegulatorDriveStrength(SPC_Type *base, spc_sys_ldo_drive_strength_t driveStrength);
2161
2162 /*!
2163 * @brief Get System LDO Regulator drive strength in Low Power Mode.
2164 *
2165 * @param base SPC peripheral base address.
2166 * @return System LDO regulator drive strength in Low Power Mode, please refer to @ref spc_sys_ldo_drive_strength_t.
2167 */
SPC_GetLowPowerModeSystemLDORegulatorDriveStrength(SPC_Type * base)2168 static inline spc_sys_ldo_drive_strength_t SPC_GetLowPowerModeSystemLDORegulatorDriveStrength(SPC_Type *base)
2169 {
2170 return (spc_sys_ldo_drive_strength_t)(uint32_t)((base->LP_CFG & SPC_LP_CFG_SYSLDO_VDD_DS_MASK) >>
2171 SPC_LP_CFG_SYSLDO_VDD_DS_SHIFT);
2172 }
2173 /*! @} */
2174 #endif /* FSL_FEATURE_MCX_SPC_HAS_SYS_LDO */
2175
2176 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC) && FSL_FEATURE_MCX_SPC_HAS_DCDC)
2177 /*!
2178 * @name Low Level APIs To Set DCDC Regulator
2179 * @{
2180 */
2181
2182 /*!
2183 * @brief Enable/Disable DCDC Regulator.
2184 *
2185 * @note The DCDC enable bit is write-once, settings only reset after a POR, LVD, or HVD event.
2186 *
2187 * @param base SPC peripheral base address.
2188 * @param enable Enable/Disable DCDC Regulator.
2189 * true - Enable DCDC Regulator.
2190 * false - Disable DCDC Regulator.
2191 */
SPC_EnableDCDCRegulator(SPC_Type * base,bool enable)2192 static inline void SPC_EnableDCDCRegulator(SPC_Type *base, bool enable)
2193 {
2194 if (enable)
2195 {
2196 base->CNTRL |= SPC_CNTRL_DCDC_EN_MASK;
2197 }
2198 else
2199 {
2200 /*
2201 * $Branch Coverage Justification$
2202 * If DCDC is disabled, all RAMs data will powered off.
2203 */
2204 base->CNTRL &= ~SPC_CNTRL_DCDC_EN_MASK;
2205 }
2206 }
2207
2208 /*!
2209 * @brief Config DCDC Burst options
2210 *
2211 * @param base SPC peripheral base address.
2212 * @param config Pointer to spc_dcdc_burst_config_t structure.
2213 */
2214 void SPC_SetDCDCBurstConfig(SPC_Type *base, spc_dcdc_burst_config_t *config);
2215
2216 /*!
2217 * @brief Trigger a software burst request to DCDC.
2218 *
2219 * @param base SPC peripheral base address.
2220 */
SPC_TriggerDCDCBurstRequest(SPC_Type * base)2221 static inline void SPC_TriggerDCDCBurstRequest(SPC_Type *base)
2222 {
2223 /* Blocking until previous DCDC burst completed. */
2224 while ((base->DCDC_BURST_CFG & SPC_DCDC_BURST_CFG_BURST_ACK_MASK) == 0UL)
2225 {
2226 }
2227
2228 base->DCDC_BURST_CFG |= SPC_DCDC_BURST_CFG_BURST_REQ_MASK;
2229 }
2230
2231 /*!
2232 * @brief Check if burst acknowlege flag is asserted.
2233 *
2234 * @param base SPC peripheral base address.
2235 *
2236 * @retval false DCDC burst not complete.
2237 * @retval true DCDC burst complete.
2238 */
SPC_CheckDCDCBurstAck(SPC_Type * base)2239 static inline bool SPC_CheckDCDCBurstAck(SPC_Type *base)
2240 {
2241 return ((base->DCDC_BURST_CFG & SPC_DCDC_BURST_CFG_BURST_ACK_MASK) != 0UL);
2242 }
2243
2244 /*!
2245 * @brief Clear DCDC busrt acknowledge flag.
2246 *
2247 * @param base SPC periphral base address.
2248 */
SPC_ClearDCDCBurstAckFlag(SPC_Type * base)2249 static inline void SPC_ClearDCDCBurstAckFlag(SPC_Type *base)
2250 {
2251 base->DCDC_BURST_CFG |= SPC_DCDC_BURST_CFG_BURST_ACK_MASK;
2252 }
2253
2254 /*!
2255 * @brief Set the count value of the reference clock to configure the period of DCDC not active.
2256 *
2257 * @note This function is only useful when DCDC's drive strength is set as pulse refresh.
2258 * @note The pulse duration(time between on and off) is: reference clock period * (count + 2).
2259 *
2260 * @param base SPC peripheral base address.
2261 * @param count The count value, 16 bit width.
2262 */
2263 void SPC_SetDCDCRefreshCount(SPC_Type *base, uint16_t count);
2264
2265 #if (defined(FSL_FEATURE_MCX_SPC_HAS_DCDC_CFG_BLEED_EN) && FSL_FEATURE_MCX_SPC_HAS_DCDC_CFG_BLEED_EN)
2266 /*!
2267 * @brief Enable a bleed resistor to discharge DCDC output when DCDC is disabled.
2268 *
2269 * @param base SPC peripheral base address.
2270 * @param enable Used to enable/disable bleed resistor.
2271 */
SPC_EnableDCDCBleedResistor(SPC_Type * base,bool enable)2272 static inline void SPC_EnableDCDCBleedResistor(SPC_Type *base, bool enable)
2273 {
2274 if (enable)
2275 {
2276 base->DCDC_CFG |= SPC_DCDC_CFG_BLEED_EN_MASK;
2277 }
2278 else
2279 {
2280 base->DCDC_CFG &= ~SPC_DCDC_CFG_BLEED_EN_MASK;
2281 }
2282 }
2283 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC_CFG_BLEED_EN */
2284
2285 /*!
2286 * @brief Configs DCDC_CORE Regulator in Active mode.
2287 *
2288 * @note When changing the DCDC output voltage level, take care to change the CORE LDO voltage level.
2289 *
2290 * @param base SPC peripheral base address.
2291 * @param option Pointer to the spc_active_mode_dcdc_option_t structure.
2292 *
2293 * @retval #kStatus_Success Config DCDC regulator in Active power mode successful.
2294 * @retval #kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
2295 * @retval #kStatus_SPC_BandgapModeWrong Set DCDC_CORE Regulator drive strength to Normal, the Bandgap must be enabled.
2296 */
2297 status_t SPC_SetActiveModeDCDCRegulatorConfig(SPC_Type *base, const spc_active_mode_dcdc_option_t *option);
2298
2299 /*!
2300 * @brief Set DCDC_CORE Regulator voltage level in Active mode.
2301 *
2302 * @note When changing the DCDC output voltage level, take care to change the CORE LDO voltage level.
2303 *
2304 * @param base SPC peripheral base address.
2305 * @param voltageLevel Specify the DCDC_CORE Regulator voltage level, please refer to @ref spc_dcdc_voltage_level_t.
2306 */
SPC_SetActiveModeDCDCRegulatorVoltageLevel(SPC_Type * base,spc_dcdc_voltage_level_t voltageLevel)2307 static inline void SPC_SetActiveModeDCDCRegulatorVoltageLevel(SPC_Type *base, spc_dcdc_voltage_level_t voltageLevel)
2308 {
2309 base->ACTIVE_CFG =
2310 (base->ACTIVE_CFG & (~SPC_ACTIVE_CFG_DCDC_VDD_LVL_MASK)) | SPC_ACTIVE_CFG_DCDC_VDD_LVL(voltageLevel);
2311 }
2312
2313 /*!
2314 * @brief Get DCDC_CORE Regulator voltage level in Active mode.
2315 *
2316 * @param base SPC peripheral base address.
2317 * @return DCDC_CORE Regulator voltage level, please refer to @ref spc_dcdc_voltage_level_t.
2318 */
SPC_GetActiveModeDCDCRegulatorVoltageLevel(SPC_Type * base)2319 static inline spc_dcdc_voltage_level_t SPC_GetActiveModeDCDCRegulatorVoltageLevel(SPC_Type *base)
2320 {
2321 return (spc_dcdc_voltage_level_t)((uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_DCDC_VDD_LVL_MASK) >>
2322 SPC_ACTIVE_CFG_DCDC_VDD_LVL_SHIFT));
2323 }
2324
2325 /*!
2326 * @brief Set DCDC_CORE Regulator drive strength in Active mode.
2327 *
2328 * @note To set DCDC drive strength as Normal, the bandgap must be enabled.
2329 *
2330 * @param base SPC peripheral base address.
2331 * @param driveStrength Specify the DCDC_CORE regulator drive strength, please refer to @ref spc_dcdc_drive_strength_t.
2332 *
2333 * @retval #kStatus_Success Set DCDC_CORE Regulator drive strength in Active mode successfully.
2334 * @retval #kStatus_SPC_BandgapModeWrong Set DCDC_CORE Regulator drive strength to Normal, the Bandgap must be enabled.
2335 */
2336 status_t SPC_SetActiveModeDCDCRegulatorDriveStrength(SPC_Type *base, spc_dcdc_drive_strength_t driveStrength);
2337
2338 /*!
2339 * @brief Get DCDC_CORE Regulator drive strength in Active mode.
2340 *
2341 * @param base SPC peripheral base address.
2342 * @return DCDC_CORE Regulator drive strength, please refer to @ref spc_dcdc_drive_strength_t.
2343 */
SPC_GetActiveModeDCDCRegulatorDriveStrength(SPC_Type * base)2344 static inline spc_dcdc_drive_strength_t SPC_GetActiveModeDCDCRegulatorDriveStrength(SPC_Type *base)
2345 {
2346 return (spc_dcdc_drive_strength_t)((uint32_t)((base->ACTIVE_CFG & SPC_ACTIVE_CFG_DCDC_VDD_DS_MASK) >>
2347 SPC_ACTIVE_CFG_DCDC_VDD_DS_SHIFT));
2348 }
2349
2350 /*!
2351 * @brief Configs DCDC_CORE Regulator in Low power modes.
2352 *
2353 * @note If DCDC_CORE Drive Strength is set to Normal, the Bandgap mode in Low Power mode must be programmed
2354 * to a value that enables the Bandgap.
2355 * @note In Deep Power Down mode, DCDC regulator is always turned off.
2356 *
2357 * @param base SPC peripheral base address.
2358 * @param option Pointer to the spc_lowpower_mode_dcdc_option_t structure.
2359 *
2360 * @retval #kStatus_Success Config DCDC regulator in low power mode successfully.
2361 * @retval #kStatus_SPC_Busy The SPC instance is busy to execute any type of power mode transition.
2362 * @retval #kStatus_SPC_BandgapModeWrong The bandgap mode setting in Low Power mode is wrong.
2363 */
2364 status_t SPC_SetLowPowerModeDCDCRegulatorConfig(SPC_Type *base, const spc_lowpower_mode_dcdc_option_t *option);
2365
2366 /*!
2367 * @brief Set DCDC_CORE Regulator drive strength in Low power mode.
2368 *
2369 * @note To set drive strength as normal, the bandgap must be enabled.
2370 *
2371 * @param base SPC peripheral base address.
2372 * @param driveStrength Specify the DCDC_CORE Regulator drive strength, please refer to @ref spc_dcdc_drive_strength_t.
2373 *
2374 * @retval #kStatus_Success Set DCDC_CORE Regulator drive strength in Low power mode successfully.
2375 * @retval #kStatus_SPC_BandgapModeWrong Set DCDC_CORE Regulator drive strength to Normal, the Bandgap must be enabled.
2376 */
2377 status_t SPC_SetLowPowerModeDCDCRegulatorDriveStrength(SPC_Type *base, spc_dcdc_drive_strength_t driveStrength);
2378
2379 /*!
2380 * @brief Get DCDC_CORE Regulator drive strength in Low power mode.
2381 *
2382 * @param base SPC peripheral base address.
2383 * @return DCDC_CORE Regulator drive strength, please refer to @ref spc_dcdc_drive_strength_t.
2384 */
SPC_GetLowPowerModeDCDCRegulatorDriveStrength(SPC_Type * base)2385 static inline spc_dcdc_drive_strength_t SPC_GetLowPowerModeDCDCRegulatorDriveStrength(SPC_Type *base)
2386 {
2387 return (spc_dcdc_drive_strength_t)((uint32_t)((base->LP_CFG & SPC_LP_CFG_DCDC_VDD_DS_MASK) >>
2388 SPC_LP_CFG_DCDC_VDD_DS_SHIFT));
2389 }
2390
2391 /*!
2392 * @brief Set DCDC_CORE Regulator voltage level in Low power mode.
2393 *
2394 * @note To change DCDC level in Low-Power mode:
2395 * 1. Configure LP_CFG[DCDC_VDD_LVL] to desired level;
2396 * 2. Configure LP_CFG[DCDC_VDD_DS] to low driver strength;
2397 * 3. Configure ACTIVE_CFG[DCDC_VDD_LVL] to same level programmed in #1.
2398 *
2399 * @note After invoking this function, the voltage level in active mode(wakeup from low power modes) also changed,
2400 * if it is necessary, please invoke SPC_SetActiveModeDCDCRegulatorVoltageLevel() to change to desried voltage level.
2401 *
2402 * @param base SPC peripheral base address.
2403 * @param voltageLevel Specify the DCDC_CORE Regulator voltage level, please refer to @ref spc_dcdc_voltage_level_t.
2404 */
SPC_SetLowPowerModeDCDCRegulatorVoltageLevel(SPC_Type * base,spc_dcdc_voltage_level_t voltageLevel)2405 static inline void SPC_SetLowPowerModeDCDCRegulatorVoltageLevel(SPC_Type *base, spc_dcdc_voltage_level_t voltageLevel)
2406 {
2407 base->LP_CFG = (base->LP_CFG & (~SPC_LP_CFG_DCDC_VDD_LVL_MASK)) | SPC_LP_CFG_DCDC_VDD_LVL(voltageLevel);
2408 (void)SPC_SetLowPowerModeDCDCRegulatorDriveStrength(base, kSPC_DCDC_LowDriveStrength);
2409 SPC_SetActiveModeDCDCRegulatorVoltageLevel(base, voltageLevel);
2410 }
2411
2412 /*!
2413 * @brief Get DCDC_CORE Regulator voltage level in Low power mode.
2414 *
2415 * @param base SPC peripheral base address.
2416 * @return DCDC_CORE Regulator voltage level, please refer to @ref spc_dcdc_voltage_level_t.
2417 */
SPC_GetLowPowerModeDCDCRegulatorVoltageLevel(SPC_Type * base)2418 static inline spc_dcdc_voltage_level_t SPC_GetLowPowerModeDCDCRegulatorVoltageLevel(SPC_Type *base)
2419 {
2420 return (spc_dcdc_voltage_level_t)((uint32_t)((base->LP_CFG & SPC_LP_CFG_DCDC_VDD_LVL_MASK) >>
2421 SPC_LP_CFG_DCDC_VDD_LVL_SHIFT));
2422 }
2423
2424 /*! @} */
2425 #endif /* FSL_FEATURE_MCX_SPC_HAS_DCDC */
2426
2427 #if defined(__cplusplus)
2428 }
2429 #endif /* __cplusplus */
2430
2431 /*! @} */
2432
2433 #endif /* FSL_SPC_H_ */
2434