nrf_power.h 40 KB

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