drivers: can: convert enum can_mode to a bit field
Convert the can_mode enum to a bit field to prepare for future extensions (CAN-FD mode, transmitter delay compensation, one-shot mode, 3-samples mode, ...). Rename the existing modes: - CAN_NORMAL_MODE -> CAN_MODE_NORMAL - CAN_SILENT_MODE -> CAN_MODE_LISTENONLY - CAN_LOOPBACK_MODE -> CAN_MODE_LOOPBACK These mode names align with the Linux naming for CAN control modes. The old CAN_SILENT_LOOPBACK_MODE can be set with the bitmask (CAN_MODE_LISTENONLY | CAN_MODE_LOOPBACK). Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
85c2c9147b
commit
3f97d11afd
25 changed files with 155 additions and 110 deletions
|
@ -179,13 +179,18 @@ static int mcux_flexcan_set_timing(const struct device *dev,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int mcux_flexcan_set_mode(const struct device *dev, enum can_mode mode)
|
||||
static int mcux_flexcan_set_mode(const struct device *dev, can_mode_t mode)
|
||||
{
|
||||
const struct mcux_flexcan_config *config = dev->config;
|
||||
uint32_t ctrl1;
|
||||
uint32_t mcr;
|
||||
int err;
|
||||
|
||||
if ((mode & ~(CAN_MODE_LOOPBACK | CAN_MODE_LISTENONLY)) != 0) {
|
||||
LOG_ERR("unsupported mode: 0x%08x", mode);
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
if (config->phy != NULL) {
|
||||
err = can_transceiver_enable(config->phy);
|
||||
if (err != 0) {
|
||||
|
@ -199,7 +204,7 @@ static int mcux_flexcan_set_mode(const struct device *dev, enum can_mode mode)
|
|||
ctrl1 = config->base->CTRL1;
|
||||
mcr = config->base->MCR;
|
||||
|
||||
if (mode == CAN_LOOPBACK_MODE || mode == CAN_SILENT_LOOPBACK_MODE) {
|
||||
if ((mode & CAN_MODE_LOOPBACK) != 0) {
|
||||
/* Enable loopback and self-reception */
|
||||
ctrl1 |= CAN_CTRL1_LPB_MASK;
|
||||
mcr &= ~(CAN_MCR_SRXDIS_MASK);
|
||||
|
@ -209,7 +214,7 @@ static int mcux_flexcan_set_mode(const struct device *dev, enum can_mode mode)
|
|||
mcr |= CAN_MCR_SRXDIS_MASK;
|
||||
}
|
||||
|
||||
if (mode == CAN_SILENT_MODE || mode == CAN_SILENT_LOOPBACK_MODE) {
|
||||
if ((mode & CAN_MODE_LISTENONLY) != 0) {
|
||||
/* Enable listen-only mode */
|
||||
ctrl1 |= CAN_CTRL1_LOM_MASK;
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue