Zephyr API Documentation 3.7.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
126struct onoff_manager *z_nrf_clock_control_get_onoff(clock_control_subsys_t sys);
127
136void z_nrf_clock_control_lf_on(enum nrf_lfclk_start_mode start_mode);
137
150void z_nrf_clock_bt_ctlr_hf_request(void);
151
156void z_nrf_clock_bt_ctlr_hf_release(void);
157
158#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
159
160
161#if defined(CONFIG_CLOCK_CONTROL_NRF2)
162
163/* Specifies to use the maximum available frequency for a given clock. */
164#define NRF_CLOCK_CONTROL_FREQUENCY_MAX UINT32_MAX
165
166/* Specifies to use the maximum available accuracy for a given clock. */
167#define NRF_CLOCK_CONTROL_ACCURACY_MAX 1
168/* Specifies the required clock accuracy in parts-per-million. */
169#define NRF_CLOCK_CONTROL_ACCURACY_PPM(ppm) (ppm)
170
171/* Specifies that high precision of the clock is required. */
172#define NRF_CLOCK_CONTROL_PRECISION_HIGH 1
173/* Specifies that default precision of the clock is sufficient. */
174#define NRF_CLOCK_CONTROL_PRECISION_DEFAULT 0
175
176struct nrf_clock_spec {
177 uint32_t frequency;
178 uint16_t accuracy : 15;
179 uint16_t precision : 1;
180};
181
182__subsystem struct nrf_clock_control_driver_api {
183 struct clock_control_driver_api std_api;
184
185 int (*request)(const struct device *dev,
186 const struct nrf_clock_spec *spec,
187 struct onoff_client *cli);
188 int (*release)(const struct device *dev,
189 const struct nrf_clock_spec *spec);
190 int (*cancel_or_release)(const struct device *dev,
191 const struct nrf_clock_spec *spec,
192 struct onoff_client *cli);
193};
194
227static inline
228int nrf_clock_control_request(const struct device *dev,
229 const struct nrf_clock_spec *spec,
230 struct onoff_client *cli)
231{
232 const struct nrf_clock_control_driver_api *api =
233 (const struct nrf_clock_control_driver_api *)dev->api;
234
235 return api->request(dev, spec, cli);
236}
237
252static inline
253int nrf_clock_control_release(const struct device *dev,
254 const struct nrf_clock_spec *spec)
255{
256 const struct nrf_clock_control_driver_api *api =
257 (const struct nrf_clock_control_driver_api *)dev->api;
258
259 return api->release(dev, spec);
260}
261
284static inline
285int nrf_clock_control_cancel_or_release(const struct device *dev,
286 const struct nrf_clock_spec *spec,
287 struct onoff_client *cli)
288{
289 const struct nrf_clock_control_driver_api *api =
290 (const struct nrf_clock_control_driver_api *)dev->api;
291
292 return api->cancel_or_release(dev, spec, cli);
293}
294
295#endif /* defined(CONFIG_CLOCK_CONTROL_NRF2) */
296
297#ifdef __cplusplus
298}
299#endif
300
301#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:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
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