Zephyr API Documentation 4.2.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ptp_clock.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Intel Corporation.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_DRIVERS_PTP_CLOCK_H_
8#define ZEPHYR_INCLUDE_DRIVERS_PTP_CLOCK_H_
9
16
17#include <zephyr/kernel.h>
18#include <stdint.h>
19#include <zephyr/device.h>
20#include <zephyr/sys/util.h>
21#include <zephyr/net/ptp_time.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* Name of the PTP clock driver */
28#if !defined(PTP_CLOCK_NAME)
29#define PTP_CLOCK_NAME "PTP_CLOCK"
30#endif
31
32__subsystem struct ptp_clock_driver_api {
33 int (*set)(const struct device *dev, struct net_ptp_time *tm);
34 int (*get)(const struct device *dev, struct net_ptp_time *tm);
35 int (*adjust)(const struct device *dev, int increment);
36 int (*rate_adjust)(const struct device *dev, double ratio);
37};
38
47static inline int ptp_clock_set(const struct device *dev,
48 struct net_ptp_time *tm)
49{
50 const struct ptp_clock_driver_api *api =
51 (const struct ptp_clock_driver_api *)dev->api;
52
53 return api->set(dev, tm);
54}
55
64__syscall int ptp_clock_get(const struct device *dev, struct net_ptp_time *tm);
65
66static inline int z_impl_ptp_clock_get(const struct device *dev,
67 struct net_ptp_time *tm)
68{
69 const struct ptp_clock_driver_api *api =
70 (const struct ptp_clock_driver_api *)dev->api;
71
72 return api->get(dev, tm);
73}
74
83static inline int ptp_clock_adjust(const struct device *dev, int increment)
84{
85 const struct ptp_clock_driver_api *api =
86 (const struct ptp_clock_driver_api *)dev->api;
87
88 return api->adjust(dev, increment);
89}
90
99static inline int ptp_clock_rate_adjust(const struct device *dev, double rate)
100{
101 const struct ptp_clock_driver_api *api =
102 (const struct ptp_clock_driver_api *)dev->api;
103
104 return api->rate_adjust(dev, rate);
105}
106
107#ifdef __cplusplus
108}
109#endif
110
111#include <zephyr/syscalls/ptp_clock.h>
112
116
117#endif /* ZEPHYR_INCLUDE_DRIVERS_PTP_CLOCK_H_ */
static int ptp_clock_rate_adjust(const struct device *dev, double rate)
Adjust the PTP clock rate ratio based on its nominal frequency.
Definition ptp_clock.h:99
static int ptp_clock_set(const struct device *dev, struct net_ptp_time *tm)
Set the time of the PTP clock.
Definition ptp_clock.h:47
int ptp_clock_get(const struct device *dev, struct net_ptp_time *tm)
Get the time of the PTP clock.
static int ptp_clock_adjust(const struct device *dev, int increment)
Adjust the PTP clock time.
Definition ptp_clock.h:83
Public kernel APIs.
Public functions for the Precision Time Protocol time specification.
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
Definition ptp_clock.h:32
int(* get)(const struct device *dev, struct net_ptp_time *tm)
Definition ptp_clock.h:34
int(* adjust)(const struct device *dev, int increment)
Definition ptp_clock.h:35
int(* rate_adjust)(const struct device *dev, double ratio)
Definition ptp_clock.h:36
int(* set)(const struct device *dev, struct net_ptp_time *tm)
Definition ptp_clock.h:33
Definition time.h:24
Misc utilities.