Zephyr Project API 3.7.0
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
10#include <zephyr/kernel.h>
11#include <stdint.h>
12#include <zephyr/device.h>
13#include <zephyr/sys/util.h>
14#include <zephyr/net/ptp_time.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/* Name of the PTP clock driver */
21#if !defined(PTP_CLOCK_NAME)
22#define PTP_CLOCK_NAME "PTP_CLOCK"
23#endif
24
25__subsystem struct ptp_clock_driver_api {
26 int (*set)(const struct device *dev, struct net_ptp_time *tm);
27 int (*get)(const struct device *dev, struct net_ptp_time *tm);
28 int (*adjust)(const struct device *dev, int increment);
29 int (*rate_adjust)(const struct device *dev, double ratio);
30};
31
40static inline int ptp_clock_set(const struct device *dev,
41 struct net_ptp_time *tm)
42{
43 const struct ptp_clock_driver_api *api =
44 (const struct ptp_clock_driver_api *)dev->api;
45
46 return api->set(dev, tm);
47}
48
57__syscall int ptp_clock_get(const struct device *dev, struct net_ptp_time *tm);
58
59static inline int z_impl_ptp_clock_get(const struct device *dev,
60 struct net_ptp_time *tm)
61{
62 const struct ptp_clock_driver_api *api =
63 (const struct ptp_clock_driver_api *)dev->api;
64
65 return api->get(dev, tm);
66}
67
76static inline int ptp_clock_adjust(const struct device *dev, int increment)
77{
78 const struct ptp_clock_driver_api *api =
79 (const struct ptp_clock_driver_api *)dev->api;
80
81 return api->adjust(dev, increment);
82}
83
92static inline int ptp_clock_rate_adjust(const struct device *dev, double rate)
93{
94 const struct ptp_clock_driver_api *api =
95 (const struct ptp_clock_driver_api *)dev->api;
96
97 return api->rate_adjust(dev, rate);
98}
99
100#ifdef __cplusplus
101}
102#endif
103
104#include <zephyr/syscalls/ptp_clock.h>
105
106#endif /* ZEPHYR_INCLUDE_DRIVERS_PTP_CLOCK_H_ */
Public kernel APIs.
static int ptp_clock_rate_adjust(const struct device *dev, double rate)
Adjust the PTP clock time change rate when compared to its neighbor.
Definition ptp_clock.h:92
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:40
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:76
Public functions for the Precision Time Protocol time specification.
Runtime device structure (in ROM) per driver instance.
Definition device.h:403
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:409
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:109
Definition ptp_clock.h:25
int(* get)(const struct device *dev, struct net_ptp_time *tm)
Definition ptp_clock.h:27
int(* adjust)(const struct device *dev, int increment)
Definition ptp_clock.h:28
int(* rate_adjust)(const struct device *dev, double ratio)
Definition ptp_clock.h:29
int(* set)(const struct device *dev, struct net_ptp_time *tm)
Definition ptp_clock.h:26
Definition time.h:24
Misc utilities.