Branch data Line data Source code
1 : : /*
2 : : * Copyright (c) 2015 - 2022, Nordic Semiconductor ASA
3 : : * All rights reserved.
4 : : *
5 : : * SPDX-License-Identifier: BSD-3-Clause
6 : : *
7 : : * Redistribution and use in source and binary forms, with or without
8 : : * modification, are permitted provided that the following conditions are met:
9 : : *
10 : : * 1. Redistributions of source code must retain the above copyright notice, this
11 : : * list of conditions and the following disclaimer.
12 : : *
13 : : * 2. Redistributions in binary form must reproduce the above copyright
14 : : * notice, this list of conditions and the following disclaimer in the
15 : : * documentation and/or other materials provided with the distribution.
16 : : *
17 : : * 3. Neither the name of the copyright holder nor the names of its
18 : : * contributors may be used to endorse or promote products derived from this
19 : : * software without specific prior written permission.
20 : : *
21 : : * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 : : * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 : : * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 : : * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 : : * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 : : * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 : : * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 : : * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 : : * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 : : * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 : : * POSSIBILITY OF SUCH DAMAGE.
32 : : */
33 : :
34 : : #ifndef NRF_CLOCK_H__
35 : : #define NRF_CLOCK_H__
36 : :
37 : : #include <nrfx.h>
38 : :
39 : : #ifdef __cplusplus
40 : : extern "C" {
41 : : #endif
42 : :
43 : : /**
44 : : * @defgroup nrf_clock_hal Clock HAL
45 : : * @{
46 : : * @ingroup nrf_clock
47 : : * @brief Hardware access layer for managing the CLOCK peripheral.
48 : : *
49 : : * This code can be used to manage low-frequency clock (LFCLK), high-frequency clock (HFCLK),
50 : : * high-frequency 192 MHz clock (HFCLK192M) and high-frequency audio clock (HFCLKAUDIO)
51 : : * settings.
52 : : */
53 : :
54 : : #if defined(CLOCK_LFCLKSRC_BYPASS_Msk) && defined(CLOCK_LFCLKSRC_EXTERNAL_Msk)
55 : : // Enable support for external LFCLK sources. Read more in the Product Specification.
56 : : #define NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES
57 : : #endif
58 : :
59 : : #if defined(CLOCK_INTENSET_DONE_Msk) || defined(__NRFX_DOXYGEN__)
60 : : /** @brief Presence of the Low Frequency Clock calibration. */
61 : : #define NRF_CLOCK_HAS_CALIBRATION 1
62 : : #else
63 : : #define NRF_CLOCK_HAS_CALIBRATION 0
64 : : #endif
65 : :
66 : : #if defined(CLOCK_CTIV_CTIV_Msk) || defined(__NRFX_DOXYGEN__)
67 : : /** @brief Presence of the Low Frequency Clock calibration timer. */
68 : : #define NRF_CLOCK_HAS_CALIBRATION_TIMER 1
69 : : #else
70 : : #define NRF_CLOCK_HAS_CALIBRATION_TIMER 0
71 : : #endif
72 : :
73 : : #if (defined(CLOCK_INTENSET_HFCLK192MSTARTED_Msk) && !defined(NRF5340_XXAA_NETWORK)) \
74 : : || defined(__NRFX_DOXYGEN__)
75 : : /** @brief Presence of the 192 MHz clock. */
76 : : #define NRF_CLOCK_HAS_HFCLK192M 1
77 : : #else
78 : : #define NRF_CLOCK_HAS_HFCLK192M 0
79 : : #endif
80 : :
81 : : #if (defined(CLOCK_INTENSET_HFCLKAUDIOSTARTED_Msk) && !defined(NRF5340_XXAA_NETWORK)) \
82 : : || defined(__NRFX_DOXYGEN__)
83 : : /** @brief Presence of the Audio clock. */
84 : : #define NRF_CLOCK_HAS_HFCLKAUDIO 1
85 : : #else
86 : : #define NRF_CLOCK_HAS_HFCLKAUDIO 0
87 : : #endif
88 : :
89 : : #if defined(CLOCK_LFCLKALWAYSRUN_ALWAYSRUN_Msk) || defined(__NRFX_DOXYGEN__)
90 : : /** @brief Presence of ALWAYSRUN registers. */
91 : : #define NRF_CLOCK_HAS_ALWAYSRUN 1
92 : : #else
93 : : #define NRF_CLOCK_HAS_ALWAYSRUN 0
94 : : #endif
95 : :
96 : : #if defined(CLOCK_HFCLKSRC_SRC_Msk) || defined(__NRFX_DOXYGEN__)
97 : : /** @brief Presence of HFCLKSRC register. */
98 : : #define NRF_CLOCK_HAS_HFCLKSRC 1
99 : : #else
100 : : #define NRF_CLOCK_HAS_HFCLKSRC 0
101 : : #endif
102 : :
103 : : /**
104 : : * @brief Low-frequency clock sources.
105 : : * @details Used by LFCLKSRC, LFCLKSTAT, and LFCLKSRCCOPY registers.
106 : : */
107 : : typedef enum
108 : : {
109 : : #if defined(CLOCK_LFCLKSRC_SRC_LFULP) || defined(__NRFX_DOXYGEN__)
110 : : NRF_CLOCK_LFCLK_LFULP = CLOCK_LFCLKSRC_SRC_LFULP, /**< Internal 32 kHz Ultra-low power oscillator. */
111 : : #endif
112 : :
113 : : #if defined(CLOCK_LFCLKSRC_SRC_RC) || defined(__NRFX_DOXYGEN__)
114 : : NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_RC, /**< Internal 32 kHz RC oscillator. */
115 : : #else
116 : : NRF_CLOCK_LFCLK_RC = CLOCK_LFCLKSRC_SRC_LFRC, /**< Internal 32 kHz RC oscillator. */
117 : : #endif
118 : :
119 : : #if defined(CLOCK_LFCLKSRC_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
120 : : NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_Xtal, /**< External 32 kHz crystal. */
121 : : #else
122 : : NRF_CLOCK_LFCLK_Xtal = CLOCK_LFCLKSRC_SRC_LFXO, /**< External 32 kHz crystal. */
123 : : #endif
124 : :
125 : : #if defined(CLOCK_LFCLKSRC_SRC_Synth) || defined(__NRFX_DOXYGEN__)
126 : : NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_Synth, /**< Internal 32 kHz synthesized from HFCLK system clock. */
127 : : #elif defined(CLOCK_LFCLKSRC_SRC_LFSYNT)
128 : : NRF_CLOCK_LFCLK_Synth = CLOCK_LFCLKSRC_SRC_LFSYNT, /**< Internal 32 kHz synthesized from HFCLK system clock. */
129 : : #endif
130 : :
131 : : #if defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
132 : : /**
133 : : * External 32 kHz low swing signal. Used only with the LFCLKSRC register.
134 : : * For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
135 : : */
136 : : NRF_CLOCK_LFCLK_Xtal_Low_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
137 : : (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
138 : : /**
139 : : * External 32 kHz full swing signal. Used only with the LFCLKSRC register.
140 : : * For the others @ref NRF_CLOCK_LFCLK_Xtal is returned for this setting.
141 : : */
142 : : NRF_CLOCK_LFCLK_Xtal_Full_Swing = (CLOCK_LFCLKSRC_SRC_Xtal |
143 : : (CLOCK_LFCLKSRC_BYPASS_Enabled << CLOCK_LFCLKSRC_BYPASS_Pos) |
144 : : (CLOCK_LFCLKSRC_EXTERNAL_Enabled << CLOCK_LFCLKSRC_EXTERNAL_Pos)),
145 : : #endif // defined(NRF_CLOCK_USE_EXTERNAL_LFCLK_SOURCES) || defined(__NRFX_DOXYGEN__)
146 : : } nrf_clock_lfclk_t;
147 : :
148 : : /**
149 : : * @brief High-frequency clock sources.
150 : : * @details Used by HFCLKSTAT and HFCLK192MSTAT registers.
151 : : */
152 : : typedef enum
153 : : {
154 : : #if defined(CLOCK_HFCLKSTAT_SRC_RC) || defined(__NRFX_DOXYGEN__)
155 : : NRF_CLOCK_HFCLK_LOW_ACCURACY = CLOCK_HFCLKSTAT_SRC_RC, /**< Internal 16 MHz RC oscillator. */
156 : : #elif defined(CLOCK_HFCLKSTAT_SRC_HFINT)
157 : : NRF_CLOCK_HFCLK_LOW_ACCURACY = CLOCK_HFCLKSTAT_SRC_HFINT, /**< Internal 16 MHz RC oscillator. */
158 : : #endif
159 : : #if defined(CLOCK_HFCLKSTAT_SRC_Xtal) || defined(__NRFX_DOXYGEN__)
160 : : NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_Xtal /**< External 16 MHz/32 MHz crystal oscillator. */
161 : : #else
162 : : NRF_CLOCK_HFCLK_HIGH_ACCURACY = CLOCK_HFCLKSTAT_SRC_HFXO /**< External 32 MHz crystal oscillator. */
163 : : #endif
164 : : } nrf_clock_hfclk_t;
165 : :
166 : : /** @brief Clock domains. */
167 : : typedef enum
168 : : {
169 : : NRF_CLOCK_DOMAIN_LFCLK,
170 : : NRF_CLOCK_DOMAIN_HFCLK,
171 : : #if NRF_CLOCK_HAS_HFCLK192M
172 : : NRF_CLOCK_DOMAIN_HFCLK192M,
173 : : #endif
174 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
175 : : NRF_CLOCK_DOMAIN_HFCLKAUDIO,
176 : : #endif
177 : : } nrf_clock_domain_t;
178 : :
179 : : #if defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT) || NRF_CLOCK_HAS_HFCLK192M
180 : : /**
181 : : * @brief High-frequency clock frequency configuration.
182 : : * @details Used by HFCLKCTRL and HFCLK192MCTRL registers.
183 : : */
184 : : typedef enum
185 : : {
186 : : NRF_CLOCK_HFCLK_DIV_1 = CLOCK_HFCLKCTRL_HCLK_Div1, /**< Divide HFCLK/HFCLK192M by 1 */
187 : : NRF_CLOCK_HFCLK_DIV_2 = CLOCK_HFCLKCTRL_HCLK_Div2, /**< Divide HFCLK/HFCLK192M by 2 */
188 : : #if NRF_CLOCK_HAS_HFCLK192M
189 : : NRF_CLOCK_HFCLK_DIV_4 = CLOCK_HFCLK192MCTRL_HCLK192M_Div4, /**< Divide HFCLK192M by 4 */
190 : : #endif
191 : : } nrf_clock_hfclk_div_t;
192 : : #endif // defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT) || NRF_CLOCK_HAS_HFCLK192M
193 : :
194 : : /**
195 : : * @brief Trigger status of task LFCLKSTART/HFCLKSTART.
196 : : *
197 : : * @note This enum is deprecated.
198 : : *
199 : : * @details Used by LFCLKRUN and HFCLKRUN registers.
200 : : */
201 : : typedef enum
202 : : {
203 : : NRF_CLOCK_START_TASK_NOT_TRIGGERED = CLOCK_LFCLKRUN_STATUS_NotTriggered, /**< Task LFCLKSTART/HFCLKSTART has not been triggered. */
204 : : NRF_CLOCK_START_TASK_TRIGGERED = CLOCK_LFCLKRUN_STATUS_Triggered /**< Task LFCLKSTART/HFCLKSTART has been triggered. */
205 : : } nrf_clock_start_task_status_t;
206 : :
207 : : /** @brief Interrupts. */
208 : : typedef enum
209 : : {
210 : : NRF_CLOCK_INT_HF_STARTED_MASK = CLOCK_INTENSET_HFCLKSTARTED_Msk, /**< Interrupt on HFCLKSTARTED event. */
211 : : NRF_CLOCK_INT_LF_STARTED_MASK = CLOCK_INTENSET_LFCLKSTARTED_Msk, /**< Interrupt on LFCLKSTARTED event. */
212 : : #if NRF_CLOCK_HAS_CALIBRATION
213 : : NRF_CLOCK_INT_DONE_MASK = CLOCK_INTENSET_DONE_Msk, /**< Interrupt on DONE event. */
214 : : #endif
215 : : #if NRF_CLOCK_HAS_CALIBRATION_TIMER
216 : : NRF_CLOCK_INT_CTTO_MASK = CLOCK_INTENSET_CTTO_Msk, /**< Interrupt on CTTO event. */
217 : : #endif
218 : : #if defined(CLOCK_INTENSET_CTSTARTED_Msk) || defined(__NRFX_DOXYGEN__)
219 : : NRF_CLOCK_INT_CTSTARTED_MASK = CLOCK_INTENSET_CTSTARTED_Msk, /**< Interrupt on CTSTARTED event. */
220 : : NRF_CLOCK_INT_CTSTOPPED_MASK = CLOCK_INTENSET_CTSTOPPED_Msk /**< Interrupt on CTSTOPPED event. */
221 : : #endif
222 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
223 : : NRF_CLOCK_INT_HFAUDIO_STARTED_MASK = CLOCK_INTENSET_HFCLKAUDIOSTARTED_Msk, /**< Interrupt on HFCLKAUDIOSTARTED event. */
224 : : #endif
225 : :
226 : : #if NRF_CLOCK_HAS_HFCLK192M
227 : : NRF_CLOCK_INT_HF192M_STARTED_MASK = CLOCK_INTENSET_HFCLK192MSTARTED_Msk, /**< Interrupt on HFCLK192MSTARTED event. */
228 : : #endif
229 : : } nrf_clock_int_mask_t;
230 : :
231 : : /**
232 : : * @brief Tasks.
233 : : *
234 : : * @details The NRF_CLOCK_TASK_LFCLKSTOP task cannot be set when the low-frequency clock is not running.
235 : : * The NRF_CLOCK_TASK_HFCLKSTOP task cannot be set when the high-frequency clock is not running.
236 : : */
237 : : typedef enum
238 : : {
239 : : NRF_CLOCK_TASK_HFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTART), /**< Start HFCLK clock source. */
240 : : NRF_CLOCK_TASK_HFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLKSTOP), /**< Stop HFCLK clock source. */
241 : : NRF_CLOCK_TASK_LFCLKSTART = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTART), /**< Start LFCLK clock source. */
242 : : NRF_CLOCK_TASK_LFCLKSTOP = offsetof(NRF_CLOCK_Type, TASKS_LFCLKSTOP), /**< Stop LFCLK clock source. */
243 : : #if NRF_CLOCK_HAS_CALIBRATION
244 : : NRF_CLOCK_TASK_CAL = offsetof(NRF_CLOCK_Type, TASKS_CAL), /**< Start calibration of LFCLK RC oscillator. */
245 : : #endif
246 : : #if NRF_CLOCK_HAS_CALIBRATION_TIMER
247 : : NRF_CLOCK_TASK_CTSTART = offsetof(NRF_CLOCK_Type, TASKS_CTSTART), /**< Start calibration timer. */
248 : : NRF_CLOCK_TASK_CTSTOP = offsetof(NRF_CLOCK_Type, TASKS_CTSTOP) /**< Stop calibration timer. */
249 : : #endif
250 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
251 : : NRF_CLOCK_TASK_HFCLKAUDIOSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLKAUDIOSTART), /**< Start HFCLKAUDIO clock source. */
252 : : NRF_CLOCK_TASK_HFCLKAUDIOSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLKAUDIOSTOP), /**< Stop HFCLKAUDIO clock source. */
253 : : #endif
254 : : #if NRF_CLOCK_HAS_HFCLK192M
255 : : NRF_CLOCK_TASK_HFCLK192MSTART = offsetof(NRF_CLOCK_Type, TASKS_HFCLK192MSTART), /**< Start HFCLK192M clock source. */
256 : : NRF_CLOCK_TASK_HFCLK192MSTOP = offsetof(NRF_CLOCK_Type, TASKS_HFCLK192MSTOP), /**< Stop HFCLK192M clock source. */
257 : : #endif
258 : : } nrf_clock_task_t;
259 : :
260 : : /** @brief Events. */
261 : : typedef enum
262 : : {
263 : : NRF_CLOCK_EVENT_HFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKSTARTED), /**< HFCLK oscillator started. */
264 : : NRF_CLOCK_EVENT_LFCLKSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_LFCLKSTARTED), /**< LFCLK oscillator started. */
265 : : #if NRF_CLOCK_HAS_CALIBRATION
266 : : NRF_CLOCK_EVENT_DONE = offsetof(NRF_CLOCK_Type, EVENTS_DONE), /**< Calibration of LFCLK RC oscillator completed. */
267 : : #endif
268 : : #if NRF_CLOCK_HAS_CALIBRATION_TIMER
269 : : NRF_CLOCK_EVENT_CTTO = offsetof(NRF_CLOCK_Type, EVENTS_CTTO), /**< Calibration timer time-out. */
270 : : #endif
271 : : #if defined(CLOCK_INTENSET_CTSTARTED_Msk) || defined(__NRFX_DOXYGEN__)
272 : : NRF_CLOCK_EVENT_CTSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_CTSTARTED), /**< Calibration timer started. */
273 : : NRF_CLOCK_EVENT_CTSTOPPED = offsetof(NRF_CLOCK_Type, EVENTS_CTSTOPPED) /**< Calibration timer stopped. */
274 : : #endif
275 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
276 : : NRF_CLOCK_EVENT_HFCLKAUDIOSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLKAUDIOSTARTED), /**< HFCLKAUDIO oscillator started. */
277 : : #endif
278 : : #if NRF_CLOCK_HAS_HFCLK192M
279 : : NRF_CLOCK_EVENT_HFCLK192MSTARTED = offsetof(NRF_CLOCK_Type, EVENTS_HFCLK192MSTARTED), /**< HFCLK192M oscillator started. */
280 : : #endif
281 : : } nrf_clock_event_t;
282 : :
283 : : /**
284 : : * @brief Function for enabling the specified interrupt.
285 : : *
286 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
287 : : * @param[in] mask Mask of interrupts to be enabled.
288 : : */
289 : : NRF_STATIC_INLINE void nrf_clock_int_enable(NRF_CLOCK_Type * p_reg, uint32_t mask);
290 : :
291 : : /**
292 : : * @brief Function for disabling the specified interrupt.
293 : : *
294 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
295 : : * @param[in] mask Mask of interrupts to be disabled.
296 : : */
297 : : NRF_STATIC_INLINE void nrf_clock_int_disable(NRF_CLOCK_Type * p_reg, uint32_t mask);
298 : :
299 : : /**
300 : : * @brief Function for checking if the specified interrupts are enabled.
301 : : *
302 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
303 : : * @param[in] mask Mask of interrupts to be checked.
304 : : *
305 : : * @return Mask of enabled interrupts.
306 : : */
307 : : NRF_STATIC_INLINE uint32_t nrf_clock_int_enable_check(NRF_CLOCK_Type const * p_reg, uint32_t mask);
308 : :
309 : : /**
310 : : * @brief Function for retrieving the address of the specified task.
311 : : * @details This function can be used by the PPI module.
312 : : *
313 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
314 : : * @param[in] task CLOCK Task.
315 : : *
316 : : * @return Address of the requested task register.
317 : : */
318 : : NRF_STATIC_INLINE uint32_t nrf_clock_task_address_get(NRF_CLOCK_Type const * p_reg,
319 : : nrf_clock_task_t task);
320 : :
321 : : /**
322 : : * @brief Function for setting the specified task.
323 : : *
324 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
325 : : * @param[in] task Task to be activated.
326 : : */
327 : : NRF_STATIC_INLINE void nrf_clock_task_trigger(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task);
328 : :
329 : : /**
330 : : * @brief Function for retrieving the address of the specified event.
331 : : * @details This function can be used by the PPI module.
332 : : *
333 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
334 : : * @param[in] event CLOCK Event.
335 : : *
336 : : * @return Address of the specified event register.
337 : : */
338 : : NRF_STATIC_INLINE uint32_t nrf_clock_event_address_get(NRF_CLOCK_Type const * p_reg,
339 : : nrf_clock_event_t event);
340 : :
341 : : /**
342 : : * @brief Function for clearing the specified event.
343 : : *
344 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
345 : : * @param[in] event Event to clear.
346 : : */
347 : : NRF_STATIC_INLINE void nrf_clock_event_clear(NRF_CLOCK_Type * p_reg, nrf_clock_event_t event);
348 : :
349 : : /**
350 : : * @brief Function for retrieving the state of the specified event.
351 : : *
352 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
353 : : * @param[in] event Event to be checked.
354 : : *
355 : : * @retval true The event has been generated.
356 : : * @retval false The event has not been generated.
357 : : */
358 : : NRF_STATIC_INLINE bool nrf_clock_event_check(NRF_CLOCK_Type const * p_reg, nrf_clock_event_t event);
359 : :
360 : : /**
361 : : * @brief Function for retrieving the trigger status of the task START for given domain.
362 : : *
363 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
364 : : * @param[in] domain Clock domain.
365 : : *
366 : : * @retval false The task START for the given domain has not been triggered.
367 : : * @retval true The task START for the given domain has been triggered.
368 : : */
369 : : NRF_STATIC_INLINE bool nrf_clock_start_task_check(NRF_CLOCK_Type const * p_reg,
370 : : nrf_clock_domain_t domain);
371 : :
372 : : /**
373 : : * @brief Function for retrieving the state of the clock.
374 : : *
375 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
376 : : * @param[in] domain Clock domain.
377 : : * @param[out] p_clk_src Pointer to clock source that is running. Set to NULL if not needed.
378 : : * Ignored for HFCLKAUDIO domain. Variable pointed by @p p_clk_src
379 : : * must be of either @ref nrf_clock_lfclk_t type for LFCLK
380 : : * or @ref nrf_clock_hfclk_t type for HFCLK and HFCLK192M.
381 : : *
382 : : * @retval false The clock is not running.
383 : : * @retval true The clock is running.
384 : : */
385 : : NRF_STATIC_INLINE bool nrf_clock_is_running(NRF_CLOCK_Type const * p_reg,
386 : : nrf_clock_domain_t domain,
387 : : void * p_clk_src);
388 : :
389 : : /**
390 : : * @brief Function for changing the low-frequency clock source.
391 : : * @details Check in Product Specification if this function can be called when
392 : : * the low-frequency clock is running.
393 : : *
394 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
395 : : * @param[in] source New low-frequency clock source.
396 : : */
397 : : NRF_STATIC_INLINE void nrf_clock_lf_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_lfclk_t source);
398 : :
399 : : /**
400 : : * @brief Function for retrieving the selected source for the low-frequency clock.
401 : : *
402 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
403 : : *
404 : : * @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
405 : : * is the selected source for the low-frequency clock.
406 : : * @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
407 : : * is the selected source for the low-frequency clock.
408 : : * @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesized from
409 : : * the HFCLK is the selected source for the low-frequency clock.
410 : : */
411 : : NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(NRF_CLOCK_Type const * p_reg);
412 : :
413 : : /**
414 : : * @brief Function for retrieving the active source of the low-frequency clock.
415 : : *
416 : : * @note This function is deprecated. Use @ref nrf_clock_is_running instead.
417 : : *
418 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
419 : : *
420 : : * @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
421 : : * is the active source of the low-frequency clock.
422 : : * @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
423 : : * is the active source of the low-frequency clock.
424 : : * @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesized from
425 : : * the HFCLK is the active source of the low-frequency clock.
426 : : */
427 : : NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(NRF_CLOCK_Type const * p_reg);
428 : :
429 : : /**
430 : : * @brief Function for retrieving the clock source for the LFCLK clock when
431 : : * the task LKCLKSTART is triggered.
432 : : *
433 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
434 : : *
435 : : * @retval NRF_CLOCK_LFCLK_RC The internal 32 kHz RC oscillator
436 : : * is running and generating the LFCLK clock.
437 : : * @retval NRF_CLOCK_LFCLK_Xtal An external 32 kHz crystal oscillator
438 : : * is running and generating the LFCLK clock.
439 : : * @retval NRF_CLOCK_LFCLK_Synth The internal 32 kHz synthesized from
440 : : * the HFCLK is running and generating the LFCLK clock.
441 : : */
442 : : NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(NRF_CLOCK_Type const * p_reg);
443 : :
444 : : /**
445 : : * @brief Function for retrieving the state of the LFCLK clock.
446 : : *
447 : : * @note This function is deprecated. Use @ref nrf_clock_is_running instead.
448 : : *
449 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
450 : : *
451 : : * @retval false The LFCLK clock is not running.
452 : : * @retval true The LFCLK clock is running.
453 : : */
454 : : NRF_STATIC_INLINE bool nrf_clock_lf_is_running(NRF_CLOCK_Type const * p_reg);
455 : :
456 : : /**
457 : : * @brief Function for retrieving the trigger status of the task LFCLKSTART.
458 : : *
459 : : * @note This function is deprecated. Use @ref nrf_clock_start_task_check instead.
460 : : *
461 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
462 : : *
463 : : * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED The task LFCLKSTART has not been triggered.
464 : : * @retval NRF_CLOCK_START_TASK_TRIGGERED The task LFCLKSTART has been triggered.
465 : : */
466 : : NRF_STATIC_INLINE
467 : : nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(NRF_CLOCK_Type const * p_reg);
468 : :
469 : : #if NRF_CLOCK_HAS_HFCLKSRC
470 : : /**
471 : : * @brief Function for changing the high-frequency clock source.
472 : : *
473 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
474 : : * @param[in] source New high-frequency clock source.
475 : : */
476 : : NRF_STATIC_INLINE void nrf_clock_hf_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_hfclk_t source);
477 : : #endif
478 : :
479 : : /**
480 : : * @brief Function for retrieving the selected source of the high-frequency clock.
481 : : *
482 : : * For SoCs not featuring the HFCLKSRC register, this is always also the active source
483 : : * of the high-frequency clock.
484 : : *
485 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
486 : : *
487 : : * @retval NRF_CLOCK_HFCLK_LOW_ACCURACY The internal RC oscillator is the selected
488 : : * source of the high-frequency clock.
489 : : * @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY An external crystal oscillator is the selected
490 : : * source of the high-frequency clock.
491 : : */
492 : : NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(NRF_CLOCK_Type const * p_reg);
493 : :
494 : : /**
495 : : * @brief Function for retrieving the state of the HFCLK clock.
496 : : *
497 : : * @note This function is deprecated. Use @ref nrf_clock_is_running instead.
498 : : *
499 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
500 : : * @param[in] clk_src Clock source to be checked.
501 : : *
502 : : * @retval false The HFCLK clock is not running.
503 : : * @retval true The HFCLK clock is running.
504 : : */
505 : : NRF_STATIC_INLINE bool nrf_clock_hf_is_running(NRF_CLOCK_Type const * p_reg,
506 : : nrf_clock_hfclk_t clk_src);
507 : :
508 : : /**
509 : : * @brief Function for retrieving the trigger status of the task HFCLKSTART.
510 : : *
511 : : * @note This function is deprecated. Use @ref nrf_clock_start_task_check instead.
512 : : *
513 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
514 : : *
515 : : * @retval NRF_CLOCK_START_TASK_NOT_TRIGGERED The task HFCLKSTART has not been triggered.
516 : : * @retval NRF_CLOCK_START_TASK_TRIGGERED The task HFCLKSTART has been triggered.
517 : : */
518 : : NRF_STATIC_INLINE
519 : : nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(NRF_CLOCK_Type const * p_reg);
520 : :
521 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
522 : : /**
523 : : * @brief Function for changing the Audio clock FREQ_VALUE.
524 : : *
525 : : * The frequency of HFCLKAUDIO ranges from 10.666 MHz to 13.333 MHz in 40.7 Hz steps.
526 : : * To calculate @p freq_value corresponding to the chosen frequency, use the following equation:
527 : : * FREQ_VALUE = 2^16 * ((12 * f_out / 32M) - 4)
528 : : *
529 : : * @warning Chosen frequency must fit in 11.176 MHz - 11.402 MHz or 12.165 MHz - 12.411 MHz frequency bands.
530 : : *
531 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
532 : : * @param[in] freq_value New FREQ_VALUE
533 : : */
534 : : NRF_STATIC_INLINE
535 : : void nrf_clock_hfclkaudio_config_set(NRF_CLOCK_Type * p_reg, uint16_t freq_value);
536 : :
537 : : /**
538 : : * @brief Function for retrieving the Audio clock FREQ_VALUE.
539 : : *
540 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
541 : : *
542 : : * The frequency of HFCLKAUDIO ranges from 10.666 MHz to 13.333 MHz in 40.7 Hz steps.
543 : : * To calculate frequency corresponding to the returned FREQ_VALUE, use the following equation:
544 : : * f_out = 32M * (4 + FREQ_VALUE * 2^(-16))/12
545 : :
546 : : * @return FREQ_VALUE of the Audio clock.
547 : : */
548 : : NRF_STATIC_INLINE
549 : : uint16_t nrf_clock_hfclkaudio_config_get(NRF_CLOCK_Type const * p_reg);
550 : : #endif
551 : :
552 : : #if NRF_CLOCK_HAS_CALIBRATION_TIMER
553 : : /**
554 : : * @brief Function for changing the calibration timer interval.
555 : : *
556 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
557 : : * @param[in] interval New calibration timer interval in 0.25 s resolution
558 : : * (range: 0.25 seconds to 31.75 seconds).
559 : : */
560 : : NRF_STATIC_INLINE void nrf_clock_cal_timer_timeout_set(NRF_CLOCK_Type * p_reg, uint32_t interval);
561 : : #endif
562 : :
563 : : #if defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT)
564 : : /**
565 : : * @brief Function for changing the HFCLK frequency divider.
566 : : *
567 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
568 : : * @param[in] divider New HFCLK divider.
569 : : */
570 : : NRF_STATIC_INLINE void nrf_clock_hfclk_div_set(NRF_CLOCK_Type * p_reg,
571 : : nrf_clock_hfclk_div_t divider);
572 : :
573 : : /**
574 : : * @brief Function for retrieving the HFCLK frequency divider.
575 : : *
576 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
577 : : *
578 : : * @return HFCLK frequency divider.
579 : : */
580 : : NRF_STATIC_INLINE nrf_clock_hfclk_div_t nrf_clock_hfclk_div_get(NRF_CLOCK_Type const * p_reg);
581 : : #endif
582 : :
583 : : #if NRF_CLOCK_HAS_HFCLK192M
584 : : /**
585 : : * @brief Function for changing the HFCLK192M frequency divider.
586 : : *
587 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
588 : : * @param[in] divider New HFCLK192M divider.
589 : : */
590 : : NRF_STATIC_INLINE void nrf_clock_hfclk192m_div_set(NRF_CLOCK_Type * p_reg,
591 : : nrf_clock_hfclk_div_t divider);
592 : :
593 : : /**
594 : : * @brief Function for retrieving the HFCLK192M frequency divider.
595 : : *
596 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
597 : : *
598 : : * @return HFCLK192M frequency divider.
599 : : */
600 : : NRF_STATIC_INLINE nrf_clock_hfclk_div_t nrf_clock_hfclk192m_div_get(NRF_CLOCK_Type const * p_reg);
601 : :
602 : : /**
603 : : * @brief Function for changing the HFCLK192M source.
604 : : *
605 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
606 : : * @param[in] source New HFCLK192M source.
607 : : */
608 : : NRF_STATIC_INLINE void nrf_clock_hfclk192m_src_set(NRF_CLOCK_Type * p_reg,
609 : : nrf_clock_hfclk_t source);
610 : :
611 : : /**
612 : : * @brief Function for retrieving the selected source of the HFCLK192M.
613 : : *
614 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
615 : : *
616 : : * @retval NRF_CLOCK_HFCLK_LOW_ACCURACY The internal RC oscillator is the selected
617 : : * source of the HFCLK192M.
618 : : * @retval NRF_CLOCK_HFCLK_HIGH_ACCURACY An external crystal oscillator is the selected
619 : : * source of the HFCLK192M.
620 : : */
621 : : NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hfclk192m_src_get(NRF_CLOCK_Type const * p_reg);
622 : : #endif // NRF_CLOCK_HAS_HFCLK192M
623 : :
624 : : #if NRF_CLOCK_HAS_ALWAYSRUN
625 : : /**
626 : : * @brief Function for setting the clock domain to always run.
627 : : *
628 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
629 : : * @param[in] domain Clock domain.
630 : : * @param[in] alwaysrun Ensure the clock is always running.
631 : : */
632 : : NRF_STATIC_INLINE void nrf_clock_alwaysrun_set(NRF_CLOCK_Type * p_reg,
633 : : nrf_clock_domain_t domain,
634 : : bool alwaysrun);
635 : : /**
636 : : * @brief Function for checking if the clock domain is configured to always run.
637 : : *
638 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
639 : : * @param[in] domain Clock domain.
640 : : *
641 : : * @retval true The clock domain is configured to always run.
642 : : * @retval false The clock domain is not configured to always run.
643 : : */
644 : : NRF_STATIC_INLINE bool nrf_clock_alwaysrun_get(NRF_CLOCK_Type const * p_reg,
645 : : nrf_clock_domain_t domain);
646 : : /**
647 : : * @brief Function for checking if the clock domain always run setting is active.
648 : : *
649 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
650 : : * @param[in] domain Clock domain.
651 : : *
652 : : * @retval true The clock domain always run setting is active.
653 : : * @retval false The clock domain always run setting is not active.
654 : : */
655 : : NRF_STATIC_INLINE bool nrf_clock_alwaysrun_active_get(NRF_CLOCK_Type const * p_reg,
656 : : nrf_clock_domain_t domain);
657 : : #endif
658 : :
659 : : #if defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
660 : : /**
661 : : * @brief Function for setting the subscribe configuration for a given
662 : : * CLOCK task.
663 : : *
664 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
665 : : * @param[in] task Task for which to set the configuration.
666 : : * @param[in] channel Channel through which to subscribe events.
667 : : */
668 : : NRF_STATIC_INLINE void nrf_clock_subscribe_set(NRF_CLOCK_Type * p_reg,
669 : : nrf_clock_task_t task,
670 : : uint8_t channel);
671 : :
672 : : /**
673 : : * @brief Function for clearing the subscribe configuration for a given
674 : : * CLOCK task.
675 : : *
676 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
677 : : * @param[in] task Task for which to clear the configuration.
678 : : */
679 : : NRF_STATIC_INLINE void nrf_clock_subscribe_clear(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task);
680 : :
681 : : /**
682 : : * @brief Function for setting the publish configuration for a given
683 : : * CLOCK event.
684 : : *
685 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
686 : : * @param[in] event Event for which to set the configuration.
687 : : * @param[in] channel Channel through which to publish the event.
688 : : */
689 : : NRF_STATIC_INLINE void nrf_clock_publish_set(NRF_CLOCK_Type * p_reg,
690 : : nrf_clock_event_t event,
691 : : uint8_t channel);
692 : :
693 : : /**
694 : : * @brief Function for clearing the publish configuration for a given
695 : : * CLOCK event.
696 : : *
697 : : * @param[in] p_reg Pointer to the structure of registers of the peripheral.
698 : : * @param[in] event Event for which to clear the configuration.
699 : : */
700 : : NRF_STATIC_INLINE void nrf_clock_publish_clear(NRF_CLOCK_Type * p_reg, nrf_clock_event_t event);
701 : : #endif // defined(DPPI_PRESENT) || defined(__NRFX_DOXYGEN__)
702 : :
703 : : #ifndef NRF_DECLARE_ONLY
704 : :
705 : 1 : NRF_STATIC_INLINE void nrf_clock_int_enable(NRF_CLOCK_Type * p_reg, uint32_t mask)
706 : : {
707 : 1 : p_reg->INTENSET = mask;
708 : 1 : }
709 : :
710 : 1 : NRF_STATIC_INLINE void nrf_clock_int_disable(NRF_CLOCK_Type * p_reg, uint32_t mask)
711 : : {
712 : 1 : p_reg->INTENCLR = mask;
713 : 1 : }
714 : :
715 : : NRF_STATIC_INLINE uint32_t nrf_clock_int_enable_check(NRF_CLOCK_Type const * p_reg, uint32_t mask)
716 : : {
717 : : return p_reg->INTENSET & mask;
718 : : }
719 : :
720 : : NRF_STATIC_INLINE uint32_t nrf_clock_task_address_get(NRF_CLOCK_Type const * p_reg,
721 : : nrf_clock_task_t task)
722 : : {
723 : : return (uint32_t)((uint8_t *)p_reg + (uint32_t)task);
724 : : }
725 : :
726 : 2 : NRF_STATIC_INLINE void nrf_clock_task_trigger(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task)
727 : : {
728 : 2 : *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)task)) = 0x1UL;
729 : 2 : }
730 : :
731 : : NRF_STATIC_INLINE uint32_t nrf_clock_event_address_get(NRF_CLOCK_Type const * p_reg,
732 : : nrf_clock_event_t event)
733 : : {
734 : : return (uint32_t)((uint8_t *)p_reg + (uint32_t)event);
735 : : }
736 : :
737 : 3 : NRF_STATIC_INLINE void nrf_clock_event_clear(NRF_CLOCK_Type * p_reg, nrf_clock_event_t event)
738 : : {
739 : 3 : *((volatile uint32_t *)((uint8_t *)p_reg + (uint32_t)event)) = 0x0UL;
740 : 3 : nrf_event_readback((uint8_t *)p_reg + (uint32_t)event);
741 : 3 : }
742 : :
743 : 5 : NRF_STATIC_INLINE bool nrf_clock_event_check(NRF_CLOCK_Type const * p_reg, nrf_clock_event_t event)
744 : : {
745 : 5 : return (bool)*((volatile uint32_t *)((uint8_t *)p_reg + event));
746 : : }
747 : :
748 : 1 : NRF_STATIC_INLINE bool nrf_clock_start_task_check(NRF_CLOCK_Type const * p_reg,
749 : : nrf_clock_domain_t domain)
750 : : {
751 [ + - - - : 1 : switch (domain)
- ]
752 : : {
753 : 1 : case NRF_CLOCK_DOMAIN_LFCLK:
754 : 1 : return ((p_reg->LFCLKRUN & CLOCK_LFCLKRUN_STATUS_Msk)
755 : 1 : >> CLOCK_LFCLKRUN_STATUS_Pos);
756 : 0 : case NRF_CLOCK_DOMAIN_HFCLK:
757 : 0 : return ((p_reg->HFCLKRUN & CLOCK_HFCLKRUN_STATUS_Msk)
758 : 0 : >> CLOCK_HFCLKRUN_STATUS_Pos);
759 : : #if NRF_CLOCK_HAS_HFCLK192M
760 : 0 : case NRF_CLOCK_DOMAIN_HFCLK192M:
761 : 0 : return ((p_reg->HFCLK192MRUN & CLOCK_HFCLK192MRUN_STATUS_Msk)
762 : 0 : >> CLOCK_HFCLK192MRUN_STATUS_Pos);
763 : : #endif
764 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
765 : 0 : case NRF_CLOCK_DOMAIN_HFCLKAUDIO:
766 : 0 : return ((p_reg->HFCLKAUDIORUN & CLOCK_HFCLKAUDIORUN_STATUS_Msk)
767 : 0 : >> CLOCK_HFCLKAUDIORUN_STATUS_Pos);
768 : : #endif
769 : 0 : default:
770 : 0 : NRFX_ASSERT(0);
771 : 0 : return false;
772 : : }
773 : : }
774 : :
775 : 5 : NRF_STATIC_INLINE bool nrf_clock_is_running(NRF_CLOCK_Type const * p_reg,
776 : : nrf_clock_domain_t domain,
777 : : void * p_clk_src)
778 : : {
779 [ + - - - : 5 : switch (domain)
- ]
780 : : {
781 : 5 : case NRF_CLOCK_DOMAIN_LFCLK:
782 [ + - ]: 5 : if (p_clk_src != NULL)
783 : : {
784 : 5 : (*(nrf_clock_lfclk_t *)p_clk_src) =
785 : 5 : (nrf_clock_lfclk_t)((p_reg->LFCLKSTAT & CLOCK_LFCLKSTAT_SRC_Msk)
786 : : >> CLOCK_LFCLKSTAT_SRC_Pos);
787 : : }
788 [ + + ]: 5 : if ((p_reg->LFCLKSTAT & CLOCK_LFCLKSTAT_STATE_Msk)
789 : : >> CLOCK_LFCLKSTAT_STATE_Pos)
790 : : {
791 : 2 : return true;
792 : : }
793 : 3 : break;
794 : 0 : case NRF_CLOCK_DOMAIN_HFCLK:
795 [ # # ]: 0 : if (p_clk_src != NULL)
796 : : {
797 : 0 : (*(nrf_clock_hfclk_t *)p_clk_src) =
798 : 0 : (nrf_clock_hfclk_t)((p_reg->HFCLKSTAT & CLOCK_HFCLKSTAT_SRC_Msk)
799 : : >> CLOCK_HFCLKSTAT_SRC_Pos);
800 : : }
801 [ # # ]: 0 : if ((p_reg->HFCLKSTAT & CLOCK_HFCLKSTAT_STATE_Msk)
802 : : >> CLOCK_HFCLKSTAT_STATE_Pos)
803 : : {
804 : 0 : return true;
805 : : }
806 : 0 : break;
807 : : #if NRF_CLOCK_HAS_HFCLK192M
808 : 0 : case NRF_CLOCK_DOMAIN_HFCLK192M:
809 [ # # ]: 0 : if (p_clk_src != NULL)
810 : : {
811 : 0 : (*(nrf_clock_hfclk_t *)p_clk_src) =
812 : 0 : (nrf_clock_hfclk_t)((p_reg->HFCLK192MSTAT & CLOCK_HFCLK192MSTAT_SRC_Msk)
813 : : >> CLOCK_HFCLK192MSTAT_SRC_Pos);
814 : : }
815 [ # # ]: 0 : if ((p_reg->HFCLK192MSTAT & CLOCK_HFCLK192MSTAT_STATE_Msk)
816 : : >> CLOCK_HFCLK192MSTAT_STATE_Pos)
817 : : {
818 : 0 : return true;
819 : : }
820 : 0 : break;
821 : : #endif
822 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
823 : 0 : case NRF_CLOCK_DOMAIN_HFCLKAUDIO:
824 : 0 : return (p_reg->HFCLKAUDIOSTAT & CLOCK_HFCLKAUDIOSTAT_STATE_Msk) ==
825 : : CLOCK_HFCLKAUDIOSTAT_STATE_Msk;
826 : : #endif
827 : 0 : default:
828 : 0 : NRFX_ASSERT(0);
829 : 0 : return false;
830 : : }
831 : 3 : return false;
832 : : }
833 : :
834 : 3 : NRF_STATIC_INLINE void nrf_clock_lf_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_lfclk_t source)
835 : : {
836 : 3 : p_reg->LFCLKSRC = (uint32_t)(source);
837 : 3 : }
838 : :
839 : 2 : NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_src_get(NRF_CLOCK_Type const * p_reg)
840 : : {
841 : 2 : return (nrf_clock_lfclk_t)(p_reg->LFCLKSRC);
842 : : }
843 : :
844 : : NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_actv_src_get(NRF_CLOCK_Type const * p_reg)
845 : : {
846 : : nrf_clock_lfclk_t clk_src;
847 : : (void)nrf_clock_is_running(p_reg, NRF_CLOCK_DOMAIN_LFCLK, &clk_src);
848 : : return clk_src;
849 : : }
850 : :
851 : 0 : NRF_STATIC_INLINE nrf_clock_lfclk_t nrf_clock_lf_srccopy_get(NRF_CLOCK_Type const * p_reg)
852 : : {
853 : 0 : return (nrf_clock_lfclk_t)((p_reg->LFCLKSRCCOPY & CLOCK_LFCLKSRCCOPY_SRC_Msk)
854 : : >> CLOCK_LFCLKSRCCOPY_SRC_Pos);
855 : : }
856 : :
857 : : NRF_STATIC_INLINE bool nrf_clock_lf_is_running(NRF_CLOCK_Type const * p_reg)
858 : : {
859 : : return nrf_clock_is_running(p_reg, NRF_CLOCK_DOMAIN_LFCLK, NULL);
860 : : }
861 : :
862 : : NRF_STATIC_INLINE
863 : : nrf_clock_start_task_status_t nrf_clock_lf_start_task_status_get(NRF_CLOCK_Type const * p_reg)
864 : : {
865 : : return (nrf_clock_start_task_status_t)nrf_clock_start_task_check(p_reg,
866 : : NRF_CLOCK_DOMAIN_LFCLK);
867 : : }
868 : :
869 : : #if NRF_CLOCK_HAS_HFCLKSRC
870 : 1 : NRF_STATIC_INLINE void nrf_clock_hf_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_hfclk_t source)
871 : : {
872 : 1 : p_reg->HFCLKSRC = (uint32_t)(source);
873 : 1 : }
874 : : #endif
875 : :
876 : : NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hf_src_get(NRF_CLOCK_Type const * p_reg)
877 : : {
878 : : #if NRF_CLOCK_HAS_HFCLKSRC
879 : : return (nrf_clock_hfclk_t)(p_reg->HFCLKSRC);
880 : : #else
881 : : return (nrf_clock_hfclk_t)((p_reg->HFCLKSTAT & CLOCK_HFCLKSTAT_SRC_Msk)
882 : : >> CLOCK_HFCLKSTAT_SRC_Pos);
883 : : #endif
884 : : }
885 : :
886 : : NRF_STATIC_INLINE bool nrf_clock_hf_is_running(NRF_CLOCK_Type const * p_reg,
887 : : nrf_clock_hfclk_t clk_src)
888 : : {
889 : : nrf_clock_hfclk_t active_clk_src;
890 : : bool ret = nrf_clock_is_running(p_reg, NRF_CLOCK_DOMAIN_HFCLK, &active_clk_src);
891 : : return (ret && (active_clk_src == clk_src));
892 : : }
893 : :
894 : : NRF_STATIC_INLINE
895 : : nrf_clock_start_task_status_t nrf_clock_hf_start_task_status_get(NRF_CLOCK_Type const * p_reg)
896 : : {
897 : : return (nrf_clock_start_task_status_t)nrf_clock_start_task_check(p_reg,
898 : : NRF_CLOCK_DOMAIN_HFCLK);
899 : : }
900 : :
901 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
902 : : NRF_STATIC_INLINE
903 : : void nrf_clock_hfclkaudio_config_set(NRF_CLOCK_Type * p_reg, uint16_t freq_value)
904 : : {
905 : : p_reg->HFCLKAUDIO.FREQUENCY = freq_value;
906 : : }
907 : :
908 : : NRF_STATIC_INLINE
909 : : uint16_t nrf_clock_hfclkaudio_config_get(NRF_CLOCK_Type const * p_reg)
910 : : {
911 : : return (uint16_t)(p_reg->HFCLKAUDIO.FREQUENCY);
912 : : }
913 : : #endif
914 : :
915 : : #if defined(CLOCK_FEATURE_HFCLK_DIVIDE_PRESENT)
916 : : NRF_STATIC_INLINE
917 : 0 : void nrf_clock_hfclk_div_set(NRF_CLOCK_Type * p_reg, nrf_clock_hfclk_div_t divider)
918 : : {
919 : 0 : p_reg->HFCLKCTRL = (((uint8_t)(divider) << CLOCK_HFCLKCTRL_HCLK_Pos) &
920 : : CLOCK_HFCLKCTRL_HCLK_Msk);
921 : 0 : }
922 : :
923 : : NRF_STATIC_INLINE nrf_clock_hfclk_div_t nrf_clock_hfclk_div_get(NRF_CLOCK_Type const * p_reg)
924 : : {
925 : : return (nrf_clock_hfclk_div_t)((p_reg->HFCLKCTRL & CLOCK_HFCLKCTRL_HCLK_Msk)
926 : : >> CLOCK_HFCLKCTRL_HCLK_Pos);
927 : : }
928 : : #endif
929 : :
930 : : #if NRF_CLOCK_HAS_HFCLK192M
931 : : NRF_STATIC_INLINE
932 : 0 : void nrf_clock_hfclk192m_div_set(NRF_CLOCK_Type * p_reg, nrf_clock_hfclk_div_t divider)
933 : : {
934 : 0 : p_reg->HFCLK192MCTRL = (((uint8_t)(divider) << CLOCK_HFCLK192MCTRL_HCLK192M_Pos) &
935 : : CLOCK_HFCLK192MCTRL_HCLK192M_Msk);
936 : 0 : }
937 : :
938 : : NRF_STATIC_INLINE nrf_clock_hfclk_div_t nrf_clock_hfclk192m_div_get(NRF_CLOCK_Type const * p_reg)
939 : : {
940 : : return (nrf_clock_hfclk_div_t)((p_reg->HFCLK192MCTRL & CLOCK_HFCLK192MCTRL_HCLK192M_Msk)
941 : : >> CLOCK_HFCLK192MCTRL_HCLK192M_Pos);
942 : : }
943 : :
944 : 1 : NRF_STATIC_INLINE void nrf_clock_hfclk192m_src_set(NRF_CLOCK_Type * p_reg, nrf_clock_hfclk_t source)
945 : : {
946 : 1 : p_reg->HFCLK192MSRC = (uint32_t)(source);
947 : 1 : }
948 : :
949 : : NRF_STATIC_INLINE nrf_clock_hfclk_t nrf_clock_hfclk192m_src_get(NRF_CLOCK_Type const * p_reg)
950 : : {
951 : : return (nrf_clock_hfclk_t)(p_reg->HFCLK192MSRC);
952 : : }
953 : : #endif
954 : :
955 : : #if NRF_CLOCK_HAS_CALIBRATION_TIMER
956 : : NRF_STATIC_INLINE void nrf_clock_cal_timer_timeout_set(NRF_CLOCK_Type * p_reg, uint32_t interval)
957 : : {
958 : : p_reg->CTIV = ((interval << CLOCK_CTIV_CTIV_Pos) & CLOCK_CTIV_CTIV_Msk);
959 : : }
960 : : #endif
961 : :
962 : : #if NRF_CLOCK_HAS_ALWAYSRUN
963 : : NRF_STATIC_INLINE void nrf_clock_alwaysrun_set(NRF_CLOCK_Type * p_reg,
964 : : nrf_clock_domain_t domain,
965 : : bool alwaysrun)
966 : : {
967 : : switch (domain)
968 : : {
969 : : case NRF_CLOCK_DOMAIN_LFCLK:
970 : : p_reg->LFCLKALWAYSRUN =
971 : : ((alwaysrun << CLOCK_LFCLKALWAYSRUN_ALWAYSRUN_Pos)
972 : : & CLOCK_LFCLKALWAYSRUN_ALWAYSRUN_Msk);
973 : : break;
974 : : case NRF_CLOCK_DOMAIN_HFCLK:
975 : : p_reg->HFCLKALWAYSRUN =
976 : : ((alwaysrun << CLOCK_HFCLKALWAYSRUN_ALWAYSRUN_Pos)
977 : : & CLOCK_HFCLKALWAYSRUN_ALWAYSRUN_Msk);
978 : : break;
979 : : #if NRF_CLOCK_HAS_HFCLK192M
980 : : case NRF_CLOCK_DOMAIN_HFCLK192M:
981 : : p_reg->HFCLK192MALWAYSRUN =
982 : : ((alwaysrun << CLOCK_HFCLK192MALWAYSRUN_ALWAYSRUN_Pos)
983 : : & CLOCK_HFCLK192MALWAYSRUN_ALWAYSRUN_Msk);
984 : : break;
985 : : #endif
986 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
987 : : case NRF_CLOCK_DOMAIN_HFCLKAUDIO:
988 : : p_reg->HFCLKAUDIOALWAYSRUN =
989 : : ((alwaysrun << CLOCK_HFCLKAUDIOALWAYSRUN_ALWAYSRUN_Pos)
990 : : & CLOCK_HFCLKAUDIOALWAYSRUN_ALWAYSRUN_Msk);
991 : : break;
992 : : #endif
993 : : default:
994 : : NRFX_ASSERT(0);
995 : : break;
996 : : }
997 : : }
998 : :
999 : : NRF_STATIC_INLINE bool nrf_clock_alwaysrun_get(NRF_CLOCK_Type const * p_reg,
1000 : : nrf_clock_domain_t domain)
1001 : : {
1002 : : switch (domain)
1003 : : {
1004 : : case NRF_CLOCK_DOMAIN_LFCLK:
1005 : : return ((p_reg->LFCLKALWAYSRUN & CLOCK_LFCLKALWAYSRUN_ALWAYSRUN_Msk)
1006 : : >> CLOCK_LFCLKALWAYSRUN_ALWAYSRUN_Pos);
1007 : : case NRF_CLOCK_DOMAIN_HFCLK:
1008 : : return ((p_reg->HFCLKALWAYSRUN & CLOCK_HFCLKALWAYSRUN_ALWAYSRUN_Msk)
1009 : : >> CLOCK_HFCLKALWAYSRUN_ALWAYSRUN_Pos);
1010 : : #if NRF_CLOCK_HAS_HFCLK192M
1011 : : case NRF_CLOCK_DOMAIN_HFCLK192M:
1012 : : return ((p_reg->HFCLK192MALWAYSRUN & CLOCK_HFCLK192MALWAYSRUN_ALWAYSRUN_Msk)
1013 : : >> CLOCK_HFCLK192MALWAYSRUN_ALWAYSRUN_Pos);
1014 : : #endif
1015 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
1016 : : case NRF_CLOCK_DOMAIN_HFCLKAUDIO:
1017 : : return ((p_reg->HFCLKAUDIOALWAYSRUN & CLOCK_HFCLKAUDIOALWAYSRUN_ALWAYSRUN_Msk)
1018 : : >> CLOCK_HFCLKAUDIOALWAYSRUN_ALWAYSRUN_Pos);
1019 : : #endif
1020 : : default:
1021 : : NRFX_ASSERT(0);
1022 : : return false;
1023 : : }
1024 : : }
1025 : :
1026 : : NRF_STATIC_INLINE bool nrf_clock_alwaysrun_active_get(NRF_CLOCK_Type const * p_reg,
1027 : : nrf_clock_domain_t domain)
1028 : : {
1029 : : switch (domain)
1030 : : {
1031 : : case NRF_CLOCK_DOMAIN_LFCLK:
1032 : : return ((p_reg->LFCLKSTAT & CLOCK_LFCLKSTAT_ALWAYSRUNNING_Msk)
1033 : : >> CLOCK_LFCLKSTAT_ALWAYSRUNNING_Pos);
1034 : : case NRF_CLOCK_DOMAIN_HFCLK:
1035 : : return ((p_reg->HFCLKSTAT & CLOCK_HFCLKSTAT_ALWAYSRUNNING_Msk)
1036 : : >> CLOCK_HFCLKSTAT_ALWAYSRUNNING_Pos);
1037 : : #if NRF_CLOCK_HAS_HFCLK192M
1038 : : case NRF_CLOCK_DOMAIN_HFCLK192M:
1039 : : return ((p_reg->HFCLK192MSTAT & CLOCK_HFCLK192MSTAT_ALWAYSRUNNING_Msk)
1040 : : >> CLOCK_HFCLK192MSTAT_ALWAYSRUNNING_Pos);
1041 : : #endif
1042 : : #if NRF_CLOCK_HAS_HFCLKAUDIO
1043 : : case NRF_CLOCK_DOMAIN_HFCLKAUDIO:
1044 : : return ((p_reg->HFCLKAUDIOSTAT & CLOCK_HFCLKAUDIOSTAT_ALWAYSRUNNING_Msk)
1045 : : >> CLOCK_HFCLKAUDIOSTAT_ALWAYSRUNNING_Pos);
1046 : : #endif
1047 : : default:
1048 : : NRFX_ASSERT(0);
1049 : : return false;
1050 : : }
1051 : : }
1052 : : #endif // NRF_CLOCK_HAS_ALWAYSRUN
1053 : :
1054 : : #if defined(DPPI_PRESENT)
1055 : : NRF_STATIC_INLINE void nrf_clock_subscribe_set(NRF_CLOCK_Type * p_reg,
1056 : : nrf_clock_task_t task,
1057 : : uint8_t channel)
1058 : : {
1059 : : *((volatile uint32_t *) ((uint8_t *)p_reg+ (uint32_t)task + 0x80uL)) =
1060 : : ((uint32_t)channel | CLOCK_SUBSCRIBE_HFCLKSTART_EN_Msk);
1061 : : }
1062 : :
1063 : : NRF_STATIC_INLINE void nrf_clock_subscribe_clear(NRF_CLOCK_Type * p_reg, nrf_clock_task_t task)
1064 : : {
1065 : : *((volatile uint32_t *) ((uint8_t *)p_reg + (uint32_t)task + 0x80uL)) = 0;
1066 : : }
1067 : :
1068 : : NRF_STATIC_INLINE void nrf_clock_publish_set(NRF_CLOCK_Type * p_reg,
1069 : : nrf_clock_event_t event,
1070 : : uint8_t channel)
1071 : : {
1072 : : *((volatile uint32_t *) ((uint8_t *)p_reg + (uint32_t)event + 0x80uL)) =
1073 : : ((uint32_t)channel | CLOCK_PUBLISH_HFCLKSTARTED_EN_Msk);
1074 : : }
1075 : :
1076 : : NRF_STATIC_INLINE void nrf_clock_publish_clear(NRF_CLOCK_Type * p_reg, nrf_clock_event_t event)
1077 : : {
1078 : : *((volatile uint32_t *) ((uint8_t *)p_reg + (uint32_t)event + 0x80uL)) = 0;
1079 : : }
1080 : : #endif // defined(DPPI_PRESENT)
1081 : :
1082 : : #endif // NRF_DECLARE_ONLY
1083 : :
1084 : : /** @} */
1085 : :
1086 : : #ifdef __cplusplus
1087 : : }
1088 : : #endif
1089 : :
1090 : : #endif // NRF_CLOCK_H__
|