Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
nrf_clock_control.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_
14#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_
15
16#include <zephyr/device.h>
17#include <zephyr/sys/onoff.h>
19
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#if !(defined(CONFIG_SOC_SERIES_NRF54H) || defined(CONFIG_SOC_SERIES_NRF92))
31
32#include <hal/nrf_clock.h>
33
34#if defined(CONFIG_CLOCK_CONTROL_NRF)
39enum __deprecated clock_control_nrf_type {
40 CLOCK_CONTROL_NRF_TYPE_HFCLK,
41 CLOCK_CONTROL_NRF_TYPE_LFCLK,
42#if NRF_CLOCK_HAS_HFCLK24M
43 CLOCK_CONTROL_NRF_TYPE_HFCLK24M,
44#endif
45#if NRF_CLOCK_HAS_HFCLK192M
46 CLOCK_CONTROL_NRF_TYPE_HFCLK192M,
47#endif
48#if NRF_CLOCK_HAS_HFCLKAUDIO
49 CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO,
50#endif
51 CLOCK_CONTROL_NRF_TYPE_COUNT
52};
53
61#define CLOCK_CONTROL_NRF_SUBSYS_HF \
62 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK) __DEPRECATED_MACRO
64#define CLOCK_CONTROL_NRF_SUBSYS_LF \
65 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_LFCLK) __DEPRECATED_MACRO
67#define CLOCK_CONTROL_NRF_SUBSYS_HF24M \
68 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK24M) __DEPRECATED_MACRO
70#define CLOCK_CONTROL_NRF_SUBSYS_HF192M \
71 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK192M) __DEPRECATED_MACRO
73#define CLOCK_CONTROL_NRF_SUBSYS_HFAUDIO \
74 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO) __DEPRECATED_MACRO
75
77
78/* Define 32KHz clock source */
79#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC
80#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_RC __DEPRECATED_MACRO
81#endif
82#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL
83#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL __DEPRECATED_MACRO
84#endif
85#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH
86#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_SYNTH __DEPRECATED_MACRO
87#endif
88#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_LOW_SWING
89#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_LOW_SWING __DEPRECATED_MACRO
90#endif
91#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_FULL_SWING
92#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_FULL_SWING __DEPRECATED_MACRO
93#endif
94
95/* Define 32KHz clock accuracy */
96#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM
97#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 0 __DEPRECATED_MACRO
98#endif
99#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM
100#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 1 __DEPRECATED_MACRO
101#endif
102#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM
103#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 2 __DEPRECATED_MACRO
104#endif
105#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM
106#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 3 __DEPRECATED_MACRO
107#endif
108#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM
109#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 4 __DEPRECATED_MACRO
110#endif
111#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM
112#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 5 __DEPRECATED_MACRO
113#endif
114#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM
115#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 6 __DEPRECATED_MACRO
116#endif
117#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM
118#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 7 __DEPRECATED_MACRO
119#endif
120
122
123#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
124
131
133
135void z_nrf_clock_calibration_force_start(void);
136
143int z_nrf_clock_calibration_count(void);
144
151int z_nrf_clock_calibration_skips_count(void);
152
153
158bool z_nrf_clock_calibration_is_in_progress(void);
159
160#if defined(CONFIG_CLOCK_CONTROL_NRF)
167struct onoff_manager __deprecated *z_nrf_clock_control_get_onoff(clock_control_subsys_t sys);
168#endif
169
178void z_nrf_clock_control_lf_on(enum nrf_lfclk_start_mode start_mode);
179
192void z_nrf_clock_bt_ctlr_hf_request(void);
193
198void z_nrf_clock_bt_ctlr_hf_release(void);
199
205uint32_t z_nrf_clock_bt_ctlr_hf_get_startup_time_us(void);
206
208
209#endif /* !(defined(CONFIG_SOC_SERIES_NRF54H) || defined(CONFIG_SOC_SERIES_NRF92)) */
210
212#define NRF_CLOCK_CONTROL_FREQUENCY_MAX UINT32_MAX
213
215#define NRF_CLOCK_CONTROL_ACCURACY_MAX 1
217#define NRF_CLOCK_CONTROL_ACCURACY_PPM(ppm) (ppm)
218
220#define NRF_CLOCK_CONTROL_PRECISION_HIGH 1
222#define NRF_CLOCK_CONTROL_PRECISION_DEFAULT 0
223
230#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_MIN_HZ 80000000
232#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_44K1_HZ 11289591
234#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_USB24M_HZ 24000000
236#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_48K_HZ 12287963
238
240
241/* Internal helper macro to map DT property value to output frequency */
242#define _CLOCK_CONTROL_NRF_AUXPLL_MAP_FREQ(freq_val) \
243 ((freq_val) == NRF_AUXPLL_FREQ_DIV_MIN ? \
244 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_MIN_HZ : \
245 (freq_val) == NRF_AUXPLL_FREQ_DIV_AUDIO_44K1 ? \
246 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_44K1_HZ : \
247 (freq_val) == NRF_AUXPLL_FREQ_DIV_USB24M ? \
248 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_USB24M_HZ : \
249 (freq_val) == NRF_AUXPLL_FREQ_DIV_AUDIO_48K ? \
250 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_48K_HZ : 0)
251
253
260#define CLOCK_CONTROL_NRF_AUXPLL_GET_FREQ(node) \
261 COND_CODE_1(DT_NODE_HAS_PROP(node, nordic_frequency), \
262 (_CLOCK_CONTROL_NRF_AUXPLL_MAP_FREQ(DT_PROP(node, nordic_frequency))), \
263 (0))
264
268
269struct nrf_clock_spec {
270 uint32_t frequency;
271 uint16_t accuracy : 15;
272 uint16_t precision : 1;
273};
274
275__subsystem struct nrf_clock_control_driver_api {
276 struct clock_control_driver_api std_api;
277
278 int (*request)(const struct device *dev,
279 const struct nrf_clock_spec *spec,
280 struct onoff_client *cli);
281 int (*release)(const struct device *dev,
282 const struct nrf_clock_spec *spec);
283 int (*cancel_or_release)(const struct device *dev,
284 const struct nrf_clock_spec *spec,
285 struct onoff_client *cli);
286 int (*resolve)(const struct device *dev,
287 const struct nrf_clock_spec *req_spec,
288 struct nrf_clock_spec *res_spec);
289 int (*get_startup_time)(const struct device *dev,
290 const struct nrf_clock_spec *spec,
291 uint32_t *startup_time_us);
292};
293
294DEVICE_API_EXTENDS(nrf_clock_control, clock_control, std_api);
295
299
332static inline
333int nrf_clock_control_request(const struct device *dev,
334 const struct nrf_clock_spec *spec,
335 struct onoff_client *cli)
336{
337 return DEVICE_API_GET(nrf_clock_control, dev)->request(dev, spec, cli);
338}
339
355 const struct nrf_clock_spec *spec,
356 k_timeout_t timeout);
357
372static inline
373int nrf_clock_control_release(const struct device *dev,
374 const struct nrf_clock_spec *spec)
375{
376 return DEVICE_API_GET(nrf_clock_control, dev)->release(dev, spec);
377}
378
401static inline
403 const struct nrf_clock_spec *spec,
404 struct onoff_client *cli)
405{
406 return DEVICE_API_GET(nrf_clock_control, dev)->cancel_or_release(dev, spec, cli);
407}
408
419static inline int nrf_clock_control_resolve(const struct device *dev,
420 const struct nrf_clock_spec *req_spec,
421 struct nrf_clock_spec *res_spec)
422{
423 const struct nrf_clock_control_driver_api *api = DEVICE_API_GET(nrf_clock_control, dev);
424
425 if (api->resolve == NULL) {
426 return -ENOSYS;
427 }
428
429 return api->resolve(dev, req_spec, res_spec);
430}
431
442static inline int nrf_clock_control_get_startup_time(const struct device *dev,
443 const struct nrf_clock_spec *spec,
444 uint32_t *startup_time_us)
445{
446 const struct nrf_clock_control_driver_api *api = DEVICE_API_GET(nrf_clock_control, dev);
447
448 if (api->get_startup_time == NULL) {
449 return -ENOSYS;
450 }
451
452 return api->get_startup_time(dev, spec, startup_time_us);
453}
454
467
478
479#ifdef __cplusplus
480}
481#endif
482
484
485#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_ */
Main header file for clock control driver API.
#define DEVICE_API_EXTENDS(_child, _parent, _member)
Declare that API class _child is an extension of device API class _parent.
Definition device.h:1426
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1461
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
@def_driverbackendgroup{Clock Control,clock_control_interface}
Definition clock_control.h:96
void * clock_control_subsys_t
Opaque handle identifying a clock controller subsystem.
Definition clock_control.h:65
static int nrf_clock_control_get_startup_time(const struct device *dev, const struct nrf_clock_spec *spec, uint32_t *startup_time_us)
Get the startup time of a clock.
Definition nrf_clock_control.h:442
void nrf_clock_control_hfxo_request(void)
Request the HFXO from Zero Latency Interrupt context.
static int nrf_clock_control_request(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli)
Request a reservation to use a given clock with specified attributes.
Definition nrf_clock_control.h:333
static int nrf_clock_control_cancel_or_release(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli)
Safely cancel a reservation request.
Definition nrf_clock_control.h:402
void nrf_clock_control_hfxo_release(void)
Release the HFXO from Zero Latency Interrupt context.
static int nrf_clock_control_release(const struct device *dev, const struct nrf_clock_spec *spec)
Release a reserved use of a clock.
Definition nrf_clock_control.h:373
nrf_lfclk_start_mode
LF clock start modes.
Definition nrf_clock_control.h:126
static int nrf_clock_control_resolve(const struct device *dev, const struct nrf_clock_spec *req_spec, struct nrf_clock_spec *res_spec)
Resolve a requested clock spec to resulting spec.
Definition nrf_clock_control.h:419
int nrf_clock_control_request_sync(const struct device *dev, const struct nrf_clock_spec *spec, k_timeout_t timeout)
Synchronously request a reservation to use a given clock with specified attributes.
@ CLOCK_CONTROL_NRF_LF_START_AVAILABLE
Wait until the clock is available.
Definition nrf_clock_control.h:128
@ CLOCK_CONTROL_NRF_LF_START_STABLE
Wait until the clock is stable.
Definition nrf_clock_control.h:129
@ CLOCK_CONTROL_NRF_LF_START_NOWAIT
Return without waiting for the clock.
Definition nrf_clock_control.h:127
#define ENOSYS
Function not implemented.
Definition errno.h:83
#define NULL
Definition iar_missing_defs.h:20
Header file for on-off service for managing shared resources.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition device.h:525
Kernel timeout type.
Definition clock.h:65
State associated with a client of an on-off service.
Definition onoff.h:280
State associated with an on-off manager.
Definition onoff.h:160