drivers: can: split CAN classic and CAN-FD syscalls
Split CAN classic and CAN-FD syscalls into two: - can_set_timing() -> can_set_timing() + can_set_timing_data() - can_set_bitrate() -> can_set_bitrate() + can_set_bitrate_data() Fixes: #45303 Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
bad1fa4f3f
commit
18890828b8
19 changed files with 189 additions and 90 deletions
|
@ -284,11 +284,7 @@ Setting the bitrate
|
|||
*******************
|
||||
|
||||
The bitrate and sampling point is initially set at runtime. To change it from
|
||||
the application, one can use the :c:func:`can_set_timing` API. This function
|
||||
takes three arguments. The first timing parameter sets the timing for classic
|
||||
CAN and arbitration phase for CAN-FD. The second parameter sets the timing of
|
||||
the data phase for CAN-FD. For classic CAN, you can use only the first
|
||||
parameter and put NULL to the second one. The :c:func:`can_calc_timing`
|
||||
the application, one can use the :c:func:`can_set_timing` API. The :c:func:`can_calc_timing`
|
||||
function can calculate timing from a bitrate and sampling point in permille.
|
||||
The following example sets the bitrate to 250k baud with the sampling point at
|
||||
87.5%.
|
||||
|
@ -309,11 +305,14 @@ The following example sets the bitrate to 250k baud with the sampling point at
|
|||
return;
|
||||
}
|
||||
|
||||
ret = can_set_timing(can_dev, &timing, NULL);
|
||||
ret = can_set_timing(can_dev, &timing);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("Failed to set timing");
|
||||
}
|
||||
|
||||
A similar API exists for calculating and setting the timing for the data phase for CAN-FD capable
|
||||
controllers. See :c:func:`can_set_timing_data` and :c:func:`can_calc_timing_data`.
|
||||
|
||||
SocketCAN
|
||||
*********
|
||||
|
||||
|
|
|
@ -207,12 +207,9 @@ uint16_t sample_point_for_bitrate(uint32_t bitrate)
|
|||
return sample_pnt;
|
||||
}
|
||||
|
||||
int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t bitrate_data)
|
||||
int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate)
|
||||
{
|
||||
struct can_timing timing;
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
struct can_timing timing_data;
|
||||
#endif /* CONFIG_CAN_FD_MODE */
|
||||
uint32_t max_bitrate;
|
||||
uint16_t sample_pnt;
|
||||
int ret;
|
||||
|
@ -241,7 +238,25 @@ int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t
|
|||
|
||||
timing.sjw = CAN_SJW_NO_CHANGE;
|
||||
|
||||
return can_set_timing(dev, &timing);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
int z_impl_can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data)
|
||||
{
|
||||
struct can_timing timing_data;
|
||||
uint32_t max_bitrate;
|
||||
uint16_t sample_pnt;
|
||||
int ret;
|
||||
|
||||
ret = can_get_max_bitrate(dev, &max_bitrate);
|
||||
if (ret == -ENOSYS) {
|
||||
/* Maximum bitrate unknown */
|
||||
max_bitrate = 0;
|
||||
} else if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((max_bitrate > 0) && (bitrate_data > max_bitrate)) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
@ -258,8 +273,6 @@ int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t
|
|||
|
||||
timing_data.sjw = CAN_SJW_NO_CHANGE;
|
||||
|
||||
return can_set_timing(dev, &timing, &timing_data);
|
||||
#else /* CONFIG_CAN_FD_MODE */
|
||||
return can_set_timing(dev, &timing, NULL);
|
||||
#endif /* !CONFIG_CAN_FD_MODE */
|
||||
return can_set_timing_data(dev, &timing_data);
|
||||
}
|
||||
#endif /* CONFIG_CAN_FD_MODE */
|
||||
|
|
|
@ -24,21 +24,14 @@ static int z_vrfy_can_calc_timing(const struct device *dev, struct can_timing *r
|
|||
#include <syscalls/can_calc_timing_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_can_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
struct can_timing timing_copy;
|
||||
struct can_timing timing_data_copy;
|
||||
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing));
|
||||
Z_OOPS(z_user_from_copy(&timing_copy, timing, sizeof(timing_copy)));
|
||||
|
||||
if (timing_data != NULL) {
|
||||
Z_OOPS(z_user_from_copy(&timing_data_copy, timing_data, sizeof(timing_data_copy)));
|
||||
return z_impl_can_set_timing(dev, &timing_copy, &timing_data_copy);
|
||||
}
|
||||
|
||||
return z_impl_can_set_timing(dev, &timing_copy, NULL);
|
||||
return z_impl_can_set_timing(dev, &timing_copy);
|
||||
}
|
||||
#include <syscalls/can_set_timing_mrsh.c>
|
||||
|
||||
|
@ -113,6 +106,27 @@ static inline const struct can_timing *z_vrfy_can_get_timing_max_data(const stru
|
|||
}
|
||||
#include <syscalls/can_get_timing_max_data_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_can_set_timing_data(const struct device *dev,
|
||||
const struct can_timing *timing_data)
|
||||
{
|
||||
struct can_timing timing_data_copy;
|
||||
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing_data));
|
||||
Z_OOPS(z_user_from_copy(&timing_data_copy, timing_data, sizeof(timing_data_copy)));
|
||||
|
||||
return z_impl_can_set_timing_data(dev, &timing_data_copy);
|
||||
}
|
||||
#include <syscalls/can_set_timing_data_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_can_set_bitrate_data(const struct device *dev,
|
||||
uint32_t bitrate_data)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing_data));
|
||||
|
||||
return z_impl_can_set_bitrate_data(dev, bitrate_data);
|
||||
}
|
||||
#include <syscalls/can_set_bitrate_data_mrsh.c>
|
||||
|
||||
#endif /* CONFIG_CAN_FD_MODE */
|
||||
|
||||
static inline int z_vrfy_can_get_max_filters(const struct device *dev, enum can_ide id_type)
|
||||
|
@ -132,12 +146,11 @@ static inline int z_vrfy_can_set_mode(const struct device *dev, enum can_mode mo
|
|||
}
|
||||
#include <syscalls/can_set_mode_mrsh.c>
|
||||
|
||||
static inline int z_vrfy_can_set_bitrate(const struct device *dev, uint32_t bitrate,
|
||||
uint32_t bitrate_data)
|
||||
static inline int z_vrfy_can_set_bitrate(const struct device *dev, uint32_t bitrate)
|
||||
{
|
||||
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing));
|
||||
|
||||
return z_impl_can_set_bitrate(dev, bitrate, bitrate_data);
|
||||
return z_impl_can_set_bitrate(dev, bitrate);
|
||||
}
|
||||
#include <syscalls/can_set_bitrate_mrsh.c>
|
||||
|
||||
|
|
|
@ -206,12 +206,11 @@ static int can_loopback_set_mode(const struct device *dev, enum can_mode mode)
|
|||
}
|
||||
|
||||
static int can_loopback_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
ARG_UNUSED(dev);
|
||||
ARG_UNUSED(timing);
|
||||
ARG_UNUSED(timing_data);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -185,7 +185,34 @@ void can_mcan_configure_timing(struct can_mcan_reg *can,
|
|||
}
|
||||
|
||||
int can_mcan_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
const struct can_mcan_config *cfg = dev->config;
|
||||
struct can_mcan_reg *can = cfg->can;
|
||||
int ret;
|
||||
|
||||
ret = can_enter_init_mode(can, K_MSEC(CAN_INIT_TIMEOUT));
|
||||
if (ret) {
|
||||
LOG_ERR("Failed to enter init mode");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Configuration Change Enable */
|
||||
can->cccr |= CAN_MCAN_CCCR_CCE;
|
||||
|
||||
can_mcan_configure_timing(can, timing, NULL);
|
||||
|
||||
ret = can_leave_init_mode(can, K_MSEC(CAN_INIT_TIMEOUT));
|
||||
if (ret) {
|
||||
LOG_ERR("Failed to leave init mode");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
int can_mcan_set_timing_data(const struct device *dev,
|
||||
const struct can_timing *timing_data)
|
||||
{
|
||||
const struct can_mcan_config *cfg = dev->config;
|
||||
|
@ -201,7 +228,7 @@ int can_mcan_set_timing(const struct device *dev,
|
|||
/* Configuration Change Enable */
|
||||
can->cccr |= CAN_MCAN_CCCR_CCE;
|
||||
|
||||
can_mcan_configure_timing(can, timing, timing_data);
|
||||
can_mcan_configure_timing(can, NULL, timing_data);
|
||||
|
||||
ret = can_leave_init_mode(can, K_MSEC(CAN_INIT_TIMEOUT));
|
||||
if (ret) {
|
||||
|
@ -211,6 +238,7 @@ int can_mcan_set_timing(const struct device *dev,
|
|||
|
||||
return 0;
|
||||
}
|
||||
#endif /* CONFIG_CAN_FD_MODE */
|
||||
|
||||
int can_mcan_set_mode(const struct device *dev, enum can_mode mode)
|
||||
{
|
||||
|
|
|
@ -260,7 +260,9 @@ struct can_mcan_reg;
|
|||
int can_mcan_set_mode(const struct device *dev, enum can_mode mode);
|
||||
|
||||
int can_mcan_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing);
|
||||
|
||||
int can_mcan_set_timing_data(const struct device *dev,
|
||||
const struct can_timing *timing_data);
|
||||
|
||||
int can_mcan_init(const struct device *dev);
|
||||
|
|
|
@ -330,10 +330,8 @@ static int mcp2515_get_max_bitrate(const struct device *dev, uint32_t *max_bitra
|
|||
}
|
||||
|
||||
static int mcp2515_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
ARG_UNUSED(timing_data);
|
||||
struct mcp2515_data *dev_data = dev->data;
|
||||
int ret;
|
||||
|
||||
|
@ -949,7 +947,7 @@ static int mcp2515_init(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
ret = can_set_timing(dev, &timing, NULL);
|
||||
ret = can_set_timing(dev, &timing);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -152,10 +152,8 @@ static int mcux_flexcan_get_max_bitrate(const struct device *dev, uint32_t *max_
|
|||
}
|
||||
|
||||
static int mcux_flexcan_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
ARG_UNUSED(timing_data);
|
||||
struct mcux_flexcan_data *data = dev->data;
|
||||
const struct mcux_flexcan_config *config = dev->config;
|
||||
uint8_t sjw_backup = data->timing.sjw;
|
||||
|
|
|
@ -94,6 +94,7 @@ static const struct can_driver_api mcux_mcan_driver_api = {
|
|||
.prescaler = 512,
|
||||
},
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
.set_timing_data = can_mcan_set_timing_data,
|
||||
/*
|
||||
* MCUX MCAN data timing limits are specified in the "Data bit timing
|
||||
* and prescaler register (DBTP)" table in the SoC reference manual.
|
||||
|
|
|
@ -648,15 +648,12 @@ static void can_rcar_set_bittiming(const struct can_rcar_cfg *config,
|
|||
}
|
||||
|
||||
static int can_rcar_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
const struct can_rcar_cfg *config = dev->config;
|
||||
struct can_rcar_data *data = dev->data;
|
||||
int ret = 0;
|
||||
|
||||
ARG_UNUSED(timing_data);
|
||||
|
||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||
|
||||
/* Changing bittiming should be done in reset mode */
|
||||
|
@ -955,7 +952,7 @@ static int can_rcar_init(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
ret = can_rcar_set_timing(dev, &timing, NULL);
|
||||
ret = can_rcar_set_timing(dev, &timing);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ static const struct can_driver_api can_sam_driver_api = {
|
|||
.prescaler = 0x200
|
||||
},
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
.set_timing_data = can_mcan_set_timing_data,
|
||||
.timing_min_data = {
|
||||
.sjw = 0x01,
|
||||
.prop_seg = 0x00,
|
||||
|
|
|
@ -272,7 +272,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char **argv)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = can_set_bitrate(can_dev, bitrate, 0);
|
||||
ret = can_set_bitrate(can_dev, bitrate);
|
||||
if (ret) {
|
||||
shell_error(sh, "Failed to set bitrate [%d]",
|
||||
ret);
|
||||
|
|
|
@ -402,16 +402,13 @@ done:
|
|||
}
|
||||
|
||||
static int can_stm32_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
const struct can_stm32_config *cfg = dev->config;
|
||||
CAN_TypeDef *can = cfg->can;
|
||||
struct can_stm32_data *data = dev->data;
|
||||
int ret = -EIO;
|
||||
|
||||
ARG_UNUSED(timing_data);
|
||||
|
||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||
ret = can_enter_init_mode(can);
|
||||
if (ret) {
|
||||
|
@ -566,7 +563,7 @@ static int can_stm32_init(const struct device *dev)
|
|||
}
|
||||
}
|
||||
|
||||
ret = can_stm32_set_timing(dev, &timing, NULL);
|
||||
ret = can_stm32_set_timing(dev, &timing);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ static const struct can_driver_api can_stm32fd_driver_api = {
|
|||
.prescaler = 0x200
|
||||
},
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
.set_timing_data = can_mcan_set_timing_data,
|
||||
.timing_min_data = {
|
||||
.sjw = 0x01,
|
||||
.prop_seg = 0x00,
|
||||
|
|
|
@ -127,6 +127,7 @@ static const struct can_driver_api can_stm32h7_driver_api = {
|
|||
.prescaler = 0x200
|
||||
},
|
||||
#ifdef CONFIG_CAN_FD_MODE
|
||||
.set_timing_data = can_mcan_set_timing_data,
|
||||
/* Data timing limits are per the STM32H7 Reference Manual
|
||||
* (RM0433 Rev 7), section 56.5.3, FDCAN data bit timing and prescaler
|
||||
* register (FDCAN_DBTP).
|
||||
|
|
|
@ -297,7 +297,13 @@ typedef void (*can_state_change_callback_t)(const struct device *dev,
|
|||
* See @a can_set_timing() for argument description
|
||||
*/
|
||||
typedef int (*can_set_timing_t)(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing);
|
||||
|
||||
/**
|
||||
* @brief Callback API upon setting CAN bus timing for the data phase.
|
||||
* See @a can_set_timing_data() for argument description
|
||||
*/
|
||||
typedef int (*can_set_timing_data_t)(const struct device *dev,
|
||||
const struct can_timing *timing_data);
|
||||
|
||||
/**
|
||||
|
@ -388,6 +394,7 @@ __subsystem struct can_driver_api {
|
|||
/* Max values for the timing registers */
|
||||
struct can_timing timing_max;
|
||||
#if defined(CONFIG_CAN_FD_MODE) || defined(__DOXYGEN__)
|
||||
can_set_timing_data_t set_timing_data;
|
||||
/* Min values for the timing registers during the data phase */
|
||||
struct can_timing timing_min_data;
|
||||
/* Max values for the timing registers during the data phase */
|
||||
|
@ -769,6 +776,60 @@ static inline const struct can_timing *z_impl_can_get_timing_max_data(const stru
|
|||
__syscall int can_calc_timing_data(const struct device *dev, struct can_timing *res,
|
||||
uint32_t bitrate, uint16_t sample_pnt);
|
||||
|
||||
/**
|
||||
* @brief Configure the bus timing for the data phase of a CAN-FD controller.
|
||||
*
|
||||
* If the sjw equals CAN_SJW_NO_CHANGE, the sjw parameter is not changed.
|
||||
*
|
||||
* @note @kconfig{CONFIG_CAN_FD_MODE} must be selected for this function to be
|
||||
* available.
|
||||
*
|
||||
* @see can_set_timing()
|
||||
*
|
||||
* @param dev Pointer to the device structure for the driver instance.
|
||||
* @param timing_data Bus timings for data phase
|
||||
*
|
||||
* @retval 0 If successful.
|
||||
* @retval -EIO General input/output error, failed to configure device.
|
||||
*/
|
||||
__syscall int can_set_timing_data(const struct device *dev,
|
||||
const struct can_timing *timing_data);
|
||||
|
||||
static inline int z_impl_can_set_timing_data(const struct device *dev,
|
||||
const struct can_timing *timing_data)
|
||||
{
|
||||
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
|
||||
|
||||
return api->set_timing_data(dev, timing_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the bitrate for the data phase of the CAN-FD controller
|
||||
*
|
||||
* CAN in Automation (CiA) 301 v4.2.0 recommends a sample point location of
|
||||
* 87.5% percent for all bitrates. However, some CAN controllers have
|
||||
* difficulties meeting this for higher bitrates.
|
||||
*
|
||||
* This function defaults to using a sample point of 75.0% for bitrates over 800
|
||||
* kbit/s, 80.0% for bitrates over 500 kbit/s, and 87.5% for all other
|
||||
* bitrates. This is in line with the sample point locations used by the Linux
|
||||
* kernel.
|
||||
*
|
||||
* @note @kconfig{CONFIG_CAN_FD_MODE} must be selected for this function to be
|
||||
* available.
|
||||
*
|
||||
* @see can_set_bitrate()
|
||||
|
||||
* @param dev Pointer to the device structure for the driver instance.
|
||||
* @param bitrate_data Desired data phase bitrate.
|
||||
*
|
||||
* @retval 0 If successful.
|
||||
* @retval -ENOTSUP bitrate not supported by CAN controller/transceiver combination
|
||||
* @retval -EINVAL bitrate/sample point cannot be met.
|
||||
* @retval -EIO General input/output error, failed to set bitrate.
|
||||
*/
|
||||
__syscall int can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data);
|
||||
|
||||
#endif /* CONFIG_CAN_FD_MODE */
|
||||
|
||||
/**
|
||||
|
@ -800,28 +861,23 @@ int can_calc_prescaler(const struct device *dev, struct can_timing *timing,
|
|||
*
|
||||
* If the sjw equals CAN_SJW_NO_CHANGE, the sjw parameter is not changed.
|
||||
*
|
||||
* @note The parameter ``timing_data`` is only relevant for CAN-FD. If the
|
||||
* controller does not support CAN-FD or if @kconfig{CONFIG_CAN_FD_MODE} is not
|
||||
* selected, the value of this parameter is ignored.
|
||||
* @see can_set_timing_data()
|
||||
*
|
||||
* @param dev Pointer to the device structure for the driver instance.
|
||||
* @param timing Bus timings.
|
||||
* @param timing_data Bus timings for data phase (CAN-FD only).
|
||||
*
|
||||
* @retval 0 If successful.
|
||||
* @retval -EIO General input/output error, failed to configure device.
|
||||
*/
|
||||
__syscall int can_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data);
|
||||
const struct can_timing *timing);
|
||||
|
||||
static inline int z_impl_can_set_timing(const struct device *dev,
|
||||
const struct can_timing *timing,
|
||||
const struct can_timing *timing_data)
|
||||
const struct can_timing *timing)
|
||||
{
|
||||
const struct can_driver_api *api = (const struct can_driver_api *)dev->api;
|
||||
|
||||
return api->set_timing(dev, timing, timing_data);
|
||||
return api->set_timing(dev, timing);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -854,20 +910,17 @@ static inline int z_impl_can_set_mode(const struct device *dev, enum can_mode mo
|
|||
* bitrates. This is in line with the sample point locations used by the Linux
|
||||
* kernel.
|
||||
*
|
||||
* @note The parameter ``bitrate_data`` is only relevant for CAN-FD. If the
|
||||
* controller does not support CAN-FD or if @kconfig{CONFIG_CAN_FD_MODE} is not
|
||||
* selected, the value of this parameter is ignored.
|
||||
|
||||
* @see can_set_bitrate_data()
|
||||
*
|
||||
* @param dev Pointer to the device structure for the driver instance.
|
||||
* @param bitrate Desired arbitration phase bitrate.
|
||||
* @param bitrate_data Desired data phase bitrate.
|
||||
*
|
||||
* @retval 0 If successful.
|
||||
* @retval -ENOTSUP bitrate not supported by CAN controller/transceiver combination
|
||||
* @retval -EINVAL bitrate/sample point cannot be met.
|
||||
* @retval -EIO General input/output error, failed to set bitrate.
|
||||
*/
|
||||
__syscall int can_set_bitrate(const struct device *dev, uint32_t bitrate, uint32_t bitrate_data);
|
||||
__syscall int can_set_bitrate(const struct device *dev, uint32_t bitrate);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
|
|||
txArray[i].bufferFull = false;
|
||||
}
|
||||
|
||||
err = can_set_bitrate(CANmodule->dev, KHZ(CANbitRate), 0);
|
||||
err = can_set_bitrate(CANmodule->dev, KHZ(CANbitRate));
|
||||
if (err) {
|
||||
LOG_ERR("failed to configure CAN bitrate (err %d)", err);
|
||||
return CO_ERROR_ILLEGAL_ARGUMENT;
|
||||
|
|
|
@ -636,7 +636,7 @@ static void test_set_bitrate_too_high(void)
|
|||
zassert_equal(err, 0, "failed to get max bitrate (err %d)", err);
|
||||
zassert_not_equal(max, 0, "max bitrate is 0");
|
||||
|
||||
err = can_set_bitrate(can_dev, max + 1, max + 1);
|
||||
err = can_set_bitrate(can_dev, max + 1);
|
||||
zassert_equal(err, -ENOTSUP, "too high bitrate accepted");
|
||||
}
|
||||
|
||||
|
@ -647,7 +647,7 @@ static void test_set_bitrate(void)
|
|||
{
|
||||
int err;
|
||||
|
||||
err = can_set_bitrate(can_dev, TEST_BITRATE_1, 0);
|
||||
err = can_set_bitrate(can_dev, TEST_BITRATE_1);
|
||||
zassert_equal(err, 0, "failed to set bitrate");
|
||||
}
|
||||
|
||||
|
@ -981,10 +981,10 @@ static void test_filters_preserved_through_bitrate_change(void)
|
|||
zassert_equal(err, 0, "receive timeout");
|
||||
assert_frame_equal(&frame, &test_std_frame_1, 0);
|
||||
|
||||
err = can_set_bitrate(can_dev, TEST_BITRATE_2, 0);
|
||||
err = can_set_bitrate(can_dev, TEST_BITRATE_2);
|
||||
zassert_equal(err, 0, "failed to set bitrate");
|
||||
|
||||
err = can_set_bitrate(can_dev, TEST_BITRATE_1, 0);
|
||||
err = can_set_bitrate(can_dev, TEST_BITRATE_1);
|
||||
zassert_equal(err, 0, "failed to set bitrate");
|
||||
|
||||
send_test_frame(can_dev, &test_std_frame_1);
|
||||
|
|
|
@ -202,14 +202,10 @@ static void test_timing_values(const struct device *dev, const struct can_timing
|
|||
assert_timing_within_bounds(&timing, min, max);
|
||||
assert_sp_within_margin(&timing, test->sp, SAMPLE_POINT_MARGIN);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) {
|
||||
if (data_phase) {
|
||||
err = can_set_timing(dev, can_get_timing_min(dev), &timing);
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE) && data_phase) {
|
||||
err = can_set_timing_data(dev, &timing);
|
||||
} else {
|
||||
err = can_set_timing(dev, &timing, can_get_timing_min_data(dev));
|
||||
}
|
||||
} else {
|
||||
err = can_set_timing(dev, &timing, NULL);
|
||||
err = can_set_timing(dev, &timing);
|
||||
}
|
||||
zassert_equal(err, 0, "failed to set timing (err %d)", err);
|
||||
|
||||
|
@ -258,12 +254,13 @@ void test_set_timing_min(void)
|
|||
const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
|
||||
int err;
|
||||
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) {
|
||||
err = can_set_timing(dev, can_get_timing_min(dev), can_get_timing_min_data(dev));
|
||||
} else {
|
||||
err = can_set_timing(dev, can_get_timing_min(dev), NULL);
|
||||
}
|
||||
err = can_set_timing(dev, can_get_timing_min(dev));
|
||||
zassert_equal(err, 0, "failed to set minimum timing parameters (err %d)", err);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) {
|
||||
err = can_set_timing_data(dev, can_get_timing_min_data(dev));
|
||||
zassert_equal(err, 0, "failed to set minimum timing data parameters (err %d)", err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,12 +271,13 @@ void test_set_timing_max(void)
|
|||
const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
|
||||
int err;
|
||||
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) {
|
||||
err = can_set_timing(dev, can_get_timing_max(dev), can_get_timing_max_data(dev));
|
||||
} else {
|
||||
err = can_set_timing(dev, can_get_timing_max(dev), NULL);
|
||||
}
|
||||
err = can_set_timing(dev, can_get_timing_max(dev));
|
||||
zassert_equal(err, 0, "failed to set maximum timing parameters (err %d)", err);
|
||||
|
||||
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) {
|
||||
err = can_set_timing_data(dev, can_get_timing_max_data(dev));
|
||||
zassert_equal(err, 0, "failed to set maximum timing data parameters (err %d)", err);
|
||||
}
|
||||
}
|
||||
|
||||
void test_main(void)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue