Zephyr API Documentation 4.5.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#ifndef CONFIG_HAS_NORDIC_MULTI_OPTION_CLOCKS
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
171typedef void (*z_nrf_clock_control_lf_on_cb_t)(void);
172
183void z_nrf_clock_control_lf_on(enum nrf_lfclk_start_mode start_mode,
184 z_nrf_clock_control_lf_on_cb_t cb);
185
198void z_nrf_clock_bt_ctlr_hf_request(void);
199
204void z_nrf_clock_bt_ctlr_hf_release(void);
205
211uint32_t z_nrf_clock_bt_ctlr_hf_get_startup_time_us(void);
212
214
215#endif /* CONFIG_HAS_NORDIC_MULTI_OPTION_CLOCKS */
216
218#define NRF_CLOCK_CONTROL_FREQUENCY_MAX UINT32_MAX
219
221#define NRF_CLOCK_CONTROL_ACCURACY_MAX 1
223#define NRF_CLOCK_CONTROL_ACCURACY_PPM(ppm) (ppm)
224
226#define NRF_CLOCK_CONTROL_PRECISION_HIGH 1
228#define NRF_CLOCK_CONTROL_PRECISION_DEFAULT 0
229
236#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_MIN_HZ 80000000
238#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_44K1_HZ 11289591
240#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_USB24M_HZ 24000000
242#define CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_48K_HZ 12287963
244
246
247/* Internal helper macro to map DT property value to output frequency */
248#define _CLOCK_CONTROL_NRF_AUXPLL_MAP_FREQ(freq_val) \
249 ((freq_val) == NRF_AUXPLL_FREQ_DIV_MIN ? \
250 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_MIN_HZ : \
251 (freq_val) == NRF_AUXPLL_FREQ_DIV_AUDIO_44K1 ? \
252 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_44K1_HZ : \
253 (freq_val) == NRF_AUXPLL_FREQ_DIV_USB24M ? \
254 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_USB24M_HZ : \
255 (freq_val) == NRF_AUXPLL_FREQ_DIV_AUDIO_48K ? \
256 CLOCK_CONTROL_NRF_AUXPLL_FREQ_OUT_AUDIO_48K_HZ : 0)
257
259
266#define CLOCK_CONTROL_NRF_AUXPLL_GET_FREQ(node) \
267 COND_CODE_1(DT_NODE_HAS_PROP(node, nordic_frequency), \
268 (_CLOCK_CONTROL_NRF_AUXPLL_MAP_FREQ(DT_PROP(node, nordic_frequency))), \
269 (0))
270
274
275struct nrf_clock_spec {
276 uint32_t frequency;
277 uint16_t accuracy : 15;
278 uint16_t precision : 1;
279};
280
281__subsystem struct nrf_clock_control_driver_api {
282 struct clock_control_driver_api std_api;
283
284 int (*request)(const struct device *dev,
285 const struct nrf_clock_spec *spec,
286 struct onoff_client *cli);
287 int (*release)(const struct device *dev,
288 const struct nrf_clock_spec *spec);
289 int (*cancel_or_release)(const struct device *dev,
290 const struct nrf_clock_spec *spec,
291 struct onoff_client *cli);
292 int (*resolve)(const struct device *dev,
293 const struct nrf_clock_spec *req_spec,
294 struct nrf_clock_spec *res_spec);
295 int (*get_startup_time)(const struct device *dev,
296 const struct nrf_clock_spec *spec,
297 uint32_t *startup_time_us);
298};
299
300DEVICE_API_EXTENDS(nrf_clock_control, clock_control, std_api);
301
305
338static inline
339int nrf_clock_control_request(const struct device *dev,
340 const struct nrf_clock_spec *spec,
341 struct onoff_client *cli)
342{
343 return DEVICE_API_GET(nrf_clock_control, dev)->request(dev, spec, cli);
344}
345
361 const struct nrf_clock_spec *spec,
362 k_timeout_t timeout);
363
378static inline
379int nrf_clock_control_release(const struct device *dev,
380 const struct nrf_clock_spec *spec)
381{
382 return DEVICE_API_GET(nrf_clock_control, dev)->release(dev, spec);
383}
384
407static inline
409 const struct nrf_clock_spec *spec,
410 struct onoff_client *cli)
411{
412 return DEVICE_API_GET(nrf_clock_control, dev)->cancel_or_release(dev, spec, cli);
413}
414
425static inline int nrf_clock_control_resolve(const struct device *dev,
426 const struct nrf_clock_spec *req_spec,
427 struct nrf_clock_spec *res_spec)
428{
429 const struct nrf_clock_control_driver_api *api = DEVICE_API_GET(nrf_clock_control, dev);
430
431 if (api->resolve == NULL) {
432 return -ENOSYS;
433 }
434
435 return api->resolve(dev, req_spec, res_spec);
436}
437
448static inline int nrf_clock_control_get_startup_time(const struct device *dev,
449 const struct nrf_clock_spec *spec,
450 uint32_t *startup_time_us)
451{
452 const struct nrf_clock_control_driver_api *api = DEVICE_API_GET(nrf_clock_control, dev);
453
454 if (api->get_startup_time == NULL) {
455 return -ENOSYS;
456 }
457
458 return api->get_startup_time(dev, spec, startup_time_us);
459}
460
473
484
485#ifdef __cplusplus
486}
487#endif
488
490
491#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_ */
Main header file for clock control driver API.
APIs and macros for the Zephyr device model.
#define DEVICE_API_EXTENDS(_child, _parent, _member)
Declare that API class _child is an extension of device API class _parent.
Definition device.h:1470
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1505
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Callback API to enable or disable a clock.
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:448
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:339
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:408
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:379
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:425
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
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:543
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