2018-01-24 21:22:55 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 Intel Corporation.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#ifndef ZEPHYR_INCLUDE_PTP_CLOCK_H_
|
|
|
|
#define ZEPHYR_INCLUDE_PTP_CLOCK_H_
|
2018-01-24 21:22:55 +08:00
|
|
|
|
2019-05-27 16:01:49 +08:00
|
|
|
#include <kernel.h>
|
2018-01-24 21:22:55 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <device.h>
|
2019-06-26 22:33:55 +08:00
|
|
|
#include <sys/util.h>
|
2018-01-24 21:22:55 +08:00
|
|
|
#include <net/ptp_time.h>
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Name of the PTP clock driver */
|
|
|
|
#if !defined(PTP_CLOCK_NAME)
|
|
|
|
#define PTP_CLOCK_NAME "PTP_CLOCK"
|
|
|
|
#endif
|
|
|
|
|
2020-03-05 05:32:01 +08:00
|
|
|
__subsystem struct ptp_clock_driver_api {
|
2018-01-24 21:22:55 +08:00
|
|
|
int (*set)(struct device *dev, struct net_ptp_time *tm);
|
|
|
|
int (*get)(struct device *dev, struct net_ptp_time *tm);
|
|
|
|
int (*adjust)(struct device *dev, int increment);
|
|
|
|
int (*rate_adjust)(struct device *dev, float ratio);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set the time of the PTP clock.
|
|
|
|
*
|
|
|
|
* @param dev PTP clock device
|
|
|
|
* @param tm Time to set
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
|
|
|
static inline int ptp_clock_set(struct device *dev, struct net_ptp_time *tm)
|
|
|
|
{
|
2019-12-16 18:56:17 +08:00
|
|
|
const struct ptp_clock_driver_api *api =
|
|
|
|
(const struct ptp_clock_driver_api *)dev->driver_api;
|
2018-01-24 21:22:55 +08:00
|
|
|
|
|
|
|
return api->set(dev, tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the time of the PTP clock.
|
|
|
|
*
|
|
|
|
* @param dev PTP clock device
|
|
|
|
* @param tm Where to store the current time.
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
2019-05-27 16:01:49 +08:00
|
|
|
__syscall int ptp_clock_get(struct device *dev, struct net_ptp_time *tm);
|
|
|
|
|
|
|
|
static inline int z_impl_ptp_clock_get(struct device *dev,
|
|
|
|
struct net_ptp_time *tm)
|
2018-01-24 21:22:55 +08:00
|
|
|
{
|
2019-12-16 18:56:17 +08:00
|
|
|
const struct ptp_clock_driver_api *api =
|
|
|
|
(const struct ptp_clock_driver_api *)dev->driver_api;
|
2018-01-24 21:22:55 +08:00
|
|
|
|
|
|
|
return api->get(dev, tm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adjust the PTP clock time.
|
|
|
|
*
|
|
|
|
* @param dev PTP clock device
|
|
|
|
* @param increment Increment of the clock in nanoseconds
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
|
|
|
static inline int ptp_clock_adjust(struct device *dev, int increment)
|
|
|
|
{
|
2019-12-16 18:56:17 +08:00
|
|
|
const struct ptp_clock_driver_api *api =
|
|
|
|
(const struct ptp_clock_driver_api *)dev->driver_api;
|
2018-01-24 21:22:55 +08:00
|
|
|
|
|
|
|
return api->adjust(dev, increment);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Adjust the PTP clock time change rate when compared to its neighbor.
|
|
|
|
*
|
|
|
|
* @param dev PTP clock device
|
|
|
|
* @param rate Rate of the clock time change
|
|
|
|
*
|
|
|
|
* @return 0 if ok, <0 if error
|
|
|
|
*/
|
|
|
|
static inline int ptp_clock_rate_adjust(struct device *dev, float rate)
|
|
|
|
{
|
2019-12-16 18:56:17 +08:00
|
|
|
const struct ptp_clock_driver_api *api =
|
|
|
|
(const struct ptp_clock_driver_api *)dev->driver_api;
|
2018-01-24 21:22:55 +08:00
|
|
|
|
|
|
|
return api->rate_adjust(dev, rate);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-13 01:54:52 +08:00
|
|
|
#include <syscalls/ptp_clock.h>
|
|
|
|
|
2018-09-15 01:43:44 +08:00
|
|
|
#endif /* ZEPHYR_INCLUDE_PTP_CLOCK_H_ */
|