Zephyr Project API 4.2.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
15#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_
16#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_
17
27#include <errno.h>
28#include <stddef.h>
29
30#include <zephyr/types.h>
31#include <zephyr/device.h>
32#include <zephyr/sys/__assert.h>
33#include <zephyr/sys/slist.h>
34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
39/* Clock control API */
40
41/* Used to select all subsystem of a clock controller */
42#define CLOCK_CONTROL_SUBSYS_ALL NULL
43
53
60
68
75typedef void (*clock_control_cb_t)(const struct device *dev,
77 void *user_data);
78
79typedef int (*clock_control)(const struct device *dev,
81
82typedef int (*clock_control_get)(const struct device *dev,
84 uint32_t *rate);
85
86typedef int (*clock_control_async_on_fn)(const struct device *dev,
89 void *user_data);
90
92 const struct device *dev,
94
95typedef int (*clock_control_set)(const struct device *dev,
98
99typedef int (*clock_control_configure_fn)(const struct device *dev,
101 void *data);
102
112
126static inline int clock_control_on(const struct device *dev,
128{
129 const struct clock_control_driver_api *api =
130 (const struct clock_control_driver_api *)dev->api;
131
132 if (api->on == NULL) {
133 return -ENOSYS;
134 }
135
136 return api->on(dev, sys);
137}
138
149static inline int clock_control_off(const struct device *dev,
151{
152 const struct clock_control_driver_api *api =
153 (const struct clock_control_driver_api *)dev->api;
154
155 if (api->off == NULL) {
156 return -ENOSYS;
157 }
158
159 return api->off(dev, sys);
160}
161
179static inline int clock_control_async_on(const struct device *dev,
182 void *user_data)
183{
184 const struct clock_control_driver_api *api =
185 (const struct clock_control_driver_api *)dev->api;
186
187 if (api->async_on == NULL) {
188 return -ENOSYS;
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 return api->get_status(dev, sys);
213}
214
227static inline int clock_control_get_rate(const struct device *dev,
229 uint32_t *rate)
230{
231 const struct clock_control_driver_api *api =
232 (const struct clock_control_driver_api *)dev->api;
233
234 if (api->get_rate == NULL) {
235 return -ENOSYS;
236 }
237
238 return api->get_rate(dev, sys, rate);
239}
240
257static inline int clock_control_set_rate(const struct device *dev,
260{
261 const struct clock_control_driver_api *api =
262 (const struct clock_control_driver_api *)dev->api;
263
264 if (api->set_rate == NULL) {
265 return -ENOSYS;
266 }
267
268 return api->set_rate(dev, sys, rate);
269}
270
293static inline int clock_control_configure(const struct device *dev,
295 void *data)
296{
297 const struct clock_control_driver_api *api =
298 (const struct clock_control_driver_api *)dev->api;
299
300 if (api->configure == NULL) {
301 return -ENOSYS;
302 }
303
304 return api->configure(dev, sys, data);
305}
306
307#ifdef __cplusplus
308}
309#endif
310
315#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:227
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:179
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:67
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Definition clock_control.h:91
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:86
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:75
int(* clock_control_configure_fn)(const struct device *dev, clock_control_subsys_t sys, void *data)
Definition clock_control.h:99
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:257
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Definition clock_control.h:82
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Definition clock_control.h:79
int(* clock_control_set)(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Definition clock_control.h:95
void * clock_control_subsys_t
clock_control_subsys_t is a type to identify a clock controller sub-system.
Definition clock_control.h:59
clock_control_status
Current clock status.
Definition clock_control.h:47
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:149
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:126
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition clock_control.h:293
@ CLOCK_CONTROL_STATUS_ON
Definition clock_control.h:50
@ CLOCK_CONTROL_STATUS_OFF
Definition clock_control.h:49
@ CLOCK_CONTROL_STATUS_UNKNOWN
Definition clock_control.h:51
@ CLOCK_CONTROL_STATUS_STARTING
Definition clock_control.h:48
#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:103
clock_control_set set_rate
Definition clock_control.h:109
clock_control on
Definition clock_control.h:104
clock_control_get_status_fn get_status
Definition clock_control.h:108
clock_control off
Definition clock_control.h:105
clock_control_async_on_fn async_on
Definition clock_control.h:106
clock_control_get get_rate
Definition clock_control.h:107
clock_control_configure_fn configure
Definition clock_control.h:110
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
void * data
Address of the device instance private data.
Definition device.h:520
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516