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:
Henrik Brix Andersen 2022-05-03 22:05:53 +02:00 committed by Carles Cufí
commit 18890828b8
19 changed files with 189 additions and 90 deletions

View file

@ -284,11 +284,7 @@ Setting the bitrate
******************* *******************
The bitrate and sampling point is initially set at runtime. To change it from 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 the application, one can use the :c:func:`can_set_timing` API. The :c:func:`can_calc_timing`
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`
function can calculate timing from a bitrate and sampling point in permille. 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 The following example sets the bitrate to 250k baud with the sampling point at
87.5%. 87.5%.
@ -309,11 +305,14 @@ The following example sets the bitrate to 250k baud with the sampling point at
return; return;
} }
ret = can_set_timing(can_dev, &timing, NULL); ret = can_set_timing(can_dev, &timing);
if (ret != 0) { if (ret != 0) {
LOG_ERR("Failed to set timing"); 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 SocketCAN
********* *********

View file

@ -207,12 +207,9 @@ uint16_t sample_point_for_bitrate(uint32_t bitrate)
return sample_pnt; 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; struct can_timing timing;
#ifdef CONFIG_CAN_FD_MODE
struct can_timing timing_data;
#endif /* CONFIG_CAN_FD_MODE */
uint32_t max_bitrate; uint32_t max_bitrate;
uint16_t sample_pnt; uint16_t sample_pnt;
int ret; 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; timing.sjw = CAN_SJW_NO_CHANGE;
return can_set_timing(dev, &timing);
}
#ifdef CONFIG_CAN_FD_MODE #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)) { if ((max_bitrate > 0) && (bitrate_data > max_bitrate)) {
return -ENOTSUP; 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; timing_data.sjw = CAN_SJW_NO_CHANGE;
return can_set_timing(dev, &timing, &timing_data); return can_set_timing_data(dev, &timing_data);
#else /* CONFIG_CAN_FD_MODE */
return can_set_timing(dev, &timing, NULL);
#endif /* !CONFIG_CAN_FD_MODE */
} }
#endif /* CONFIG_CAN_FD_MODE */

View file

@ -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> #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)
{ {
struct can_timing timing_copy; struct can_timing timing_copy;
struct can_timing timing_data_copy;
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing)); Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing));
Z_OOPS(z_user_from_copy(&timing_copy, timing, sizeof(timing_copy))); Z_OOPS(z_user_from_copy(&timing_copy, timing, sizeof(timing_copy)));
if (timing_data != NULL) { return z_impl_can_set_timing(dev, &timing_copy);
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);
} }
#include <syscalls/can_set_timing_mrsh.c> #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> #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 */ #endif /* CONFIG_CAN_FD_MODE */
static inline int z_vrfy_can_get_max_filters(const struct device *dev, enum can_ide id_type) 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> #include <syscalls/can_set_mode_mrsh.c>
static inline int z_vrfy_can_set_bitrate(const struct device *dev, uint32_t bitrate, static inline int z_vrfy_can_set_bitrate(const struct device *dev, uint32_t bitrate)
uint32_t bitrate_data)
{ {
Z_OOPS(Z_SYSCALL_DRIVER_CAN(dev, set_timing)); 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> #include <syscalls/can_set_bitrate_mrsh.c>

View file

@ -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, static int can_loopback_set_timing(const struct device *dev,
const struct can_timing *timing, const struct can_timing *timing)
const struct can_timing *timing_data)
{ {
ARG_UNUSED(dev); ARG_UNUSED(dev);
ARG_UNUSED(timing); ARG_UNUSED(timing);
ARG_UNUSED(timing_data);
return 0; return 0;
} }

View file

@ -185,7 +185,34 @@ void can_mcan_configure_timing(struct can_mcan_reg *can,
} }
int can_mcan_set_timing(const struct device *dev, 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_timing *timing_data)
{ {
const struct can_mcan_config *cfg = dev->config; const struct can_mcan_config *cfg = dev->config;
@ -201,7 +228,7 @@ int can_mcan_set_timing(const struct device *dev,
/* Configuration Change Enable */ /* Configuration Change Enable */
can->cccr |= CAN_MCAN_CCCR_CCE; 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)); ret = can_leave_init_mode(can, K_MSEC(CAN_INIT_TIMEOUT));
if (ret) { if (ret) {
@ -211,6 +238,7 @@ int can_mcan_set_timing(const struct device *dev,
return 0; return 0;
} }
#endif /* CONFIG_CAN_FD_MODE */
int can_mcan_set_mode(const struct device *dev, enum can_mode mode) int can_mcan_set_mode(const struct device *dev, enum can_mode mode)
{ {

View file

@ -260,8 +260,10 @@ struct can_mcan_reg;
int can_mcan_set_mode(const struct device *dev, enum can_mode mode); int can_mcan_set_mode(const struct device *dev, enum can_mode mode);
int can_mcan_set_timing(const struct device *dev, int can_mcan_set_timing(const struct device *dev,
const struct can_timing *timing, const struct can_timing *timing);
const struct can_timing *timing_data);
int can_mcan_set_timing_data(const struct device *dev,
const struct can_timing *timing_data);
int can_mcan_init(const struct device *dev); int can_mcan_init(const struct device *dev);

View file

@ -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, static int mcp2515_set_timing(const struct device *dev,
const struct can_timing *timing, const struct can_timing *timing)
const struct can_timing *timing_data)
{ {
ARG_UNUSED(timing_data);
struct mcp2515_data *dev_data = dev->data; struct mcp2515_data *dev_data = dev->data;
int ret; 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) { if (ret) {
return ret; return ret;
} }

View file

@ -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, static int mcux_flexcan_set_timing(const struct device *dev,
const struct can_timing *timing, const struct can_timing *timing)
const struct can_timing *timing_data)
{ {
ARG_UNUSED(timing_data);
struct mcux_flexcan_data *data = dev->data; struct mcux_flexcan_data *data = dev->data;
const struct mcux_flexcan_config *config = dev->config; const struct mcux_flexcan_config *config = dev->config;
uint8_t sjw_backup = data->timing.sjw; uint8_t sjw_backup = data->timing.sjw;

View file

@ -94,6 +94,7 @@ static const struct can_driver_api mcux_mcan_driver_api = {
.prescaler = 512, .prescaler = 512,
}, },
#ifdef CONFIG_CAN_FD_MODE #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 * MCUX MCAN data timing limits are specified in the "Data bit timing
* and prescaler register (DBTP)" table in the SoC reference manual. * and prescaler register (DBTP)" table in the SoC reference manual.

View file

@ -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, static int can_rcar_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_rcar_cfg *config = dev->config; const struct can_rcar_cfg *config = dev->config;
struct can_rcar_data *data = dev->data; struct can_rcar_data *data = dev->data;
int ret = 0; int ret = 0;
ARG_UNUSED(timing_data);
k_mutex_lock(&data->inst_mutex, K_FOREVER); k_mutex_lock(&data->inst_mutex, K_FOREVER);
/* Changing bittiming should be done in reset mode */ /* 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) { if (ret) {
return ret; return ret;
} }

View file

@ -98,6 +98,7 @@ static const struct can_driver_api can_sam_driver_api = {
.prescaler = 0x200 .prescaler = 0x200
}, },
#ifdef CONFIG_CAN_FD_MODE #ifdef CONFIG_CAN_FD_MODE
.set_timing_data = can_mcan_set_timing_data,
.timing_min_data = { .timing_min_data = {
.sjw = 0x01, .sjw = 0x01,
.prop_seg = 0x00, .prop_seg = 0x00,

View file

@ -272,7 +272,7 @@ static int cmd_config(const struct shell *sh, size_t argc, char **argv)
return -EINVAL; return -EINVAL;
} }
ret = can_set_bitrate(can_dev, bitrate, 0); ret = can_set_bitrate(can_dev, bitrate);
if (ret) { if (ret) {
shell_error(sh, "Failed to set bitrate [%d]", shell_error(sh, "Failed to set bitrate [%d]",
ret); ret);

View file

@ -402,16 +402,13 @@ done:
} }
static int can_stm32_set_timing(const struct device *dev, static int can_stm32_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_stm32_config *cfg = dev->config; const struct can_stm32_config *cfg = dev->config;
CAN_TypeDef *can = cfg->can; CAN_TypeDef *can = cfg->can;
struct can_stm32_data *data = dev->data; struct can_stm32_data *data = dev->data;
int ret = -EIO; int ret = -EIO;
ARG_UNUSED(timing_data);
k_mutex_lock(&data->inst_mutex, K_FOREVER); k_mutex_lock(&data->inst_mutex, K_FOREVER);
ret = can_enter_init_mode(can); ret = can_enter_init_mode(can);
if (ret) { 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) { if (ret) {
return ret; return ret;
} }

View file

@ -137,6 +137,7 @@ static const struct can_driver_api can_stm32fd_driver_api = {
.prescaler = 0x200 .prescaler = 0x200
}, },
#ifdef CONFIG_CAN_FD_MODE #ifdef CONFIG_CAN_FD_MODE
.set_timing_data = can_mcan_set_timing_data,
.timing_min_data = { .timing_min_data = {
.sjw = 0x01, .sjw = 0x01,
.prop_seg = 0x00, .prop_seg = 0x00,

View file

@ -127,6 +127,7 @@ static const struct can_driver_api can_stm32h7_driver_api = {
.prescaler = 0x200 .prescaler = 0x200
}, },
#ifdef CONFIG_CAN_FD_MODE #ifdef CONFIG_CAN_FD_MODE
.set_timing_data = can_mcan_set_timing_data,
/* Data timing limits are per the STM32H7 Reference Manual /* Data timing limits are per the STM32H7 Reference Manual
* (RM0433 Rev 7), section 56.5.3, FDCAN data bit timing and prescaler * (RM0433 Rev 7), section 56.5.3, FDCAN data bit timing and prescaler
* register (FDCAN_DBTP). * register (FDCAN_DBTP).

View file

@ -297,8 +297,14 @@ typedef void (*can_state_change_callback_t)(const struct device *dev,
* See @a can_set_timing() for argument description * See @a can_set_timing() for argument description
*/ */
typedef int (*can_set_timing_t)(const struct device *dev, typedef int (*can_set_timing_t)(const struct device *dev,
const struct can_timing *timing, const struct can_timing *timing);
const struct can_timing *timing_data);
/**
* @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);
/** /**
* @brief Callback API upon setting CAN controller mode * @brief Callback API upon setting CAN controller mode
@ -388,6 +394,7 @@ __subsystem struct can_driver_api {
/* Max values for the timing registers */ /* Max values for the timing registers */
struct can_timing timing_max; struct can_timing timing_max;
#if defined(CONFIG_CAN_FD_MODE) || defined(__DOXYGEN__) #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 */ /* Min values for the timing registers during the data phase */
struct can_timing timing_min_data; struct can_timing timing_min_data;
/* Max values for the timing registers during the data phase */ /* 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, __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);
/**
* @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 */ #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. * 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 * @see can_set_timing_data()
* controller does not support CAN-FD or if @kconfig{CONFIG_CAN_FD_MODE} is not
* selected, the value of this parameter is ignored.
* *
* @param dev Pointer to the device structure for the driver instance. * @param dev Pointer to the device structure for the driver instance.
* @param timing Bus timings. * @param timing Bus timings.
* @param timing_data Bus timings for data phase (CAN-FD only).
* *
* @retval 0 If successful. * @retval 0 If successful.
* @retval -EIO General input/output error, failed to configure device. * @retval -EIO General input/output error, failed to configure device.
*/ */
__syscall int can_set_timing(const struct device *dev, __syscall int can_set_timing(const struct device *dev,
const struct can_timing *timing, const struct can_timing *timing);
const struct can_timing *timing_data);
static inline int z_impl_can_set_timing(const struct device *dev, static inline int z_impl_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_driver_api *api = (const struct can_driver_api *)dev->api; 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 * bitrates. This is in line with the sample point locations used by the Linux
* kernel. * kernel.
* *
* @note The parameter ``bitrate_data`` is only relevant for CAN-FD. If the * @see can_set_bitrate_data()
* controller does not support CAN-FD or if @kconfig{CONFIG_CAN_FD_MODE} is not *
* selected, the value of this parameter is ignored.
* @param dev Pointer to the device structure for the driver instance. * @param dev Pointer to the device structure for the driver instance.
* @param bitrate Desired arbitration phase bitrate. * @param bitrate Desired arbitration phase bitrate.
* @param bitrate_data Desired data phase bitrate.
* *
* @retval 0 If successful. * @retval 0 If successful.
* @retval -ENOTSUP bitrate not supported by CAN controller/transceiver combination * @retval -ENOTSUP bitrate not supported by CAN controller/transceiver combination
* @retval -EINVAL bitrate/sample point cannot be met. * @retval -EINVAL bitrate/sample point cannot be met.
* @retval -EIO General input/output error, failed to set bitrate. * @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);
/** @} */ /** @} */

View file

@ -223,7 +223,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
txArray[i].bufferFull = false; txArray[i].bufferFull = false;
} }
err = can_set_bitrate(CANmodule->dev, KHZ(CANbitRate), 0); err = can_set_bitrate(CANmodule->dev, KHZ(CANbitRate));
if (err) { if (err) {
LOG_ERR("failed to configure CAN bitrate (err %d)", err); LOG_ERR("failed to configure CAN bitrate (err %d)", err);
return CO_ERROR_ILLEGAL_ARGUMENT; return CO_ERROR_ILLEGAL_ARGUMENT;

View file

@ -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_equal(err, 0, "failed to get max bitrate (err %d)", err);
zassert_not_equal(max, 0, "max bitrate is 0"); 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"); zassert_equal(err, -ENOTSUP, "too high bitrate accepted");
} }
@ -647,7 +647,7 @@ static void test_set_bitrate(void)
{ {
int err; 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"); 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"); zassert_equal(err, 0, "receive timeout");
assert_frame_equal(&frame, &test_std_frame_1, 0); 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"); 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"); zassert_equal(err, 0, "failed to set bitrate");
send_test_frame(can_dev, &test_std_frame_1); send_test_frame(can_dev, &test_std_frame_1);

View file

@ -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_timing_within_bounds(&timing, min, max);
assert_sp_within_margin(&timing, test->sp, SAMPLE_POINT_MARGIN); assert_sp_within_margin(&timing, test->sp, SAMPLE_POINT_MARGIN);
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) { if (IS_ENABLED(CONFIG_CAN_FD_MODE) && data_phase) {
if (data_phase) { err = can_set_timing_data(dev, &timing);
err = can_set_timing(dev, can_get_timing_min(dev), &timing);
} else {
err = can_set_timing(dev, &timing, can_get_timing_min_data(dev));
}
} else { } 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); 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)); const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
int err; int err;
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) { err = can_set_timing(dev, can_get_timing_min(dev));
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);
}
zassert_equal(err, 0, "failed to set minimum timing parameters (err %d)", err); 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)); const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_canbus));
int err; int err;
if (IS_ENABLED(CONFIG_CAN_FD_MODE)) { err = can_set_timing(dev, can_get_timing_max(dev));
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);
}
zassert_equal(err, 0, "failed to set maximum timing parameters (err %d)", err); 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) void test_main(void)