Zephyr API Documentation  3.5.0
A Scalable Open Source RTOS
3.5.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 <errno.h>
25#include <stddef.h>
26
27#include <zephyr/types.h>
28#include <zephyr/device.h>
29#include <zephyr/sys/__assert.h>
30#include <zephyr/sys/slist.h>
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36/* Clock control API */
37
38/* Used to select all subsystem of a clock controller */
39#define CLOCK_CONTROL_SUBSYS_ALL NULL
40
49};
50
57
65
72typedef void (*clock_control_cb_t)(const struct device *dev,
74 void *user_data);
75
76typedef int (*clock_control)(const struct device *dev,
78
79typedef int (*clock_control_get)(const struct device *dev,
81 uint32_t *rate);
82
83typedef int (*clock_control_async_on_fn)(const struct device *dev,
86 void *user_data);
87
89 const struct device *dev,
91
92typedef int (*clock_control_set)(const struct device *dev,
95
96typedef int (*clock_control_configure_fn)(const struct device *dev,
98 void *data);
99
108};
109
123static inline int clock_control_on(const struct device *dev,
125{
126 const struct clock_control_driver_api *api =
127 (const struct clock_control_driver_api *)dev->api;
128
129 return api->on(dev, sys);
130}
131
142static inline int clock_control_off(const struct device *dev,
144{
145 const struct clock_control_driver_api *api =
146 (const struct clock_control_driver_api *)dev->api;
147
148 return api->off(dev, sys);
149}
150
168static inline int clock_control_async_on(const struct device *dev,
171 void *user_data)
172{
173 const struct clock_control_driver_api *api =
174 (const struct clock_control_driver_api *)dev->api;
175
176 if (api->async_on == NULL) {
177 return -ENOSYS;
178 }
179
180 return api->async_on(dev, sys, cb, user_data);
181}
182
191static inline enum clock_control_status clock_control_get_status(const struct device *dev,
193{
194 const struct clock_control_driver_api *api =
195 (const struct clock_control_driver_api *)dev->api;
196
197 if (!api->get_status) {
199 }
200
201 return api->get_status(dev, sys);
202}
203
216static inline int clock_control_get_rate(const struct device *dev,
218 uint32_t *rate)
219{
220 const struct clock_control_driver_api *api =
221 (const struct clock_control_driver_api *)dev->api;
222
223 if (api->get_rate == NULL) {
224 return -ENOSYS;
225 }
226
227 return api->get_rate(dev, sys, rate);
228}
229
246static inline int clock_control_set_rate(const struct device *dev,
249{
250 const struct clock_control_driver_api *api =
251 (const struct clock_control_driver_api *)dev->api;
252
253 if (api->set_rate == NULL) {
254 return -ENOSYS;
255 }
256
257 return api->set_rate(dev, sys, rate);
258}
259
282static inline int clock_control_configure(const struct device *dev,
284 void *data)
285{
286 const struct clock_control_driver_api *api =
287 (const struct clock_control_driver_api *)dev->api;
288
289 if (api->configure == NULL) {
290 return -ENOSYS;
291 }
292
293 return api->configure(dev, sys, data);
294}
295
296#ifdef __cplusplus
297}
298#endif
299
304#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:216
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:168
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:64
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:88
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:83
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:72
int(* clock_control_configure_fn)(const struct device *dev, clock_control_subsys_t sys, void *data)
Definition: clock_control.h:96
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:191
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:246
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Definition: clock_control.h:79
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Definition: clock_control.h:76
int(* clock_control_set)(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Definition: clock_control.h:92
void * clock_control_subsys_t
clock_control_subsys_t is a type to identify a clock controller sub-system.
Definition: clock_control.h:56
clock_control_status
Current clock status.
Definition: clock_control.h:44
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:142
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:123
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition: clock_control.h:282
@ CLOCK_CONTROL_STATUS_ON
Definition: clock_control.h:47
@ CLOCK_CONTROL_STATUS_OFF
Definition: clock_control.h:46
@ CLOCK_CONTROL_STATUS_UNKNOWN
Definition: clock_control.h:48
@ CLOCK_CONTROL_STATUS_STARTING
Definition: clock_control.h:45
#define ENOSYS
Function not implemented.
Definition: errno.h:83
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
Definition: clock_control.h:100
clock_control_set set_rate
Definition: clock_control.h:106
clock_control on
Definition: clock_control.h:101
clock_control_get_status_fn get_status
Definition: clock_control.h:105
clock_control off
Definition: clock_control.h:102
clock_control_async_on_fn async_on
Definition: clock_control.h:103
clock_control_get get_rate
Definition: clock_control.h:104
clock_control_configure_fn configure
Definition: clock_control.h:107
Runtime device structure (in ROM) per driver instance.
Definition: device.h:381
void * data
Address of the device instance private data.
Definition: device.h:391
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:387