Zephyr API Documentation  2.7.0-rc2
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 <device.h>
27#include <sys/__assert.h>
28#include <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
63typedef void (*clock_control_cb_t)(const struct device *dev,
65 void *user_data);
66
67typedef int (*clock_control)(const struct device *dev,
69
70typedef int (*clock_control_get)(const struct device *dev,
72 uint32_t *rate);
73
74typedef int (*clock_control_async_on_fn)(const struct device *dev,
77 void *user_data);
78
80 const struct device *dev,
82
89};
90
104static inline int clock_control_on(const struct device *dev,
106{
107 int ret = device_usable_check(dev);
108
109 if (ret != 0) {
110 return ret;
111 }
112
113 const struct clock_control_driver_api *api =
114 (const struct clock_control_driver_api *)dev->api;
115
116 return api->on(dev, sys);
117}
118
129static inline int clock_control_off(const struct device *dev,
131{
132 int ret = device_usable_check(dev);
133
134 if (ret != 0) {
135 return ret;
136 }
137
138 const struct clock_control_driver_api *api =
139 (const struct clock_control_driver_api *)dev->api;
140
141 return api->off(dev, sys);
142}
143
161static inline int clock_control_async_on(const struct device *dev,
164 void *user_data)
165{
166 const struct clock_control_driver_api *api =
167 (const struct clock_control_driver_api *)dev->api;
168
169 if (api->async_on == NULL) {
170 return -ENOSYS;
171 }
172
173 int ret = device_usable_check(dev);
174
175 if (ret != 0) {
176 return ret;
177 }
178
179 return api->async_on(dev, sys, cb, user_data);
180}
181
190static inline enum clock_control_status clock_control_get_status(const struct device *dev,
192{
193 const struct clock_control_driver_api *api =
194 (const struct clock_control_driver_api *)dev->api;
195
196 if (!api->get_status) {
198 }
199
200 if (!device_is_ready(dev)) {
202 }
203
204 return api->get_status(dev, sys);
205}
206
214static inline int clock_control_get_rate(const struct device *dev,
216 uint32_t *rate)
217{
218 int ret = device_usable_check(dev);
219
220 if (ret != 0) {
221 return ret;
222 }
223
224 const struct clock_control_driver_api *api =
225 (const struct clock_control_driver_api *)dev->api;
226
227 if (api->get_rate == NULL) {
228 return -ENOSYS;
229 }
230
231 return api->get_rate(dev, sys, rate);
232}
233
234#ifdef __cplusplus
235}
236#endif
237
242#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ */
void
Definition: eswifi_shell.c:15
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:161
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:79
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:74
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:63
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:190
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Definition: clock_control.h:70
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:67
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:129
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:104
@ 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
int device_usable_check(const struct device *dev)
Determine whether a device is ready for use.
static bool device_is_ready(const struct device *dev)
Verify that a device is ready for use.
Definition: device.h:686
#define ENOSYS
Definition: errno.h:83
static ZTEST_BMEM volatile int ret
Definition: k_float_disable.c:28
Single-linked list implementation.
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
Definition: clock_control.h:83
clock_control on
Definition: clock_control.h:84
clock_control_get_status_fn get_status
Definition: clock_control.h:88
clock_control off
Definition: clock_control.h:85
clock_control_async_on_fn async_on
Definition: clock_control.h:86
clock_control_get get_rate
Definition: clock_control.h:87
Runtime device structure (in ROM) per driver instance.
Definition: device.h:367
const void * api
Definition: device.h:373
static const intptr_t user_data[5]
Definition: main.c:590