drivers: can: add CAN_MODE_FD
Add support for enabling/disabling CAN-FD frame transmission/reception at run-time. Fixes: #45303 Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
6a0f3fffb5
commit
9bd97eb0b8
3 changed files with 21 additions and 8 deletions
|
@ -246,10 +246,17 @@ int can_mcan_set_mode(const struct device *dev, can_mode_t mode)
|
||||||
struct can_mcan_reg *can = cfg->can;
|
struct can_mcan_reg *can = cfg->can;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
#ifdef CONFIG_CAN_FD_MODE
|
||||||
|
if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_LISTENONLY | CAN_MODE_FD)) != 0) {
|
||||||
|
LOG_ERR("unsupported mode: 0x%08x", mode);
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
#else
|
||||||
if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_LISTENONLY)) != 0) {
|
if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_LISTENONLY)) != 0) {
|
||||||
LOG_ERR("unsupported mode: 0x%08x", mode);
|
LOG_ERR("unsupported mode: 0x%08x", mode);
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
#endif /* CONFIG_CAN_FD_MODE */
|
||||||
|
|
||||||
if (cfg->phy != NULL) {
|
if (cfg->phy != NULL) {
|
||||||
ret = can_transceiver_enable(cfg->phy);
|
ret = can_transceiver_enable(cfg->phy);
|
||||||
|
@ -289,6 +296,14 @@ int can_mcan_set_mode(const struct device *dev, can_mode_t mode)
|
||||||
can->cccr &= ~CAN_MCAN_CCCR_MON;
|
can->cccr &= ~CAN_MCAN_CCCR_MON;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_CAN_FD_MODE
|
||||||
|
if ((mode & CAN_MODE_FD) != 0) {
|
||||||
|
can->cccr |= CAN_MCAN_CCCR_FDOE | CAN_MCAN_CCCR_BRSE;
|
||||||
|
} else {
|
||||||
|
can->cccr &= ~(CAN_MCAN_CCCR_FDOE | CAN_MCAN_CCCR_BRSE);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_CAN_FD_MODE */
|
||||||
|
|
||||||
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) {
|
||||||
LOG_ERR("Failed to leave init mode");
|
LOG_ERR("Failed to leave init mode");
|
||||||
|
@ -407,13 +422,8 @@ int can_mcan_init(const struct device *dev)
|
||||||
/ 16 + 5) << CAN_MCAN_RXESC_RBDS_POS);
|
/ 16 + 5) << CAN_MCAN_RXESC_RBDS_POS);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
can->cccr &= ~(CAN_MCAN_CCCR_FDOE | CAN_MCAN_CCCR_BRSE |
|
||||||
#ifdef CONFIG_CAN_FD_MODE
|
CAN_MCAN_CCCR_TEST | CAN_MCAN_CCCR_MON |
|
||||||
can->cccr |= CAN_MCAN_CCCR_FDOE | CAN_MCAN_CCCR_BRSE;
|
|
||||||
#else
|
|
||||||
can->cccr &= ~(CAN_MCAN_CCCR_FDOE | CAN_MCAN_CCCR_BRSE);
|
|
||||||
#endif
|
|
||||||
can->cccr &= ~(CAN_MCAN_CCCR_TEST | CAN_MCAN_CCCR_MON |
|
|
||||||
CAN_MCAN_CCCR_ASM);
|
CAN_MCAN_CCCR_ASM);
|
||||||
can->test &= ~(CAN_MCAN_TEST_LBCK);
|
can->test &= ~(CAN_MCAN_TEST_LBCK);
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,9 @@ extern "C" {
|
||||||
/** Controller is not allowed to send dominant bits. */
|
/** Controller is not allowed to send dominant bits. */
|
||||||
#define CAN_MODE_LISTENONLY BIT(1)
|
#define CAN_MODE_LISTENONLY BIT(1)
|
||||||
|
|
||||||
|
/** Controller allows transmitting/receiving CAN-FD frames. */
|
||||||
|
#define CAN_MODE_FD BIT(2)
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -349,7 +349,7 @@ static void test_set_loopback(void)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = can_set_mode(can_dev, CAN_MODE_LOOPBACK);
|
err = can_set_mode(can_dev, CAN_MODE_LOOPBACK | CAN_MODE_FD);
|
||||||
zassert_equal(err, 0, "failed to set loopback-mode (err %d)", err);
|
zassert_equal(err, 0, "failed to set loopback-mode (err %d)", err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue