Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
 4.1.99
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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#include <zephyr/sys/onoff.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#if defined(CONFIG_CLOCK_CONTROL_NRF)
19
20#include <hal/nrf_clock.h>
21
26enum clock_control_nrf_type {
27 CLOCK_CONTROL_NRF_TYPE_HFCLK,
28 CLOCK_CONTROL_NRF_TYPE_LFCLK,
29#if NRF_CLOCK_HAS_HFCLK192M
30 CLOCK_CONTROL_NRF_TYPE_HFCLK192M,
31#endif
32#if NRF_CLOCK_HAS_HFCLKAUDIO
33 CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO,
34#endif
35 CLOCK_CONTROL_NRF_TYPE_COUNT
36};
37
38/* Define can be used with clock control API instead of enum directly to
39 * increase code readability.
40 */
41#define CLOCK_CONTROL_NRF_SUBSYS_HF \
42 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK)
43#define CLOCK_CONTROL_NRF_SUBSYS_LF \
44 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_LFCLK)
45#define CLOCK_CONTROL_NRF_SUBSYS_HF192M \
46 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLK192M)
47#define CLOCK_CONTROL_NRF_SUBSYS_HFAUDIO \
48 ((clock_control_subsys_t)CLOCK_CONTROL_NRF_TYPE_HFCLKAUDIO)
49
51enum nrf_lfclk_start_mode {
52 CLOCK_CONTROL_NRF_LF_START_NOWAIT,
53 CLOCK_CONTROL_NRF_LF_START_AVAILABLE,
54 CLOCK_CONTROL_NRF_LF_START_STABLE,
55};
56
57/* Define 32KHz clock source */
58#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC
59#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_RC
60#endif
61#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL
62#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL
63#endif
64#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH
65#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_SYNTH
66#endif
67#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_LOW_SWING
68#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_LOW_SWING
69#endif
70#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_EXT_FULL_SWING
71#define CLOCK_CONTROL_NRF_K32SRC NRF_CLOCK_LFCLK_XTAL_FULL_SWING
72#endif
73
74/* Define 32KHz clock accuracy */
75#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_500PPM
76#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 0
77#endif
78#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_250PPM
79#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 1
80#endif
81#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_150PPM
82#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 2
83#endif
84#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_100PPM
85#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 3
86#endif
87#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_75PPM
88#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 4
89#endif
90#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_50PPM
91#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 5
92#endif
93#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_30PPM
94#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 6
95#endif
96#ifdef CONFIG_CLOCK_CONTROL_NRF_K32SRC_20PPM
97#define CLOCK_CONTROL_NRF_K32SRC_ACCURACY 7
98#endif
99
101void z_nrf_clock_calibration_force_start(void);
102
109int z_nrf_clock_calibration_count(void);
110
117int z_nrf_clock_calibration_skips_count(void);
118
119
124bool z_nrf_clock_calibration_is_in_progress(void);
125
132struct onoff_manager *z_nrf_clock_control_get_onoff(clock_control_subsys_t sys);
133
142void z_nrf_clock_control_lf_on(enum nrf_lfclk_start_mode start_mode);
143
156void z_nrf_clock_bt_ctlr_hf_request(void);
157
162void z_nrf_clock_bt_ctlr_hf_release(void);
163
169uint32_t z_nrf_clock_bt_ctlr_hf_get_startup_time_us(void);
170
171#endif /* defined(CONFIG_CLOCK_CONTROL_NRF) */
172
173/* Specifies to use the maximum available frequency for a given clock. */
174#define NRF_CLOCK_CONTROL_FREQUENCY_MAX UINT32_MAX
175
176/* Specifies to use the maximum available accuracy for a given clock. */
177#define NRF_CLOCK_CONTROL_ACCURACY_MAX 1
178/* Specifies the required clock accuracy in parts-per-million. */
179#define NRF_CLOCK_CONTROL_ACCURACY_PPM(ppm) (ppm)
180
181/* Specifies that high precision of the clock is required. */
182#define NRF_CLOCK_CONTROL_PRECISION_HIGH 1
183/* Specifies that default precision of the clock is sufficient. */
184#define NRF_CLOCK_CONTROL_PRECISION_DEFAULT 0
185
191
194
195 int (*request)(const struct device *dev,
196 const struct nrf_clock_spec *spec,
197 struct onoff_client *cli);
198 int (*release)(const struct device *dev,
199 const struct nrf_clock_spec *spec);
200 int (*cancel_or_release)(const struct device *dev,
201 const struct nrf_clock_spec *spec,
202 struct onoff_client *cli);
203 int (*resolve)(const struct device *dev,
204 const struct nrf_clock_spec *req_spec,
205 struct nrf_clock_spec *res_spec);
206 int (*get_startup_time)(const struct device *dev,
207 const struct nrf_clock_spec *spec,
208 uint32_t *startup_time_us);
209};
210
243static inline
244int nrf_clock_control_request(const struct device *dev,
245 const struct nrf_clock_spec *spec,
246 struct onoff_client *cli)
247{
248 const struct nrf_clock_control_driver_api *api =
249 (const struct nrf_clock_control_driver_api *)dev->api;
250
251 return api->request(dev, spec, cli);
252}
253
269 const struct nrf_clock_spec *spec,
270 k_timeout_t timeout);
271
286static inline
287int nrf_clock_control_release(const struct device *dev,
288 const struct nrf_clock_spec *spec)
289{
290 const struct nrf_clock_control_driver_api *api =
291 (const struct nrf_clock_control_driver_api *)dev->api;
292
293 return api->release(dev, spec);
294}
295
318static inline
320 const struct nrf_clock_spec *spec,
321 struct onoff_client *cli)
322{
323 const struct nrf_clock_control_driver_api *api =
324 (const struct nrf_clock_control_driver_api *)dev->api;
325
326 return api->cancel_or_release(dev, spec, cli);
327}
328
339static inline int nrf_clock_control_resolve(const struct device *dev,
340 const struct nrf_clock_spec *req_spec,
341 struct nrf_clock_spec *res_spec)
342{
343 const struct nrf_clock_control_driver_api *api =
344 (const struct nrf_clock_control_driver_api *)dev->api;
345
346 if (api->resolve == NULL) {
347 return -ENOSYS;
348 }
349
350 return api->resolve(dev, req_spec, res_spec);
351}
352
363static inline int nrf_clock_control_get_startup_time(const struct device *dev,
364 const struct nrf_clock_spec *spec,
365 uint32_t *startup_time_us)
366{
367 const struct nrf_clock_control_driver_api *api =
368 (const struct nrf_clock_control_driver_api *)dev->api;
369
370 if (api->get_startup_time == NULL) {
371 return -ENOSYS;
372 }
373
374 return api->get_startup_time(dev, spec, startup_time_us);
375}
376
389
400
401#ifdef __cplusplus
402}
403#endif
404
405#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
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
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:363
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:244
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:319
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:287
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:339
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.
__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:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
Kernel timeout type.
Definition sys_clock.h:65
Definition nrf_clock_control.h:192
int(* resolve)(const struct device *dev, const struct nrf_clock_spec *req_spec, struct nrf_clock_spec *res_spec)
Definition nrf_clock_control.h:203
int(* request)(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli)
Definition nrf_clock_control.h:195
int(* cancel_or_release)(const struct device *dev, const struct nrf_clock_spec *spec, struct onoff_client *cli)
Definition nrf_clock_control.h:200
struct clock_control_driver_api std_api
Definition nrf_clock_control.h:193
int(* get_startup_time)(const struct device *dev, const struct nrf_clock_spec *spec, uint32_t *startup_time_us)
Definition nrf_clock_control.h:206
int(* release)(const struct device *dev, const struct nrf_clock_spec *spec)
Definition nrf_clock_control.h:198
Definition nrf_clock_control.h:186
uint16_t accuracy
Definition nrf_clock_control.h:188
uint16_t precision
Definition nrf_clock_control.h:189
uint32_t frequency
Definition nrf_clock_control.h:187
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