xref: /nrf52832-nimble/nordic/nrfx/hal/nrf_clock.h (revision 150812a83cab50279bd772ef6db1bfaf255f2c5b)
1 /*
2  * Copyright (c) 2015 - 2018, Nordic Semiconductor ASA
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  *    list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its
16  *    contributors may be used to endorse or promote products derived from this
17  *    software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef NRF_CLOCK_H__
33 #define NRF_CLOCK_H__
34 
35 #include <nrfx.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /**
42  * @defgroup nrf_clock_hal Clock HAL
43  * @{
44  * @ingroup nrf_clock
45  * @brief   Hardware access layer for managing the CLOCK peripheral.
46  *
47  * This code can be used to managing low-frequency clock (LFCLK) and the high-frequency clock
48  * (HFCLK) settings.
49  */
50 
51 #define NRF_CLOCK_TASK_TRIGGER (1UL)
52 #define NRF_CLOCK_EVENT_CLEAR  (0UL)
53 
54 #if defined(NRF52810_XXAA) || \
55     defined(NRF52832_XXAA) || defined(NRF52832_XXAB) || \
56     defined(NRF52840_XXAA)
57 // Enable support for external LFCLK sources. Read more in the Product Specification.
58 #define NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES
59 #endif
60 
61 #if defined(CLOCK_CTIV_CTIV_Msk) || defined(__NRFX_DOXYGEN__)
62 /**
63  * @brief Presence of the Low Frequency Clock calibration.
64  *
65  * In some MCUs there is possibility to use LFCLK calibration.
66  */
67 #define NRF_CLOCK_HAS_CALIBRATION 1
68 #else
69 #define NRF_CLOCK_HAS_CALIBRATION 0
70 #endif // defined(CLOCK_CTIV_CTIV_Msk) || defined(__NRFX_DOXYGEN__)
71 
72 /**
73  * @brief Low-frequency clock sources.
74  * @details Used by LFCLKSRC, LFCLKSTAT, and LFCLKSRCCOPY registers.
75  */
76 typedef enum
77 {
78 #if defined(CLOCK_LFCLKSRC_SRC_RC) || defined(__NRFX_DOXYGEN__)
79     NRF_CLOCK_LFCLK_RC    = CLOCK_LFCLKSRC_SRC_RC,    /**< Internal 32 kHz RC oscillator. */
80 #else
81     NRF_CLOCK_LFCLK_RC    = CLOCK_LFCLKSRC_SRC_LFRC,  /**< Internal 32 kHz RC oscillator. */
82 #endif
83 
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 
90 #if defined(CLOCK_LFCLKSRC_SRC_Synth) || defined(__NRFX_DOXYGEN__)
91     NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_Synth, /**< Internal 32 kHz synthesizer from HFCLK system clock. */
92 #endif
93 #if defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
94     /**
95      * External 32 kHz low swing signal. Used only with the LFCLKSRC register.
96      * For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
97      */
98     NRF_CLOCK_LFCLK_Xtal_Low_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
99         (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
100     /**
101      * External 32 kHz full swing signal. Used only with the LFCLKSRC register.
102      * For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
103      */
104     NRF_CLOCK_LFCLK_Xtal_Full_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
105         (CLOCK_LFCLKSRC_BYPASS_Enabled   << CLOCK_LFCLKSRC_BYPASS_Pos) |
106         (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
107 #endif // defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
108 } nrf_clock_lfclk_t;
109 
110 /**
111  * @brief High-frequency clock sources.
112  */
113 typedef enum
114 {
115 #if defined(CLOCK_HFCLKSTAT_SRC_RC) || defined(__NRFX_DOXYGEN__)
116     NRF_CLOCK_HFCLK_LOW_ACCURACY  = CLOCK_HFCLKSTAT_SRC_RC,  /**< Internal 16 MHz RC oscillator. */
117 #endif
118 #if defined(CLOCK_HFCLKSTAT_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
119     NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_Xtal /**< External 16 MHz/32 MHz crystal oscillator. */
120 #else
121     NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_HFXO /**< External 32 MHz crystal oscillator. */
122 #endif
123 } nrf_clock_hfclk_t;
124 
125 /**
126  * @brief Trigger status of task LFCLKSTART/HFCLKSTART.
127  * @details Used by LFCLKRUN and HFCLKRUN registers.
128  */
129 typedef enum
130 {
131     NRF_CLOCK_START_TASK_NOT_TRIGGERED = CLOCK_LFCLKRUN_STATUS_NotTriggered, /**< Task LFCLKSTART/HFCLKSTART has not been triggered. */
132     NRF_CLOCK_START_TASK_TRIGGERED     = CLOCK_LFCLKRUN_STATUS_Triggered     /**< Task LFCLKSTART/HFCLKSTART has been triggered. */
133 } nrf_clock_start_task_status_t;
134 
135 /**
136  * @brief Interrupts.
137  */
138 typedef enum
139 {
140     NRF_CLOCK_INT_HF_STARTED_MASK = CLOCK_INTENSET_HFCLKSTARTED_Msk, /**< Interrupt on HFCLKSTARTED event. */
141     NRF_CLOCK_INT_LF_STARTED_MASK = CLOCK_INTENSET_LFCLKSTARTED_Msk, /**< Interrupt on LFCLKSTARTED event. */
142 #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
143     NRF_CLOCK_INT_DONE_MASK       = CLOCK_INTENSET_DONE_Msk,         /**< Interrupt on DONE event. */
144     NRF_CLOCK_INT_CTTO_MASK       = CLOCK_INTENSET_CTTO_Msk          /**< Interrupt on CTTO event. */
145 #endif
146 } nrf_clock_int_mask_t;
147 
148 /**
149  * @brief Tasks.
150  *
151  * @details The NRF_CLOCK_TASK_LFCLKSTOP task cannot be set when the low-frequency clock is not running.
152  * The NRF_CLOCK_TASK_HFCLKSTOP task cannot be set when the high-frequency clock is not running.
153  */
154 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
155 {
156     NRF_CLOCK_TASK_HFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTART), /**< Start HFCLK clock source.*/
157     NRF_CLOCK_TASK_HFCLKSTOP  = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTOP),  /**< Stop HFCLK clock source.*/
158     NRF_CLOCK_TASK_LFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTART), /**< Start LFCLK clock source.*/
159     NRF_CLOCK_TASK_LFCLKSTOP  = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTOP),  /**< Stop LFCLK clock source.*/
160 #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
161     NRF_CLOCK_TASK_CAL        = offsetof(NRF_CLOCK_Type, TASKS_CAL),        /**< Start calibration of LFCLK RC oscillator.*/
162     NRF_CLOCK_TASK_CTSTART    = offsetof(NRF_CLOCK_Type, TASKS_CTSTART),    /**< Start calibration timer.*/
163     NRF_CLOCK_TASK_CTSTOP     = offsetof(NRF_CLOCK_Type, TASKS_CTSTOP)      /**< Stop calibration timer.*/
164 #endif
165 } nrf_clock_task_t;                                                         /*lint -restore */
166 
167 /**
168  * @brief Events.
169  */
170 typedef enum /*lint -save -e30 -esym(628,__INTADDR__) */
171 {
172     NRF_CLOCK_EVENT_HFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKSTARTED), /**< HFCLK oscillator started.*/
173     NRF_CLOCK_EVENT_LFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_LFCLKSTARTED), /**< LFCLK oscillator started.*/
174 #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
175     NRF_CLOCK_EVENT_DONE         = offsetof(NRF_CLOCK_Type, EVENTS_DONE),         /**< Calibration of LFCLK RC oscillator completed.*/
176     NRF_CLOCK_EVENT_CTTO         = offsetof(NRF_CLOCK_Type, EVENTS_CTTO)          /**< Calibration timer time-out.*/
177 #endif
178 } nrf_clock_event_t;                                                               /*lint -restore */
179 
180 /**
181  * @brief Function for enabling a specific interrupt.
182  *
183  * @param[in] int_mask Interrupt.
184  */
185 __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask);
186 
187 /**
188  * @brief Function for disabling a specific interrupt.
189  *
190  * @param[in] int_mask Interrupt.
191  */
192 __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask);
193 
194 /**
195  * @brief Function for retrieving the state of a specific interrupt.
196  *
197  * @param[in] int_mask Interrupt.
198  *
199  * @retval true  If the interrupt is enabled.
200  * @retval false If the interrupt is not enabled.
201  */
202 __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask);
203 
204 /**
205  * @brief Function for retrieving the address of a specific task.
206  * @details This function can be used by the PPI module.
207  *
208  * @param[in] task  Task.
209  *
210  * @return Address of the requested task register.
211  */
212 __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task);
213 
214 /**
215  * @brief Function for setting a specific task.
216  *
217  * @param[in] task  Task.
218  */
219 __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task);
220 
221 /**
222  * @brief Function for retrieving the address of a specific event.
223  * @details This function can be used by the PPI module.
224  *
225  * @param[in] event Event.
226  *
227  * @return Address of the requested event register.
228  */
229 __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event);
230 
231 /**
232  * @brief Function for clearing a specific event.
233  *
234  * @param[in] event Event.
235  */
236 __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event);
237 
238 /**
239  * @brief Function for retrieving the state of a specific event.
240  *
241  * @param[in] event Event.
242  *
243  * @retval true  If the event is set.
244  * @retval false If the event is not set.
245  */
246 __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event);
247 
248 /**
249  * @brief Function for changing the low-frequency clock source.
250  * @details This function cannot be called when the low-frequency clock is running.
251  *
252  * @param[in] source New low-frequency clock source.
253  */
254 __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source);
255 
256 /**
257  * @brief Function for retrieving the selected source for the low-frequency clock.
258  *
259  * @retval NRF_CLOCK_LFCLK_RC    If the internal 32 kHz RC oscillator
260  *                               is the selected source for the low-frequency clock.
261  * @retval NRF_CLOCK_LFCLK_Xtal  If an external 32 kHz crystal oscillator
262  *                               is the selected source for the low-frequency clock.
263  * @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from
264  *                               the HFCLK is the selected source for the low-frequency clock.
265  */
266 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void);
267 
268 /**
269  * @brief Function for retrieving the active source of the low-frequency clock.
270  *
271  * @retval NRF_CLOCK_LFCLK_RC    If the internal 32 kHz RC oscillator
272  *                               is the active source of the low-frequency clock.
273  * @retval NRF_CLOCK_LFCLK_Xtal  If an external 32 kHz crystal oscillator
274  *                               is the active source of the low-frequency clock.
275  * @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from
276  *                               the HFCLK is the active source of the low-frequency clock.
277  */
278 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void);
279 
280 /**
281  * @brief Function for retrieving the clock source for the LFCLK clock when
282  *        the task LKCLKSTART is triggered.
283  *
284  * @retval NRF_CLOCK_LFCLK_RC    If the internal 32 kHz RC oscillator
285  *                               is running and generating the LFCLK clock.
286  * @retval NRF_CLOCK_LFCLK_Xtal  If an external 32 kHz crystal oscillator
287  *                               is running and generating the LFCLK clock.
288  * @retval NRF_CLOCK_LFCLK_Synth If the internal 32 kHz synthesizer from
289  *                               the HFCLK is running and generating the LFCLK clock.
290  */
291 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void);
292 
293 /**
294  * @brief Function for retrieving the state of the LFCLK clock.
295  *
296  * @retval false If the LFCLK clock is not running.
297  * @retval true  If the LFCLK clock is running.
298  */
299 __STATIC_INLINE bool nrf_clock_lf_is_running(void);
300 
301 /**
302  * @brief Function for retrieving the trigger status of the task LFCLKSTART.
303  *
304  * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED If the task LFCLKSTART has not been triggered.
305  * @retval NRF_CLOCK_START_TASK_TRIGGERED     If the task LFCLKSTART has been triggered.
306  */
307 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void);
308 
309 /**
310  * @brief Function for retrieving the active source of the high-frequency clock.
311  *
312  * @retval NRF_CLOCK_HFCLK_LOW_ACCURACY  If the internal RC oscillator is the active
313  *                                       source of the high-frequency clock.
314  * @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY If an external crystal oscillator is the active
315  *                                       source of the high-frequency clock.
316  */
317 __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void);
318 
319 /**
320  * @brief Function for retrieving the state of the HFCLK clock.
321  *
322  * @param[in] clk_src Clock source to be checked.
323  *
324  * @retval false If the HFCLK clock is not running.
325  * @retval true  If the HFCLK clock is running.
326  */
327 __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src);
328 
329 /**
330  * @brief Function for retrieving the trigger status of the task HFCLKSTART.
331  *
332  * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED If the task HFCLKSTART has not been triggered.
333  * @retval NRF_CLOCK_START_TASK_TRIGGERED     If the task HFCLKSTART has been triggered.
334  */
335 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void);
336 
337 #if (NRF_CLOCK_HAS_CALIBRATION) || defined(__NRFX_DOXYGEN__)
338 /**
339  * @brief Function for changing the calibration timer interval.
340  *
341  * @param[in] interval New calibration timer interval in 0.25 s resolution
342  *                     (range: 0.25 seconds to 31.75 seconds).
343  */
344 __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval);
345 #endif
346 
347 #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
348 /**
349  * @brief Function for setting the subscribe configuration for a given
350  *        CLOCK task.
351  *
352  * @param[in] task    Task for which to set the configuration.
353  * @param[in] channel Channel through which to subscribe events.
354  */
355 __STATIC_INLINE void nrf_clock_subscribe_set(nrf_clock_task_t task,
356                                              uint8_t          channel);
357 
358 /**
359  * @brief Function for clearing the subscribe configuration for a given
360  *        CLOCK task.
361  *
362  * @param[in] task Task for which to clear the configuration.
363  */
364 __STATIC_INLINE void nrf_clock_subscribe_clear(nrf_clock_task_t task);
365 
366 /**
367  * @brief Function for setting the publish configuration for a given
368  *        CLOCK event.
369  *
370  * @param[in] event   Event for which to set the configuration.
371  * @param[in] channel Channel through which to publish the event.
372  */
373 __STATIC_INLINE void nrf_clock_publish_set(nrf_clock_event_t event,
374                                            uint8_t           channel);
375 
376 /**
377  * @brief Function for clearing the publish configuration for a given
378  *        CLOCK event.
379  *
380  * @param[in] event Event for which to clear the configuration.
381  */
382 __STATIC_INLINE void nrf_clock_publish_clear(nrf_clock_event_t event);
383 #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
384 
385 #ifndef SUPPRESS_INLINE_IMPLEMENTATION
386 
nrf_clock_int_enable(uint32_t int_mask)387 __STATIC_INLINE void nrf_clock_int_enable(uint32_t int_mask)
388 {
389     NRF_CLOCK->INTENSET = int_mask;
390 }
391 
nrf_clock_int_disable(uint32_t int_mask)392 __STATIC_INLINE void nrf_clock_int_disable(uint32_t int_mask)
393 {
394     NRF_CLOCK->INTENCLR = int_mask;
395 }
396 
nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask)397 __STATIC_INLINE bool nrf_clock_int_enable_check(nrf_clock_int_mask_t int_mask)
398 {
399     return (bool)(NRF_CLOCK->INTENCLR & int_mask);
400 }
401 
nrf_clock_task_address_get(nrf_clock_task_t task)402 __STATIC_INLINE uint32_t nrf_clock_task_address_get(nrf_clock_task_t task)
403 {
404     return ((uint32_t )NRF_CLOCK + task);
405 }
406 
nrf_clock_task_trigger(nrf_clock_task_t task)407 __STATIC_INLINE void nrf_clock_task_trigger(nrf_clock_task_t task)
408 {
409     *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + task)) = NRF_CLOCK_TASK_TRIGGER;
410 }
411 
nrf_clock_event_address_get(nrf_clock_event_t event)412 __STATIC_INLINE uint32_t nrf_clock_event_address_get(nrf_clock_event_t event)
413 {
414     return ((uint32_t)NRF_CLOCK + event);
415 }
416 
nrf_clock_event_clear(nrf_clock_event_t event)417 __STATIC_INLINE void nrf_clock_event_clear(nrf_clock_event_t event)
418 {
419     *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event)) = NRF_CLOCK_EVENT_CLEAR;
420 #if __CORTEX_M == 0x04
421     volatile uint32_t dummy = *((volatile uint32_t *)((uint8_t *)NRF_CLOCK + (uint32_t)event));
422     (void)dummy;
423 #endif
424 }
425 
nrf_clock_event_check(nrf_clock_event_t event)426 __STATIC_INLINE bool nrf_clock_event_check(nrf_clock_event_t event)
427 {
428     return (bool)*((volatile uint32_t *)((uint8_t *)NRF_CLOCK + event));
429 }
430 
nrf_clock_lf_src_set(nrf_clock_lfclk_t source)431 __STATIC_INLINE void nrf_clock_lf_src_set(nrf_clock_lfclk_t source)
432 {
433     NRF_CLOCK->LFCLKSRC = (uint32_t)(source);
434 }
435 
nrf_clock_lf_src_get(void)436 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(void)
437 {
438     return (nrf_clock_lfclk_t)(NRF_CLOCK->LFCLKSRC);
439 }
440 
nrf_clock_lf_actv_src_get(void)441 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(void)
442 {
443     return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSTAT &
444                                 CLOCK_LFCLKSTAT_SRC_Msk) >> CLOCK_LFCLKSTAT_SRC_Pos);
445 }
446 
nrf_clock_lf_srccopy_get(void)447 __STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(void)
448 {
449     return (nrf_clock_lfclk_t)((NRF_CLOCK->LFCLKSRCCOPY &
450                                 CLOCK_LFCLKSRCCOPY_SRC_Msk) >> CLOCK_LFCLKSRCCOPY_SRC_Pos);
451 }
452 
nrf_clock_lf_is_running(void)453 __STATIC_INLINE bool nrf_clock_lf_is_running(void)
454 {
455     return ((NRF_CLOCK->LFCLKSTAT &
456              CLOCK_LFCLKSTAT_STATE_Msk) >> CLOCK_LFCLKSTAT_STATE_Pos);
457 }
458 
nrf_clock_lf_start_task_status_get(void)459 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(void)
460 {
461     return (nrf_clock_start_task_status_t)((NRF_CLOCK->LFCLKRUN &
462                                  CLOCK_LFCLKRUN_STATUS_Msk) >> CLOCK_LFCLKRUN_STATUS_Pos);
463 }
464 
nrf_clock_hf_src_get(void)465 __STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(void)
466 {
467     return (nrf_clock_hfclk_t)((NRF_CLOCK->HFCLKSTAT &
468                                 CLOCK_HFCLKSTAT_SRC_Msk) >> CLOCK_HFCLKSTAT_SRC_Pos);
469 }
470 
nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src)471 __STATIC_INLINE bool nrf_clock_hf_is_running(nrf_clock_hfclk_t clk_src)
472 {
473     return (NRF_CLOCK->HFCLKSTAT & (CLOCK_HFCLKSTAT_STATE_Msk | CLOCK_HFCLKSTAT_SRC_Msk)) ==
474             (CLOCK_HFCLKSTAT_STATE_Msk | (clk_src << CLOCK_HFCLKSTAT_SRC_Pos));
475 }
476 
nrf_clock_hf_start_task_status_get(void)477 __STATIC_INLINE nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(void)
478 {
479     return (nrf_clock_start_task_status_t)((NRF_CLOCK->HFCLKRUN &
480                                  CLOCK_HFCLKRUN_STATUS_Msk) >> CLOCK_HFCLKRUN_STATUS_Pos);
481 }
482 
483 #if (NRF_CLOCK_HAS_CALIBRATION)
nrf_clock_cal_timer_timeout_set(uint32_t interval)484 __STATIC_INLINE void nrf_clock_cal_timer_timeout_set(uint32_t interval)
485 {
486     NRF_CLOCK->CTIV = ((interval << CLOCK_CTIV_CTIV_Pos) & CLOCK_CTIV_CTIV_Msk);
487 }
488 #endif
489 
490 #if defined(DPPI_PRESENT)
nrf_clock_subscribe_set(nrf_clock_task_t task,uint8_t channel)491 __STATIC_INLINE void nrf_clock_subscribe_set(nrf_clock_task_t task,
492                                              uint8_t          channel)
493 {
494     *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) task + 0x80uL)) =
495             ((uint32_t)channel | CLOCK_SUBSCRIBE_HFCLKSTART_EN_Msk);
496 }
497 
nrf_clock_subscribe_clear(nrf_clock_task_t task)498 __STATIC_INLINE void nrf_clock_subscribe_clear(nrf_clock_task_t task)
499 {
500     *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) task + 0x80uL)) = 0;
501 }
502 
nrf_clock_publish_set(nrf_clock_event_t event,uint8_t channel)503 __STATIC_INLINE void nrf_clock_publish_set(nrf_clock_event_t event,
504                                            uint8_t           channel)
505 {
506     *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) event + 0x80uL)) =
507             ((uint32_t)channel | CLOCK_PUBLISH_HFCLKSTARTED_EN_Msk);
508 }
509 
nrf_clock_publish_clear(nrf_clock_event_t event)510 __STATIC_INLINE void nrf_clock_publish_clear(nrf_clock_event_t event)
511 {
512     *((volatile uint32_t *) ((uint8_t *) NRF_CLOCK + (uint32_t) event + 0x80uL)) = 0;
513 }
514 #endif // defined(DPPI_PRESENT)
515 
516 #endif // SUPPRESS_INLINE_IMPLEMENTATION
517 
518 /** @} */
519 
520 #ifdef __cplusplus
521 }
522 #endif
523 
524 #endif // NRF_CLOCK_H__
525