Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
26#include <errno.h>
27#include <stddef.h>
28
29#include <zephyr/types.h>
30#include <zephyr/device.h>
31#include <zephyr/sys/__assert.h>
32#include <zephyr/sys/slist.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38/* Clock control API */
39
40/* Used to select all subsystem of a clock controller */
41#define CLOCK_CONTROL_SUBSYS_ALL NULL
42
52
59
67
74typedef void (*clock_control_cb_t)(const struct device *dev,
76 void *user_data);
77
78typedef int (*clock_control)(const struct device *dev,
80
81typedef int (*clock_control_get)(const struct device *dev,
83 uint32_t *rate);
84
85typedef int (*clock_control_async_on_fn)(const struct device *dev,
88 void *user_data);
89
91 const struct device *dev,
93
94typedef int (*clock_control_set)(const struct device *dev,
97
98typedef int (*clock_control_configure_fn)(const struct device *dev,
100 void *data);
101
111
125static inline int clock_control_on(const struct device *dev,
127{
128 const struct clock_control_driver_api *api =
129 (const struct clock_control_driver_api *)dev->api;
130
131 if (api->on == NULL) {
132 return -ENOSYS;
133 }
134
135 return api->on(dev, sys);
136}
137
148static inline int clock_control_off(const struct device *dev,
150{
151 const struct clock_control_driver_api *api =
152 (const struct clock_control_driver_api *)dev->api;
153
154 if (api->off == NULL) {
155 return -ENOSYS;
156 }
157
158 return api->off(dev, sys);
159}
160
178static inline int clock_control_async_on(const struct device *dev,
181 void *user_data)
182{
183 const struct clock_control_driver_api *api =
184 (const struct clock_control_driver_api *)dev->api;
185
186 if (api->async_on == NULL) {
187 return -ENOSYS;
188 }
189
190 return api->async_on(dev, sys, cb, user_data);
191}
192
201static inline enum clock_control_status clock_control_get_status(const struct device *dev,
203{
204 const struct clock_control_driver_api *api =
205 (const struct clock_control_driver_api *)dev->api;
206
207 if (!api->get_status) {
209 }
210
211 return api->get_status(dev, sys);
212}
213
226static inline int clock_control_get_rate(const struct device *dev,
228 uint32_t *rate)
229{
230 const struct clock_control_driver_api *api =
231 (const struct clock_control_driver_api *)dev->api;
232
233 if (api->get_rate == NULL) {
234 return -ENOSYS;
235 }
236
237 return api->get_rate(dev, sys, rate);
238}
239
256static inline int clock_control_set_rate(const struct device *dev,
259{
260 const struct clock_control_driver_api *api =
261 (const struct clock_control_driver_api *)dev->api;
262
263 if (api->set_rate == NULL) {
264 return -ENOSYS;
265 }
266
267 return api->set_rate(dev, sys, rate);
268}
269
292static inline int clock_control_configure(const struct device *dev,
294 void *data)
295{
296 const struct clock_control_driver_api *api =
297 (const struct clock_control_driver_api *)dev->api;
298
299 if (api->configure == NULL) {
300 return -ENOSYS;
301 }
302
303 return api->configure(dev, sys, data);
304}
305
306#ifdef __cplusplus
307}
308#endif
309
314#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ */
System error numbers.
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:178
void * clock_control_subsys_rate_t
clock_control_subsys_rate_t is a type to identify a clock controller sub-system rate.
Definition clock_control.h:66
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Definition clock_control.h:90
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:85
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:74
int(* clock_control_configure_fn)(const struct device *dev, clock_control_subsys_t sys, void *data)
Definition clock_control.h:98
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:201
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:256
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Definition clock_control.h:81
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Definition clock_control.h:78
int(* clock_control_set)(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Definition clock_control.h:94
void * clock_control_subsys_t
clock_control_subsys_t is a type to identify a clock controller sub-system.
Definition clock_control.h:58
clock_control_status
Current clock status.
Definition clock_control.h:46
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:148
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:125
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition clock_control.h:292
@ CLOCK_CONTROL_STATUS_ON
Definition clock_control.h:49
@ CLOCK_CONTROL_STATUS_OFF
Definition clock_control.h:48
@ CLOCK_CONTROL_STATUS_UNKNOWN
Definition clock_control.h:50
@ CLOCK_CONTROL_STATUS_STARTING
Definition clock_control.h:47
#define ENOSYS
Function not implemented.
Definition errno.h:82
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Definition clock_control.h:102
clock_control_set set_rate
Definition clock_control.h:108
clock_control on
Definition clock_control.h:103
clock_control_get_status_fn get_status
Definition clock_control.h:107
clock_control off
Definition clock_control.h:104
clock_control_async_on_fn async_on
Definition clock_control.h:105
clock_control_get get_rate
Definition clock_control.h:106
clock_control_configure_fn configure
Definition clock_control.h:109
Runtime device structure (in ROM) per driver instance.
Definition device.h:504
void * data
Address of the device instance private data.
Definition device.h:514
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:510