Zephyr API Documentation 4.4.0
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
31
32#include <errno.h>
33#include <stddef.h>
34
35#include <zephyr/types.h>
36#include <zephyr/device.h>
37#include <zephyr/sys/__assert.h>
38#include <zephyr/sys/slist.h>
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44/* Clock control API */
45
47#define CLOCK_CONTROL_SUBSYS_ALL NULL
48
58
66
74
81typedef void (*clock_control_cb_t)(const struct device *dev,
83 void *user_data);
84
90
96typedef int (*clock_control)(const struct device *dev, clock_control_subsys_t sys);
97
103typedef int (*clock_control_get)(const struct device *dev,
105 uint32_t *rate);
106
112typedef int (*clock_control_async_on_fn)(const struct device *dev,
115 void *user_data);
116
123 const struct device *dev,
125
131typedef int (*clock_control_set)(const struct device *dev,
134
140typedef int (*clock_control_configure_fn)(const struct device *dev,
142 void *data);
143
163
165
179static inline int clock_control_on(const struct device *dev,
181{
182 const struct clock_control_driver_api *api =
183 (const struct clock_control_driver_api *)dev->api;
184
185 if (api->on == NULL) {
186 return -ENOSYS;
187 }
188
189 return api->on(dev, sys);
190}
191
202static inline int clock_control_off(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->off == NULL) {
209 return -ENOSYS;
210 }
211
212 return api->off(dev, sys);
213}
214
232static inline int clock_control_async_on(const struct device *dev,
235 void *user_data)
236{
237 const struct clock_control_driver_api *api =
238 (const struct clock_control_driver_api *)dev->api;
239
240 if (api->async_on == NULL) {
241 return -ENOSYS;
242 }
243
244 return api->async_on(dev, sys, cb, user_data);
245}
246
255static inline enum clock_control_status clock_control_get_status(const struct device *dev,
257{
258 const struct clock_control_driver_api *api =
259 (const struct clock_control_driver_api *)dev->api;
260
261 if (!api->get_status) {
263 }
264
265 return api->get_status(dev, sys);
266}
267
280static inline int clock_control_get_rate(const struct device *dev,
282 uint32_t *rate)
283{
284 const struct clock_control_driver_api *api =
285 (const struct clock_control_driver_api *)dev->api;
286
287 if (api->get_rate == NULL) {
288 return -ENOSYS;
289 }
290
291 return api->get_rate(dev, sys, rate);
292}
293
310static inline int clock_control_set_rate(const struct device *dev,
313{
314 const struct clock_control_driver_api *api =
315 (const struct clock_control_driver_api *)dev->api;
316
317 if (api->set_rate == NULL) {
318 return -ENOSYS;
319 }
320
321 return api->set_rate(dev, sys, rate);
322}
323
346static inline int clock_control_configure(const struct device *dev,
348 void *data)
349{
350 const struct clock_control_driver_api *api =
351 (const struct clock_control_driver_api *)dev->api;
352
353 if (api->configure == NULL) {
354 return -ENOSYS;
355 }
356
357 return api->configure(dev, sys, data);
358}
359
360#ifdef __cplusplus
361}
362#endif
363
367
368#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:122
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:112
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:140
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:103
int(* clock_control)(const struct device *dev, clock_control_subsys_t sys)
Callback API to enable or disable a clock.
Definition clock_control.h:96
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:131
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:280
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:232
void * clock_control_subsys_rate_t
Opaque handle identifying the rate of a clock controller subsystem.
Definition clock_control.h:73
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:81
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:255
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:310
void * clock_control_subsys_t
Opaque handle identifying a clock controller subsystem.
Definition clock_control.h:65
clock_control_status
Current clock status.
Definition clock_control.h:52
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:202
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:179
static int clock_control_configure(const struct device *dev, clock_control_subsys_t sys, void *data)
Configure a source clock.
Definition clock_control.h:346
@ CLOCK_CONTROL_STATUS_ON
Clock is on.
Definition clock_control.h:55
@ CLOCK_CONTROL_STATUS_OFF
Clock is off.
Definition clock_control.h:54
@ CLOCK_CONTROL_STATUS_UNKNOWN
Clock status is unknown.
Definition clock_control.h:56
@ CLOCK_CONTROL_STATUS_STARTING
Clock is starting.
Definition clock_control.h:53
#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:147
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:159
clock_control on
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:149
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:157
clock_control off
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_control.h:151
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:153
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:155
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:161
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