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 <hebad@vestas.com>
This commit is contained in:
Henrik Brix Andersen 2022-03-24 14:38:36 +01:00 committed by Marti Bolivar
commit 15fde0a357
2 changed files with 113 additions and 0 deletions

View file

@ -39,6 +39,42 @@ static inline int z_vrfy_can_get_max_bitrate(const struct device *dev,
} }
#include <syscalls/can_get_max_bitrate_mrsh.c> #include <syscalls/can_get_max_bitrate_mrsh.c>
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 <syscalls/can_get_timing_min_mrsh.c>
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 <syscalls/can_get_timing_max_mrsh.c>
#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 <syscalls/can_get_timing_min_data_mrsh.c>
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 <syscalls/can_get_timing_max_data_mrsh.c>
#endif /* CONFIG_CAN_FD_MODE */
static inline int z_vrfy_can_send(const struct device *dev, static inline int z_vrfy_can_send(const struct device *dev,
const struct zcan_frame *frame, const struct zcan_frame *frame,
k_timeout_t timeout, k_timeout_t timeout,

View file

@ -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); 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 * @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); uint32_t bitrate, uint16_t sample_pnt);
#if defined(CONFIG_CAN_FD_MODE) || defined(__DOXYGEN__) #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 * @brief Calculate timing parameters for the data phase
* *