nrf_clock.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /**
  2. * Copyright (c) 2015 - 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_CLOCK_H__
  41. #define NRF_CLOCK_H__
  42. #include <nrfx.h>
  43. #ifdef __cplusplus
  44. extern "C" {
  45. #endif
  46. /**
  47. * @defgroup nrf_clock_hal Clock HAL
  48. * @{
  49. * @ingroup nrf_clock
  50. * @brief Hardware access layer for managing the CLOCK peripheral.
  51. *
  52. * This code can be used to managing low-frequency clock (LFCLK) and the high-frequency clock
  53. * (HFCLK) settings.
  54. */
  55. #if defined(CLOCK_LFCLKSRC_BYPASS_Msk) && defined(CLOCK_LFCLKSRC_EXTERNAL_Msk)
  56. // Enable support for external LFCLK sources. Read more in the Product Specification.
  57. #define NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES
  58. #endif
  59. #if defined(CLOCK_CTIV_CTIV_Msk) || defined(__NRFX_DOXYGEN__)
  60. /**
  61. * @brief Presence of the Low Frequency Clock calibration.
  62. *
  63. * In some MCUs there is possibility to use LFCLK calibration.
  64. */
  65. #define NRF_CLOCK_HAS_CALIBRATION 1
  66. #else
  67. #define NRF_CLOCK_HAS_CALIBRATION 0
  68. #endif // defined(CLOCK_CTIV_CTIV_Msk) || defined(__NRFX_DOXYGEN__)
  69. /**
  70. * @brief Low-frequency clock sources.
  71. * @details Used by LFCLKSRC, LFCLKSTAT, and LFCLKSRCCOPY registers.
  72. */
  73. typedef enum
  74. {
  75. #if defined(CLOCK_LFCLKSRC_SRC_RC) || defined(__NRFX_DOXYGEN__)
  76. NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_RC, /**< Internal 32 kHz RC oscillator. */
  77. #else
  78. NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_LFRC, /**< Internal 32 kHz RC oscillator. */
  79. #endif
  80. #if defined(CLOCK_LFCLKSRC_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
  81. NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_Xtal, /**< External 32 kHz crystal. */
  82. #else
  83. NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_LFXO, /**< External 32 kHz crystal. */
  84. #endif
  85. #if defined(CLOCK_LFCLKSRC_SRC_Synth) || defined(__NRFX_DOXYGEN__)
  86. NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_Synth, /**< Internal 32 kHz synthesizer from HFCLK system clock. */
  87. #endif
  88. #if defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
  89. /**
  90. * External 32 kHz low swing signal. Used only with the LFCLKSRC register.
  91. * For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
  92. */
  93. NRF_CLOCK_LFCLK_Xtal_Low_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
  94. (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
  95. /**
  96. * External 32 kHz full swing signal. Used only with the LFCLKSRC register.
  97. * For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
  98. */
  99. NRF_CLOCK_LFCLK_Xtal_Full_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
  100. (CLOCK_LFCLKSRC_BYPASS_Enabled << CLOCK_LFCLKSRC_BYPASS_Pos) |
  101. (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
  102. #endif // defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
  103. } nrf_clock_lfclk_t;
  104. /** @brief High-frequency clock sources. */
  105. typedef enum
  106. {
  107. #if defined(CLOCK_HFCLKSTAT_SRC_RC) || defined(__NRFX_DOXYGEN__)
  108. NRF_CLOCK_HFCLK_LOW_ACCURACY = CLOCK_HFCLKSTAT_SRC_RC, /**< Internal 16 MHz RC oscillator. */
  109. #endif
  110. #if defined(CLOCK_HFCLKSTAT_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
  111. NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_Xtal /**< External 16 MHz/32 MHz crystal oscillator. */
  112. #else
  113. NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_HFXO /**< External 32 MHz crystal oscillator. */
  114. #endif
  115. } nrf_clock_hfclk_t;
  116. /**
  117. * @brief Trigger status of task LFCLKSTART/HFCLKSTART.
  118. * @details Used by LFCLKRUN and HFCLKRUN registers.
  119. */
  120. typedef enum
  121. {
  122. NRF_CLOCK_START_TASK_NOT_TRIGGERED = CLOCK_LFCLKRUN_STATUS_NotTriggered, /**< Task LFCLKSTART/HFCLKSTART has not been triggered. */
  123. NRF_CLOCK_START_TASK_TRIGGERED = CLOCK_LFCLKRUN_STATUS_Triggered /**< Task LFCLKSTART/HFCLKSTART has been triggered. */
  124. } nrf_clock_start_task_status_t;
  125. /** @brief Interrupts. */
  126. typedef enum
  127. {
  128. NRF_CLOCK_INT_HF_STARTED_MASK = CLOCK_INTENSET_HFCLKSTARTED_Msk, /**< Interrupt on HFCLKSTARTED event. */
  129. NRF_CLOCK_INT_LF_STARTED_MASK = CLOCK_INTENSET_LFCLKSTARTED_Msk, /**< Interrupt on LFCLKSTARTED event. */
  130. #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
  131. NRF_CLOCK_INT_DONE_MASK = CLOCK_INTENSET_DONE_Msk, /**< Interrupt on DONE event. */
  132. NRF_CLOCK_INT_CTTO_MASK = CLOCK_INTENSET_CTTO_Msk, /**< Interrupt on CTTO event. */
  133. #endif
  134. #if defined(CLOCK_INTENSET_CTSTARTED_Msk) || defined(__NRFX_DOXYGEN__)
  135. NRF_CLOCK_INT_CTSTARTED_MASK = CLOCK_INTENSET_CTSTARTED_Msk, /**< Interrupt on CTSTARTED event. */
  136. NRF_CLOCK_INT_CTSTOPPED_MASK = CLOCK_INTENSET_CTSTOPPED_Msk /**< Interrupt on CTSTOPPED event. */
  137. #endif
  138. } nrf_clock_int_mask_t;
  139. /**
  140. * @brief Tasks.
  141. *
  142. * @details The NRF_CLOCK_TASK_LFCLKSTOP task cannot be set when the low-frequency clock is not running.
  143. * The NRF_CLOCK_TASK_HFCLKSTOP task cannot be set when the high-frequency clock is not running.
  144. */
  145. typedef enum
  146. {
  147. NRF_CLOCK_TASK_HFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTART), /**< Start HFCLK clock source.*/
  148. NRF_CLOCK_TASK_HFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTOP), /**< Stop HFCLK clock source.*/
  149. NRF_CLOCK_TASK_LFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTART), /**< Start LFCLK clock source.*/
  150. NRF_CLOCK_TASK_LFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTOP), /**< Stop LFCLK clock source.*/
  151. #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
  152. NRF_CLOCK_TASK_CAL = offsetof(NRF_CLOCK_Type, TASKS_CAL), /**< Start calibration of LFCLK RC oscillator.*/
  153. NRF_CLOCK_TASK_CTSTART = offsetof(NRF_CLOCK_Type, TASKS_CTSTART), /**< Start calibration timer.*/
  154. NRF_CLOCK_TASK_CTSTOP = offsetof(NRF_CLOCK_Type, TASKS_CTSTOP) /**< Stop calibration timer.*/
  155. #endif
  156. } nrf_clock_task_t;
  157. /** @brief Events. */
  158. typedef enum
  159. {
  160. NRF_CLOCK_EVENT_HFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKSTARTED), /**< HFCLK oscillator started.*/
  161. NRF_CLOCK_EVENT_LFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_LFCLKSTARTED), /**< LFCLK oscillator started.*/
  162. #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
  163. NRF_CLOCK_EVENT_DONE = offsetof(NRF_CLOCK_Type, EVENTS_DONE), /**< Calibration of LFCLK RC oscillator completed.*/
  164. NRF_CLOCK_EVENT_CTTO = offsetof(NRF_CLOCK_Type, EVENTS_CTTO), /**< Calibration timer time-out.*/
  165. #endif
  166. #if defined(CLOCK_INTENSET_CTSTARTED_Msk) || defined(__NRFX_DOXYGEN__)
  167. NRF_CLOCK_EVENT_CTSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_CTSTARTED), /**< Calibration timer started.*/
  168. NRF_CLOCK_EVENT_CTSTOPPED = offsetof(NRF_CLOCK_Type, EVENTS_CTSTOPPED) /**< Calibration timer stopped.*/
  169. #endif
  170. } nrf_clock_event_t;
  171. /**
  172. * @brief Function for enabling the specified interrupt.
  173. *
  174. * @param[in] int_mask Interrupt.
  175. */
  176. __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask);
  177. /**
  178. * @brief Function for disabling the specified interrupt.
  179. *
  180. * @param[in] int_mask Interrupt.
  181. */
  182. __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask);
  183. /**
  184. * @brief Function for retrieving the state of the specified interrupt.
  185. *
  186. * @param[in] int_mask Interrupt.
  187. *
  188. * @retval true The interrupt is enabled.
  189. * @retval false The interrupt is not enabled.
  190. */
  191. __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask);
  192. /**
  193. * @brief Function for retrieving the address of the specified task.
  194. * @details This function can be used by the PPI module.
  195. *
  196. * @param[in] task CLOCK Task.
  197. *
  198. * @return Address of the requested task register.
  199. */
  200. __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task);
  201. /**
  202. * @brief Function for setting the specified task.
  203. *
  204. * @param[in] task Task to be activated.
  205. */
  206. __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task);
  207. /**
  208. * @brief Function for retrieving the address of the specified event.
  209. * @details This function can be used by the PPI module.
  210. *
  211. * @param[in] event CLOCK Event.
  212. *
  213. * @return Address of the specified event register.
  214. */
  215. __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event);
  216. /**
  217. * @brief Function for clearing the specified event.
  218. *
  219. * @param[in] event Event to clear.
  220. */
  221. __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event);
  222. /**
  223. * @brief Function for retrieving the state of the specified event.
  224. *
  225. * @param[in] event Event to be checked.
  226. *
  227. * @retval true The event has been generated.
  228. * @retval false The event has not been generated.
  229. */
  230. __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event);
  231. /**
  232. * @brief Function for changing the low-frequency clock source.
  233. * @details This function cannot be called when the low-frequency clock is running.
  234. *
  235. * @param[in] source New low-frequency clock source.
  236. */
  237. __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source);
  238. /**
  239. * @brief Function for retrieving the selected source for the low-frequency clock.
  240. *
  241. * @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
  242. * is the selected source for the low-frequency clock.
  243. * @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
  244. * is the selected source for the low-frequency clock.
  245. * @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesizer from
  246. * the HFCLK is the selected source for the low-frequency clock.
  247. */
  248. __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void);
  249. /**
  250. * @brief Function for retrieving the active source of the low-frequency clock.
  251. *
  252. * @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
  253. * is the active source of the low-frequency clock.
  254. * @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
  255. * is the active source of the low-frequency clock.
  256. * @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesizer from
  257. * the HFCLK is the active source of the low-frequency clock.
  258. */
  259. __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void);
  260. /**
  261. * @brief Function for retrieving the clock source for the LFCLK clock when
  262. * the task LKCLKSTART is triggered.
  263. *
  264. * @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
  265. * is running and generating the LFCLK clock.
  266. * @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
  267. * is running and generating the LFCLK clock.
  268. * @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesizer from
  269. * the HFCLK is running and generating the LFCLK clock.
  270. */
  271. __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void);
  272. /**
  273. * @brief Function for retrieving the state of the LFCLK clock.
  274. *
  275. * @retval false The LFCLK clock is not running.
  276. * @retval true The LFCLK clock is running.
  277. */
  278. __STATIC_INLINE bool nrf_clock_lf_is_running(void);
  279. /**
  280. * @brief Function for retrieving the trigger status of the task LFCLKSTART.
  281. *
  282. * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED The task LFCLKSTART has not been triggered.
  283. * @retval NRF_CLOCK_START_TASK_TRIGGERED The task LFCLKSTART has been triggered.
  284. */
  285. __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void);
  286. /**
  287. * @brief Function for retrieving the active source of the high-frequency clock.
  288. *
  289. * @retval NRF_CLOCK_HFCLK_LOW_ACCURACY The internal RC oscillator is the active
  290. * source of the high-frequency clock.
  291. * @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY An external crystal oscillator is the active
  292. * source of the high-frequency clock.
  293. */
  294. __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void);
  295. /**
  296. * @brief Function for retrieving the state of the HFCLK clock.
  297. *
  298. * @param[in] clk_src Clock source to be checked.
  299. *
  300. * @retval false The HFCLK clock is not running.
  301. * @retval true The HFCLK clock is running.
  302. */
  303. __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src);
  304. /**
  305. * @brief Function for retrieving the trigger status of the task HFCLKSTART.
  306. *
  307. * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED The task HFCLKSTART has not been triggered.
  308. * @retval NRF_CLOCK_START_TASK_TRIGGERED The task HFCLKSTART has been triggered.
  309. */
  310. __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void);
  311. #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
  312. /**
  313. * @brief Function for changing the calibration timer interval.
  314. *
  315. * @param[in] interval New calibration timer interval in 0.25 s resolution
  316. * (range: 0.25 seconds to 31.75 seconds).
  317. */
  318. __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval);
  319. #endif
  320. #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  321. /**
  322. * @brief Function for setting the subscribe configuration for a given
  323. * CLOCK task.
  324. *
  325. * @param[in] task Task for which to set the configuration.
  326. * @param[in] channel Channel through which to subscribe events.
  327. */
  328. __STATIC_INLINE void nrf_clock_subscribe_set(nrf_clock_task_t task,
  329. uint8_t channel);
  330. /**
  331. * @brief Function for clearing the subscribe configuration for a given
  332. * CLOCK task.
  333. *
  334. * @param[in] task Task for which to clear the configuration.
  335. */
  336. __STATIC_INLINE void nrf_clock_subscribe_clear(nrf_clock_task_t task);
  337. /**
  338. * @brief Function for setting the publish configuration for a given
  339. * CLOCK event.
  340. *
  341. * @param[in] event Event for which to set the configuration.
  342. * @param[in] channel Channel through which to publish the event.
  343. */
  344. __STATIC_INLINE void nrf_clock_publish_set(nrf_clock_event_t event,
  345. uint8_t channel);
  346. /**
  347. * @brief Function for clearing the publish configuration for a given
  348. * CLOCK event.
  349. *
  350. * @param[in] event Event for which to clear the configuration.
  351. */
  352. __STATIC_INLINE void nrf_clock_publish_clear(nrf_clock_event_t event);
  353. #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
  354. #ifndef SUPPRESS_INLINE_IMPLEMENTATION
  355. __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask)
  356. {
  357. NRF_CLOCK->INTENSET = int_mask;
  358. }
  359. __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask)
  360. {
  361. NRF_CLOCK->INTENCLR = int_mask;
  362. }
  363. __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask)
  364. {
  365. return (bool)(NRF_CLOCK->INTENCLR & int_mask);
  366. }
  367. __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task)
  368. {
  369. return ((uint32_t )NRF_CLOCK + task);
  370. }
  371. __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task)
  372. {
  373. *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + task)) = 0x1UL;
  374. }
  375. __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event)
  376. {
  377. return ((uint32_t)NRF_CLOCK + event);
  378. }
  379. __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event)
  380. {
  381. *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event)) = 0x0UL;
  382. #if __CORTEX_M == 0x04
  383. volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + (uint32_t)event));
  384. (void)dummy;
  385. #endif
  386. }
  387. __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event)
  388. {
  389. return (bool)*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
  390. }
  391. __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
  392. {
  393. NRF_CLOCK->LFCLKSRC = (uint32_t)(source);
  394. }
  395. __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void)
  396. {
  397. return (nrf_clock_lfclk_t)(NRF_CLOCK->LFCLKSRC);
  398. }
  399. __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void)
  400. {
  401. return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSTAT &
  402. CLOCK_LFCLKSTAT_SRC_Msk) >> CLOCK_LFCLKSTAT_SRC_Pos);
  403. }
  404. __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void)
  405. {
  406. return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSRCCOPY &
  407. CLOCK_LFCLKSRCCOPY_SRC_Msk) >> CLOCK_LFCLKSRCCOPY_SRC_Pos);
  408. }
  409. __STATIC_INLINE bool nrf_clock_lf_is_running(void)
  410. {
  411. return ((NRF_CLOCK->LFCLKSTAT &
  412. CLOCK_LFCLKSTAT_STATE_Msk) >> CLOCK_LFCLKSTAT_STATE_Pos);
  413. }
  414. __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void)
  415. {
  416. return (nrf_clock_start_task_status_t)((NRF_CLOCK->LFCLKRUN &
  417. CLOCK_LFCLKRUN_STATUS_Msk) >> CLOCK_LFCLKRUN_STATUS_Pos);
  418. }
  419. __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void)
  420. {
  421. return (nrf_clock_hfclk_t)((NRF_CLOCK->HFCLKSTAT &
  422. CLOCK_HFCLKSTAT_SRC_Msk) >> CLOCK_HFCLKSTAT_SRC_Pos);
  423. }
  424. __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src)
  425. {
  426. return (NRF_CLOCK->HFCLKSTAT & (CLOCK_HFCLKSTAT_STATE_Msk | CLOCK_HFCLKSTAT_SRC_Msk)) ==
  427. (CLOCK_HFCLKSTAT_STATE_Msk | (clk_src << CLOCK_HFCLKSTAT_SRC_Pos));
  428. }
  429. __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void)
  430. {
  431. return (nrf_clock_start_task_status_t)((NRF_CLOCK->HFCLKRUN &
  432. CLOCK_HFCLKRUN_STATUS_Msk) >> CLOCK_HFCLKRUN_STATUS_Pos);
  433. }
  434. #if (NRF_CLOCK_HAS_CALIBRATION)
  435. __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval)
  436. {
  437. NRF_CLOCK->CTIV = ((interval << CLOCK_CTIV_CTIV_Pos) & CLOCK_CTIV_CTIV_Msk);
  438. }
  439. #endif
  440. #if defined(DPPI_PRESENT)
  441. __STATIC_INLINE void nrf_clock_subscribe_set(nrf_clock_task_t task,
  442. uint8_t channel)
  443. {
  444. *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) task + 0x80uL)) =
  445. ((uint32_t)channel | CLOCK_SUBSCRIBE_HFCLKSTART_EN_Msk);
  446. }
  447. __STATIC_INLINE void nrf_clock_subscribe_clear(nrf_clock_task_t task)
  448. {
  449. *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) task + 0x80uL)) = 0;
  450. }
  451. __STATIC_INLINE void nrf_clock_publish_set(nrf_clock_event_t event,
  452. uint8_t channel)
  453. {
  454. *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) event + 0x80uL)) =
  455. ((uint32_t)channel | CLOCK_PUBLISH_HFCLKSTARTED_EN_Msk);
  456. }
  457. __STATIC_INLINE void nrf_clock_publish_clear(nrf_clock_event_t event)
  458. {
  459. *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) event + 0x80uL)) = 0;
  460. }
  461. #endif // defined(DPPI_PRESENT)
  462. #endif // SUPPRESS_INLINE_IMPLEMENTATION
  463. /** @} */
  464. #ifdef __cplusplus
  465. }
  466. #endif
  467. #endif // NRF_CLOCK_H__