From 15fde0a3571f1a50659b3be0a96cb8305826fa46 Mon Sep 17 00:00:00 2001 From: Henrik Brix Andersen Date: Thu, 24 Mar 2022 14:38:36 +0100 Subject: [PATCH] drivers: can: add syscalls for getting min/max timing values Add CAN system calls for getting the minimum/maximum timing values supported by a given CAN controller device driver instance: - can_get_timing_min() - can_get_timing_max() - can_get_timing_min_data() - can_get_timing_max_data(); Signed-off-by: Henrik Brix Andersen --- drivers/can/can_handlers.c | 36 ++++++++++++++++++ include/drivers/can.h | 77 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) diff --git a/drivers/can/can_handlers.c b/drivers/can/can_handlers.c index a91505969f1..eefbbdf448c 100644 --- a/drivers/can/can_handlers.c +++ b/drivers/can/can_handlers.c @@ -39,6 +39,42 @@ static inline int z_vrfy_can_get_max_bitrate(const struct device *dev, } #include +static inline const struct can_timing *z_vrfy_can_get_timing_min(const struct device *dev) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN)); + + return z_impl_can_get_timing_min(dev); +} +#include + +static inline const struct can_timing *z_vrfy_can_get_timing_max(const struct device *dev) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN)); + + return z_impl_can_get_timing_max(dev); +} +#include + +#ifdef CONFIG_CAN_FD_MODE + +static inline const struct can_timing *z_vrfy_can_get_timing_min_data(const struct device *dev) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN)); + + return z_impl_can_get_timing_min_data(dev); +} +#include + +static inline const struct can_timing *z_vrfy_can_get_timing_max_data(const struct device *dev) +{ + Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN)); + + return z_impl_can_get_timing_max_data(dev); +} +#include + +#endif /* CONFIG_CAN_FD_MODE */ + static inline int z_vrfy_can_send(const struct device *dev, const struct zcan_frame *frame, k_timeout_t timeout, diff --git a/include/drivers/can.h b/include/drivers/can.h index 383266dc46c..46c0d9e2a9a 100644 --- a/include/drivers/can.h +++ b/include/drivers/can.h @@ -647,6 +647,38 @@ static inline int z_impl_can_get_max_bitrate(const struct device *dev, uint32_t return api->get_max_bitrate(dev, max_bitrate); } +/** + * @brief Get the minimum supported timing parameter values. + * + * @param dev Pointer to the device structure for the driver instance. + * + * @return Pointer to the minimum supported timing parameter values. + */ +__syscall const struct can_timing *can_get_timing_min(const struct device *dev); + +static inline const struct can_timing *z_impl_can_get_timing_min(const struct device *dev) +{ + const struct can_driver_api *api = (const struct can_driver_api *)dev->api; + + return &api->timing_min; +} + +/** + * @brief Get the maximum supported timing parameter values. + * + * @param dev Pointer to the device structure for the driver instance. + * + * @return Pointer to the maximum supported timing parameter values. + */ +__syscall const struct can_timing *can_get_timing_max(const struct device *dev); + +static inline const struct can_timing *z_impl_can_get_timing_max(const struct device *dev) +{ + const struct can_driver_api *api = (const struct can_driver_api *)dev->api; + + return &api->timing_max; +} + /** * @brief Calculate timing parameters from bitrate and sample point * @@ -671,6 +703,51 @@ int can_calc_timing(const struct device *dev, struct can_timing *res, uint32_t bitrate, uint16_t sample_pnt); #if defined(CONFIG_CAN_FD_MODE) || defined(__DOXYGEN__) + +/** + * @brief Get the minimum supported timing parameter values for the data phase. + * + * Same as @a can_get_timing_min() but for the minimum values for the data phase. + * + * @note @kconfig{CONFIG_CAN_FD_MODE} must be selected for this function to be + * available. + * + * @param dev Pointer to the device structure for the driver instance. + * + * @return Pointer to the minimum supported timing parameter values, or NULL if + * CAN-FD is not supported. + */ +__syscall const struct can_timing *can_get_timing_min_data(const struct device *dev); + +static inline const struct can_timing *z_impl_can_get_timing_min_data(const struct device *dev) +{ + const struct can_driver_api *api = (const struct can_driver_api *)dev->api; + + return &api->timing_min_data; +} + +/** + * @brief Get the maximum supported timing parameter values for the data phase. + * + * Same as @a can_get_timing_max() but for the maximum values for the data phase. + * + * @note @kconfig{CONFIG_CAN_FD_MODE} must be selected for this function to be + * available. + * + * @param dev Pointer to the device structure for the driver instance. + * + * @return Pointer to the maximum supported timing parameter values, or NULL if + * CAN-FD is not supported. + */ +__syscall const struct can_timing *can_get_timing_max_data(const struct device *dev); + +static inline const struct can_timing *z_impl_can_get_timing_max_data(const struct device *dev) +{ + const struct can_driver_api *api = (const struct can_driver_api *)dev->api; + + return &api->timing_max_data; +} + /** * @brief Calculate timing parameters for the data phase *