nrf_power.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045
  1. /**
  2. * Copyright (c) 2017 - 2018, Nordic Semiconductor ASA
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without modification,
  7. * are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. *
  12. * 2. Redistributions in binary form, except as embedded into a Nordic
  13. * Semiconductor ASA integrated circuit in a product or a software update for
  14. * such product, must reproduce the above copyright notice, this list of
  15. * conditions and the following disclaimer in the documentation and/or other
  16. * materials provided with the distribution.
  17. *
  18. * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * 4. This software, with or without modification, must only be used with a
  23. * Nordic Semiconductor ASA integrated circuit.
  24. *
  25. * 5. Any software provided in binary form under this license must not be reverse
  26. * engineered, decompiled, modified and/or disassembled.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA "AS IS" AND ANY EXPRESS
  29. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  30. * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
  31. * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
  32. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  33. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  34. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  37. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. *
  39. */
  40. #ifndef NRF_POWER_H__
  41. #define NRF_POWER_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_power_hal POWER HAL
  48. * @{
  49. * @ingroup nrf_power
  50. * @brief Hardware access layer for managing the POWER peripheral.
  51. */
  52. #if defined(POWER_RAMSTATUS_RAMBLOCK0_Msk)
  53. #define NRF_POWER_HAS_RAMSTATUS 1
  54. #else
  55. #define NRF_POWER_HAS_RAMSTATUS 0
  56. #endif
  57. /**
  58. * @name The implemented functionality
  59. * @{
  60. *
  61. * Macros that defines functionality that is implemented into POWER peripheral.
  62. */
  63. #if defined(POWER_INTENSET_SLEEPENTER_Msk) || defined(__NRFX_DOXYGEN__)
  64. /**
  65. * @brief The fact that sleep events are present
  66. *
  67. * In some MCUs there is possibility to process sleep entering and exiting
  68. * events.
  69. */
  70. #define NRF_POWER_HAS_SLEEPEVT 1
  71. #else
  72. #define NRF_POWER_HAS_SLEEPEVT 0
  73. #endif
  74. #if defined(POWER_RAM_POWER_S0POWER_Msk) || defined(__NRFX_DOXYGEN__)
  75. /**
  76. * @brief The fact that RAMPOWER registers are present
  77. *
  78. * After nRF51, new way to manage RAM power was implemented.
  79. * Special registers, one for every RAM block that makes it possible to
  80. * power ON or OFF RAM segments and turn ON and OFF RAM retention in system OFF
  81. * state.
  82. */
  83. #define NRF_POWER_HAS_RAMPOWER_REGS 1
  84. #else
  85. #define NRF_POWER_HAS_RAMPOWER_REGS 0
  86. #endif
  87. #if defined(POWER_POFCON_THRESHOLDVDDH_Msk) || defined(__NRFX_DOXYGEN__)
  88. /**
  89. * @brief Auxiliary definition to mark the fact that VDDH is present
  90. *
  91. * This definition can be used in a code to decide if the part with VDDH
  92. * related settings should be implemented.
  93. */
  94. #define NRF_POWER_HAS_VDDH 1
  95. #else
  96. #define NRF_POWER_HAS_VDDH 0
  97. #endif
  98. #if defined(POWER_USBREGSTATUS_VBUSDETECT_Msk) || defined(__NRFX_DOXYGEN__)
  99. /**
  100. * @brief The fact that power module manages USB regulator
  101. *
  102. * In devices that have USB, power peripheral manages also connection
  103. * detection and USB power regulator, that converts 5&nbsp;V to 3.3&nbsp;V
  104. * used by USBD peripheral.
  105. */
  106. #define NRF_POWER_HAS_USBREG 1
  107. #else
  108. #define NRF_POWER_HAS_USBREG 0
  109. #endif
  110. /** @} */
  111. /* ------------------------------------------------------------------------------------------------
  112. * Begin of automatically generated part
  113. * ------------------------------------------------------------------------------------------------
  114. */
  115. /**
  116. * @brief POWER tasks
  117. */
  118. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  119. {
  120. NRF_POWER_TASK_CONSTLAT = offsetof(NRF_POWER_Type, TASKS_CONSTLAT), /**< Enable constant latency mode */
  121. NRF_POWER_TASK_LOWPWR = offsetof(NRF_POWER_Type, TASKS_LOWPWR ), /**< Enable low power mode (variable latency) */
  122. }nrf_power_task_t; /*lint -restore */
  123. /**
  124. * @brief POWER events
  125. */
  126. typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
  127. {
  128. NRF_POWER_EVENT_POFWARN = offsetof(NRF_POWER_Type, EVENTS_POFWARN ), /**< Power failure warning */
  129. #if NRF_POWER_HAS_SLEEPEVT
  130. NRF_POWER_EVENT_SLEEPENTER = offsetof(NRF_POWER_Type, EVENTS_SLEEPENTER ), /**< CPU entered WFI/WFE sleep */
  131. NRF_POWER_EVENT_SLEEPEXIT = offsetof(NRF_POWER_Type, EVENTS_SLEEPEXIT ), /**< CPU exited WFI/WFE sleep */
  132. #endif
  133. #if NRF_POWER_HAS_USBREG
  134. NRF_POWER_EVENT_USBDETECTED = offsetof(NRF_POWER_Type, EVENTS_USBDETECTED), /**< Voltage supply detected on VBUS */
  135. NRF_POWER_EVENT_USBREMOVED = offsetof(NRF_POWER_Type, EVENTS_USBREMOVED ), /**< Voltage supply removed from VBUS */
  136. NRF_POWER_EVENT_USBPWRRDY = offsetof(NRF_POWER_Type, EVENTS_USBPWRRDY ), /**< USB 3.3&nbsp;V supply ready */
  137. #endif
  138. }nrf_power_event_t; /*lint -restore */
  139. /**
  140. * @brief POWER interrupts
  141. */
  142. typedef enum
  143. {
  144. NRF_POWER_INT_POFWARN_MASK = POWER_INTENSET_POFWARN_Msk , /**< Write '1' to Enable interrupt for POFWARN event */
  145. #if NRF_POWER_HAS_SLEEPEVT
  146. NRF_POWER_INT_SLEEPENTER_MASK = POWER_INTENSET_SLEEPENTER_Msk , /**< Write '1' to Enable interrupt for SLEEPENTER event */
  147. NRF_POWER_INT_SLEEPEXIT_MASK = POWER_INTENSET_SLEEPEXIT_Msk , /**< Write '1' to Enable interrupt for SLEEPEXIT event */
  148. #endif
  149. #if NRF_POWER_HAS_USBREG
  150. NRF_POWER_INT_USBDETECTED_MASK = POWER_INTENSET_USBDETECTED_Msk, /**< Write '1' to Enable interrupt for USBDETECTED event */
  151. NRF_POWER_INT_USBREMOVED_MASK = POWER_INTENSET_USBREMOVED_Msk , /**< Write '1' to Enable interrupt for USBREMOVED event */
  152. NRF_POWER_INT_USBPWRRDY_MASK = POWER_INTENSET_USBPWRRDY_Msk , /**< Write '1' to Enable interrupt for USBPWRRDY event */
  153. #endif
  154. }nrf_power_int_mask_t;
  155. /**
  156. * @brief Function for activating a specific POWER task.
  157. *
  158. * @param task Task.
  159. */
  160. __STATIC_INLINE void nrf_power_task_trigger(nrf_power_task_t task);
  161. /**
  162. * @brief Function for returning the address of a specific POWER task register.
  163. *
  164. * @param task Task.
  165. *
  166. * @return Task address.
  167. */
  168. __STATIC_INLINE uint32_t nrf_power_task_address_get(nrf_power_task_t task);
  169. /**
  170. * @brief Function for clearing a specific event.
  171. *
  172. * @param event Event.
  173. */
  174. __STATIC_INLINE void nrf_power_event_clear(nrf_power_event_t event);
  175. /**
  176. * @brief Function for returning the state of a specific event.
  177. *
  178. * @param event Event.
  179. *
  180. * @retval true If the event is set.
  181. * @retval false If the event is not set.
  182. */
  183. __STATIC_INLINE bool nrf_power_event_check(nrf_power_event_t event);
  184. /**
  185. * @brief Function for getting and clearing the state of specific event
  186. *
  187. * This function checks the state of the event and clears it.
  188. *
  189. * @param event Event.
  190. *
  191. * @retval true If the event was set.
  192. * @retval false If the event was not set.
  193. */
  194. __STATIC_INLINE bool nrf_power_event_get_and_clear(nrf_power_event_t event);
  195. /**
  196. * @brief Function for returning the address of a specific POWER event register.
  197. *
  198. * @param event Event.
  199. *
  200. * @return Address.
  201. */
  202. __STATIC_INLINE uint32_t nrf_power_event_address_get(nrf_power_event_t event);
  203. /**
  204. * @brief Function for enabling selected interrupts.
  205. *
  206. * @param int_mask Interrupts mask.
  207. */
  208. __STATIC_INLINE void nrf_power_int_enable(uint32_t int_mask);
  209. /**
  210. * @brief Function for retrieving the state of selected interrupts.
  211. *
  212. * @param int_mask Interrupts mask.
  213. *
  214. * @retval true If any of selected interrupts is enabled.
  215. * @retval false If none of selected interrupts is enabled.
  216. */
  217. __STATIC_INLINE bool nrf_power_int_enable_check(uint32_t int_mask);
  218. /**
  219. * @brief Function for retrieving the information about enabled interrupts.
  220. *
  221. * @return The flags of enabled interrupts.
  222. */
  223. __STATIC_INLINE uint32_t nrf_power_int_enable_get(void);
  224. /**
  225. * @brief Function for disabling selected interrupts.
  226. *
  227. * @param int_mask Interrupts mask.
  228. */
  229. __STATIC_INLINE void nrf_power_int_disable(uint32_t int_mask);
  230. /** @} */ /* End of nrf_power_hal */
  231. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  232. /* ------------------------------------------------------------------------------------------------
  233. * Internal functions
  234. */
  235. /**
  236. * @internal
  237. * @brief Internal function for getting task/event register address
  238. *
  239. * @oaram offset Offset of the register from the instance beginning
  240. *
  241. * @attention offset has to be modulo 4 value. In other case we can get hardware fault.
  242. * @return Pointer to the register
  243. */
  244. __STATIC_INLINE volatile uint32_t * nrf_power_regptr_get(uint32_t offset)
  245. {
  246. return (volatile uint32_t *)(((uint8_t *)NRF_POWER) + (uint32_t)offset);
  247. }
  248. /**
  249. * @internal
  250. * @brief Internal function for getting task/event register address - constant version
  251. *
  252. * @oaram offset Offset of the register from the instance beginning
  253. *
  254. * @attention offset has to be modulo 4 value. In other case we can get hardware fault.
  255. * @return Pointer to the register
  256. */
  257. __STATIC_INLINE volatile const uint32_t * nrf_power_regptr_get_c(
  258. uint32_t offset)
  259. {
  260. return (volatile const uint32_t *)(((uint8_t *)NRF_POWER) +
  261. (uint32_t)offset);
  262. }
  263. /* ------------------------------------------------------------------------------------------------
  264. * Interface functions definitions
  265. */
  266. void nrf_power_task_trigger(nrf_power_task_t task)
  267. {
  268. *(nrf_power_regptr_get((uint32_t)task)) = 1UL;
  269. }
  270. uint32_t nrf_power_task_address_get(nrf_power_task_t task)
  271. {
  272. return (uint32_t)nrf_power_regptr_get_c((uint32_t)task);
  273. }
  274. void nrf_power_event_clear(nrf_power_event_t event)
  275. {
  276. *(nrf_power_regptr_get((uint32_t)event)) = 0UL;
  277. }
  278. bool nrf_power_event_check(nrf_power_event_t event)
  279. {
  280. return (bool)*nrf_power_regptr_get_c((uint32_t)event);
  281. }
  282. bool nrf_power_event_get_and_clear(nrf_power_event_t event)
  283. {
  284. bool ret = nrf_power_event_check(event);
  285. if (ret)
  286. {
  287. nrf_power_event_clear(event);
  288. }
  289. return ret;
  290. }
  291. uint32_t nrf_power_event_address_get(nrf_power_event_t event)
  292. {
  293. return (uint32_t)nrf_power_regptr_get_c((uint32_t)event);
  294. }
  295. void nrf_power_int_enable(uint32_t int_mask)
  296. {
  297. NRF_POWER->INTENSET = int_mask;
  298. }
  299. bool nrf_power_int_enable_check(uint32_t int_mask)
  300. {
  301. return !!(NRF_POWER->INTENSET & int_mask);
  302. }
  303. uint32_t nrf_power_int_enable_get(void)
  304. {
  305. return NRF_POWER->INTENSET;
  306. }
  307. void nrf_power_int_disable(uint32_t int_mask)
  308. {
  309. NRF_POWER->INTENCLR = int_mask;
  310. }
  311. #endif /* SUPPRESS_INLINE_IMPLEMENTATION */
  312. /* ------------------------------------------------------------------------------------------------
  313. * End of automatically generated part
  314. * ------------------------------------------------------------------------------------------------
  315. */
  316. /**
  317. * @ingroup nrf_power_hal
  318. * @{
  319. */
  320. /**
  321. * @brief Reset reason
  322. */
  323. typedef enum
  324. {
  325. NRF_POWER_RESETREAS_RESETPIN_MASK = POWER_RESETREAS_RESETPIN_Msk, /*!< Bit mask of RESETPIN field. *///!< NRF_POWER_RESETREAS_RESETPIN_MASK
  326. NRF_POWER_RESETREAS_DOG_MASK = POWER_RESETREAS_DOG_Msk , /*!< Bit mask of DOG field. */ //!< NRF_POWER_RESETREAS_DOG_MASK
  327. NRF_POWER_RESETREAS_SREQ_MASK = POWER_RESETREAS_SREQ_Msk , /*!< Bit mask of SREQ field. */ //!< NRF_POWER_RESETREAS_SREQ_MASK
  328. NRF_POWER_RESETREAS_LOCKUP_MASK = POWER_RESETREAS_LOCKUP_Msk , /*!< Bit mask of LOCKUP field. */ //!< NRF_POWER_RESETREAS_LOCKUP_MASK
  329. NRF_POWER_RESETREAS_OFF_MASK = POWER_RESETREAS_OFF_Msk , /*!< Bit mask of OFF field. */ //!< NRF_POWER_RESETREAS_OFF_MASK
  330. #if defined(POWER_RESETREAS_LPCOMP_Msk) || defined(__NRFX_DOXYGEN__)
  331. NRF_POWER_RESETREAS_LPCOMP_MASK = POWER_RESETREAS_LPCOMP_Msk , /*!< Bit mask of LPCOMP field. */ //!< NRF_POWER_RESETREAS_LPCOMP_MASK
  332. #endif
  333. NRF_POWER_RESETREAS_DIF_MASK = POWER_RESETREAS_DIF_Msk , /*!< Bit mask of DIF field. */ //!< NRF_POWER_RESETREAS_DIF_MASK
  334. #if defined(POWER_RESETREAS_NFC_Msk) || defined(__NRFX_DOXYGEN__)
  335. NRF_POWER_RESETREAS_NFC_MASK = POWER_RESETREAS_NFC_Msk , /*!< Bit mask of NFC field. */
  336. #endif
  337. #if defined(POWER_RESETREAS_VBUS_Msk) || defined(__NRFX_DOXYGEN__)
  338. NRF_POWER_RESETREAS_VBUS_MASK = POWER_RESETREAS_VBUS_Msk , /*!< Bit mask of VBUS field. */
  339. #endif
  340. }nrf_power_resetreas_mask_t;
  341. #if NRF_POWER_HAS_USBREG
  342. /**
  343. * @brief USBREGSTATUS register bit masks
  344. *
  345. * @sa nrf_power_usbregstatus_get
  346. */
  347. typedef enum
  348. {
  349. NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK = POWER_USBREGSTATUS_VBUSDETECT_Msk, /**< USB detected or removed */
  350. NRF_POWER_USBREGSTATUS_OUTPUTRDY_MASK = POWER_USBREGSTATUS_OUTPUTRDY_Msk /**< USB 3.3&nbsp;V supply ready */
  351. }nrf_power_usbregstatus_mask_t;
  352. #endif
  353. #if NRF_POWER_HAS_RAMSTATUS
  354. /**
  355. * @brief RAM blocks numbers
  356. *
  357. * @sa nrf_power_ramblock_mask_t
  358. * @note
  359. * Ram blocks has to been used in nrf51.
  360. * In new CPU ram is divided into segments and this functionality is depreciated.
  361. * For the newer MCU see the PS for mapping between internal RAM and RAM blocks,
  362. * because this mapping is not 1:1, and functions related to old style blocks
  363. * should not be used.
  364. */
  365. typedef enum
  366. {
  367. NRF_POWER_RAMBLOCK0 = POWER_RAMSTATUS_RAMBLOCK0_Pos,
  368. NRF_POWER_RAMBLOCK1 = POWER_RAMSTATUS_RAMBLOCK1_Pos,
  369. NRF_POWER_RAMBLOCK2 = POWER_RAMSTATUS_RAMBLOCK2_Pos,
  370. NRF_POWER_RAMBLOCK3 = POWER_RAMSTATUS_RAMBLOCK3_Pos
  371. }nrf_power_ramblock_t;
  372. /**
  373. * @brief RAM blocks masks
  374. *
  375. * @sa nrf_power_ramblock_t
  376. */
  377. typedef enum
  378. {
  379. NRF_POWER_RAMBLOCK0_MASK = POWER_RAMSTATUS_RAMBLOCK0_Msk,
  380. NRF_POWER_RAMBLOCK1_MASK = POWER_RAMSTATUS_RAMBLOCK1_Msk,
  381. NRF_POWER_RAMBLOCK2_MASK = POWER_RAMSTATUS_RAMBLOCK2_Msk,
  382. NRF_POWER_RAMBLOCK3_MASK = POWER_RAMSTATUS_RAMBLOCK3_Msk
  383. }nrf_power_ramblock_mask_t;
  384. #endif // NRF_POWER_HAS_RAMSTATUS
  385. /**
  386. * @brief RAM power state position of the bits
  387. *
  388. * @sa nrf_power_onoffram_mask_t
  389. */
  390. typedef enum
  391. {
  392. NRF_POWER_ONRAM0, /**< Keep RAM block 0 on or off in system ON Mode */
  393. NRF_POWER_OFFRAM0, /**< Keep retention on RAM block 0 when RAM block is switched off */
  394. NRF_POWER_ONRAM1, /**< Keep RAM block 1 on or off in system ON Mode */
  395. NRF_POWER_OFFRAM1, /**< Keep retention on RAM block 1 when RAM block is switched off */
  396. NRF_POWER_ONRAM2, /**< Keep RAM block 2 on or off in system ON Mode */
  397. NRF_POWER_OFFRAM2, /**< Keep retention on RAM block 2 when RAM block is switched off */
  398. NRF_POWER_ONRAM3, /**< Keep RAM block 3 on or off in system ON Mode */
  399. NRF_POWER_OFFRAM3, /**< Keep retention on RAM block 3 when RAM block is switched off */
  400. }nrf_power_onoffram_t;
  401. /**
  402. * @brief RAM power state bit masks
  403. *
  404. * @sa nrf_power_onoffram_t
  405. */
  406. typedef enum
  407. {
  408. NRF_POWER_ONRAM0_MASK = 1U << NRF_POWER_ONRAM0, /**< Keep RAM block 0 on or off in system ON Mode */
  409. NRF_POWER_OFFRAM0_MASK = 1U << NRF_POWER_OFFRAM0, /**< Keep retention on RAM block 0 when RAM block is switched off */
  410. NRF_POWER_ONRAM1_MASK = 1U << NRF_POWER_ONRAM1, /**< Keep RAM block 1 on or off in system ON Mode */
  411. NRF_POWER_OFFRAM1_MASK = 1U << NRF_POWER_OFFRAM1, /**< Keep retention on RAM block 1 when RAM block is switched off */
  412. NRF_POWER_ONRAM2_MASK = 1U << NRF_POWER_ONRAM2, /**< Keep RAM block 2 on or off in system ON Mode */
  413. NRF_POWER_OFFRAM2_MASK = 1U << NRF_POWER_OFFRAM2, /**< Keep retention on RAM block 2 when RAM block is switched off */
  414. NRF_POWER_ONRAM3_MASK = 1U << NRF_POWER_ONRAM3, /**< Keep RAM block 3 on or off in system ON Mode */
  415. NRF_POWER_OFFRAM3_MASK = 1U << NRF_POWER_OFFRAM3, /**< Keep retention on RAM block 3 when RAM block is switched off */
  416. }nrf_power_onoffram_mask_t;
  417. /**
  418. * @brief Power failure comparator thresholds
  419. */
  420. typedef enum
  421. {
  422. NRF_POWER_POFTHR_V21 = POWER_POFCON_THRESHOLD_V21, /**< Set threshold to 2.1&nbsp;V */
  423. NRF_POWER_POFTHR_V23 = POWER_POFCON_THRESHOLD_V23, /**< Set threshold to 2.3&nbsp;V */
  424. NRF_POWER_POFTHR_V25 = POWER_POFCON_THRESHOLD_V25, /**< Set threshold to 2.5&nbsp;V */
  425. NRF_POWER_POFTHR_V27 = POWER_POFCON_THRESHOLD_V27, /**< Set threshold to 2.7&nbsp;V */
  426. #if defined(POWER_POFCON_THRESHOLD_V17) || defined(__NRFX_DOXYGEN__)
  427. NRF_POWER_POFTHR_V17 = POWER_POFCON_THRESHOLD_V17, /**< Set threshold to 1.7&nbsp;V */
  428. NRF_POWER_POFTHR_V18 = POWER_POFCON_THRESHOLD_V18, /**< Set threshold to 1.8&nbsp;V */
  429. NRF_POWER_POFTHR_V19 = POWER_POFCON_THRESHOLD_V19, /**< Set threshold to 1.9&nbsp;V */
  430. NRF_POWER_POFTHR_V20 = POWER_POFCON_THRESHOLD_V20, /**< Set threshold to 2.0&nbsp;V */
  431. NRF_POWER_POFTHR_V22 = POWER_POFCON_THRESHOLD_V22, /**< Set threshold to 2.2&nbsp;V */
  432. NRF_POWER_POFTHR_V24 = POWER_POFCON_THRESHOLD_V24, /**< Set threshold to 2.4&nbsp;V */
  433. NRF_POWER_POFTHR_V26 = POWER_POFCON_THRESHOLD_V26, /**< Set threshold to 2.6&nbsp;V */
  434. NRF_POWER_POFTHR_V28 = POWER_POFCON_THRESHOLD_V28, /**< Set threshold to 2.8&nbsp;V */
  435. #endif
  436. }nrf_power_pof_thr_t;
  437. #if NRF_POWER_HAS_VDDH
  438. /**
  439. * @brief Power failure comparator thresholds for VDDH
  440. */
  441. typedef enum
  442. {
  443. NRF_POWER_POFTHRVDDH_V27 = POWER_POFCON_THRESHOLDVDDH_V27, /**< Set threshold to 2.7&nbsp;V */
  444. NRF_POWER_POFTHRVDDH_V28 = POWER_POFCON_THRESHOLDVDDH_V28, /**< Set threshold to 2.8&nbsp;V */
  445. NRF_POWER_POFTHRVDDH_V29 = POWER_POFCON_THRESHOLDVDDH_V29, /**< Set threshold to 2.9&nbsp;V */
  446. NRF_POWER_POFTHRVDDH_V30 = POWER_POFCON_THRESHOLDVDDH_V30, /**< Set threshold to 3.0&nbsp;V */
  447. NRF_POWER_POFTHRVDDH_V31 = POWER_POFCON_THRESHOLDVDDH_V31, /**< Set threshold to 3.1&nbsp;V */
  448. NRF_POWER_POFTHRVDDH_V32 = POWER_POFCON_THRESHOLDVDDH_V32, /**< Set threshold to 3.2&nbsp;V */
  449. NRF_POWER_POFTHRVDDH_V33 = POWER_POFCON_THRESHOLDVDDH_V33, /**< Set threshold to 3.3&nbsp;V */
  450. NRF_POWER_POFTHRVDDH_V34 = POWER_POFCON_THRESHOLDVDDH_V34, /**< Set threshold to 3.4&nbsp;V */
  451. NRF_POWER_POFTHRVDDH_V35 = POWER_POFCON_THRESHOLDVDDH_V35, /**< Set threshold to 3.5&nbsp;V */
  452. NRF_POWER_POFTHRVDDH_V36 = POWER_POFCON_THRESHOLDVDDH_V36, /**< Set threshold to 3.6&nbsp;V */
  453. NRF_POWER_POFTHRVDDH_V37 = POWER_POFCON_THRESHOLDVDDH_V37, /**< Set threshold to 3.7&nbsp;V */
  454. NRF_POWER_POFTHRVDDH_V38 = POWER_POFCON_THRESHOLDVDDH_V38, /**< Set threshold to 3.8&nbsp;V */
  455. NRF_POWER_POFTHRVDDH_V39 = POWER_POFCON_THRESHOLDVDDH_V39, /**< Set threshold to 3.9&nbsp;V */
  456. NRF_POWER_POFTHRVDDH_V40 = POWER_POFCON_THRESHOLDVDDH_V40, /**< Set threshold to 4.0&nbsp;V */
  457. NRF_POWER_POFTHRVDDH_V41 = POWER_POFCON_THRESHOLDVDDH_V41, /**< Set threshold to 4.1&nbsp;V */
  458. NRF_POWER_POFTHRVDDH_V42 = POWER_POFCON_THRESHOLDVDDH_V42, /**< Set threshold to 4.2&nbsp;V */
  459. }nrf_power_pof_thrvddh_t;
  460. /**
  461. * @brief Main regulator status
  462. */
  463. typedef enum
  464. {
  465. NRF_POWER_MAINREGSTATUS_NORMAL = POWER_MAINREGSTATUS_MAINREGSTATUS_Normal, /**< Normal voltage mode. Voltage supplied on VDD. */
  466. NRF_POWER_MAINREGSTATUS_HIGH = POWER_MAINREGSTATUS_MAINREGSTATUS_High /**< High voltage mode. Voltage supplied on VDDH. */
  467. }nrf_power_mainregstatus_t;
  468. #endif /* NRF_POWER_HAS_VDDH */
  469. #if NRF_POWER_HAS_RAMPOWER_REGS
  470. /**
  471. * @brief Bit positions for RAMPOWER register
  472. *
  473. * All possible bits described, even if they are not used in selected MCU.
  474. */
  475. typedef enum
  476. {
  477. /** Keep RAM section S0 ON in System ON mode */
  478. NRF_POWER_RAMPOWER_S0POWER = POWER_RAM_POWER_S0POWER_Pos,
  479. NRF_POWER_RAMPOWER_S1POWER, /**< Keep RAM section S1 ON in System ON mode */
  480. NRF_POWER_RAMPOWER_S2POWER, /**< Keep RAM section S2 ON in System ON mode */
  481. NRF_POWER_RAMPOWER_S3POWER, /**< Keep RAM section S3 ON in System ON mode */
  482. NRF_POWER_RAMPOWER_S4POWER, /**< Keep RAM section S4 ON in System ON mode */
  483. NRF_POWER_RAMPOWER_S5POWER, /**< Keep RAM section S5 ON in System ON mode */
  484. NRF_POWER_RAMPOWER_S6POWER, /**< Keep RAM section S6 ON in System ON mode */
  485. NRF_POWER_RAMPOWER_S7POWER, /**< Keep RAM section S7 ON in System ON mode */
  486. NRF_POWER_RAMPOWER_S8POWER, /**< Keep RAM section S8 ON in System ON mode */
  487. NRF_POWER_RAMPOWER_S9POWER, /**< Keep RAM section S9 ON in System ON mode */
  488. NRF_POWER_RAMPOWER_S10POWER, /**< Keep RAM section S10 ON in System ON mode */
  489. NRF_POWER_RAMPOWER_S11POWER, /**< Keep RAM section S11 ON in System ON mode */
  490. NRF_POWER_RAMPOWER_S12POWER, /**< Keep RAM section S12 ON in System ON mode */
  491. NRF_POWER_RAMPOWER_S13POWER, /**< Keep RAM section S13 ON in System ON mode */
  492. NRF_POWER_RAMPOWER_S14POWER, /**< Keep RAM section S14 ON in System ON mode */
  493. NRF_POWER_RAMPOWER_S15POWER, /**< Keep RAM section S15 ON in System ON mode */
  494. /** Keep section retention in OFF mode when section is OFF */
  495. NRF_POWER_RAMPOWER_S0RETENTION = POWER_RAM_POWER_S0RETENTION_Pos,
  496. NRF_POWER_RAMPOWER_S1RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  497. NRF_POWER_RAMPOWER_S2RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  498. NRF_POWER_RAMPOWER_S3RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  499. NRF_POWER_RAMPOWER_S4RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  500. NRF_POWER_RAMPOWER_S5RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  501. NRF_POWER_RAMPOWER_S6RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  502. NRF_POWER_RAMPOWER_S7RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  503. NRF_POWER_RAMPOWER_S8RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  504. NRF_POWER_RAMPOWER_S9RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  505. NRF_POWER_RAMPOWER_S10RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  506. NRF_POWER_RAMPOWER_S11RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  507. NRF_POWER_RAMPOWER_S12RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  508. NRF_POWER_RAMPOWER_S13RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  509. NRF_POWER_RAMPOWER_S14RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  510. NRF_POWER_RAMPOWER_S15RETENTION, /**< Keep section retention in OFF mode when section is OFF */
  511. }nrf_power_rampower_t;
  512. #if defined ( __CC_ARM )
  513. #pragma push
  514. #pragma diag_suppress 66
  515. #endif
  516. /**
  517. * @brief Bit masks for RAMPOWER register
  518. *
  519. * All possible bits described, even if they are not used in selected MCU.
  520. */
  521. typedef enum
  522. {
  523. NRF_POWER_RAMPOWER_S0POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S0POWER ,
  524. NRF_POWER_RAMPOWER_S1POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S1POWER ,
  525. NRF_POWER_RAMPOWER_S2POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S2POWER ,
  526. NRF_POWER_RAMPOWER_S3POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S3POWER ,
  527. NRF_POWER_RAMPOWER_S4POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S4POWER ,
  528. NRF_POWER_RAMPOWER_S5POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S5POWER ,
  529. NRF_POWER_RAMPOWER_S7POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S7POWER ,
  530. NRF_POWER_RAMPOWER_S8POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S8POWER ,
  531. NRF_POWER_RAMPOWER_S9POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S9POWER ,
  532. NRF_POWER_RAMPOWER_S10POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S10POWER,
  533. NRF_POWER_RAMPOWER_S11POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S11POWER,
  534. NRF_POWER_RAMPOWER_S12POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S12POWER,
  535. NRF_POWER_RAMPOWER_S13POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S13POWER,
  536. NRF_POWER_RAMPOWER_S14POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S14POWER,
  537. NRF_POWER_RAMPOWER_S15POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S15POWER,
  538. NRF_POWER_RAMPOWER_S0RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S0RETENTION ,
  539. NRF_POWER_RAMPOWER_S1RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S1RETENTION ,
  540. NRF_POWER_RAMPOWER_S2RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S2RETENTION ,
  541. NRF_POWER_RAMPOWER_S3RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S3RETENTION ,
  542. NRF_POWER_RAMPOWER_S4RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S4RETENTION ,
  543. NRF_POWER_RAMPOWER_S5RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S5RETENTION ,
  544. NRF_POWER_RAMPOWER_S7RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S7RETENTION ,
  545. NRF_POWER_RAMPOWER_S8RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S8RETENTION ,
  546. NRF_POWER_RAMPOWER_S9RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S9RETENTION ,
  547. NRF_POWER_RAMPOWER_S10RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S10RETENTION,
  548. NRF_POWER_RAMPOWER_S11RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S11RETENTION,
  549. NRF_POWER_RAMPOWER_S12RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S12RETENTION,
  550. NRF_POWER_RAMPOWER_S13RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S13RETENTION,
  551. NRF_POWER_RAMPOWER_S14RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S14RETENTION,
  552. NRF_POWER_RAMPOWER_S15RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S15RETENTION,
  553. }nrf_power_rampower_mask_t;
  554. #if defined ( __CC_ARM )
  555. #pragma pop
  556. #endif
  557. #endif /* NRF_POWER_HAS_RAMPOWER_REGS */
  558. /**
  559. * @brief Get reset reason mask
  560. *
  561. * Function returns the reset reason.
  562. * Unless cleared, the RESETREAS register is cumulative.
  563. * A field is cleared by writing '1' to it (see @ref nrf_power_resetreas_clear).
  564. * If none of the reset sources are flagged,
  565. * this indicates that the chip was reset from the on-chip reset generator,
  566. * which indicates a power-on-reset or a brown out reset.
  567. *
  568. * @return The mask of reset reasons constructed with @ref nrf_power_resetreas_mask_t.
  569. */
  570. __STATIC_INLINE uint32_t nrf_power_resetreas_get(void);
  571. /**
  572. * @brief Clear selected reset reason field
  573. *
  574. * Function clears selected reset reason fields.
  575. *
  576. * @param[in] mask The mask constructed from @ref nrf_power_resetreas_mask_t enumerator values.
  577. * @sa nrf_power_resetreas_get
  578. */
  579. __STATIC_INLINE void nrf_power_resetreas_clear(uint32_t mask);
  580. #if NRF_POWER_HAS_RAMSTATUS
  581. /**
  582. * @brief Get RAMSTATUS register
  583. *
  584. * Returns the masks of RAM blocks that are powered ON.
  585. *
  586. * @return Value with bits sets according to masks in @ref nrf_power_ramblock_mask_t.
  587. */
  588. __STATIC_INLINE uint32_t nrf_power_ramstatus_get(void);
  589. #endif // NRF_POWER_HAS_RAMSTATUS
  590. /**
  591. * @brief Go to system OFF
  592. *
  593. * This function puts the CPU into system off mode.
  594. * The only way to wake up the CPU is by reset.
  595. *
  596. * @note This function never returns.
  597. */
  598. __STATIC_INLINE void nrf_power_system_off(void);
  599. /**
  600. * @brief Set power failure comparator configuration
  601. *
  602. * Sets power failure comparator threshold and enable/disable flag.
  603. *
  604. * @param enabled Set to true if power failure comparator should be enabled.
  605. * @param thr Set the voltage threshold value.
  606. *
  607. * @note
  608. * If VDDH settings is present in the device, this function would
  609. * clear it settings (set to the lowest voltage).
  610. * Use @ref nrf_power_pofcon_vddh_set function to set new value.
  611. */
  612. __STATIC_INLINE void nrf_power_pofcon_set(bool enabled, nrf_power_pof_thr_t thr);
  613. /**
  614. * @brief Get power failure comparator configuration
  615. *
  616. * Get power failure comparator threshold and enable bit.
  617. *
  618. * @param[out] p_enabled Function would set this boolean variable to true
  619. * if power failure comparator is enabled.
  620. * The pointer can be NULL if we do not need this information.
  621. * @return Threshold setting for power failure comparator
  622. */
  623. __STATIC_INLINE nrf_power_pof_thr_t nrf_power_pofcon_get(bool * p_enabled);
  624. #if NRF_POWER_HAS_VDDH
  625. /**
  626. * @brief Set VDDH power failure comparator threshold
  627. *
  628. * @param thr Threshold to be set
  629. */
  630. __STATIC_INLINE void nrf_power_pofcon_vddh_set(nrf_power_pof_thrvddh_t thr);
  631. /**
  632. * @brief Get VDDH power failure comparator threshold
  633. *
  634. * @return VDDH threshold currently configured
  635. */
  636. __STATIC_INLINE nrf_power_pof_thrvddh_t nrf_power_pofcon_vddh_get(void);
  637. #endif
  638. /**
  639. * @brief Set general purpose retention register
  640. *
  641. * @param val Value to be set in the register
  642. */
  643. __STATIC_INLINE void nrf_power_gpregret_set(uint8_t val);
  644. /**
  645. * @brief Get general purpose retention register
  646. *
  647. * @return The value from the register
  648. */
  649. __STATIC_INLINE uint8_t nrf_power_gpregret_get(void);
  650. #if defined(POWER_GPREGRET2_GPREGRET_Msk) || defined(__NRFX_DOXYGEN__)
  651. /**
  652. * @brief Set general purpose retention register 2
  653. *
  654. * @param val Value to be set in the register
  655. * @note This register is not available in nrf51 MCU family
  656. */
  657. __STATIC_INLINE void nrf_power_gpregret2_set(uint8_t val);
  658. /**
  659. * @brief Get general purpose retention register 2
  660. *
  661. * @return The value from the register
  662. * @note This register is not available in all MCUs.
  663. */
  664. __STATIC_INLINE uint8_t nrf_power_gpregret2_get(void);
  665. #endif
  666. /**
  667. * @brief Enable or disable DCDC converter
  668. *
  669. * @param enable Set true to enable or false to disable DCDC converter.
  670. *
  671. * @note
  672. * If the device consist of high voltage power input (VDDH) this setting
  673. * would relate to the converter on low voltage side (1.3&nbsp;V output).
  674. */
  675. __STATIC_INLINE void nrf_power_dcdcen_set(bool enable);
  676. /**
  677. * @brief Get the state of DCDC converter
  678. *
  679. * @retval true Converter is enabled
  680. * @retval false Converter is disabled
  681. *
  682. * @note
  683. * If the device consist of high voltage power input (VDDH) this setting
  684. * would relate to the converter on low voltage side (1.3&nbsp;V output).
  685. */
  686. __STATIC_INLINE bool nrf_power_dcdcen_get(void);
  687. #if NRF_POWER_HAS_RAMPOWER_REGS
  688. /**
  689. * @brief Turn ON sections in selected RAM block.
  690. *
  691. * This function turns ON sections in block and also block retention.
  692. *
  693. * @sa nrf_power_rampower_mask_t
  694. * @sa nrf_power_rampower_mask_off
  695. *
  696. * @param block RAM block index.
  697. * @param section_mask Mask of the sections created by merging
  698. * @ref nrf_power_rampower_mask_t flags.
  699. */
  700. __STATIC_INLINE void nrf_power_rampower_mask_on(uint8_t block, uint32_t section_mask);
  701. /**
  702. * @brief Turn ON sections in selected RAM block.
  703. *
  704. * This function turns OFF sections in block and also block retention.
  705. *
  706. * @sa nrf_power_rampower_mask_t
  707. * @sa nrf_power_rampower_mask_off
  708. *
  709. * @param block RAM block index.
  710. * @param section_mask Mask of the sections created by merging
  711. * @ref nrf_power_rampower_mask_t flags.
  712. */
  713. __STATIC_INLINE void nrf_power_rampower_mask_off(uint8_t block, uint32_t section_mask);
  714. /**
  715. * @brief Get the mask of ON and retention sections in selected RAM block.
  716. *
  717. * @param block RAM block index.
  718. * @return Mask of sections state composed from @ref nrf_power_rampower_mask_t flags.
  719. */
  720. __STATIC_INLINE uint32_t nrf_power_rampower_mask_get(uint8_t block);
  721. #endif /* NRF_POWER_HAS_RAMPOWER_REGS */
  722. #if NRF_POWER_HAS_VDDH
  723. /**
  724. * @brief Enable of disable DCDC converter on VDDH
  725. *
  726. * @param enable Set true to enable or false to disable DCDC converter.
  727. */
  728. __STATIC_INLINE void nrf_power_dcdcen_vddh_set(bool enable);
  729. /**
  730. * @brief Get the state of DCDC converter on VDDH
  731. *
  732. * @retval true Converter is enabled
  733. * @retval false Converter is disabled
  734. */
  735. __STATIC_INLINE bool nrf_power_dcdcen_vddh_get(void);
  736. /**
  737. * @brief Get main supply status
  738. *
  739. * @return Current main supply status
  740. */
  741. __STATIC_INLINE nrf_power_mainregstatus_t nrf_power_mainregstatus_get(void);
  742. #endif /* NRF_POWER_HAS_VDDH */
  743. #if NRF_POWER_HAS_USBREG
  744. /**
  745. *
  746. * @return Get the whole USBREGSTATUS register
  747. *
  748. * @return The USBREGSTATUS register value.
  749. * Use @ref nrf_power_usbregstatus_mask_t values for bit masking.
  750. *
  751. * @sa nrf_power_usbregstatus_vbusdet_get
  752. * @sa nrf_power_usbregstatus_outrdy_get
  753. */
  754. __STATIC_INLINE uint32_t nrf_power_usbregstatus_get(void);
  755. /**
  756. * @brief VBUS input detection status
  757. *
  758. * USBDETECTED and USBREMOVED events are derived from this information
  759. *
  760. * @retval false VBUS voltage below valid threshold
  761. * @retval true VBUS voltage above valid threshold
  762. *
  763. * @sa nrf_power_usbregstatus_get
  764. */
  765. __STATIC_INLINE bool nrf_power_usbregstatus_vbusdet_get(void);
  766. /**
  767. * @brief USB supply output settling time elapsed
  768. *
  769. * @retval false USBREG output settling time not elapsed
  770. * @retval true USBREG output settling time elapsed
  771. * (same information as USBPWRRDY event)
  772. *
  773. * @sa nrf_power_usbregstatus_get
  774. */
  775. __STATIC_INLINE bool nrf_power_usbregstatus_outrdy_get(void);
  776. #endif /* NRF_POWER_HAS_USBREG */
  777. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  778. __STATIC_INLINE uint32_t nrf_power_resetreas_get(void)
  779. {
  780. return NRF_POWER->RESETREAS;
  781. }
  782. __STATIC_INLINE void nrf_power_resetreas_clear(uint32_t mask)
  783. {
  784. NRF_POWER->RESETREAS = mask;
  785. }
  786. #if NRF_POWER_HAS_RAMSTATUS
  787. __STATIC_INLINE uint32_t nrf_power_ramstatus_get(void)
  788. {
  789. return NRF_POWER->RAMSTATUS;
  790. }
  791. #endif // NRF_POWER_HAS_RAMSTATUS
  792. __STATIC_INLINE void nrf_power_system_off(void)
  793. {
  794. NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter;
  795. __DSB();
  796. /* Solution for simulated System OFF in debug mode */
  797. while (true)
  798. {
  799. __WFE();
  800. }
  801. }
  802. __STATIC_INLINE void nrf_power_pofcon_set(bool enabled, nrf_power_pof_thr_t thr)
  803. {
  804. NRFX_ASSERT(thr == (thr & (POWER_POFCON_THRESHOLD_Msk >> POWER_POFCON_THRESHOLD_Pos)));
  805. #if NRF_POWER_HAS_VDDH
  806. uint32_t pofcon = NRF_POWER->POFCON;
  807. pofcon &= ~(POWER_POFCON_THRESHOLD_Msk | POWER_POFCON_POF_Msk);
  808. pofcon |=
  809. #else /* NRF_POWER_HAS_VDDH */
  810. NRF_POWER->POFCON =
  811. #endif
  812. (((uint32_t)thr) << POWER_POFCON_THRESHOLD_Pos) |
  813. (enabled ?
  814. (POWER_POFCON_POF_Enabled << POWER_POFCON_POF_Pos)
  815. :
  816. (POWER_POFCON_POF_Disabled << POWER_POFCON_POF_Pos));
  817. #if NRF_POWER_HAS_VDDH
  818. NRF_POWER->POFCON = pofcon;
  819. #endif
  820. }
  821. __STATIC_INLINE nrf_power_pof_thr_t nrf_power_pofcon_get(bool * p_enabled)
  822. {
  823. uint32_t pofcon = NRF_POWER->POFCON;
  824. if (NULL != p_enabled)
  825. {
  826. (*p_enabled) = ((pofcon & POWER_POFCON_POF_Msk) >> POWER_POFCON_POF_Pos)
  827. == POWER_POFCON_POF_Enabled;
  828. }
  829. return (nrf_power_pof_thr_t)((pofcon & POWER_POFCON_THRESHOLD_Msk) >>
  830. POWER_POFCON_THRESHOLD_Pos);
  831. }
  832. #if NRF_POWER_HAS_VDDH
  833. __STATIC_INLINE void nrf_power_pofcon_vddh_set(nrf_power_pof_thrvddh_t thr)
  834. {
  835. NRFX_ASSERT(thr == (thr & (POWER_POFCON_THRESHOLDVDDH_Msk >> POWER_POFCON_THRESHOLDVDDH_Pos)));
  836. uint32_t pofcon = NRF_POWER->POFCON;
  837. pofcon &= ~POWER_POFCON_THRESHOLDVDDH_Msk;
  838. pofcon |= (((uint32_t)thr) << POWER_POFCON_THRESHOLDVDDH_Pos);
  839. NRF_POWER->POFCON = pofcon;
  840. }
  841. __STATIC_INLINE nrf_power_pof_thrvddh_t nrf_power_pofcon_vddh_get(void)
  842. {
  843. return (nrf_power_pof_thrvddh_t)((NRF_POWER->POFCON &
  844. POWER_POFCON_THRESHOLDVDDH_Msk) >> POWER_POFCON_THRESHOLDVDDH_Pos);
  845. }
  846. #endif /* NRF_POWER_HAS_VDDH */
  847. __STATIC_INLINE void nrf_power_gpregret_set(uint8_t val)
  848. {
  849. NRF_POWER->GPREGRET = val;
  850. }
  851. __STATIC_INLINE uint8_t nrf_power_gpregret_get(void)
  852. {
  853. return NRF_POWER->GPREGRET;
  854. }
  855. #if defined(POWER_GPREGRET2_GPREGRET_Msk) || defined(__NRFX_DOXYGEN__)
  856. void nrf_power_gpregret2_set(uint8_t val)
  857. {
  858. NRF_POWER->GPREGRET2 = val;
  859. }
  860. __STATIC_INLINE uint8_t nrf_power_gpregret2_get(void)
  861. {
  862. return NRF_POWER->GPREGRET2;
  863. }
  864. #endif
  865. __STATIC_INLINE void nrf_power_dcdcen_set(bool enable)
  866. {
  867. NRF_POWER->DCDCEN = (enable ?
  868. POWER_DCDCEN_DCDCEN_Enabled : POWER_DCDCEN_DCDCEN_Disabled) <<
  869. POWER_DCDCEN_DCDCEN_Pos;
  870. }
  871. __STATIC_INLINE bool nrf_power_dcdcen_get(void)
  872. {
  873. return (NRF_POWER->DCDCEN & POWER_DCDCEN_DCDCEN_Msk)
  874. ==
  875. (POWER_DCDCEN_DCDCEN_Enabled << POWER_DCDCEN_DCDCEN_Pos);
  876. }
  877. #if NRF_POWER_HAS_RAMPOWER_REGS
  878. __STATIC_INLINE void nrf_power_rampower_mask_on(uint8_t block, uint32_t section_mask)
  879. {
  880. NRFX_ASSERT(block < ARRAY_SIZE(NRF_POWER->RAM));
  881. NRF_POWER->RAM[block].POWERSET = section_mask;
  882. }
  883. __STATIC_INLINE void nrf_power_rampower_mask_off(uint8_t block, uint32_t section_mask)
  884. {
  885. NRFX_ASSERT(block < ARRAY_SIZE(NRF_POWER->RAM));
  886. NRF_POWER->RAM[block].POWERCLR = section_mask;
  887. }
  888. __STATIC_INLINE uint32_t nrf_power_rampower_mask_get(uint8_t block)
  889. {
  890. NRFX_ASSERT(block < ARRAY_SIZE(NRF_POWER->RAM));
  891. return NRF_POWER->RAM[block].POWER;
  892. }
  893. #endif /* NRF_POWER_HAS_RAMPOWER_REGS */
  894. #if NRF_POWER_HAS_VDDH
  895. __STATIC_INLINE void nrf_power_dcdcen_vddh_set(bool enable)
  896. {
  897. NRF_POWER->DCDCEN0 = (enable ?
  898. POWER_DCDCEN0_DCDCEN_Enabled : POWER_DCDCEN0_DCDCEN_Disabled) <<
  899. POWER_DCDCEN0_DCDCEN_Pos;
  900. }
  901. bool nrf_power_dcdcen_vddh_get(void)
  902. {
  903. return (NRF_POWER->DCDCEN0 & POWER_DCDCEN0_DCDCEN_Msk)
  904. ==
  905. (POWER_DCDCEN0_DCDCEN_Enabled << POWER_DCDCEN0_DCDCEN_Pos);
  906. }
  907. nrf_power_mainregstatus_t nrf_power_mainregstatus_get(void)
  908. {
  909. return (nrf_power_mainregstatus_t)(((NRF_POWER->MAINREGSTATUS) &
  910. POWER_MAINREGSTATUS_MAINREGSTATUS_Msk) >>
  911. POWER_MAINREGSTATUS_MAINREGSTATUS_Pos);
  912. }
  913. #endif /* NRF_POWER_HAS_VDDH */
  914. #if NRF_POWER_HAS_USBREG
  915. __STATIC_INLINE uint32_t nrf_power_usbregstatus_get(void)
  916. {
  917. return NRF_POWER->USBREGSTATUS;
  918. }
  919. __STATIC_INLINE bool nrf_power_usbregstatus_vbusdet_get(void)
  920. {
  921. return (nrf_power_usbregstatus_get() &
  922. NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK) != 0;
  923. }
  924. __STATIC_INLINE bool nrf_power_usbregstatus_outrdy_get(void)
  925. {
  926. return (nrf_power_usbregstatus_get() &
  927. NRF_POWER_USBREGSTATUS_OUTPUTRDY_MASK) != 0;
  928. }
  929. #endif /* NRF_POWER_HAS_USBREG */
  930. #endif /* SUPPRESS_INLINE_IMPLEMENTATION */
  931. /** @} */
  932. #ifdef __cplusplus
  933. }
  934. #endif
  935. #endif /* NRF_POWER_H__ */