Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
clock_monitor.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12
13#ifndef ZEPHYR_INCLUDE_DRIVERS_CLOCK_MONITOR_H_
14#define ZEPHYR_INCLUDE_DRIVERS_CLOCK_MONITOR_H_
15
24
25#include <errno.h>
26#include <stdbool.h>
27#include <stdint.h>
28
29#include <zephyr/device.h>
30#include <zephyr/kernel.h>
31#include <zephyr/sys/util.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
58
60enum {
69};
70
80
86
96
107typedef void (*clock_monitor_callback_t)(const struct device *dev,
108 const struct clock_monitor_event_data *evt,
109 void *user_data);
110
135
140
142typedef int (*clock_monitor_api_configure)(const struct device *dev,
143 const struct clock_monitor_config *cfg);
144
146typedef int (*clock_monitor_api_start)(const struct device *dev);
147
149typedef int (*clock_monitor_api_stop)(const struct device *dev);
150
152typedef int (*clock_monitor_api_get_rate)(const struct device *dev,
153 uint32_t *rate_hz);
154
156typedef int (*clock_monitor_api_set_source)(const struct device *dev,
157 uint32_t reference,
158 uint32_t target);
159
185
187
206__syscall int clock_monitor_configure(const struct device *dev,
207 const struct clock_monitor_config *cfg);
208
209static inline int z_impl_clock_monitor_configure(const struct device *dev,
210 const struct clock_monitor_config *cfg)
211{
212 return DEVICE_API_GET(clock_monitor, dev)->configure(dev, cfg);
213}
214
247__syscall int clock_monitor_start(const struct device *dev);
248
249static inline int z_impl_clock_monitor_start(const struct device *dev)
250{
251 return DEVICE_API_GET(clock_monitor, dev)->start(dev);
252}
253
269__syscall int clock_monitor_stop(const struct device *dev);
270
271static inline int z_impl_clock_monitor_stop(const struct device *dev)
272{
273 return DEVICE_API_GET(clock_monitor, dev)->stop(dev);
274}
275
294__syscall int clock_monitor_get_rate(const struct device *dev,
295 uint32_t *rate_hz);
296
297static inline int z_impl_clock_monitor_get_rate(const struct device *dev,
298 uint32_t *rate_hz)
299{
300 const struct clock_monitor_driver_api *api =
301 DEVICE_API_GET(clock_monitor, dev);
302
303 if (api->get_rate == NULL) {
304 return -ENOSYS;
305 }
306 return api->get_rate(dev, rate_hz);
307}
308
328__syscall int clock_monitor_set_source(const struct device *dev,
329 uint32_t reference, uint32_t target);
330
331static inline int z_impl_clock_monitor_set_source(const struct device *dev,
332 uint32_t reference,
333 uint32_t target)
334{
335 const struct clock_monitor_driver_api *api =
336 DEVICE_API_GET(clock_monitor, dev);
337
338 if (api->set_source == NULL) {
339 return -ENOSYS;
340 }
341 return api->set_source(dev, reference, target);
342}
343
344#ifdef __cplusplus
345}
346#endif
347
351
352#include <zephyr/syscalls/clock_monitor.h>
353
354#endif /* ZEPHYR_INCLUDE_DRIVERS_CLOCK_MONITOR_H_ */
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1425
System error numbers.
int(* clock_monitor_api_stop)(const struct device *dev)
Callback API for stopping the clock monitor (ISR-safe).
Definition clock_monitor.h:149
int(* clock_monitor_api_configure)(const struct device *dev, const struct clock_monitor_config *cfg)
Callback API for configuring a clock monitor.
Definition clock_monitor.h:142
int(* clock_monitor_api_start)(const struct device *dev)
Callback API for starting the configured mode.
Definition clock_monitor.h:146
int(* clock_monitor_api_set_source)(const struct device *dev, uint32_t reference, uint32_t target)
Callback API for switching the reference / target clock inputs.
Definition clock_monitor.h:156
int(* clock_monitor_api_get_rate)(const struct device *dev, uint32_t *rate_hz)
Callback API for polling the most recent measured rate.
Definition clock_monitor.h:152
void(* clock_monitor_callback_t)(const struct device *dev, const struct clock_monitor_event_data *evt, void *user_data)
Callback invoked on clock monitor events.
Definition clock_monitor.h:107
int clock_monitor_set_source(const struct device *dev, uint32_t reference, uint32_t target)
Switch the reference / target clock inputs at runtime.
int clock_monitor_start(const struct device *dev)
Start operation of the configured mode.
int clock_monitor_stop(const struct device *dev)
Stop the monitor.
int clock_monitor_configure(const struct device *dev, const struct clock_monitor_config *cfg)
Apply a monitor configuration.
int clock_monitor_get_rate(const struct device *dev, uint32_t *rate_hz)
Poll the most recent completed measurement.
clock_monitor_mode
Operating mode of a clock monitor instance.
Definition clock_monitor.h:42
@ CLOCK_MONITOR_EVT_MEASURE_DONE
Frequency measurement completed.
Definition clock_monitor.h:68
@ CLOCK_MONITOR_EVT_CLOCK_LOST
Monitored clock stopped or stuck.
Definition clock_monitor.h:66
@ CLOCK_MONITOR_EVT_FREQ_HIGH
Monitored frequency exceeded the upper threshold.
Definition clock_monitor.h:62
@ CLOCK_MONITOR_EVT_FREQ_LOW
Monitored frequency fell below the lower threshold.
Definition clock_monitor.h:64
@ CLOCK_MONITOR_MODE_WINDOW
Continuous high/low threshold window check: the frequency of the monitored clock is continuously comp...
Definition clock_monitor.h:48
@ CLOCK_MONITOR_MODE_MEASURE
One frequency measurement per clock_monitor_start, reported in Hz through the configure-time callback...
Definition clock_monitor.h:56
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:82
Public kernel APIs.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
Top-level configuration handed to clock_monitor_configure.
Definition clock_monitor.h:120
struct clock_monitor_measure_cfg measure
Honored when mode is MEASURE.
Definition clock_monitor.h:128
void * user_data
Opaque user pointer passed to callback.
Definition clock_monitor.h:133
enum clock_monitor_mode mode
Operating mode to activate.
Definition clock_monitor.h:122
struct clock_monitor_window_cfg window
Honored when mode is WINDOW.
Definition clock_monitor.h:126
clock_monitor_callback_t callback
Optional callback for asynchronous event delivery.
Definition clock_monitor.h:131
<span class="mlabel">Driver Operations</span> CLOCK_MONITOR driver operations
Definition clock_monitor.h:163
clock_monitor_api_configure configure
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition clock_monitor.h:167
clock_monitor_api_stop stop
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition clock_monitor.h:175
clock_monitor_api_get_rate get_rate
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_monitor.h:179
clock_monitor_api_start start
<span class="op-badge op-req" title="This operation MUST be implemented by the driver....
Definition clock_monitor.h:171
clock_monitor_api_set_source set_source
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition clock_monitor.h:183
Event payload delivered to the user callback.
Definition clock_monitor.h:88
uint32_t events
Bitmask of latched CLOCK_MONITOR_EVT_* flags.
Definition clock_monitor.h:90
uint32_t measured_hz
Result of the measurement that completed with this event (Hz); valid when events & CLOCK_MONITOR_EVT_...
Definition clock_monitor.h:94
Configuration for CLOCK_MONITOR_MODE_MEASURE.
Definition clock_monitor.h:82
uint32_t window_ns
Measurement window duration in ns.
Definition clock_monitor.h:84
Configuration for CLOCK_MONITOR_MODE_WINDOW.
Definition clock_monitor.h:72
uint32_t expected_hz
Nominal expected frequency of the monitored clock (Hz).
Definition clock_monitor.h:74
uint32_t tolerance_ppm
Acceptable deviation in parts-per-million (± value).
Definition clock_monitor.h:76
uint32_t window_ns
Measurement window duration in ns.
Definition clock_monitor.h:78
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Misc utilities.