1 /*
2 * Copyright (c) 2018 - 2024, Nordic Semiconductor ASA
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright notice, this
11 * list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #ifndef NRF_REGULATORS_H__
35 #define NRF_REGULATORS_H__
36
37 #include <nrfx.h>
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 /**
44 * @defgroup nrf_regulators_hal REGULATORS HAL
45 * @{
46 * @ingroup nrf_power
47 * @brief Hardware access layer for managing the REGULATORS peripheral.
48 */
49
50 #if defined(REGULATORS_VREGH_DCDCEN_DCDCEN_Msk) || defined(__NRFX_DOXYGEN__)
51 /** @brief Symbol indicating whether high voltage regulator (VREGH) is present. */
52 #define NRF_REGULATORS_HAS_VREG_HIGH 1
53 #else
54 #define NRF_REGULATORS_HAS_VREG_HIGH 0
55 #endif
56
57 #if defined(REGULATORS_VREGM_ENABLE_ENABLE_Msk) || defined(__NRFX_DOXYGEN__)
58 /** @brief Symbol indicating whether medium voltage regulator (VREGM) is present. */
59 #define NRF_REGULATORS_HAS_VREG_MEDIUM 1
60 #else
61 #define NRF_REGULATORS_HAS_VREG_MEDIUM 0
62 #endif
63
64 #if defined(REGULATORS_VREGRADIO_DCDCEN_DCDCEN_Msk) || defined(__NRFX_DOXYGEN__)
65 /** @brief Symbol indicating whether radio regulator (VREGRADIO) is present. */
66 #define NRF_REGULATORS_HAS_VREG_RADIO 1
67 #else
68 #define NRF_REGULATORS_HAS_VREG_RADIO 0
69 #endif
70
71 #if defined(REGULATORS_POFCON_POF_Msk) || defined(__NRFX_DOXYGEN__)
72 /** @brief Symbol indicating whether Power-On-Fail Comparator (POF Comparator) is present. */
73 #define NRF_REGULATORS_HAS_POF 1
74 #else
75 #define NRF_REGULATORS_HAS_POF 0
76 #endif
77
78 #if defined(REGULATORS_POFCON_THRESHOLDVDDH_Msk) || defined(__NRFX_DOXYGEN__)
79 /** @brief Symbol indicating whether POF Comparator for VDDH is present. */
80 #define NRF_REGULATORS_HAS_POF_VDDH 1
81 #else
82 #define NRF_REGULATORS_HAS_POF_VDDH 0
83 #endif
84
85 #if defined(REGULATORS_POFCON_EVENTDISABLE_Msk) || defined(__NRFX_DOXYGEN__)
86 /** @brief Symbol indicating whether POF Comparator can disable POFWARN event. */
87 #define NRF_REGULATORS_HAS_POF_WARN_DISABLE 1
88 #else
89 #define NRF_REGULATORS_HAS_POF_WARN_DISABLE 0
90 #endif
91
92 #if defined(REGULATORS_POFSTAT_COMPARATOR_Msk) || defined(__NRFX_DOXYGEN__)
93 /** @brief Symbol indicating whether POF Comparator status is present. */
94 #define NRF_REGULATORS_HAS_POF_STATUS 1
95 #else
96 #define NRF_REGULATORS_HAS_POF_STATUS 0
97 #endif
98
99 #if defined(REGULATORS_TRIM_ResetValue) || defined(__NRFX_DOXYGEN__)
100 /** @brief Symbol indicating whether TRIM register is present. */
101 #define NRF_REGULATORS_HAS_TRIM 1
102 #else
103 #define NRF_REGULATORS_HAS_TRIM 0
104 #endif
105
106 #if defined(REGULATORS_MAINREGSTATUS_VREGH_Msk) || defined(__NRFX_DOXYGEN__)
107 /** @brief Symbol indicating whether main supply status is present. */
108 #define NRF_REGULATORS_HAS_MAIN_STATUS 1
109 #else
110 #define NRF_REGULATORS_HAS_MAIN_STATUS 0
111 #endif
112
113 #if defined(REGULATORS_VREGMAIN_INDUCTORDET_DETECTED_Msk) || defined(__NRFX_DOXYGEN__)
114 /** @brief Symbol indicating whether inductor detection is present. */
115 #define NRF_REGULATORS_HAS_INDUCTOR_DET 1
116 #else
117 #define NRF_REGULATORS_HAS_INDUCTOR_DET 0
118 #endif
119
120 /** @brief Voltage regulators. */
121 typedef enum
122 {
123 NRF_REGULATORS_VREG_MAIN, ///< Main voltage regulator (VREGMAIN).
124 #if NRF_REGULATORS_HAS_VREG_HIGH
125 NRF_REGULATORS_VREG_HIGH, ///< High voltage regulator (VREGH).
126 #endif
127 #if NRF_REGULATORS_HAS_VREG_MEDIUM
128 NRF_REGULATORS_VREG_MEDIUM, ///< Medium voltage regulator (VREGM).
129 #endif
130 #if NRF_REGULATORS_HAS_VREG_RADIO
131 NRF_REGULATORS_VREG_RADIO, ///< Radio voltage regulator (VREGRADIO).
132 #endif
133 } nrf_regulators_vreg_t;
134
135 #if NRF_REGULATORS_HAS_POF
136 /** @brief POF Comparator thresholds. */
137 typedef enum
138 {
139 #if defined(REGULATORS_POFCON_THRESHOLD_V17) || defined(__NRFX_DOXYGEN__)
140 NRF_REGULATORS_POF_THR_1V7 = REGULATORS_POFCON_THRESHOLD_V17, ///< Set threshold to 1.7 V.
141 #endif
142 #if defined(REGULATORS_POFCON_THRESHOLD_V18) || defined(__NRFX_DOXYGEN__)
143 NRF_REGULATORS_POF_THR_1V8 = REGULATORS_POFCON_THRESHOLD_V18, ///< Set threshold to 1.8 V.
144 #endif
145 NRF_REGULATORS_POF_THR_1V9 = REGULATORS_POFCON_THRESHOLD_V19, ///< Set threshold to 1.9 V.
146 NRF_REGULATORS_POF_THR_2V0 = REGULATORS_POFCON_THRESHOLD_V20, ///< Set threshold to 2.0 V.
147 NRF_REGULATORS_POF_THR_2V1 = REGULATORS_POFCON_THRESHOLD_V21, ///< Set threshold to 2.1 V.
148 NRF_REGULATORS_POF_THR_2V2 = REGULATORS_POFCON_THRESHOLD_V22, ///< Set threshold to 2.2 V.
149 NRF_REGULATORS_POF_THR_2V3 = REGULATORS_POFCON_THRESHOLD_V23, ///< Set threshold to 2.3 V.
150 NRF_REGULATORS_POF_THR_2V4 = REGULATORS_POFCON_THRESHOLD_V24, ///< Set threshold to 2.4 V.
151 NRF_REGULATORS_POF_THR_2V5 = REGULATORS_POFCON_THRESHOLD_V25, ///< Set threshold to 2.5 V.
152 NRF_REGULATORS_POF_THR_2V6 = REGULATORS_POFCON_THRESHOLD_V26, ///< Set threshold to 2.6 V.
153 NRF_REGULATORS_POF_THR_2V7 = REGULATORS_POFCON_THRESHOLD_V27, ///< Set threshold to 2.7 V.
154 NRF_REGULATORS_POF_THR_2V8 = REGULATORS_POFCON_THRESHOLD_V28, ///< Set threshold to 2.8 V.
155 } nrf_regulators_pof_thr_t;
156 #endif
157
158 #if NRF_REGULATORS_HAS_POF_VDDH
159 /** @brief POF Comparator thresholds for VDDH. */
160 typedef enum
161 {
162 NRF_REGULATORS_POF_THR_VDDH_2V7 = REGULATORS_POFCON_THRESHOLDVDDH_V27, ///< Set threshold to 2.7 V.
163 NRF_REGULATORS_POF_THR_VDDH_2V8 = REGULATORS_POFCON_THRESHOLDVDDH_V28, ///< Set threshold to 2.8 V.
164 NRF_REGULATORS_POF_THR_VDDH_2V9 = REGULATORS_POFCON_THRESHOLDVDDH_V29, ///< Set threshold to 2.9 V.
165 NRF_REGULATORS_POF_THR_VDDH_3V0 = REGULATORS_POFCON_THRESHOLDVDDH_V30, ///< Set threshold to 3.0 V.
166 NRF_REGULATORS_POF_THR_VDDH_3V1 = REGULATORS_POFCON_THRESHOLDVDDH_V31, ///< Set threshold to 3.1 V.
167 NRF_REGULATORS_POF_THR_VDDH_3V2 = REGULATORS_POFCON_THRESHOLDVDDH_V32, ///< Set threshold to 3.2 V.
168 NRF_REGULATORS_POF_THR_VDDH_3V3 = REGULATORS_POFCON_THRESHOLDVDDH_V33, ///< Set threshold to 3.3 V.
169 NRF_REGULATORS_POF_THR_VDDH_3V4 = REGULATORS_POFCON_THRESHOLDVDDH_V34, ///< Set threshold to 3.4 V.
170 NRF_REGULATORS_POF_THR_VDDH_3V5 = REGULATORS_POFCON_THRESHOLDVDDH_V35, ///< Set threshold to 3.5 V.
171 NRF_REGULATORS_POF_THR_VDDH_3V6 = REGULATORS_POFCON_THRESHOLDVDDH_V36, ///< Set threshold to 3.6 V.
172 NRF_REGULATORS_POF_THR_VDDH_3V7 = REGULATORS_POFCON_THRESHOLDVDDH_V37, ///< Set threshold to 3.7 V.
173 NRF_REGULATORS_POF_THR_VDDH_3V8 = REGULATORS_POFCON_THRESHOLDVDDH_V38, ///< Set threshold to 3.8 V.
174 NRF_REGULATORS_POF_THR_VDDH_3V9 = REGULATORS_POFCON_THRESHOLDVDDH_V39, ///< Set threshold to 3.9 V.
175 NRF_REGULATORS_POF_THR_VDDH_4V0 = REGULATORS_POFCON_THRESHOLDVDDH_V40, ///< Set threshold to 4.0 V.
176 NRF_REGULATORS_POF_THR_VDDH_4V1 = REGULATORS_POFCON_THRESHOLDVDDH_V41, ///< Set threshold to 4.1 V.
177 NRF_REGULATORS_POF_THR_VDDH_4V2 = REGULATORS_POFCON_THRESHOLDVDDH_V42, ///< Set threshold to 4.2 V.
178 } nrf_regulators_pof_thr_vddh_t;
179 #endif
180
181 #if NRF_REGULATORS_HAS_TRIM
182 /** @brief Components allowed to introduce ELV mode. */
183 typedef enum
184 {
185 NRF_REGULATORS_ELV_MODE_ALLOW_MASK_EXT ///< Reserved. For internal use only.
186 } nrf_regulators_elv_mode_allow_mask_t;
187 #endif // NRF_REGULATORS_HAS_TRIM
188
189 #if NRF_REGULATORS_HAS_POF
190 /** @brief POF Comparator configuration structure. */
191 typedef struct {
192 bool enable; ///< Enable or disable POF Comparator.
193 nrf_regulators_pof_thr_t thr; ///< Threshold to be set for POF Comparator.
194 #if NRF_REGULATORS_HAS_POF_VDDH
195 nrf_regulators_pof_thr_vddh_t thr_vddh; ///< Threshold to be set for POF Comparator for VDDH.
196 #endif
197 #if NRF_REGULATORS_HAS_POF_WARN_DISABLE
198 bool warn_disable; ///< Disable or enable POFWARN event.
199 #endif
200 } nrf_regulators_pof_config_t;
201 #endif
202
203 #if NRF_REGULATORS_HAS_MAIN_STATUS
204 /** @brief Main supply status. */
205 typedef enum
206 {
207 NRF_REGULATORS_MAIN_STATUS_NORMAL = REGULATORS_MAINREGSTATUS_VREGH_Inactive, ///< Normal voltage mode. Voltage supplied on VDD and VDDH.
208 NRF_REGULATORS_MAIN_STATUS_HIGH = REGULATORS_MAINREGSTATUS_VREGH_Active ///< High voltage mode. Voltage supplied on VDDH.
209 } nrf_regulators_main_status_t;
210 #endif
211
212 /**
213 * @brief Function for enabling or disabling the specified voltage regulator.
214 *
215 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
216 * @param[in] regulator Regulator to be enabled or disabled.
217 * @param[in] enable True if specified voltage regulator is to be enabled, false otherwise.
218 */
219 NRF_STATIC_INLINE void nrf_regulators_vreg_enable_set(NRF_REGULATORS_Type * p_reg,
220 nrf_regulators_vreg_t regulator,
221 bool enable);
222
223 /**
224 * @brief Function for checking whether the specified voltage regulator is enabled.
225 *
226 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
227 * @param[in] regulator Regulator to be checked.
228 *
229 * @retval true Specified voltage regulator is enabled.
230 * @retval false Specified voltage regulator is disabled.
231 */
232 NRF_STATIC_INLINE bool nrf_regulators_vreg_enable_check(NRF_REGULATORS_Type const * p_reg,
233 nrf_regulators_vreg_t regulator);
234
235 /**
236 * @brief Function for putting the CPU in System OFF mode.
237 *
238 * @note This function never returns.
239 *
240 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
241 */
242 NRF_STATIC_INLINE void nrf_regulators_system_off(NRF_REGULATORS_Type * p_reg);
243
244 #if NRF_REGULATORS_HAS_MAIN_STATUS
245 /**
246 * @brief Function for getting the main supply status.
247 *
248 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
249 *
250 * @return The current main supply status.
251 */
252 NRF_STATIC_INLINE
253 nrf_regulators_main_status_t nrf_regulators_main_status_get(NRF_REGULATORS_Type const * p_reg);
254 #endif
255
256 #if NRF_REGULATORS_HAS_POF
257 /**
258 * @brief Function for setting the POF Comparator configuration.
259 *
260 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
261 * @param[in] p_config Pointer to the structure containing POF Comparator configuration.
262 */
263 NRF_STATIC_INLINE void nrf_regulators_pof_config_set(NRF_REGULATORS_Type * p_reg,
264 nrf_regulators_pof_config_t const * p_config);
265
266 /**
267 * @brief Function for getting the POF Comparator configuration.
268 *
269 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
270 * @param[out] p_config Pointer to the structure to be filled with POF Comparator configuration.
271 */
272 NRF_STATIC_INLINE void nrf_regulators_pof_config_get(NRF_REGULATORS_Type const * p_reg,
273 nrf_regulators_pof_config_t * p_config);
274 #endif // NRF_REGULATORS_HAS_POF
275
276 #if NRF_REGULATORS_HAS_POF_STATUS
277 /**
278 * @brief Function for checking if the detected voltage is below or above the threshold of VPOF (POF Comparator's threshold voltage).
279 *
280 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
281 *
282 * @retval true Voltage below VPOF threshold has been detected.
283 * @retval false Voltage above VPOF threshold has been detected.
284 */
285 NRF_STATIC_INLINE bool nrf_regulators_pof_below_thr_check(NRF_REGULATORS_Type const * p_reg);
286 #endif
287
288 #if NRF_REGULATORS_HAS_TRIM
289 /**
290 * @brief Function for setting components that are allowed to introduce the ELV mode.
291 *
292 * @warning This register is retained when retention is enabled.
293 *
294 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
295 * @param[in] mask Mask of components to be set, created using @ref nrf_regulators_elv_mode_allow_mask_t.
296 */
297 NRF_STATIC_INLINE void nrf_regulators_elv_mode_allow_set(NRF_REGULATORS_Type * p_reg,
298 uint32_t mask);
299
300 /**
301 * @brief Function for geting components that are allowed to introduce the ELV mode.
302 *
303 * @warning This register is retained when retention is enabled.
304 *
305 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
306 *
307 * @return Mask of components allowed to introduce ELV mode,
308 * created using @ref nrf_regulators_elv_mode_allow_mask_t.
309 */
310 NRF_STATIC_INLINE uint32_t nrf_regulators_elv_mode_allow_get(NRF_REGULATORS_Type const * p_reg);
311 #endif // NRF_REGULATORS_HAS_TRIM
312
313 #if NRF_REGULATORS_HAS_INDUCTOR_DET
314 /**
315 * @brief Function for checking whether an inductor is connected to the DCC pin.
316 *
317 * @note The detection can only take place if the VREG_MAIN DC/DC converter is not enabled.
318 *
319 * @param[in] p_reg Pointer to the structure of registers of the peripheral.
320 *
321 * @retval true Inductor detected.
322 * @retval false Inductor not detected.
323 */
324 NRF_STATIC_INLINE bool nrf_regulators_inductor_check(NRF_REGULATORS_Type const * p_reg);
325 #endif
326
327 #ifndef NRF_DECLARE_ONLY
328
nrf_regulators_vreg_enable_set(NRF_REGULATORS_Type * p_reg,nrf_regulators_vreg_t regulator,bool enable)329 NRF_STATIC_INLINE void nrf_regulators_vreg_enable_set(NRF_REGULATORS_Type * p_reg,
330 nrf_regulators_vreg_t regulator,
331 bool enable)
332 {
333 switch (regulator)
334 {
335 case NRF_REGULATORS_VREG_MAIN:
336 #if defined(REGULATORS_DCDCEN_DCDCEN_Msk)
337 p_reg->DCDCEN = (enable ? REGULATORS_DCDCEN_DCDCEN_Enabled :
338 REGULATORS_DCDCEN_DCDCEN_Disabled) << REGULATORS_DCDCEN_DCDCEN_Pos;
339 #elif defined(REGULATORS_VREGMAIN_DCDCEN_VAL_Msk)
340 p_reg->VREGMAIN.DCDCEN = (enable ? REGULATORS_VREGMAIN_DCDCEN_VAL_Enabled :
341 REGULATORS_VREGMAIN_DCDCEN_VAL_Disabled)
342 << REGULATORS_VREGMAIN_DCDCEN_VAL_Pos;
343 #else
344 p_reg->VREGMAIN.DCDCEN = (enable ? REGULATORS_VREGMAIN_DCDCEN_DCDCEN_Enabled :
345 REGULATORS_VREGMAIN_DCDCEN_DCDCEN_Disabled)
346 << REGULATORS_VREGMAIN_DCDCEN_DCDCEN_Pos;
347 #endif
348 break;
349
350 #if NRF_REGULATORS_HAS_VREG_HIGH
351 case NRF_REGULATORS_VREG_HIGH:
352 p_reg->VREGH.DCDCEN = (enable ? REGULATORS_VREGH_DCDCEN_DCDCEN_Enabled :
353 REGULATORS_VREGH_DCDCEN_DCDCEN_Disabled)
354 << REGULATORS_VREGH_DCDCEN_DCDCEN_Pos;
355 break;
356 #endif
357
358 #if NRF_REGULATORS_HAS_VREG_MEDIUM
359 case NRF_REGULATORS_VREG_MEDIUM:
360 p_reg->VREGM.ENABLE = (enable ? REGULATORS_VREGM_ENABLE_ENABLE_Enabled :
361 REGULATORS_VREGM_ENABLE_ENABLE_Disabled)
362 << REGULATORS_VREGM_ENABLE_ENABLE_Pos;
363 break;
364 #endif
365
366 #if NRF_REGULATORS_HAS_VREG_RADIO
367 case NRF_REGULATORS_VREG_RADIO:
368 p_reg->VREGRADIO.DCDCEN = (enable ? REGULATORS_VREGRADIO_DCDCEN_DCDCEN_Enabled :
369 REGULATORS_VREGRADIO_DCDCEN_DCDCEN_Disabled)
370 << REGULATORS_VREGRADIO_DCDCEN_DCDCEN_Pos;
371 break;
372 #endif
373
374 default:
375 NRFX_ASSERT(false);
376 break;
377 }
378 }
379
nrf_regulators_vreg_enable_check(NRF_REGULATORS_Type const * p_reg,nrf_regulators_vreg_t regulator)380 NRF_STATIC_INLINE bool nrf_regulators_vreg_enable_check(NRF_REGULATORS_Type const * p_reg,
381 nrf_regulators_vreg_t regulator)
382 {
383 switch (regulator)
384 {
385 case NRF_REGULATORS_VREG_MAIN:
386 #if defined(REGULATORS_DCDCEN_DCDCEN_Msk)
387 return (p_reg->DCDCEN >> REGULATORS_DCDCEN_DCDCEN_Pos) ==
388 REGULATORS_DCDCEN_DCDCEN_Enabled;
389 #elif defined(REGULATORS_VREGMAIN_DCDCEN_VAL_Msk)
390 return (p_reg->VREGMAIN.DCDCEN >> REGULATORS_VREGMAIN_DCDCEN_VAL_Pos) ==
391 REGULATORS_VREGMAIN_DCDCEN_VAL_Enabled;
392 #else
393 return (p_reg->VREGMAIN.DCDCEN >> REGULATORS_VREGMAIN_DCDCEN_DCDCEN_Pos) ==
394 REGULATORS_VREGMAIN_DCDCEN_DCDCEN_Enabled;
395 #endif
396
397 #if NRF_REGULATORS_HAS_VREG_HIGH
398 case NRF_REGULATORS_VREG_HIGH:
399 return (p_reg->VREGH.DCDCEN >> REGULATORS_VREGH_DCDCEN_DCDCEN_Pos) ==
400 REGULATORS_VREGH_DCDCEN_DCDCEN_Enabled;
401 #endif
402
403 #if NRF_REGULATORS_HAS_VREG_MEDIUM
404 case NRF_REGULATORS_VREG_MEDIUM:
405 return (p_reg->VREGM.ENABLE >> REGULATORS_VREGM_ENABLE_ENABLE_Pos) ==
406 REGULATORS_VREGM_ENABLE_ENABLE_Enabled;
407 #endif
408
409 #if NRF_REGULATORS_HAS_VREG_RADIO
410 case NRF_REGULATORS_VREG_RADIO:
411 return (p_reg->VREGRADIO.DCDCEN >> REGULATORS_VREGRADIO_DCDCEN_DCDCEN_Pos) ==
412 REGULATORS_VREGRADIO_DCDCEN_DCDCEN_Enabled;
413 #endif
414
415 default:
416 NRFX_ASSERT(false);
417 return false;
418 }
419 }
420
nrf_regulators_system_off(NRF_REGULATORS_Type * p_reg)421 NRF_STATIC_INLINE void nrf_regulators_system_off(NRF_REGULATORS_Type * p_reg)
422 {
423 p_reg->SYSTEMOFF = REGULATORS_SYSTEMOFF_SYSTEMOFF_Msk;
424 __DSB();
425
426 /* Solution for simulated System OFF in debug mode */
427 while (true)
428 {
429 __WFE();
430 }
431 }
432
433 #if NRF_REGULATORS_HAS_MAIN_STATUS
434 NRF_STATIC_INLINE
nrf_regulators_main_status_get(NRF_REGULATORS_Type const * p_reg)435 nrf_regulators_main_status_t nrf_regulators_main_status_get(NRF_REGULATORS_Type const * p_reg)
436 {
437 return (nrf_regulators_main_status_t)p_reg->MAINREGSTATUS;
438 }
439 #endif
440
441 #if NRF_REGULATORS_HAS_POF
nrf_regulators_pof_config_set(NRF_REGULATORS_Type * p_reg,nrf_regulators_pof_config_t const * p_config)442 NRF_STATIC_INLINE void nrf_regulators_pof_config_set(NRF_REGULATORS_Type * p_reg,
443 nrf_regulators_pof_config_t const * p_config)
444 {
445 NRFX_ASSERT(p_config);
446
447 p_reg->POFCON = ((p_config->enable ? REGULATORS_POFCON_POF_Enabled :
448 REGULATORS_POFCON_POF_Disabled) << REGULATORS_POFCON_POF_Pos) |
449 (((uint32_t)p_config->thr) << REGULATORS_POFCON_THRESHOLD_Pos) |
450 #if NRF_REGULATORS_HAS_POF_VDDH
451 (((uint32_t)p_config->thr_vddh) << REGULATORS_POFCON_THRESHOLDVDDH_Pos) |
452 #endif
453 #if NRF_REGULATORS_HAS_POF_WARN_DISABLE
454 ((p_config->warn_disable ? REGULATORS_POFCON_EVENTDISABLE_Disabled :
455 REGULATORS_POFCON_EVENTDISABLE_Enabled)
456 << REGULATORS_POFCON_EVENTDISABLE_Pos) |
457 #endif
458 0;
459 }
460
nrf_regulators_pof_config_get(NRF_REGULATORS_Type const * p_reg,nrf_regulators_pof_config_t * p_config)461 NRF_STATIC_INLINE void nrf_regulators_pof_config_get(NRF_REGULATORS_Type const * p_reg,
462 nrf_regulators_pof_config_t * p_config)
463 {
464 NRFX_ASSERT(p_config);
465
466 p_config->enable = ((p_reg->POFCON & REGULATORS_POFCON_POF_Msk) >> REGULATORS_POFCON_POF_Pos)
467 == REGULATORS_POFCON_POF_Enabled;
468
469 p_config->thr = (nrf_regulators_pof_thr_t)((p_reg->POFCON & REGULATORS_POFCON_THRESHOLD_Msk)
470 >> REGULATORS_POFCON_THRESHOLD_Pos);
471
472
473 #if NRF_REGULATORS_HAS_POF_VDDH
474 p_config->thr_vddh = (nrf_regulators_pof_thr_vddh_t)((p_reg->POFCON &
475 REGULATORS_POFCON_THRESHOLDVDDH_Msk)
476 >> REGULATORS_POFCON_THRESHOLDVDDH_Pos);
477 #endif
478
479 #if NRF_REGULATORS_HAS_POF_WARN_DISABLE
480 p_config->warn_disable = ((p_reg->POFCON & REGULATORS_POFCON_EVENTDISABLE_Msk)
481 >> REGULATORS_POFCON_EVENTDISABLE_Pos)
482 == REGULATORS_POFCON_EVENTDISABLE_Disabled;
483 #endif
484 }
485 #endif // NRF_REGULATORS_HAS_POF
486
487 #if NRF_REGULATORS_HAS_POF_STATUS
nrf_regulators_pof_below_thr_check(NRF_REGULATORS_Type const * p_reg)488 NRF_STATIC_INLINE bool nrf_regulators_pof_below_thr_check(NRF_REGULATORS_Type const * p_reg)
489 {
490 return (p_reg->POFSTAT & REGULATORS_POFSTAT_COMPARATOR_Msk) >> REGULATORS_POFSTAT_COMPARATOR_Pos
491 == REGULATORS_POFSTAT_COMPARATOR_Below;
492 }
493 #endif
494
495 #if NRF_REGULATORS_HAS_TRIM
nrf_regulators_elv_mode_allow_set(NRF_REGULATORS_Type * p_reg,uint32_t mask)496 NRF_STATIC_INLINE void nrf_regulators_elv_mode_allow_set(NRF_REGULATORS_Type * p_reg,
497 uint32_t mask)
498 {
499 p_reg->TRIM = ((p_reg->TRIM & ~NRF_REGULATORS_ELV_MODE_ALL_MASK) |
500 (~mask & NRF_REGULATORS_ELV_MODE_ALL_MASK));
501 }
502
nrf_regulators_elv_mode_allow_get(NRF_REGULATORS_Type const * p_reg)503 NRF_STATIC_INLINE uint32_t nrf_regulators_elv_mode_allow_get(NRF_REGULATORS_Type const * p_reg)
504 {
505 return ~(p_reg->TRIM & NRF_REGULATORS_ELV_MODE_ALL_MASK);
506 }
507 #endif // NRF_REGULATORS_HAS_TRIM
508
509 #if NRF_REGULATORS_HAS_INDUCTOR_DET
nrf_regulators_inductor_check(NRF_REGULATORS_Type const * p_reg)510 NRF_STATIC_INLINE bool nrf_regulators_inductor_check(NRF_REGULATORS_Type const * p_reg)
511 {
512 return (p_reg->VREGMAIN.INDUCTORDET & REGULATORS_VREGMAIN_INDUCTORDET_DETECTED_Msk)
513 >> REGULATORS_VREGMAIN_INDUCTORDET_DETECTED_Pos
514 == REGULATORS_VREGMAIN_INDUCTORDET_DETECTED_InductorDetected;
515 }
516 #endif
517
518 #endif // NRF_DECLARE_ONLY
519
520 /** @} */
521
522 #ifdef __cplusplus
523 }
524 #endif
525
526 #endif // NRF_REGULATORS_H__
527