Zephyr API Documentation 4.4.0-rc1
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
15#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_
16#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_
17
26
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
84
90typedef int (*clock_control)(const struct device *dev, clock_control_subsys_t sys);
91
97typedef int (*clock_control_get)(const struct device *dev,
99 uint32_t *rate);
100
106typedef int (*clock_control_async_on_fn)(const struct device *dev,
109 void *user_data);
110
117 const struct device *dev,
119
125typedef int (*clock_control_set)(const struct device *dev,
128
134typedef int (*clock_control_configure_fn)(const struct device *dev,
136 void *data);
137
157
159
173static inline int clock_control_on(const struct device *dev,
175{
176 const struct clock_control_driver_api *api =
177 (const struct clock_control_driver_api *)dev->api;
178
179 if (api->on == NULL) {
180 return -ENOSYS;
181 }
182
183 return api->on(dev, sys);
184}
185
196static inline int clock_control_off(const struct device *dev,
198{
199 const struct clock_control_driver_api *api =
200 (const struct clock_control_driver_api *)dev->api;
201
202 if (api->off == NULL) {
203 return -ENOSYS;
204 }
205
206 return api->off(dev, sys);
207}
208
226static inline int clock_control_async_on(const struct device *dev,
229 void *user_data)
230{
231 const struct clock_control_driver_api *api =
232 (const struct clock_control_driver_api *)dev->api;
233
234 if (api->async_on == NULL) {
235 return -ENOSYS;
236 }
237
238 return api->async_on(dev, sys, cb, user_data);
239}
240
249static inline enum clock_control_status clock_control_get_status(const struct device *dev,
251{
252 const struct clock_control_driver_api *api =
253 (const struct clock_control_driver_api *)dev->api;
254
255 if (!api->get_status) {
257 }
258
259 return api->get_status(dev, sys);
260}
261
274static inline int clock_control_get_rate(const struct device *dev,
276 uint32_t *rate)
277{
278 const struct clock_control_driver_api *api =
279 (const struct clock_control_driver_api *)dev->api;
280
281 if (api->get_rate == NULL) {
282 return -ENOSYS;
283 }
284
285 return api->get_rate(dev, sys, rate);
286}
287
304static inline int clock_control_set_rate(const struct device *dev,
307{
308 const struct clock_control_driver_api *api =
309 (const struct clock_control_driver_api *)dev->api;
310
311 if (api->set_rate == NULL) {
312 return -ENOSYS;
313 }
314
315 return api->set_rate(dev, sys, rate);
316}
317
340static inline int clock_control_configure(const struct device *dev,
342 void *data)
343{
344 const struct clock_control_driver_api *api =
345 (const struct clock_control_driver_api *)dev->api;
346
347 if (api->configure == NULL) {
348 return -ENOSYS;
349 }
350
351 return api->configure(dev, sys, data);
352}
353
354#ifdef __cplusplus
355}
356#endif
357
361
362#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_CONTROL_H_ */
System error numbers.
enum clock_control_status(* clock_control_get_status_fn)(const struct device *dev, clock_control_subsys_t sys)
Callback API to get a clock status.
Definition clock_control.h:116
int(* clock_control_async_on_fn)(const struct device *dev, clock_control_subsys_t sys, clock_control_cb_t cb, void *user_data)
Callback API to start a clock asynchronously.
Definition clock_control.h:106
int(* clock_control_configure_fn)(const struct device *dev, clock_control_subsys_t sys, void *data)
Callback API to configure a clock.
Definition clock_control.h:134
int(* clock_control_get)(const struct device *dev, clock_control_subsys_t sys, uint32_t *rate)
Callback API to get a clock rate.
Definition clock_control.h:97
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Callback API to enable or disable a clock.
Definition clock_control.h:90
int(* clock_control_set)(const struct device *dev, clock_control_subsys_t sys, clock_control_subsys_rate_t rate)
Callback API to set a clock rate.
Definition clock_control.h:125
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:274
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:226
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
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
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:249
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:304
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:196
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:173
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition clock_control.h:340
@ CLOCK_CONTROL_STATUS_ON
Clock is on.
Definition clock_control.h:50
@ CLOCK_CONTROL_STATUS_OFF
Clock is off.
Definition clock_control.h:49
@ CLOCK_CONTROL_STATUS_UNKNOWN
Clock status is unknown.
Definition clock_control.h:51
@ CLOCK_CONTROL_STATUS_STARTING
Clock is 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
<span class="mlabel">Driver Operations</span> Clock Control driver operations
Definition clock_control.h:141
clock_control_set set_rate
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:153
clock_control on
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:143
clock_control_get_status_fn get_status
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:151
clock_control off
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:145
clock_control_async_on_fn async_on
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:147
clock_control_get get_rate
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:149
clock_control_configure_fn configure
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:155
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
void * data
Address of the device instance private data.
Definition device.h:523
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:519