Zephyr API Documentation 4.0.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
7#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_
8#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_
9
10#include <zephyr/device.h>
11#ifdef NRF_CLOCK
12#include <hal/nrf_clock.h>
13#endif
14#include <zephyr/sys/onoff.h>
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21#if defined(CONFIG_CLOCK_CONTROL_NRF)
22
27enum clock_control_nrf_type {
28 CLOCK_CONTROL_NRF_TYPE_HFCLK,
29 CLOCK_CONTROL_NRF_TYPE_LFCLK,
30#if NRF_CLOCK_HAS_HFCLK192M
31 CLOCK_CONTROL_NRF_TYPE_HFCLK192M,
32#endif
33#if NRF_CLOCK_HAS_HFCLKAUDIO
34 CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO,
35#endif
36 CLOCK_CONTROL_NRF_TYPE_COUNT
37};
38
39/* Define can be used with clock control API instead of enum directly to
40 * increase code readability.
41 */
42#define CLOCK_CONTROL_NRF_SUBSYS_HF \
43 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK)
44#define CLOCK_CONTROL_NRF_SUBSYS_LF \
45 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_LFCLK)
46#define CLOCK_CONTROL_NRF_SUBSYS_HF192M \
47 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK192M)
48#define CLOCK_CONTROL_NRF_SUBSYS_HFAUDIO \
49 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO)
50
52enum nrf_lfclk_start_mode {
53 CLOCK_CONTROL_NRF_LF_START_NOWAIT,
54 CLOCK_CONTROL_NRF_LF_START_AVAILABLE,
55 CLOCK_CONTROL_NRF_LF_START_STABLE,
56};
57
58/* Define 32KHz clock source */
59#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC
60#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_RC
61#endif
62#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL
63#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL
64#endif
65#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH
66#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_SYNTH
67#endif
68#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_LOW_SWING
69#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_LOW_SWING
70#endif
71#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_FULL_SWING
72#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_FULL_SWING
73#endif
74
75/* Define 32KHz clock accuracy */
76#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM
77#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 0
78#endif
79#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM
80#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 1
81#endif
82#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM
83#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 2
84#endif
85#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM
86#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 3
87#endif
88#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM
89#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 4
90#endif
91#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM
92#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 5
93#endif
94#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM
95#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 6
96#endif
97#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM
98#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 7
99#endif
100
102void z_nrf_clock_calibration_force_start(void);
103
110int z_nrf_clock_calibration_count(void);
111
118int z_nrf_clock_calibration_skips_count(void);
119
120
125bool z_nrf_clock_calibration_is_in_progress(void);
126
133struct onoff_manager *z_nrf_clock_control_get_onoff(clock_control_subsys_t sys);
134
143void z_nrf_clock_control_lf_on(enum nrf_lfclk_start_mode start_mode);
144
157void z_nrf_clock_bt_ctlr_hf_request(void);
158
163void z_nrf_clock_bt_ctlr_hf_release(void);
164
165#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
166
167
168#if defined(CONFIG_CLOCK_CONTROL_NRF2)
169
170/* Specifies to use the maximum available frequency for a given clock. */
171#define NRF_CLOCK_CONTROL_FREQUENCY_MAX UINT32_MAX
172
173/* Specifies to use the maximum available accuracy for a given clock. */
174#define NRF_CLOCK_CONTROL_ACCURACY_MAX 1
175/* Specifies the required clock accuracy in parts-per-million. */
176#define NRF_CLOCK_CONTROL_ACCURACY_PPM(ppm) (ppm)
177
178/* Specifies that high precision of the clock is required. */
179#define NRF_CLOCK_CONTROL_PRECISION_HIGH 1
180/* Specifies that default precision of the clock is sufficient. */
181#define NRF_CLOCK_CONTROL_PRECISION_DEFAULT 0
182
183struct nrf_clock_spec {
184 uint32_t frequency;
185 uint16_t accuracy : 15;
186 uint16_t precision : 1;
187};
188
189__subsystem struct nrf_clock_control_driver_api {
190 struct clock_control_driver_api std_api;
191
192 int (*request)(const struct device *dev,
193 const struct nrf_clock_spec *spec,
194 struct onoff_client *cli);
195 int (*release)(const struct device *dev,
196 const struct nrf_clock_spec *spec);
197 int (*cancel_or_release)(const struct device *dev,
198 const struct nrf_clock_spec *spec,
199 struct onoff_client *cli);
200};
201
234static inline
235int nrf_clock_control_request(const struct device *dev,
236 const struct nrf_clock_spec *spec,
237 struct onoff_client *cli)
238{
239 const struct nrf_clock_control_driver_api *api =
240 (const struct nrf_clock_control_driver_api *)dev->api;
241
242 return api->request(dev, spec, cli);
243}
244
259int nrf_clock_control_request_sync(const struct device *dev,
260 const struct nrf_clock_spec *spec,
261 k_timeout_t timeout);
262
277static inline
278int nrf_clock_control_release(const struct device *dev,
279 const struct nrf_clock_spec *spec)
280{
281 const struct nrf_clock_control_driver_api *api =
282 (const struct nrf_clock_control_driver_api *)dev->api;
283
284 return api->release(dev, spec);
285}
286
309static inline
310int nrf_clock_control_cancel_or_release(const struct device *dev,
311 const struct nrf_clock_spec *spec,
312 struct onoff_client *cli)
313{
314 const struct nrf_clock_control_driver_api *api =
315 (const struct nrf_clock_control_driver_api *)dev->api;
316
317 return api->cancel_or_release(dev, spec, cli);
318}
319
331void nrf_clock_control_hfxo_request(void);
332
342void nrf_clock_control_hfxo_release(void);
343
344#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */
345
346#ifdef __cplusplus
347}
348#endif
349
350#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_NRF_CLOCK_CONTROL_H_ */
Public Clock Control APIs.
void * clock_control_subsys_t
clock_control_subsys_t is a type to identify a clock controller sub-system.
Definition clock_control.h:58
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Definition clock_control.h:102
Runtime device structure (in ROM) per driver instance.
Definition device.h:411
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:417
Kernel timeout type.
Definition sys_clock.h:65
State associated with a client of an on-off service.
Definition onoff.h:274
State associated with an on-off manager.
Definition onoff.h:154