From 52be66919ec454e0943292be325b1fdb8f3ef2ec Mon Sep 17 00:00:00 2001 From: Xabier Marquiegui Date: Thu, 27 Jan 2022 09:49:20 +0100 Subject: [PATCH] net: gptp: convert clock sync ratio from float to double Using clock sync ratio as double instead of float improves synchronization smoothness Signed-off-by: Xabier Marquiegui --- drivers/ethernet/eth_e1000.c | 2 +- drivers/ethernet/eth_mcux.c | 6 +++--- drivers/ethernet/eth_native_posix.c | 2 +- drivers/ethernet/eth_sam_gmac.c | 2 +- drivers/ethernet/eth_stm32_hal.c | 2 +- include/drivers/ptp_clock.h | 4 ++-- tests/net/ptp/clock/src/main.c | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/ethernet/eth_e1000.c b/drivers/ethernet/eth_e1000.c index 92a23235169..f500b010ca8 100644 --- a/drivers/ethernet/eth_e1000.c +++ b/drivers/ethernet/eth_e1000.c @@ -380,7 +380,7 @@ static int ptp_clock_e1000_adjust(const struct device *dev, int increment) return 0; } -static int ptp_clock_e1000_rate_adjust(const struct device *dev, float ratio) +static int ptp_clock_e1000_rate_adjust(const struct device *dev, double ratio) { const int hw_inc = NSEC_PER_SEC / CONFIG_ETH_E1000_PTP_CLOCK_SRC_HZ; struct ptp_context *ptp_context = dev->data; diff --git a/drivers/ethernet/eth_mcux.c b/drivers/ethernet/eth_mcux.c index 5f8652718e1..ae544e6b851 100644 --- a/drivers/ethernet/eth_mcux.c +++ b/drivers/ethernet/eth_mcux.c @@ -164,7 +164,7 @@ struct eth_context { struct net_pkt *ts_tx_pkt; const struct device *ptp_clock; enet_ptp_config_t ptp_config; - float clk_ratio; + double clk_ratio; struct k_mutex ptp_mutex; #endif struct k_sem tx_buf_sem; @@ -1646,14 +1646,14 @@ static int ptp_clock_mcux_adjust(const struct device *dev, int increment) return ret; } -static int ptp_clock_mcux_rate_adjust(const struct device *dev, float ratio) +static int ptp_clock_mcux_rate_adjust(const struct device *dev, double ratio) { const int hw_inc = NSEC_PER_SEC / CONFIG_ETH_MCUX_PTP_CLOCK_SRC_HZ; struct ptp_context *ptp_context = dev->data; struct eth_context *context = ptp_context->eth_context; int corr; int32_t mul; - float val; + double val; /* No change needed. */ if ((ratio > 1.0 && ratio - 1.0 < 0.00000001) || diff --git a/drivers/ethernet/eth_native_posix.c b/drivers/ethernet/eth_native_posix.c index 49da3dce8a3..6d560280314 100644 --- a/drivers/ethernet/eth_native_posix.c +++ b/drivers/ethernet/eth_native_posix.c @@ -695,7 +695,7 @@ static int ptp_clock_adjust_native_posix(const struct device *clk, } static int ptp_clock_rate_adjust_native_posix(const struct device *clk, - float ratio) + double ratio) { ARG_UNUSED(clk); ARG_UNUSED(ratio); diff --git a/drivers/ethernet/eth_sam_gmac.c b/drivers/ethernet/eth_sam_gmac.c index 7d41c83cefb..177859f87ec 100644 --- a/drivers/ethernet/eth_sam_gmac.c +++ b/drivers/ethernet/eth_sam_gmac.c @@ -2448,7 +2448,7 @@ static int ptp_clock_sam_gmac_adjust(const struct device *dev, int increment) } static int ptp_clock_sam_gmac_rate_adjust(const struct device *dev, - float ratio) + double ratio) { return -ENOTSUP; } diff --git a/drivers/ethernet/eth_stm32_hal.c b/drivers/ethernet/eth_stm32_hal.c index 7dad465c3d0..b59aef2b64a 100644 --- a/drivers/ethernet/eth_stm32_hal.c +++ b/drivers/ethernet/eth_stm32_hal.c @@ -1267,7 +1267,7 @@ static int ptp_clock_stm32_adjust(const struct device *dev, int increment) return ret; } -static int ptp_clock_stm32_rate_adjust(const struct device *dev, float ratio) +static int ptp_clock_stm32_rate_adjust(const struct device *dev, double ratio) { struct ptp_context *ptp_context = dev->data; struct eth_stm32_hal_dev_data *eth_dev_data = ptp_context->eth_dev_data; diff --git a/include/drivers/ptp_clock.h b/include/drivers/ptp_clock.h index 8748ff80753..a9018bcd552 100644 --- a/include/drivers/ptp_clock.h +++ b/include/drivers/ptp_clock.h @@ -26,7 +26,7 @@ __subsystem struct ptp_clock_driver_api { int (*set)(const struct device *dev, struct net_ptp_time *tm); int (*get)(const struct device *dev, struct net_ptp_time *tm); int (*adjust)(const struct device *dev, int increment); - int (*rate_adjust)(const struct device *dev, float ratio); + int (*rate_adjust)(const struct device *dev, double ratio); }; /** @@ -89,7 +89,7 @@ static inline int ptp_clock_adjust(const struct device *dev, int increment) * * @return 0 if ok, <0 if error */ -static inline int ptp_clock_rate_adjust(const struct device *dev, float rate) +static inline int ptp_clock_rate_adjust(const struct device *dev, double rate) { const struct ptp_clock_driver_api *api = (const struct ptp_clock_driver_api *)dev->api; diff --git a/tests/net/ptp/clock/src/main.c b/tests/net/ptp/clock/src/main.c index bd956432881..8bbabb588f8 100644 --- a/tests/net/ptp/clock/src/main.c +++ b/tests/net/ptp/clock/src/main.c @@ -218,7 +218,7 @@ static int my_ptp_clock_adjust(const struct device *dev, int increment) return 0; } -static int my_ptp_clock_rate_adjust(const struct device *dev, float ratio) +static int my_ptp_clock_rate_adjust(const struct device *dev, double ratio) { return 0; }