drivers: can: convert can_calc_timing*() to syscalls
Convert can_calc_timing() + can_calc_timing_data() to syscalls and use the newly added syscalls calls for determing the minimum/maximum supported timing parameter values. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
15fde0a357
commit
372cee4268
3 changed files with 50 additions and 16 deletions
|
@ -127,10 +127,12 @@ static int can_calc_timing_int(uint32_t core_clock, struct can_timing *res,
|
||||||
return sp_err_min == UINT16_MAX ? -EINVAL : (int)sp_err_min;
|
return sp_err_min == UINT16_MAX ? -EINVAL : (int)sp_err_min;
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_calc_timing(const struct device *dev, struct can_timing *res,
|
|
||||||
uint32_t bitrate, uint16_t sample_pnt)
|
int z_impl_can_calc_timing(const struct device *dev, struct can_timing *res,
|
||||||
|
uint32_t bitrate, uint16_t sample_pnt)
|
||||||
{
|
{
|
||||||
const struct can_driver_api *api = dev->api;
|
const struct can_timing *min = can_get_timing_min(dev);
|
||||||
|
const struct can_timing *max = can_get_timing_max(dev);
|
||||||
uint32_t core_clock;
|
uint32_t core_clock;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -139,15 +141,15 @@ int can_calc_timing(const struct device *dev, struct can_timing *res,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return can_calc_timing_int(core_clock, res, &api->timing_min,
|
return can_calc_timing_int(core_clock, res, min, max, bitrate, sample_pnt);
|
||||||
&api->timing_max, bitrate, sample_pnt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_FD_MODE
|
#ifdef CONFIG_CAN_FD_MODE
|
||||||
int can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
int z_impl_can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
||||||
uint32_t bitrate, uint16_t sample_pnt)
|
uint32_t bitrate, uint16_t sample_pnt)
|
||||||
{
|
{
|
||||||
const struct can_driver_api *api = dev->api;
|
const struct can_timing *min = can_get_timing_min_data(dev);
|
||||||
|
const struct can_timing *max = can_get_timing_max_data(dev);
|
||||||
uint32_t core_clock;
|
uint32_t core_clock;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
@ -156,10 +158,9 @@ int can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
return can_calc_timing_int(core_clock, res, &api->timing_min_data,
|
return can_calc_timing_int(core_clock, res, min, max, bitrate, sample_pnt);
|
||||||
&api->timing_max_data, bitrate, sample_pnt);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* CONFIG_CAN_FD_MODE */
|
||||||
|
|
||||||
int can_calc_prescaler(const struct device *dev, struct can_timing *timing,
|
int can_calc_prescaler(const struct device *dev, struct can_timing *timing,
|
||||||
uint32_t bitrate)
|
uint32_t bitrate)
|
||||||
|
@ -184,7 +185,7 @@ int can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t bitrate
|
||||||
struct can_timing timing;
|
struct can_timing timing;
|
||||||
#ifdef CONFIG_CAN_FD_MODE
|
#ifdef CONFIG_CAN_FD_MODE
|
||||||
struct can_timing timing_data;
|
struct can_timing timing_data;
|
||||||
#endif
|
#endif /* CONFIG_CAN_FD_MODE */
|
||||||
uint32_t max_bitrate;
|
uint32_t max_bitrate;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,22 @@
|
||||||
#include <syscall_handler.h>
|
#include <syscall_handler.h>
|
||||||
#include <drivers/can.h>
|
#include <drivers/can.h>
|
||||||
|
|
||||||
|
static int z_vrfy_can_calc_timing(const struct device *dev, struct can_timing *res,
|
||||||
|
uint32_t bitrate, uint16_t sample_pnt)
|
||||||
|
{
|
||||||
|
struct can_timing local_res;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_core_clock));
|
||||||
|
Z_OOPS(z_user_from_copy(&local_res, res, sizeof(local_res)));
|
||||||
|
|
||||||
|
err = z_impl_can_calc_timing(dev, &local_res, bitrate, sample_pnt);
|
||||||
|
Z_OOPS(z_user_to_copy(res, &local_res, sizeof(*res)));
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#include <syscalls/can_calc_timing_mrsh.c>
|
||||||
|
|
||||||
static inline int z_vrfy_can_set_timing(const struct device *dev,
|
static inline int z_vrfy_can_set_timing(const struct device *dev,
|
||||||
const struct can_timing *timing,
|
const struct can_timing *timing,
|
||||||
const struct can_timing *timing_data)
|
const struct can_timing *timing_data)
|
||||||
|
@ -57,6 +73,22 @@ static inline const struct can_timing *z_vrfy_can_get_timing_max(const struct de
|
||||||
|
|
||||||
#ifdef CONFIG_CAN_FD_MODE
|
#ifdef CONFIG_CAN_FD_MODE
|
||||||
|
|
||||||
|
static int z_vrfy_can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
||||||
|
uint32_t bitrate, uint16_t sample_pnt)
|
||||||
|
{
|
||||||
|
struct can_timing local_res;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, get_core_clock));
|
||||||
|
Z_OOPS(z_user_from_copy(&local_res, res, sizeof(local_res)));
|
||||||
|
|
||||||
|
err = z_impl_can_calc_timing_data(dev, &local_res, bitrate, sample_pnt);
|
||||||
|
Z_OOPS(z_user_to_copy(res, &local_res, sizeof(*res)));
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#include <syscalls/can_calc_timing_data_mrsh.c>
|
||||||
|
|
||||||
static inline const struct can_timing *z_vrfy_can_get_timing_min_data(const struct device *dev)
|
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));
|
Z_OOPS(Z_SYSCALL_OBJ(dev, K_OBJ_DRIVER_CAN));
|
||||||
|
|
|
@ -699,8 +699,8 @@ static inline const struct can_timing *z_impl_can_get_timing_max(const struct de
|
||||||
* @retval -EINVAL if there is no solution for the desired values.
|
* @retval -EINVAL if there is no solution for the desired values.
|
||||||
* @retval -EIO if @a can_get_core_clock() is not available.
|
* @retval -EIO if @a can_get_core_clock() is not available.
|
||||||
*/
|
*/
|
||||||
int can_calc_timing(const struct device *dev, struct can_timing *res,
|
__syscall 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__)
|
||||||
|
|
||||||
|
@ -766,8 +766,9 @@ static inline const struct can_timing *z_impl_can_get_timing_max_data(const stru
|
||||||
* @retval -EINVAL if there is no solution for the desired values.
|
* @retval -EINVAL if there is no solution for the desired values.
|
||||||
* @retval -EIO if @a can_get_core_clock() is not available.
|
* @retval -EIO if @a can_get_core_clock() is not available.
|
||||||
*/
|
*/
|
||||||
int can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
__syscall int can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
||||||
uint32_t bitrate, uint16_t sample_pnt);
|
uint32_t bitrate, uint16_t sample_pnt);
|
||||||
|
|
||||||
#endif /* CONFIG_CAN_FD_MODE */
|
#endif /* CONFIG_CAN_FD_MODE */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue