Zephyr Project API  3.2.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
47};
48
55
63
70typedef void (*clock_control_cb_t)(const struct device *dev,
72 void *user_data);
73
74typedef int (*clock_control)(const struct device *dev,
76
77typedef int (*clock_control_get)(const struct device *dev,
79 uint32_t *rate);
80
81typedef int (*clock_control_async_on_fn)(const struct device *dev,
84 void *user_data);
85
87 const struct device *dev,
89
90typedef int (*clock_control_set)(const struct device *dev,
93
94typedef int (*clock_control_configure_fn)(const struct device *dev,
96 void *data);
97
106};
107
121static inline int clock_control_on(const struct device *dev,
123{
124 const struct clock_control_driver_api *api =
125 (const struct clock_control_driver_api *)dev->api;
126
127 return api->on(dev, sys);
128}
129
140static inline int clock_control_off(const struct device *dev,
142{
143 const struct clock_control_driver_api *api =
144 (const struct clock_control_driver_api *)dev->api;
145
146 return api->off(dev, sys);
147}
148
166static inline int clock_control_async_on(const struct device *dev,
169 void *user_data)
170{
171 const struct clock_control_driver_api *api =
172 (const struct clock_control_driver_api *)dev->api;
173
174 if (api->async_on == NULL) {
175 return -ENOSYS;
176 }
177
178 return api->async_on(dev, sys, cb, user_data);
179}
180
189static inline enum clock_control_status clock_control_get_status(const struct device *dev,
191{
192 const struct clock_control_driver_api *api =
193 (const struct clock_control_driver_api *)dev->api;
194
195 if (!api->get_status) {
197 }
198
199 return api->get_status(dev, sys);
200}
201
214static inline int clock_control_get_rate(const struct device *dev,
216 uint32_t *rate)
217{
218 const struct clock_control_driver_api *api =
219 (const struct clock_control_driver_api *)dev->api;
220
221 if (api->get_rate == NULL) {
222 return -ENOSYS;
223 }
224
225 return api->get_rate(dev, sys, rate);
226}
227
244static inline int clock_control_set_rate(const struct device *dev,
247{
248 const struct clock_control_driver_api *api =
249 (const struct clock_control_driver_api *)dev->api;
250
251 if (api->set_rate == NULL) {
252 return -ENOSYS;
253 }
254
255 return api->set_rate(dev, sys, rate);
256}
257
280static inline int clock_control_configure(const struct device *dev,
282 void *data)
283{
284 const struct clock_control_driver_api *api =
285 (const struct clock_control_driver_api *)dev->api;
286
287 if (api->configure == NULL) {
288 return -ENOSYS;
289 }
290
291 return api->configure(dev, sys, data);
292}
293
294#ifdef __cplusplus
295}
296#endif
297
302#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:214
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:166
void * clock_control_subsys_rate_t
Definition: clock_control.h:62
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:86
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:81
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:70
int(* clock_control_configure_fn)(const struct device *dev, clock_control_subsys_t sys, void *data)
Definition: clock_control.h:94
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:189
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:244
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Definition: clock_control.h:77
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:74
int(* clock_control_set)(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Definition: clock_control.h:90
void * clock_control_subsys_t
Definition: clock_control.h:54
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:140
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:121
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition: clock_control.h:280
@ 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:46
@ CLOCK_CONTROL_STATUS_STARTING
Definition: clock_control.h:43
#define ENOSYS
Definition: errno.h:83
Single-linked list implementation.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Definition: clock_control.h:98
clock_control_set set_rate
Definition: clock_control.h:104
clock_control on
Definition: clock_control.h:99
clock_control_get_status_fn get_status
Definition: clock_control.h:103
clock_control off
Definition: clock_control.h:100
clock_control_async_on_fn async_on
Definition: clock_control.h:101
clock_control_get get_rate
Definition: clock_control.h:102
clock_control_configure_fn configure
Definition: clock_control.h:105
Runtime device structure (in ROM) per driver instance.
Definition: device.h:435
const void * api
Definition: device.h:441
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
static const intptr_t user_data[5]
Definition: main.c:588