nrf_clock.h 20 KB

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