Zephyr Project API  3.1.0
A Scalable Open Source RTOS
clock_control.h
Go to the documentation of this file.
1/* clock_control.h - public clock controller driver API */
2
3/*
4 * Copyright (c) 2015 Intel Corporation
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
14#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_
15#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_
16
24#include <zephyr/types.h>
25#include <stddef.h>
26#include <zephyr/device.h>
27#include <zephyr/sys/__assert.h>
28#include <zephyr/sys/slist.h>
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/* Clock control API */
35
36/* Used to select all subsystem of a clock controller */
37#define CLOCK_CONTROL_SUBSYS_ALL NULL
38
48};
49
56
64
71typedef void (*clock_control_cb_t)(const struct device *dev,
73 void *user_data);
74
75typedef int (*clock_control)(const struct device *dev,
77
78typedef int (*clock_control_get)(const struct device *dev,
80 uint32_t *rate);
81
82typedef int (*clock_control_async_on_fn)(const struct device *dev,
85 void *user_data);
86
88 const struct device *dev,
90
91typedef int (*clock_control_set)(const struct device *dev,
94
95typedef int (*clock_control_configure_fn)(const struct device *dev,
97 void *data);
98
107};
108
122static inline int clock_control_on(const struct device *dev,
124{
125 if (!device_is_ready(dev)) {
126 return -ENODEV;
127 }
128
129 const struct clock_control_driver_api *api =
130 (const struct clock_control_driver_api *)dev->api;
131
132 return api->on(dev, sys);
133}
134
145static inline int clock_control_off(const struct device *dev,
147{
148 if (!device_is_ready(dev)) {
149 return -ENODEV;
150 }
151
152 const struct clock_control_driver_api *api =
153 (const struct clock_control_driver_api *)dev->api;
154
155 return api->off(dev, sys);
156}
157
175static inline int clock_control_async_on(const struct device *dev,
178 void *user_data)
179{
180 const struct clock_control_driver_api *api =
181 (const struct clock_control_driver_api *)dev->api;
182
183 if (api->async_on == NULL) {
184 return -ENOSYS;
185 }
186
187 if (!device_is_ready(dev)) {
188 return -ENODEV;
189 }
190
191 return api->async_on(dev, sys, cb, user_data);
192}
193
202static inline enum clock_control_status clock_control_get_status(const struct device *dev,
204{
205 const struct clock_control_driver_api *api =
206 (const struct clock_control_driver_api *)dev->api;
207
208 if (!api->get_status) {
210 }
211
212 if (!device_is_ready(dev)) {
214 }
215
216 return api->get_status(dev, sys);
217}
218
226static inline int clock_control_get_rate(const struct device *dev,
228 uint32_t *rate)
229{
230 if (!device_is_ready(dev)) {
231 return -ENODEV;
232 }
233
234 const struct clock_control_driver_api *api =
235 (const struct clock_control_driver_api *)dev->api;
236
237 if (api->get_rate == NULL) {
238 return -ENOSYS;
239 }
240
241 return api->get_rate(dev, sys, rate);
242}
243
260static inline int clock_control_set_rate(const struct device *dev,
263{
264 if (!device_is_ready(dev)) {
265 return -ENODEV;
266 }
267
268 const struct clock_control_driver_api *api =
269 (const struct clock_control_driver_api *)dev->api;
270
271 if (api->set_rate == NULL) {
272 return -ENOSYS;
273 }
274
275 return api->set_rate(dev, sys, rate);
276}
277
300static inline int clock_control_configure(const struct device *dev,
302 void *data)
303{
304 if (!device_is_ready(dev)) {
305 return -ENODEV;
306 }
307
308 const struct clock_control_driver_api *api =
309 (const struct clock_control_driver_api *)dev->api;
310
311 if (api->configure == NULL) {
312 return -ENOSYS;
313 }
314
315 return api->configure(dev, sys, data);
316}
317
318#ifdef __cplusplus
319}
320#endif
321
326#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ */
static int clock_control_get_rate(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Obtain the clock rate of given sub-system.
Definition: clock_control.h:226
static int clock_control_async_on(const struct device *dev, clock_control_subsys_t sys, clock_control_cb_t cb, void *user_data)
Request clock to start with notification when clock has been started.
Definition: clock_control.h:175
void * clock_control_subsys_rate_t
Definition: clock_control.h:63
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:87
int(* clock_control_async_on_fn)(const struct device *dev, clock_control_subsys_t sys, clock_control_cb_t cb, void *user_data)
Definition: clock_control.h:82
void(* clock_control_cb_t)(const struct device *dev, clock_control_subsys_t subsys, void *user_data)
Callback called on clock started.
Definition: clock_control.h:71
int(* clock_control_configure_fn)(const struct device *dev, clock_control_subsys_t sys, void *data)
Definition: clock_control.h:95
static enum clock_control_status clock_control_get_status(const struct device *dev, clock_control_subsys_t sys)
Get clock status.
Definition: clock_control.h:202
static int clock_control_set_rate(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Set the rate of the clock controlled by the device.
Definition: clock_control.h:260
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Definition: clock_control.h:78
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:75
int(* clock_control_set)(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Definition: clock_control.h:91
void * clock_control_subsys_t
Definition: clock_control.h:55
clock_control_status
Current clock status.
Definition: clock_control.h:42
static int clock_control_off(const struct device *dev, clock_control_subsys_t sys)
Disable a clock controlled by the device.
Definition: clock_control.h:145
static int clock_control_on(const struct device *dev, clock_control_subsys_t sys)
Enable a clock controlled by the device.
Definition: clock_control.h:122
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition: clock_control.h:300
@ CLOCK_CONTROL_STATUS_ON
Definition: clock_control.h:45
@ CLOCK_CONTROL_STATUS_OFF
Definition: clock_control.h:44
@ CLOCK_CONTROL_STATUS_UNKNOWN
Definition: clock_control.h:47
@ CLOCK_CONTROL_STATUS_UNAVAILABLE
Definition: clock_control.h:46
@ CLOCK_CONTROL_STATUS_STARTING
Definition: clock_control.h:43
bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
#define ENOSYS
Definition: errno.h:83
#define ENODEV
Definition: errno.h:58
Single-linked list implementation.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Definition: clock_control.h:99
clock_control_set set_rate
Definition: clock_control.h:105
clock_control on
Definition: clock_control.h:100
clock_control_get_status_fn get_status
Definition: clock_control.h:104
clock_control off
Definition: clock_control.h:101
clock_control_async_on_fn async_on
Definition: clock_control.h:102
clock_control_get get_rate
Definition: clock_control.h:103
clock_control_configure_fn configure
Definition: clock_control.h:106
Runtime device structure (in ROM) per driver instance.
Definition: device.h:456
const void * api
Definition: device.h:462
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static const intptr_t user_data[5]
Definition: main.c:590