nrf_power.h 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /**
  2. * Copyright (c) 2017 - 2020, 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_INTENSET_SLEEPENTER_Msk) || defined(__NRFX_DOXYGEN__)
  53. /** @brief Symbol indicating whether sleep events are present. */
  54. #define NRF_POWER_HAS_SLEEPEVT 1
  55. #else
  56. #define NRF_POWER_HAS_SLEEPEVT 0
  57. #endif // defined(POWER_INTENSET_SLEEPENTER_Msk) || defined(__NRFX_DOXYGEN__)
  58. #if defined(POWER_USBREGSTATUS_VBUSDETECT_Msk) || defined(__NRFX_DOXYGEN__)
  59. /** @brief Symbol indicating whether the POWER peripheral controls the USB regulator. */
  60. #define NRF_POWER_HAS_USBREG 1
  61. #else
  62. #define NRF_POWER_HAS_USBREG 0
  63. #endif // defined(POWER_USBREGSTATUS_VBUSDETECT_Msk) || defined(__NRFX_DOXYGEN__)
  64. #if defined(POWER_POFCON_THRESHOLDVDDH_Msk) || defined(__NRFX_DOXYGEN__)
  65. /** @brief Symbol indicating whether VDDH is present. */
  66. #define NRF_POWER_HAS_VDDH 1
  67. #else
  68. #define NRF_POWER_HAS_VDDH 0
  69. #endif // defined(POWER_POFCON_THRESHOLDVDDH_Msk) || defined(__NRFX_DOXYGEN__)
  70. #if defined(POWER_DCDCEN0_DCDCEN_Msk) || defined(__NRFX_DOXYGEN__)
  71. /** @brief Symbol indicating whether DCDCEN for REG0 is present. */
  72. #define NRF_POWER_HAS_DCDCEN_VDDH 1
  73. #else
  74. #define NRF_POWER_HAS_DCDCEN_VDDH 0
  75. #endif
  76. #if defined(POWER_DCDCEN_DCDCEN_Msk) || defined(__NRFX_DOXYGEN__)
  77. /** @brief Symbol indicating whether DCDCEN for REG1 is present. */
  78. #define NRF_POWER_HAS_DCDCEN 1
  79. #else
  80. #define NRF_POWER_HAS_DCDCEN 0
  81. #endif
  82. #if defined(POWER_POFCON_THRESHOLD_Msk) || defined(__NRFX_DOXYGEN__)
  83. /** @brief Symbol indicating whether POFCON is present. */
  84. #define NRF_POWER_HAS_POFCON 1
  85. #else
  86. #define NRF_POWER_HAS_POFCON 0
  87. #endif
  88. /** @brief POWER tasks. */
  89. typedef enum
  90. {
  91. NRF_POWER_TASK_CONSTLAT = offsetof(NRF_POWER_Type, TASKS_CONSTLAT), /**< Enable constant latency mode. */
  92. NRF_POWER_TASK_LOWPWR = offsetof(NRF_POWER_Type, TASKS_LOWPWR ), /**< Enable low-power mode (variable latency). */
  93. } nrf_power_task_t;
  94. /** @brief POWER events. */
  95. typedef enum
  96. {
  97. #if NRF_POWER_HAS_POFCON
  98. NRF_POWER_EVENT_POFWARN = offsetof(NRF_POWER_Type, EVENTS_POFWARN ), /**< Power failure warning. */
  99. #endif
  100. #if NRF_POWER_HAS_SLEEPEVT
  101. NRF_POWER_EVENT_SLEEPENTER = offsetof(NRF_POWER_Type, EVENTS_SLEEPENTER ), /**< CPU entered WFI/WFE sleep. */
  102. NRF_POWER_EVENT_SLEEPEXIT = offsetof(NRF_POWER_Type, EVENTS_SLEEPEXIT ), /**< CPU exited WFI/WFE sleep. */
  103. #endif
  104. #if NRF_POWER_HAS_USBREG
  105. NRF_POWER_EVENT_USBDETECTED = offsetof(NRF_POWER_Type, EVENTS_USBDETECTED), /**< Voltage supply detected on VBUS. */
  106. NRF_POWER_EVENT_USBREMOVED = offsetof(NRF_POWER_Type, EVENTS_USBREMOVED ), /**< Voltage supply removed from VBUS. */
  107. NRF_POWER_EVENT_USBPWRRDY = offsetof(NRF_POWER_Type, EVENTS_USBPWRRDY ), /**< USB 3.3&nbsp;V supply ready. */
  108. #endif
  109. } nrf_power_event_t;
  110. /** @brief POWER interrupts. */
  111. typedef enum
  112. {
  113. #if NRF_POWER_HAS_POFCON
  114. NRF_POWER_INT_POFWARN_MASK = POWER_INTENSET_POFWARN_Msk , /**< Write '1' to Enable interrupt for POFWARN event. */
  115. #endif
  116. #if NRF_POWER_HAS_SLEEPEVT
  117. NRF_POWER_INT_SLEEPENTER_MASK = POWER_INTENSET_SLEEPENTER_Msk , /**< Write '1' to Enable interrupt for SLEEPENTER event. */
  118. NRF_POWER_INT_SLEEPEXIT_MASK = POWER_INTENSET_SLEEPEXIT_Msk , /**< Write '1' to Enable interrupt for SLEEPEXIT event. */
  119. #endif
  120. #if NRF_POWER_HAS_USBREG
  121. NRF_POWER_INT_USBDETECTED_MASK = POWER_INTENSET_USBDETECTED_Msk, /**< Write '1' to Enable interrupt for USBDETECTED event. */
  122. NRF_POWER_INT_USBREMOVED_MASK = POWER_INTENSET_USBREMOVED_Msk , /**< Write '1' to Enable interrupt for USBREMOVED event. */
  123. NRF_POWER_INT_USBPWRRDY_MASK = POWER_INTENSET_USBPWRRDY_Msk , /**< Write '1' to Enable interrupt for USBPWRRDY event. */
  124. #endif
  125. } nrf_power_int_mask_t;
  126. /** @brief Reset reason. */
  127. typedef enum
  128. {
  129. NRF_POWER_RESETREAS_RESETPIN_MASK = POWER_RESETREAS_RESETPIN_Msk, /*!< Bit mask of RESETPIN field. *///!< NRF_POWER_RESETREAS_RESETPIN_MASK
  130. NRF_POWER_RESETREAS_DOG_MASK = POWER_RESETREAS_DOG_Msk , /*!< Bit mask of DOG field. */ //!< NRF_POWER_RESETREAS_DOG_MASK
  131. NRF_POWER_RESETREAS_SREQ_MASK = POWER_RESETREAS_SREQ_Msk , /*!< Bit mask of SREQ field. */ //!< NRF_POWER_RESETREAS_SREQ_MASK
  132. NRF_POWER_RESETREAS_LOCKUP_MASK = POWER_RESETREAS_LOCKUP_Msk , /*!< Bit mask of LOCKUP field. */ //!< NRF_POWER_RESETREAS_LOCKUP_MASK
  133. NRF_POWER_RESETREAS_OFF_MASK = POWER_RESETREAS_OFF_Msk , /*!< Bit mask of OFF field. */ //!< NRF_POWER_RESETREAS_OFF_MASK
  134. #if defined(POWER_RESETREAS_LPCOMP_Msk) || defined(__NRFX_DOXYGEN__)
  135. NRF_POWER_RESETREAS_LPCOMP_MASK = POWER_RESETREAS_LPCOMP_Msk , /*!< Bit mask of LPCOMP field. */ //!< NRF_POWER_RESETREAS_LPCOMP_MASK
  136. #endif
  137. NRF_POWER_RESETREAS_DIF_MASK = POWER_RESETREAS_DIF_Msk , /*!< Bit mask of DIF field. */ //!< NRF_POWER_RESETREAS_DIF_MASK
  138. #if defined(POWER_RESETREAS_NFC_Msk) || defined(__NRFX_DOXYGEN__)
  139. NRF_POWER_RESETREAS_NFC_MASK = POWER_RESETREAS_NFC_Msk , /*!< Bit mask of NFC field. */
  140. #endif
  141. #if defined(POWER_RESETREAS_VBUS_Msk) || defined(__NRFX_DOXYGEN__)
  142. NRF_POWER_RESETREAS_VBUS_MASK = POWER_RESETREAS_VBUS_Msk , /*!< Bit mask of VBUS field. */
  143. #endif
  144. } nrf_power_resetreas_mask_t;
  145. #if NRF_POWER_HAS_USBREG
  146. /**
  147. * @brief USBREGSTATUS register bit masks
  148. *
  149. * @sa nrf_power_usbregstatus_get
  150. */
  151. typedef enum
  152. {
  153. NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK = POWER_USBREGSTATUS_VBUSDETECT_Msk, /**< USB detected or removed. */
  154. NRF_POWER_USBREGSTATUS_OUTPUTRDY_MASK = POWER_USBREGSTATUS_OUTPUTRDY_Msk /**< USB 3.3&nbsp;V supply ready. */
  155. } nrf_power_usbregstatus_mask_t;
  156. #endif // NRF_POWER_HAS_USBREG
  157. #if defined(POWER_RAMSTATUS_RAMBLOCK0_Msk) || defined(__NRFX_DOXYGEN__)
  158. /**
  159. * @brief Numbers of RAM blocks
  160. *
  161. * @sa nrf_power_ramblock_mask_t
  162. * @note
  163. * RAM blocks must be used in nRF51.
  164. * In newer SoCs, RAM is divided into segments and this functionality is not supported.
  165. * See the PS for mapping between the internal RAM and RAM blocks, because this
  166. * mapping is not 1:1, and functions related to old style blocks must not be used.
  167. */
  168. typedef enum
  169. {
  170. NRF_POWER_RAMBLOCK0 = POWER_RAMSTATUS_RAMBLOCK0_Pos,
  171. NRF_POWER_RAMBLOCK1 = POWER_RAMSTATUS_RAMBLOCK1_Pos,
  172. #if defined(POWER_RAMSTATUS_RAMBLOCK2_Pos) || defined(__NRFX_DOXYGEN__)
  173. NRF_POWER_RAMBLOCK2 = POWER_RAMSTATUS_RAMBLOCK2_Pos,
  174. #endif
  175. #if defined(POWER_RAMSTATUS_RAMBLOCK3_Pos) || defined(__NRFX_DOXYGEN__)
  176. NRF_POWER_RAMBLOCK3 = POWER_RAMSTATUS_RAMBLOCK3_Pos
  177. #endif
  178. } nrf_power_ramblock_t;
  179. /**
  180. * @brief Masks of RAM blocks.
  181. *
  182. * @sa nrf_power_ramblock_t
  183. */
  184. typedef enum
  185. {
  186. NRF_POWER_RAMBLOCK0_MASK = POWER_RAMSTATUS_RAMBLOCK0_Msk,
  187. NRF_POWER_RAMBLOCK1_MASK = POWER_RAMSTATUS_RAMBLOCK1_Msk,
  188. #if defined(POWER_RAMSTATUS_RAMBLOCK2_Msk) || defined(__NRFX_DOXYGEN__)
  189. NRF_POWER_RAMBLOCK2_MASK = POWER_RAMSTATUS_RAMBLOCK2_Msk,
  190. #endif
  191. #if defined(POWER_RAMSTATUS_RAMBLOCK3_Msk) || defined(__NRFX_DOXYGEN__)
  192. NRF_POWER_RAMBLOCK3_MASK = POWER_RAMSTATUS_RAMBLOCK3_Msk
  193. #endif
  194. } nrf_power_ramblock_mask_t;
  195. #endif // defined(POWER_RAMSTATUS_RAMBLOCK0_Msk) || defined(__NRFX_DOXYGEN__)
  196. /**
  197. * @brief RAM power state position of the bits
  198. *
  199. * @sa nrf_power_onoffram_mask_t
  200. */
  201. typedef enum
  202. {
  203. NRF_POWER_ONRAM0, /**< Keep RAM block 0 ON or OFF in System ON mode. */
  204. NRF_POWER_OFFRAM0, /**< Keep retention on RAM block 0 when RAM block is switched OFF. */
  205. NRF_POWER_ONRAM1, /**< Keep RAM block 1 ON or OFF in System ON mode. */
  206. NRF_POWER_OFFRAM1, /**< Keep retention on RAM block 1 when RAM block is switched OFF. */
  207. NRF_POWER_ONRAM2, /**< Keep RAM block 2 ON or OFF in System ON mode. */
  208. NRF_POWER_OFFRAM2, /**< Keep retention on RAM block 2 when RAM block is switched OFF. */
  209. NRF_POWER_ONRAM3, /**< Keep RAM block 3 ON or OFF in System ON mode. */
  210. NRF_POWER_OFFRAM3, /**< Keep retention on RAM block 3 when RAM block is switched OFF. */
  211. }nrf_power_onoffram_t;
  212. /**
  213. * @brief RAM power state bit masks
  214. *
  215. * @sa nrf_power_onoffram_t
  216. */
  217. typedef enum
  218. {
  219. NRF_POWER_ONRAM0_MASK = 1U << NRF_POWER_ONRAM0, /**< Keep RAM block 0 ON or OFF in System ON mode. */
  220. NRF_POWER_OFFRAM0_MASK = 1U << NRF_POWER_OFFRAM0, /**< Keep retention on RAM block 0 when RAM block is switched OFF. */
  221. NRF_POWER_ONRAM1_MASK = 1U << NRF_POWER_ONRAM1, /**< Keep RAM block 1 ON or OFF in System ON mode. */
  222. NRF_POWER_OFFRAM1_MASK = 1U << NRF_POWER_OFFRAM1, /**< Keep retention on RAM block 1 when RAM block is switched OFF. */
  223. NRF_POWER_ONRAM2_MASK = 1U << NRF_POWER_ONRAM2, /**< Keep RAM block 2 ON or OFF in System ON mode. */
  224. NRF_POWER_OFFRAM2_MASK = 1U << NRF_POWER_OFFRAM2, /**< Keep retention on RAM block 2 when RAM block is switched OFF. */
  225. NRF_POWER_ONRAM3_MASK = 1U << NRF_POWER_ONRAM3, /**< Keep RAM block 3 ON or OFF in System ON mode. */
  226. NRF_POWER_OFFRAM3_MASK = 1U << NRF_POWER_OFFRAM3, /**< Keep retention on RAM block 3 when RAM block is switched OFF. */
  227. }nrf_power_onoffram_mask_t;
  228. #if NRF_POWER_HAS_POFCON
  229. /** @brief Power failure comparator thresholds. */
  230. typedef enum
  231. {
  232. NRF_POWER_POFTHR_V21 = POWER_POFCON_THRESHOLD_V21, /**< Set threshold to 2.1&nbsp;V. */
  233. NRF_POWER_POFTHR_V23 = POWER_POFCON_THRESHOLD_V23, /**< Set threshold to 2.3&nbsp;V. */
  234. NRF_POWER_POFTHR_V25 = POWER_POFCON_THRESHOLD_V25, /**< Set threshold to 2.5&nbsp;V. */
  235. NRF_POWER_POFTHR_V27 = POWER_POFCON_THRESHOLD_V27, /**< Set threshold to 2.7&nbsp;V. */
  236. #if defined(POWER_POFCON_THRESHOLD_V17) || defined(__NRFX_DOXYGEN__)
  237. NRF_POWER_POFTHR_V17 = POWER_POFCON_THRESHOLD_V17, /**< Set threshold to 1.7&nbsp;V. */
  238. NRF_POWER_POFTHR_V18 = POWER_POFCON_THRESHOLD_V18, /**< Set threshold to 1.8&nbsp;V. */
  239. NRF_POWER_POFTHR_V19 = POWER_POFCON_THRESHOLD_V19, /**< Set threshold to 1.9&nbsp;V. */
  240. NRF_POWER_POFTHR_V20 = POWER_POFCON_THRESHOLD_V20, /**< Set threshold to 2.0&nbsp;V. */
  241. NRF_POWER_POFTHR_V22 = POWER_POFCON_THRESHOLD_V22, /**< Set threshold to 2.2&nbsp;V. */
  242. NRF_POWER_POFTHR_V24 = POWER_POFCON_THRESHOLD_V24, /**< Set threshold to 2.4&nbsp;V. */
  243. NRF_POWER_POFTHR_V26 = POWER_POFCON_THRESHOLD_V26, /**< Set threshold to 2.6&nbsp;V. */
  244. NRF_POWER_POFTHR_V28 = POWER_POFCON_THRESHOLD_V28, /**< Set threshold to 2.8&nbsp;V. */
  245. #endif // defined(POWER_POFCON_THRESHOLD_V17) || defined(__NRFX_DOXYGEN__)
  246. } nrf_power_pof_thr_t;
  247. #endif // NRF_POWER_HAS_POFCON
  248. #if NRF_POWER_HAS_VDDH
  249. /** @brief Power failure comparator thresholds for VDDH. */
  250. typedef enum
  251. {
  252. NRF_POWER_POFTHRVDDH_V27 = POWER_POFCON_THRESHOLDVDDH_V27, /**< Set threshold to 2.7&nbsp;V. */
  253. NRF_POWER_POFTHRVDDH_V28 = POWER_POFCON_THRESHOLDVDDH_V28, /**< Set threshold to 2.8&nbsp;V. */
  254. NRF_POWER_POFTHRVDDH_V29 = POWER_POFCON_THRESHOLDVDDH_V29, /**< Set threshold to 2.9&nbsp;V. */
  255. NRF_POWER_POFTHRVDDH_V30 = POWER_POFCON_THRESHOLDVDDH_V30, /**< Set threshold to 3.0&nbsp;V. */
  256. NRF_POWER_POFTHRVDDH_V31 = POWER_POFCON_THRESHOLDVDDH_V31, /**< Set threshold to 3.1&nbsp;V. */
  257. NRF_POWER_POFTHRVDDH_V32 = POWER_POFCON_THRESHOLDVDDH_V32, /**< Set threshold to 3.2&nbsp;V. */
  258. NRF_POWER_POFTHRVDDH_V33 = POWER_POFCON_THRESHOLDVDDH_V33, /**< Set threshold to 3.3&nbsp;V. */
  259. NRF_POWER_POFTHRVDDH_V34 = POWER_POFCON_THRESHOLDVDDH_V34, /**< Set threshold to 3.4&nbsp;V. */
  260. NRF_POWER_POFTHRVDDH_V35 = POWER_POFCON_THRESHOLDVDDH_V35, /**< Set threshold to 3.5&nbsp;V. */
  261. NRF_POWER_POFTHRVDDH_V36 = POWER_POFCON_THRESHOLDVDDH_V36, /**< Set threshold to 3.6&nbsp;V. */
  262. NRF_POWER_POFTHRVDDH_V37 = POWER_POFCON_THRESHOLDVDDH_V37, /**< Set threshold to 3.7&nbsp;V. */
  263. NRF_POWER_POFTHRVDDH_V38 = POWER_POFCON_THRESHOLDVDDH_V38, /**< Set threshold to 3.8&nbsp;V. */
  264. NRF_POWER_POFTHRVDDH_V39 = POWER_POFCON_THRESHOLDVDDH_V39, /**< Set threshold to 3.9&nbsp;V. */
  265. NRF_POWER_POFTHRVDDH_V40 = POWER_POFCON_THRESHOLDVDDH_V40, /**< Set threshold to 4.0&nbsp;V. */
  266. NRF_POWER_POFTHRVDDH_V41 = POWER_POFCON_THRESHOLDVDDH_V41, /**< Set threshold to 4.1&nbsp;V. */
  267. NRF_POWER_POFTHRVDDH_V42 = POWER_POFCON_THRESHOLDVDDH_V42, /**< Set threshold to 4.2&nbsp;V. */
  268. } nrf_power_pof_thrvddh_t;
  269. /** @brief Main regulator status. */
  270. typedef enum
  271. {
  272. NRF_POWER_MAINREGSTATUS_NORMAL = POWER_MAINREGSTATUS_MAINREGSTATUS_Normal, /**< Normal voltage mode. Voltage supplied on VDD. */
  273. NRF_POWER_MAINREGSTATUS_HIGH = POWER_MAINREGSTATUS_MAINREGSTATUS_High /**< High voltage mode. Voltage supplied on VDDH. */
  274. } nrf_power_mainregstatus_t;
  275. #endif // NRF_POWER_HAS_VDDH
  276. #if defined(POWER_RAM_POWER_S0POWER_Msk) || defined(__NRFX_DOXYGEN__)
  277. /**
  278. * @brief Bit positions for RAMPOWER register
  279. *
  280. * All possible bits described, even if they are not used in selected MCU.
  281. */
  282. typedef enum
  283. {
  284. /** Keep RAM section S0 ON in System ON mode */
  285. NRF_POWER_RAMPOWER_S0POWER = POWER_RAM_POWER_S0POWER_Pos,
  286. NRF_POWER_RAMPOWER_S1POWER, /**< Keep RAM section S1 ON in System ON mode. */
  287. NRF_POWER_RAMPOWER_S2POWER, /**< Keep RAM section S2 ON in System ON mode. */
  288. NRF_POWER_RAMPOWER_S3POWER, /**< Keep RAM section S3 ON in System ON mode. */
  289. NRF_POWER_RAMPOWER_S4POWER, /**< Keep RAM section S4 ON in System ON mode. */
  290. NRF_POWER_RAMPOWER_S5POWER, /**< Keep RAM section S5 ON in System ON mode. */
  291. NRF_POWER_RAMPOWER_S6POWER, /**< Keep RAM section S6 ON in System ON mode. */
  292. NRF_POWER_RAMPOWER_S7POWER, /**< Keep RAM section S7 ON in System ON mode. */
  293. NRF_POWER_RAMPOWER_S8POWER, /**< Keep RAM section S8 ON in System ON mode. */
  294. NRF_POWER_RAMPOWER_S9POWER, /**< Keep RAM section S9 ON in System ON mode. */
  295. NRF_POWER_RAMPOWER_S10POWER, /**< Keep RAM section S10 ON in System ON mode. */
  296. NRF_POWER_RAMPOWER_S11POWER, /**< Keep RAM section S11 ON in System ON mode. */
  297. NRF_POWER_RAMPOWER_S12POWER, /**< Keep RAM section S12 ON in System ON mode. */
  298. NRF_POWER_RAMPOWER_S13POWER, /**< Keep RAM section S13 ON in System ON mode. */
  299. NRF_POWER_RAMPOWER_S14POWER, /**< Keep RAM section S14 ON in System ON mode. */
  300. NRF_POWER_RAMPOWER_S15POWER, /**< Keep RAM section S15 ON in System ON mode. */
  301. /** Keep section retention in OFF mode when section is OFF */
  302. NRF_POWER_RAMPOWER_S0RETENTION = POWER_RAM_POWER_S0RETENTION_Pos,
  303. NRF_POWER_RAMPOWER_S1RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  304. NRF_POWER_RAMPOWER_S2RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  305. NRF_POWER_RAMPOWER_S3RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  306. NRF_POWER_RAMPOWER_S4RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  307. NRF_POWER_RAMPOWER_S5RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  308. NRF_POWER_RAMPOWER_S6RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  309. NRF_POWER_RAMPOWER_S7RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  310. NRF_POWER_RAMPOWER_S8RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  311. NRF_POWER_RAMPOWER_S9RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  312. NRF_POWER_RAMPOWER_S10RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  313. NRF_POWER_RAMPOWER_S11RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  314. NRF_POWER_RAMPOWER_S12RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  315. NRF_POWER_RAMPOWER_S13RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  316. NRF_POWER_RAMPOWER_S14RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  317. NRF_POWER_RAMPOWER_S15RETENTION, /**< Keep section retention in OFF mode when section is OFF. */
  318. } nrf_power_rampower_t;
  319. /**
  320. * @brief Bit masks for RAMPOWER register
  321. *
  322. * All possible bits described, even if they are not used in selected MCU.
  323. */
  324. typedef enum
  325. {
  326. NRF_POWER_RAMPOWER_S0POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S0POWER ,
  327. NRF_POWER_RAMPOWER_S1POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S1POWER ,
  328. NRF_POWER_RAMPOWER_S2POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S2POWER ,
  329. NRF_POWER_RAMPOWER_S3POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S3POWER ,
  330. NRF_POWER_RAMPOWER_S4POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S4POWER ,
  331. NRF_POWER_RAMPOWER_S5POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S5POWER ,
  332. NRF_POWER_RAMPOWER_S7POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S7POWER ,
  333. NRF_POWER_RAMPOWER_S8POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S8POWER ,
  334. NRF_POWER_RAMPOWER_S9POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S9POWER ,
  335. NRF_POWER_RAMPOWER_S10POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S10POWER,
  336. NRF_POWER_RAMPOWER_S11POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S11POWER,
  337. NRF_POWER_RAMPOWER_S12POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S12POWER,
  338. NRF_POWER_RAMPOWER_S13POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S13POWER,
  339. NRF_POWER_RAMPOWER_S14POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S14POWER,
  340. NRF_POWER_RAMPOWER_S15POWER_MASK = 1UL << NRF_POWER_RAMPOWER_S15POWER,
  341. NRF_POWER_RAMPOWER_S0RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S0RETENTION ,
  342. NRF_POWER_RAMPOWER_S1RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S1RETENTION ,
  343. NRF_POWER_RAMPOWER_S2RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S2RETENTION ,
  344. NRF_POWER_RAMPOWER_S3RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S3RETENTION ,
  345. NRF_POWER_RAMPOWER_S4RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S4RETENTION ,
  346. NRF_POWER_RAMPOWER_S5RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S5RETENTION ,
  347. NRF_POWER_RAMPOWER_S7RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S7RETENTION ,
  348. NRF_POWER_RAMPOWER_S8RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S8RETENTION ,
  349. NRF_POWER_RAMPOWER_S9RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S9RETENTION ,
  350. NRF_POWER_RAMPOWER_S10RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S10RETENTION,
  351. NRF_POWER_RAMPOWER_S11RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S11RETENTION,
  352. NRF_POWER_RAMPOWER_S12RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S12RETENTION,
  353. NRF_POWER_RAMPOWER_S13RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S13RETENTION,
  354. NRF_POWER_RAMPOWER_S14RETENTION_MASK = 1UL << NRF_POWER_RAMPOWER_S14RETENTION,
  355. NRF_POWER_RAMPOWER_S15RETENTION_MASK = (int)(1UL << NRF_POWER_RAMPOWER_S15RETENTION),
  356. } nrf_power_rampower_mask_t;
  357. #endif // defined(POWER_RAM_POWER_S0POWER_Msk) || defined(__NRFX_DOXYGEN__)
  358. /**
  359. * @brief Function for activating a specific POWER task.
  360. *
  361. * @param[in] task Task.
  362. */
  363. __STATIC_INLINE void nrf_power_task_trigger(nrf_power_task_t task);
  364. /**
  365. * @brief Function for returning the address of a specific POWER task register.
  366. *
  367. * @param[in] task Task.
  368. *
  369. * @return Task address.
  370. */
  371. __STATIC_INLINE uint32_t nrf_power_task_address_get(nrf_power_task_t task);
  372. /**
  373. * @brief Function for clearing a specific event.
  374. *
  375. * @param[in] event Event.
  376. */
  377. __STATIC_INLINE void nrf_power_event_clear(nrf_power_event_t event);
  378. /**
  379. * @brief Function for retrieving the state of the POWER event.
  380. *
  381. * @param[in] event Event to be checked.
  382. *
  383. * @retval true The event has been generated.
  384. * @retval false The event has not been generated.
  385. */
  386. __STATIC_INLINE bool nrf_power_event_check(nrf_power_event_t event);
  387. /**
  388. * @brief Function for getting and clearing the state of specific event
  389. *
  390. * This function checks the state of the event and clears it.
  391. *
  392. * @param[in] event Event.
  393. *
  394. * @retval true The event was set.
  395. * @retval false The event was not set.
  396. */
  397. __STATIC_INLINE bool nrf_power_event_get_and_clear(nrf_power_event_t event);
  398. /**
  399. * @brief Function for returning the address of a specific POWER event register.
  400. *
  401. * @param[in] event Event.
  402. *
  403. * @return Address.
  404. */
  405. __STATIC_INLINE uint32_t nrf_power_event_address_get(nrf_power_event_t event);
  406. /**
  407. * @brief Function for enabling selected interrupts.
  408. *
  409. * @param[in] int_mask Interrupts mask.
  410. */
  411. __STATIC_INLINE void nrf_power_int_enable(uint32_t int_mask);
  412. /**
  413. * @brief Function for retrieving the state of selected interrupts.
  414. *
  415. * @param[in] int_mask Interrupts mask.
  416. *
  417. * @retval true Any of selected interrupts is enabled.
  418. * @retval false None of selected interrupts is enabled.
  419. */
  420. __STATIC_INLINE bool nrf_power_int_enable_check(uint32_t int_mask);
  421. /**
  422. * @brief Function for retrieving the information about enabled interrupts.
  423. *
  424. * @return The flags of enabled interrupts.
  425. */
  426. __STATIC_INLINE uint32_t nrf_power_int_enable_get(void);
  427. /**
  428. * @brief Function for disabling selected interrupts.
  429. *
  430. * @param[in] int_mask Interrupts mask.
  431. */
  432. __STATIC_INLINE void nrf_power_int_disable(uint32_t int_mask);
  433. #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  434. /**
  435. * @brief Function for setting the subscribe configuration for a given
  436. * POWER task.
  437. *
  438. * @param[in] task Task for which to set the configuration.
  439. * @param[in] channel Channel through which to subscribe events.
  440. */
  441. __STATIC_INLINE void nrf_power_subscribe_set(nrf_power_task_t task,
  442. uint8_t channel);
  443. /**
  444. * @brief Function for clearing the subscribe configuration for a given
  445. * POWER task.
  446. *
  447. * @param[in] task Task for which to clear the configuration.
  448. */
  449. __STATIC_INLINE void nrf_power_subscribe_clear(nrf_power_task_t task);
  450. /**
  451. * @brief Function for setting the publish configuration for a given
  452. * POWER event.
  453. *
  454. * @param[in] event Event for which to set the configuration.
  455. * @param[in] channel Channel through which to publish the event.
  456. */
  457. __STATIC_INLINE void nrf_power_publish_set(nrf_power_event_t event,
  458. uint8_t channel);
  459. /**
  460. * @brief Function for clearing the publish configuration for a given
  461. * POWER event.
  462. *
  463. * @param[in] event Event for which to clear the configuration.
  464. */
  465. __STATIC_INLINE void nrf_power_publish_clear(nrf_power_event_t event);
  466. #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  467. /**
  468. * @brief Function for getting the reset reason bitmask.
  469. *
  470. * This function returns the reset reason bitmask.
  471. * Unless cleared, the RESETREAS register is cumulative.
  472. * A field is cleared by writing '1' to it (see @ref nrf_power_resetreas_clear).
  473. * If none of the reset sources is flagged,
  474. * the chip was reset from the on-chip reset generator,
  475. * which indicates a power-on-reset or a brown out reset.
  476. *
  477. * @return The mask of reset reasons constructed with @ref nrf_power_resetreas_mask_t.
  478. */
  479. __STATIC_INLINE uint32_t nrf_power_resetreas_get(void);
  480. /**
  481. * @brief Function for clearing the selected reset reason field.
  482. *
  483. * This function clears the selected reset reason field.
  484. *
  485. * @param[in] mask The mask constructed from @ref nrf_power_resetreas_mask_t enumerator values.
  486. * @sa nrf_power_resetreas_get
  487. */
  488. __STATIC_INLINE void nrf_power_resetreas_clear(uint32_t mask);
  489. #if defined(POWER_POWERSTATUS_LTEMODEM_Msk) || defined(__NRFX_DOXYGEN__)
  490. /**
  491. * @brief Function for getting power status of the LTE Modem domain.
  492. *
  493. * @retval true The LTE Modem domain is powered on.
  494. * @retval false The LTE Modem domain is powered off.
  495. */
  496. __STATIC_INLINE bool nrf_power_powerstatus_get(void);
  497. #endif
  498. #if defined(POWER_RAMSTATUS_RAMBLOCK0_Msk) || defined(__NRFX_DOXYGEN__)
  499. /**
  500. * @brief Function for getting the RAMSTATUS register.
  501. *
  502. * @return Value with bits set according to the masks in @ref nrf_power_ramblock_mask_t.
  503. */
  504. __STATIC_INLINE uint32_t nrf_power_ramstatus_get(void);
  505. #endif // defined(POWER_RAMSTATUS_RAMBLOCK0_Msk) || defined(__NRFX_DOXYGEN__)
  506. #if defined(POWER_SYSTEMOFF_SYSTEMOFF_Enter)
  507. /**
  508. * @brief Function for going into System OFF mode.
  509. *
  510. * This function puts the CPU in System OFF mode.
  511. * The only way to wake up the CPU is by reset.
  512. *
  513. * @note This function never returns.
  514. */
  515. __STATIC_INLINE void nrf_power_system_off(void);
  516. #endif // defined(POWER_SYSTEMOFF_SYSTEMOFF_Enter)
  517. #if NRF_POWER_HAS_POFCON
  518. /**
  519. * @brief Function for setting the power failure comparator configuration.
  520. *
  521. * This function sets the power failure comparator threshold and enables or disables flag.
  522. * @note
  523. * If VDDH settings are present in the device, this function will
  524. * clear its settings (set to the lowest voltage).
  525. * Use @ref nrf_power_pofcon_vddh_set function to set new value.
  526. *
  527. * @param enabled Sets to true if power failure comparator is to be enabled.
  528. * @param thr Sets the voltage threshold value.
  529. *
  530. */
  531. __STATIC_INLINE void nrf_power_pofcon_set(bool enabled, nrf_power_pof_thr_t thr);
  532. /**
  533. * @brief Function for getting the power failure comparator configuration.
  534. *
  535. * @param[out] p_enabled Function sets this boolean variable to true
  536. * if power failure comparator is enabled.
  537. * The pointer can be NULL if we do not need this information.
  538. *
  539. * @return Threshold setting for power failure comparator.
  540. */
  541. __STATIC_INLINE nrf_power_pof_thr_t nrf_power_pofcon_get(bool * p_enabled);
  542. #endif // NRF_POWER_HAS_POFCON
  543. #if NRF_POWER_HAS_VDDH
  544. /**
  545. * @brief Function for setting the VDDH power failure comparator threshold.
  546. *
  547. * @param thr Threshold to be set.
  548. */
  549. __STATIC_INLINE void nrf_power_pofcon_vddh_set(nrf_power_pof_thrvddh_t thr);
  550. /**
  551. * @brief Function for getting the VDDH power failure comparator threshold.
  552. *
  553. * @return VDDH threshold currently configured.
  554. */
  555. __STATIC_INLINE nrf_power_pof_thrvddh_t nrf_power_pofcon_vddh_get(void);
  556. #endif // NRF_POWER_HAS_VDDH
  557. /**
  558. * @brief Function for setting the general purpose retention register.
  559. *
  560. * @param[in] val Value to be set in the register.
  561. */
  562. __STATIC_INLINE void nrf_power_gpregret_set(uint8_t val);
  563. /**
  564. * @brief Function for getting general purpose retention register.
  565. *
  566. * @return The value from the register.
  567. */
  568. __STATIC_INLINE uint8_t nrf_power_gpregret_get(void);
  569. #if defined(POWER_GPREGRET2_GPREGRET_Msk) || defined(__NRFX_DOXYGEN__)
  570. /**
  571. * @brief Function for setting the general purpose retention register 2.
  572. *
  573. * @note This register is not available in the nRF51 MCU family.
  574. *
  575. * @param[in] val Value to be set in the register.
  576. */
  577. __STATIC_INLINE void nrf_power_gpregret2_set(uint8_t val);
  578. /**
  579. * @brief Function for getting the general purpose retention register 2.
  580. *
  581. * @note This register is not available in all MCUs.
  582. *
  583. * @return The value from the register.
  584. */
  585. __STATIC_INLINE uint8_t nrf_power_gpregret2_get(void);
  586. #endif // defined(POWER_GPREGRET2_GPREGRET_Msk) || defined(__NRFX_DOXYGEN__)
  587. /**
  588. * @brief Function for getting value of the particular general purpose retention register
  589. *
  590. * @param[in] reg_num General purpose retention register number.
  591. *
  592. * @return The value from the register
  593. */
  594. __STATIC_INLINE uint8_t nrf_power_gpregret_ext_get(uint8_t reg_num);
  595. /**
  596. * @brief Function for setting particular general purpose retention register.
  597. *
  598. * @param[in] reg_num General purpose retention register number.
  599. * @param[in] val Value to be set in the register
  600. */
  601. __STATIC_INLINE void nrf_power_gpregret_ext_set(uint8_t reg_num,
  602. uint8_t val);
  603. #if NRF_POWER_HAS_DCDCEN
  604. /**
  605. * @brief Enable or disable DCDC converter
  606. *
  607. * @note
  608. * If the device consist of high voltage power input (VDDH), this setting
  609. * will relate to the converter on low voltage side (1.3&nbsp;V output).
  610. *
  611. * @param[in] enable Set true to enable the DCDC converter or false to disable the DCDC converter.
  612. */
  613. __STATIC_INLINE void nrf_power_dcdcen_set(bool enable);
  614. /**
  615. * @brief Function for getting the state of the DCDC converter.
  616. *
  617. * @note
  618. * If the device consist of high voltage power input (VDDH), this setting
  619. * will relate to the converter on low voltage side (1.3&nbsp;V output).
  620. *
  621. * @retval true Converter is enabled.
  622. * @retval false Converter is disabled.
  623. */
  624. __STATIC_INLINE bool nrf_power_dcdcen_get(void);
  625. #endif // NRF_POWER_HAS_DCDCEN
  626. #if defined(POWER_RAM_POWER_S0POWER_Msk) || defined(__NRFX_DOXYGEN__)
  627. /**
  628. * @brief Turn ON sections in the selected RAM block.
  629. *
  630. * This function turns ON several sections in one block and also block retention.
  631. *
  632. * @sa nrf_power_rampower_mask_t
  633. * @sa nrf_power_rampower_mask_off
  634. *
  635. * @param[in] block RAM block index.
  636. * @param[in] section_mask Mask of the sections created by merging
  637. * @ref nrf_power_rampower_mask_t flags.
  638. */
  639. __STATIC_INLINE void nrf_power_rampower_mask_on(uint8_t block, uint32_t section_mask);
  640. /**
  641. * @brief Turn ON sections in the selected RAM block.
  642. *
  643. * This function turns OFF several sections in one block and also block retention.
  644. *
  645. * @sa nrf_power_rampower_mask_t
  646. * @sa nrf_power_rampower_mask_off
  647. *
  648. * @param[in] block RAM block index.
  649. * @param[in] section_mask Mask of the sections created by merging
  650. * @ref nrf_power_rampower_mask_t flags.
  651. */
  652. __STATIC_INLINE void nrf_power_rampower_mask_off(uint8_t block, uint32_t section_mask);
  653. /**
  654. * @brief Function for getting the ON mask and retention sections in the selected RAM block.
  655. *
  656. * @param[in] block RAM block index.
  657. *
  658. * @return Mask of sections state composed from @ref nrf_power_rampower_mask_t flags.
  659. */
  660. __STATIC_INLINE uint32_t nrf_power_rampower_mask_get(uint8_t block);
  661. #endif /* defined(POWER_RAM_POWER_S0POWER_Msk) || defined(__NRFX_DOXYGEN__) */
  662. #if NRF_POWER_HAS_DCDCEN_VDDH
  663. /**
  664. * @brief Function for enabling or disabling the DCDC converter on VDDH.
  665. *
  666. * @param enable Set true to enable the DCDC converter or false to disable the DCDC converter.
  667. */
  668. __STATIC_INLINE void nrf_power_dcdcen_vddh_set(bool enable);
  669. /**
  670. * @brief Function for getting the state of DCDC converter on VDDH.
  671. *
  672. * @retval true Converter is enabled.
  673. * @retval false Converter is disabled.
  674. */
  675. __STATIC_INLINE bool nrf_power_dcdcen_vddh_get(void);
  676. #endif // NRF_POWER_HAS_DCDCEN_VDDH
  677. #if NRF_POWER_HAS_VDDH
  678. /**
  679. * @brief Function for getting the main supply status.
  680. *
  681. * @return The current main supply status.
  682. */
  683. __STATIC_INLINE nrf_power_mainregstatus_t nrf_power_mainregstatus_get(void);
  684. #endif // NRF_POWER_HAS_VDDH
  685. #if NRF_POWER_HAS_USBREG
  686. /**
  687. * @brief Function for getting the whole USBREGSTATUS register.
  688. *
  689. * @return The USBREGSTATUS register value.
  690. * Use @ref nrf_power_usbregstatus_mask_t values for bit masking.
  691. *
  692. * @sa nrf_power_usbregstatus_vbusdet_get
  693. * @sa nrf_power_usbregstatus_outrdy_get
  694. */
  695. __STATIC_INLINE uint32_t nrf_power_usbregstatus_get(void);
  696. /**
  697. * @brief Function for getting the VBUS input detection status.
  698. *
  699. * USBDETECTED and USBREMOVED events are derived from this information
  700. *
  701. * @retval false VBUS voltage below valid threshold.
  702. * @retval true VBUS voltage above valid threshold.
  703. *
  704. * @sa nrf_power_usbregstatus_get
  705. */
  706. __STATIC_INLINE bool nrf_power_usbregstatus_vbusdet_get(void);
  707. /**
  708. * @brief Function for getting the state of the elapsed time for the USB supply output settling.
  709. *
  710. * @retval false USBREG output settling time not elapsed.
  711. * @retval true USBREG output settling time elapsed
  712. * (same information as USBPWRRDY event).
  713. *
  714. * @sa nrf_power_usbregstatus_get
  715. */
  716. __STATIC_INLINE bool nrf_power_usbregstatus_outrdy_get(void);
  717. #endif // NRF_POWER_HAS_USBREG
  718. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  719. __STATIC_INLINE void nrf_power_task_trigger(nrf_power_task_t task)
  720. {
  721. *((volatile uint32_t *)((uint8_t *)NRF_POWER + (uint32_t)task)) = 0x1UL;
  722. }
  723. __STATIC_INLINE uint32_t nrf_power_task_address_get(nrf_power_task_t task)
  724. {
  725. return ((uint32_t)NRF_POWER + (uint32_t)task);
  726. }
  727. __STATIC_INLINE void nrf_power_event_clear(nrf_power_event_t event)
  728. {
  729. *((volatile uint32_t *)((uint8_t *)NRF_POWER + (uint32_t)event)) = 0x0UL;
  730. #if __CORTEX_M == 0x04
  731. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_POWER + (uint32_t)event));
  732. (void)dummy;
  733. #endif
  734. }
  735. __STATIC_INLINE bool nrf_power_event_check(nrf_power_event_t event)
  736. {
  737. return (bool)*(volatile uint32_t *)((uint8_t *)NRF_POWER + (uint32_t)event);
  738. }
  739. __STATIC_INLINE bool nrf_power_event_get_and_clear(nrf_power_event_t event)
  740. {
  741. bool ret = nrf_power_event_check(event);
  742. if (ret)
  743. {
  744. nrf_power_event_clear(event);
  745. }
  746. return ret;
  747. }
  748. __STATIC_INLINE uint32_t nrf_power_event_address_get(nrf_power_event_t event)
  749. {
  750. return ((uint32_t)NRF_POWER + (uint32_t)event);
  751. }
  752. __STATIC_INLINE void nrf_power_int_enable(uint32_t int_mask)
  753. {
  754. NRF_POWER->INTENSET = int_mask;
  755. }
  756. __STATIC_INLINE bool nrf_power_int_enable_check(uint32_t int_mask)
  757. {
  758. return (bool)(NRF_POWER->INTENSET & int_mask);
  759. }
  760. __STATIC_INLINE uint32_t nrf_power_int_enable_get(void)
  761. {
  762. return NRF_POWER->INTENSET;
  763. }
  764. __STATIC_INLINE void nrf_power_int_disable(uint32_t int_mask)
  765. {
  766. NRF_POWER->INTENCLR = int_mask;
  767. }
  768. #if defined(DPPI_PRESENT)
  769. __STATIC_INLINE void nrf_power_subscribe_set(nrf_power_task_t task,
  770. uint8_t channel)
  771. {
  772. *((volatile uint32_t *) ((uint8_t *) NRF_POWER + (uint32_t) task + 0x80uL)) =
  773. ((uint32_t)channel | POWER_SUBSCRIBE_CONSTLAT_EN_Msk);
  774. }
  775. __STATIC_INLINE void nrf_power_subscribe_clear(nrf_power_task_t task)
  776. {
  777. *((volatile uint32_t *) ((uint8_t *) NRF_POWER + (uint32_t) task + 0x80uL)) = 0;
  778. }
  779. __STATIC_INLINE void nrf_power_publish_set(nrf_power_event_t event,
  780. uint8_t channel)
  781. {
  782. *((volatile uint32_t *) ((uint8_t *) NRF_POWER + (uint32_t) event + 0x80uL)) =
  783. ((uint32_t)channel | POWER_PUBLISH_SLEEPENTER_EN_Msk);
  784. }
  785. __STATIC_INLINE void nrf_power_publish_clear(nrf_power_event_t event)
  786. {
  787. *((volatile uint32_t *) ((uint8_t *) NRF_POWER + (uint32_t) event + 0x80uL)) = 0;
  788. }
  789. #endif // defined(DPPI_PRESENT)
  790. __STATIC_INLINE uint32_t nrf_power_resetreas_get(void)
  791. {
  792. return NRF_POWER->RESETREAS;
  793. }
  794. __STATIC_INLINE void nrf_power_resetreas_clear(uint32_t mask)
  795. {
  796. NRF_POWER->RESETREAS = mask;
  797. }
  798. #if defined(POWER_POWERSTATUS_LTEMODEM_Msk)
  799. __STATIC_INLINE bool nrf_power_powerstatus_get(void)
  800. {
  801. return (NRF_POWER->POWERSTATUS & POWER_POWERSTATUS_LTEMODEM_Msk) ==
  802. (POWER_POWERSTATUS_LTEMODEM_ON << POWER_POWERSTATUS_LTEMODEM_Pos);
  803. }
  804. #endif // (POWER_POWERSTATUS_LTEMODEM_Msk)
  805. #if defined(POWER_RAMSTATUS_RAMBLOCK0_Msk)
  806. __STATIC_INLINE uint32_t nrf_power_ramstatus_get(void)
  807. {
  808. return NRF_POWER->RAMSTATUS;
  809. }
  810. #endif // defined(POWER_RAMSTATUS_RAMBLOCK0_Msk)
  811. #if defined(POWER_SYSTEMOFF_SYSTEMOFF_Enter)
  812. __STATIC_INLINE void nrf_power_system_off(void)
  813. {
  814. NRF_POWER->SYSTEMOFF = POWER_SYSTEMOFF_SYSTEMOFF_Enter;
  815. __DSB();
  816. /* Solution for simulated System OFF in debug mode */
  817. while (true)
  818. {
  819. __WFE();
  820. }
  821. }
  822. #endif // defined(POWER_SYSTEMOFF_SYSTEMOFF_Enter)
  823. #if NRF_POWER_HAS_POFCON
  824. __STATIC_INLINE void nrf_power_pofcon_set(bool enabled, nrf_power_pof_thr_t thr)
  825. {
  826. NRFX_ASSERT(thr == (thr & (POWER_POFCON_THRESHOLD_Msk >> POWER_POFCON_THRESHOLD_Pos)));
  827. #if NRF_POWER_HAS_VDDH
  828. uint32_t pofcon = NRF_POWER->POFCON;
  829. pofcon &= ~(POWER_POFCON_THRESHOLD_Msk | POWER_POFCON_POF_Msk);
  830. pofcon |=
  831. #else // NRF_POWER_HAS_VDDH
  832. NRF_POWER->POFCON =
  833. #endif
  834. (((uint32_t)thr) << POWER_POFCON_THRESHOLD_Pos) |
  835. (enabled ?
  836. (POWER_POFCON_POF_Enabled << POWER_POFCON_POF_Pos)
  837. :
  838. (POWER_POFCON_POF_Disabled << POWER_POFCON_POF_Pos));
  839. #if NRF_POWER_HAS_VDDH
  840. NRF_POWER->POFCON = pofcon;
  841. #endif
  842. }
  843. __STATIC_INLINE nrf_power_pof_thr_t nrf_power_pofcon_get(bool * p_enabled)
  844. {
  845. uint32_t pofcon = NRF_POWER->POFCON;
  846. if (NULL != p_enabled)
  847. {
  848. (*p_enabled) = ((pofcon & POWER_POFCON_POF_Msk) >> POWER_POFCON_POF_Pos)
  849. == POWER_POFCON_POF_Enabled;
  850. }
  851. return (nrf_power_pof_thr_t)((pofcon & POWER_POFCON_THRESHOLD_Msk) >>
  852. POWER_POFCON_THRESHOLD_Pos);
  853. }
  854. #endif // NRF_POWER_HAS_POFCON
  855. #if NRF_POWER_HAS_VDDH
  856. __STATIC_INLINE void nrf_power_pofcon_vddh_set(nrf_power_pof_thrvddh_t thr)
  857. {
  858. NRFX_ASSERT(thr == (thr & (POWER_POFCON_THRESHOLDVDDH_Msk >> POWER_POFCON_THRESHOLDVDDH_Pos)));
  859. uint32_t pofcon = NRF_POWER->POFCON;
  860. pofcon &= ~POWER_POFCON_THRESHOLDVDDH_Msk;
  861. pofcon |= (((uint32_t)thr) << POWER_POFCON_THRESHOLDVDDH_Pos);
  862. NRF_POWER->POFCON = pofcon;
  863. }
  864. __STATIC_INLINE nrf_power_pof_thrvddh_t nrf_power_pofcon_vddh_get(void)
  865. {
  866. return (nrf_power_pof_thrvddh_t)((NRF_POWER->POFCON &
  867. POWER_POFCON_THRESHOLDVDDH_Msk) >> POWER_POFCON_THRESHOLDVDDH_Pos);
  868. }
  869. #endif // NRF_POWER_HAS_VDDH
  870. __STATIC_INLINE void nrf_power_gpregret_set(uint8_t val)
  871. {
  872. volatile uint32_t * p_gpregret;
  873. if (sizeof(NRF_POWER->GPREGRET) > sizeof(uint32_t))
  874. {
  875. p_gpregret = &((volatile uint32_t *)NRF_POWER->GPREGRET)[0];
  876. }
  877. else
  878. {
  879. p_gpregret = &((volatile uint32_t *)&NRF_POWER->GPREGRET)[0];
  880. }
  881. *p_gpregret = val;
  882. }
  883. __STATIC_INLINE uint8_t nrf_power_gpregret_get(void)
  884. {
  885. volatile uint32_t * p_gpregret;
  886. if (sizeof(NRF_POWER->GPREGRET) > sizeof(uint32_t))
  887. {
  888. p_gpregret = &((volatile uint32_t *)NRF_POWER->GPREGRET)[0];
  889. }
  890. else
  891. {
  892. p_gpregret = &((volatile uint32_t *)&NRF_POWER->GPREGRET)[0];
  893. }
  894. return *p_gpregret;
  895. }
  896. __STATIC_INLINE void nrf_power_gpregret_ext_set(uint8_t reg_num, uint8_t val)
  897. {
  898. #ifdef NRF91_SERIES
  899. NRF_POWER->GPREGRET[reg_num] = val;
  900. #else
  901. NRFX_ASSERT(reg_num < 1);
  902. NRF_POWER->GPREGRET = val;
  903. #endif
  904. }
  905. __STATIC_INLINE uint8_t nrf_power_gpregret_ext_get(uint8_t reg_num)
  906. {
  907. #ifdef NRF91_SERIES
  908. return NRF_POWER->GPREGRET[reg_num];
  909. #else
  910. NRFX_ASSERT(reg_num < 1);
  911. return NRF_POWER->GPREGRET;
  912. #endif
  913. }
  914. #if defined(POWER_GPREGRET2_GPREGRET_Msk)
  915. __STATIC_INLINE void nrf_power_gpregret2_set(uint8_t val)
  916. {
  917. NRF_POWER->GPREGRET2 = val;
  918. }
  919. __STATIC_INLINE uint8_t nrf_power_gpregret2_get(void)
  920. {
  921. return NRF_POWER->GPREGRET2;
  922. }
  923. #endif
  924. #if NRF_POWER_HAS_DCDCEN
  925. __STATIC_INLINE void nrf_power_dcdcen_set(bool enable)
  926. {
  927. NRF_POWER->DCDCEN = (enable ?
  928. POWER_DCDCEN_DCDCEN_Enabled : POWER_DCDCEN_DCDCEN_Disabled) <<
  929. POWER_DCDCEN_DCDCEN_Pos;
  930. }
  931. __STATIC_INLINE bool nrf_power_dcdcen_get(void)
  932. {
  933. return (NRF_POWER->DCDCEN & POWER_DCDCEN_DCDCEN_Msk)
  934. ==
  935. (POWER_DCDCEN_DCDCEN_Enabled << POWER_DCDCEN_DCDCEN_Pos);
  936. }
  937. #endif // NRF_POWER_HAS_DCDCEN
  938. #if defined(POWER_RAM_POWER_S0POWER_Msk)
  939. __STATIC_INLINE void nrf_power_rampower_mask_on(uint8_t block, uint32_t section_mask)
  940. {
  941. NRFX_ASSERT(block < NRFX_ARRAY_SIZE(NRF_POWER->RAM));
  942. NRF_POWER->RAM[block].POWERSET = section_mask;
  943. }
  944. __STATIC_INLINE void nrf_power_rampower_mask_off(uint8_t block, uint32_t section_mask)
  945. {
  946. NRFX_ASSERT(block < NRFX_ARRAY_SIZE(NRF_POWER->RAM));
  947. NRF_POWER->RAM[block].POWERCLR = section_mask;
  948. }
  949. __STATIC_INLINE uint32_t nrf_power_rampower_mask_get(uint8_t block)
  950. {
  951. NRFX_ASSERT(block < NRFX_ARRAY_SIZE(NRF_POWER->RAM));
  952. return NRF_POWER->RAM[block].POWER;
  953. }
  954. #endif /* defined(POWER_RAM_POWER_S0POWER_Msk) */
  955. #if NRF_POWER_HAS_DCDCEN_VDDH
  956. __STATIC_INLINE void nrf_power_dcdcen_vddh_set(bool enable)
  957. {
  958. NRF_POWER->DCDCEN0 = (enable ?
  959. POWER_DCDCEN0_DCDCEN_Enabled : POWER_DCDCEN0_DCDCEN_Disabled) <<
  960. POWER_DCDCEN0_DCDCEN_Pos;
  961. }
  962. __STATIC_INLINE bool nrf_power_dcdcen_vddh_get(void)
  963. {
  964. return (NRF_POWER->DCDCEN0 & POWER_DCDCEN0_DCDCEN_Msk)
  965. ==
  966. (POWER_DCDCEN0_DCDCEN_Enabled << POWER_DCDCEN0_DCDCEN_Pos);
  967. }
  968. #endif // NRF_POWER_HAS_DCDCEN_VDDH
  969. #if NRF_POWER_HAS_VDDH
  970. __STATIC_INLINE nrf_power_mainregstatus_t nrf_power_mainregstatus_get(void)
  971. {
  972. return (nrf_power_mainregstatus_t)(((NRF_POWER->MAINREGSTATUS) &
  973. POWER_MAINREGSTATUS_MAINREGSTATUS_Msk) >>
  974. POWER_MAINREGSTATUS_MAINREGSTATUS_Pos);
  975. }
  976. #endif // NRF_POWER_HAS_VDDH
  977. #if NRF_POWER_HAS_USBREG
  978. __STATIC_INLINE uint32_t nrf_power_usbregstatus_get(void)
  979. {
  980. return NRF_POWER->USBREGSTATUS;
  981. }
  982. __STATIC_INLINE bool nrf_power_usbregstatus_vbusdet_get(void)
  983. {
  984. return (nrf_power_usbregstatus_get() &
  985. NRF_POWER_USBREGSTATUS_VBUSDETECT_MASK) != 0;
  986. }
  987. __STATIC_INLINE bool nrf_power_usbregstatus_outrdy_get(void)
  988. {
  989. return (nrf_power_usbregstatus_get() &
  990. NRF_POWER_USBREGSTATUS_OUTPUTRDY_MASK) != 0;
  991. }
  992. #endif // NRF_POWER_HAS_USBREG
  993. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  994. /** @} */
  995. #ifdef __cplusplus
  996. }
  997. #endif
  998. #endif // NRF_POWER_H__