drivers: can: deprecate the use of CAN-specific error return values
Deprecate the use of CAN-specific error return values and replace them with standard errno values. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
28d9b5428b
commit
f499559434
18 changed files with 162 additions and 152 deletions
|
@ -164,7 +164,7 @@ a mailbox. When a transmitting mailbox is assigned, sending cannot be canceled.
|
||||||
can_dev = device_get_binding("CAN_0");
|
can_dev = device_get_binding("CAN_0");
|
||||||
|
|
||||||
ret = can_send(can_dev, &frame, K_MSEC(100), NULL, NULL);
|
ret = can_send(can_dev, &frame, K_MSEC(100), NULL, NULL);
|
||||||
if (ret != CAN_TX_OK) {
|
if (ret != 0) {
|
||||||
LOG_ERR("Sending failed [%d]", ret);
|
LOG_ERR("Sending failed [%d]", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ void tx_thread(void *data_arg, void *arg2, void *arg3)
|
||||||
if (!frame.cb) {
|
if (!frame.cb) {
|
||||||
k_sem_give(frame.tx_compl);
|
k_sem_give(frame.tx_compl);
|
||||||
} else {
|
} else {
|
||||||
frame.cb(CAN_TX_OK, frame.cb_arg);
|
frame.cb(0, frame.cb_arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ int can_loopback_send(const struct device *dev,
|
||||||
|
|
||||||
if (frame->dlc > CAN_MAX_DLC) {
|
if (frame->dlc > CAN_MAX_DLC) {
|
||||||
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data->loopback) {
|
if (!data->loopback) {
|
||||||
|
@ -118,7 +118,7 @@ int can_loopback_send(const struct device *dev,
|
||||||
k_sem_take(&tx_sem, K_FOREVER);
|
k_sem_take(&tx_sem, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret ? CAN_TIMEOUT : CAN_TX_OK;
|
return ret ? -EAGAIN : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ static inline int get_free_filter(struct can_loopback_filter *filters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_loopback_attach_isr(const struct device *dev, can_rx_callback_t isr,
|
int can_loopback_attach_isr(const struct device *dev, can_rx_callback_t isr,
|
||||||
|
|
|
@ -34,7 +34,7 @@ static int can_exit_sleep_mode(struct can_mcan_reg *can)
|
||||||
if (k_cycle_get_32() - start_time >
|
if (k_cycle_get_32() - start_time >
|
||||||
k_ms_to_cyc_ceil32(CAN_INIT_TIMEOUT)) {
|
k_ms_to_cyc_ceil32(CAN_INIT_TIMEOUT)) {
|
||||||
can->cccr |= CAN_MCAN_CCCR_CSR;
|
can->cccr |= CAN_MCAN_CCCR_CSR;
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ static int can_enter_init_mode(struct can_mcan_reg *can, k_timeout_t timeout)
|
||||||
while ((can->cccr & CAN_MCAN_CCCR_INIT) == 0U) {
|
while ((can->cccr & CAN_MCAN_CCCR_INIT) == 0U) {
|
||||||
if (k_uptime_ticks() - start_time > timeout.ticks) {
|
if (k_uptime_ticks() - start_time > timeout.ticks) {
|
||||||
can->cccr &= ~CAN_MCAN_CCCR_INIT;
|
can->cccr &= ~CAN_MCAN_CCCR_INIT;
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ static int can_leave_init_mode(struct can_mcan_reg *can, k_timeout_t timeout)
|
||||||
|
|
||||||
while ((can->cccr & CAN_MCAN_CCCR_INIT) != 0U) {
|
while ((can->cccr & CAN_MCAN_CCCR_INIT) != 0U) {
|
||||||
if (k_uptime_ticks() - start_time > timeout.ticks) {
|
if (k_uptime_ticks() - start_time > timeout.ticks) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -431,7 +431,7 @@ static void can_mcan_tc_event_handler(struct can_mcan_reg *can,
|
||||||
if (tx_cb == NULL) {
|
if (tx_cb == NULL) {
|
||||||
k_sem_give(&data->tx_fin_sem[tx_idx]);
|
k_sem_give(&data->tx_fin_sem[tx_idx]);
|
||||||
} else {
|
} else {
|
||||||
tx_cb(CAN_TX_OK, data->tx_fin_cb_arg[tx_idx]);
|
tx_cb(0, data->tx_fin_cb_arg[tx_idx]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -658,21 +658,21 @@ int can_mcan_send(const struct can_mcan_config *cfg,
|
||||||
if (data_length > sizeof(frame->data)) {
|
if (data_length > sizeof(frame->data)) {
|
||||||
LOG_ERR("data length (%zu) > max frame data length (%zu)",
|
LOG_ERR("data length (%zu) > max frame data length (%zu)",
|
||||||
data_length, sizeof(frame->data));
|
data_length, sizeof(frame->data));
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frame->fd != 1 && frame->dlc > MCAN_MAX_DLC) {
|
if (frame->fd != 1 && frame->dlc > MCAN_MAX_DLC) {
|
||||||
LOG_ERR("DLC of %d without fd flag set.", frame->dlc);
|
LOG_ERR("DLC of %d without fd flag set.", frame->dlc);
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (can->psr & CAN_MCAN_PSR_BO) {
|
if (can->psr & CAN_MCAN_PSR_BO) {
|
||||||
return CAN_TX_BUS_OFF;
|
return -ENETDOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = k_sem_take(&data->tx_sem, timeout);
|
ret = k_sem_take(&data->tx_sem, timeout);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
__ASSERT_NO_MSG((can->txfqs & CAN_MCAN_TXFQS_TFQF) !=
|
__ASSERT_NO_MSG((can->txfqs & CAN_MCAN_TXFQS_TFQF) !=
|
||||||
|
@ -715,7 +715,7 @@ int can_mcan_send(const struct can_mcan_config *cfg,
|
||||||
k_sem_take(&data->tx_fin_sem[put_idx], K_FOREVER);
|
k_sem_take(&data->tx_fin_sem[put_idx], K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_TX_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int can_mcan_get_free_std(volatile struct can_mcan_std_filter *filters)
|
static int can_mcan_get_free_std(volatile struct can_mcan_std_filter *filters)
|
||||||
|
@ -726,7 +726,7 @@ static int can_mcan_get_free_std(volatile struct can_mcan_std_filter *filters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use masked configuration only for simplicity. If someone needs more than
|
/* Use masked configuration only for simplicity. If someone needs more than
|
||||||
|
@ -749,9 +749,9 @@ int can_mcan_attach_std(struct can_mcan_data *data,
|
||||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||||
filter_nr = can_mcan_get_free_std(msg_ram->std_filt);
|
filter_nr = can_mcan_get_free_std(msg_ram->std_filt);
|
||||||
|
|
||||||
if (filter_nr == CAN_NO_FREE_FILTER) {
|
if (filter_nr == -ENOSPC) {
|
||||||
LOG_INF("No free standard id filter left");
|
LOG_INF("No free standard id filter left");
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO propper fifo balancing */
|
/* TODO propper fifo balancing */
|
||||||
|
@ -790,7 +790,7 @@ static int can_mcan_get_free_ext(volatile struct can_mcan_ext_filter *filters)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int can_mcan_attach_ext(struct can_mcan_data *data,
|
static int can_mcan_attach_ext(struct can_mcan_data *data,
|
||||||
|
@ -808,9 +808,9 @@ static int can_mcan_attach_ext(struct can_mcan_data *data,
|
||||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||||
filter_nr = can_mcan_get_free_ext(msg_ram->ext_filt);
|
filter_nr = can_mcan_get_free_ext(msg_ram->ext_filt);
|
||||||
|
|
||||||
if (filter_nr == CAN_NO_FREE_FILTER) {
|
if (filter_nr == -ENOSPC) {
|
||||||
LOG_INF("No free extender id filter left");
|
LOG_INF("No free extender id filter left");
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO propper fifo balancing */
|
/* TODO propper fifo balancing */
|
||||||
|
@ -861,7 +861,7 @@ int can_mcan_attach_isr(struct can_mcan_data *data,
|
||||||
filter_nr += NUM_STD_FILTER_DATA;
|
filter_nr += NUM_STD_FILTER_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter_nr == CAN_NO_FREE_FILTER) {
|
if (filter_nr == -ENOSPC) {
|
||||||
LOG_INF("No free filter left");
|
LOG_INF("No free filter left");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -470,11 +470,11 @@ static int mcp2515_send(const struct device *dev,
|
||||||
if (frame->dlc > CAN_MAX_DLC) {
|
if (frame->dlc > CAN_MAX_DLC) {
|
||||||
LOG_ERR("DLC of %d exceeds maximum (%d)",
|
LOG_ERR("DLC of %d exceeds maximum (%d)",
|
||||||
frame->dlc, CAN_MAX_DLC);
|
frame->dlc, CAN_MAX_DLC);
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k_sem_take(&dev_data->tx_sem, timeout) != 0) {
|
if (k_sem_take(&dev_data->tx_sem, timeout) != 0) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_mutex_lock(&dev_data->mutex, K_FOREVER);
|
k_mutex_lock(&dev_data->mutex, K_FOREVER);
|
||||||
|
@ -491,7 +491,7 @@ static int mcp2515_send(const struct device *dev,
|
||||||
|
|
||||||
if (tx_idx == MCP2515_TX_CNT) {
|
if (tx_idx == MCP2515_TX_CNT) {
|
||||||
LOG_WRN("no free tx slot available");
|
LOG_WRN("no free tx slot available");
|
||||||
return CAN_TX_ERR;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
dev_data->tx_cb[tx_idx].cb = callback;
|
dev_data->tx_cb[tx_idx].cb = callback;
|
||||||
|
@ -545,7 +545,7 @@ static int mcp2515_attach_isr(const struct device *dev,
|
||||||
dev_data->cb_arg[filter_idx] = cb_arg;
|
dev_data->cb_arg[filter_idx] = cb_arg;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
filter_idx = CAN_NO_FREE_FILTER;
|
filter_idx = -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_mutex_unlock(&dev_data->mutex);
|
k_mutex_unlock(&dev_data->mutex);
|
||||||
|
|
|
@ -328,7 +328,7 @@ static int mcux_flexcan_send(const struct device *dev,
|
||||||
|
|
||||||
if (frame->dlc > CAN_MAX_DLC) {
|
if (frame->dlc > CAN_MAX_DLC) {
|
||||||
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -342,7 +342,7 @@ static int mcux_flexcan_send(const struct device *dev,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k_sem_take(&data->tx_allocs_sem, timeout) != 0) {
|
if (k_sem_take(&data->tx_allocs_sem, timeout) != 0) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ static int mcux_flexcan_send(const struct device *dev,
|
||||||
status = FLEXCAN_TransferSendNonBlocking(config->base, &data->handle,
|
status = FLEXCAN_TransferSendNonBlocking(config->base, &data->handle,
|
||||||
&xfer);
|
&xfer);
|
||||||
if (status != kStatus_Success) {
|
if (status != kStatus_Success) {
|
||||||
return CAN_TX_ERR;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback == NULL) {
|
if (callback == NULL) {
|
||||||
|
@ -363,7 +363,7 @@ static int mcux_flexcan_send(const struct device *dev,
|
||||||
return data->tx_cbs[alloc].status;
|
return data->tx_cbs[alloc].status;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_TX_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mcux_flexcan_attach_isr(const struct device *dev,
|
static int mcux_flexcan_attach_isr(const struct device *dev,
|
||||||
|
@ -376,7 +376,7 @@ static int mcux_flexcan_attach_isr(const struct device *dev,
|
||||||
flexcan_mb_transfer_t xfer;
|
flexcan_mb_transfer_t xfer;
|
||||||
status_t status;
|
status_t status;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
int alloc = CAN_NO_FREE_FILTER;
|
int alloc = -ENOSPC;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
__ASSERT_NO_MSG(isr);
|
__ASSERT_NO_MSG(isr);
|
||||||
|
@ -391,7 +391,7 @@ static int mcux_flexcan_attach_isr(const struct device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (alloc == CAN_NO_FREE_FILTER) {
|
if (alloc == -ENOSPC) {
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,7 +414,7 @@ static int mcux_flexcan_attach_isr(const struct device *dev,
|
||||||
if (status != kStatus_Success) {
|
if (status != kStatus_Success) {
|
||||||
LOG_ERR("Failed to start rx for filter id %d (err = %d)",
|
LOG_ERR("Failed to start rx for filter id %d (err = %d)",
|
||||||
alloc, status);
|
alloc, status);
|
||||||
alloc = CAN_NO_FREE_FILTER;
|
alloc = -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_mutex_unlock(&data->rx_mutex);
|
k_mutex_unlock(&data->rx_mutex);
|
||||||
|
@ -473,7 +473,7 @@ int mcux_flexcan_recover(const struct device *dev, k_timeout_t timeout)
|
||||||
while (mcux_flexcan_get_state(dev, NULL) == CAN_BUS_OFF) {
|
while (mcux_flexcan_get_state(dev, NULL) == CAN_BUS_OFF) {
|
||||||
if (!K_TIMEOUT_EQ(timeout, K_FOREVER) &&
|
if (!K_TIMEOUT_EQ(timeout, K_FOREVER) &&
|
||||||
k_uptime_ticks() - start_time >= timeout.ticks) {
|
k_uptime_ticks() - start_time >= timeout.ticks) {
|
||||||
ret = CAN_TIMEOUT;
|
ret = -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -518,7 +518,7 @@ static inline void mcux_flexcan_transfer_error_status(const struct device *dev,
|
||||||
const struct mcux_flexcan_config *config = dev->config;
|
const struct mcux_flexcan_config *config = dev->config;
|
||||||
struct mcux_flexcan_data *data = dev->data;
|
struct mcux_flexcan_data *data = dev->data;
|
||||||
can_tx_callback_t function;
|
can_tx_callback_t function;
|
||||||
int status = CAN_TX_OK;
|
int status = 0;
|
||||||
void *arg;
|
void *arg;
|
||||||
int alloc;
|
int alloc;
|
||||||
enum can_state state;
|
enum can_state state;
|
||||||
|
@ -526,14 +526,14 @@ static inline void mcux_flexcan_transfer_error_status(const struct device *dev,
|
||||||
|
|
||||||
if (error & CAN_ESR1_FLTCONF(2)) {
|
if (error & CAN_ESR1_FLTCONF(2)) {
|
||||||
LOG_DBG("Tx bus off (error 0x%08llx)", error);
|
LOG_DBG("Tx bus off (error 0x%08llx)", error);
|
||||||
status = CAN_TX_BUS_OFF;
|
status = -ENETDOWN;
|
||||||
} else if ((error & kFLEXCAN_Bit0Error) ||
|
} else if ((error & kFLEXCAN_Bit0Error) ||
|
||||||
(error & kFLEXCAN_Bit1Error)) {
|
(error & kFLEXCAN_Bit1Error)) {
|
||||||
LOG_DBG("TX arbitration lost (error 0x%08llx)", error);
|
LOG_DBG("TX arbitration lost (error 0x%08llx)", error);
|
||||||
status = CAN_TX_ARB_LOST;
|
status = -EBUSY;
|
||||||
} else if (error & kFLEXCAN_AckError) {
|
} else if (error & kFLEXCAN_AckError) {
|
||||||
LOG_DBG("TX no ACK received (error 0x%08llx)", error);
|
LOG_DBG("TX no ACK received (error 0x%08llx)", error);
|
||||||
status = CAN_TX_ERR;
|
status = -EIO;
|
||||||
} else if (error & kFLEXCAN_StuffingError) {
|
} else if (error & kFLEXCAN_StuffingError) {
|
||||||
LOG_DBG("RX stuffing error (error 0x%08llx)", error);
|
LOG_DBG("RX stuffing error (error 0x%08llx)", error);
|
||||||
} else if (error & kFLEXCAN_FormError) {
|
} else if (error & kFLEXCAN_FormError) {
|
||||||
|
@ -552,7 +552,7 @@ static inline void mcux_flexcan_transfer_error_status(const struct device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (status == CAN_TX_OK) {
|
if (status == 0) {
|
||||||
/*
|
/*
|
||||||
* Error/status is not TX related. No further action
|
* Error/status is not TX related. No further action
|
||||||
* required.
|
* required.
|
||||||
|
@ -605,9 +605,9 @@ static inline void mcux_flexcan_transfer_tx_idle(const struct device *dev,
|
||||||
|
|
||||||
if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) {
|
if (atomic_test_and_clear_bit(data->tx_allocs, alloc)) {
|
||||||
if (function != NULL) {
|
if (function != NULL) {
|
||||||
function(CAN_TX_OK, arg);
|
function(0, arg);
|
||||||
} else {
|
} else {
|
||||||
data->tx_cbs[alloc].status = CAN_TX_OK;
|
data->tx_cbs[alloc].status = 0;
|
||||||
k_sem_give(&data->tx_cbs[alloc].done);
|
k_sem_give(&data->tx_cbs[alloc].done);
|
||||||
}
|
}
|
||||||
k_sem_give(&data->tx_allocs_sem);
|
k_sem_give(&data->tx_allocs_sem);
|
||||||
|
|
|
@ -232,7 +232,7 @@ static void can_rcar_tx_done(const struct device *dev)
|
||||||
|
|
||||||
data->tx_unsent--;
|
data->tx_unsent--;
|
||||||
if (tx_cb->cb != NULL) {
|
if (tx_cb->cb != NULL) {
|
||||||
tx_cb->cb(CAN_TX_OK, tx_cb->cb_arg);
|
tx_cb->cb(0, tx_cb->cb_arg);
|
||||||
} else {
|
} else {
|
||||||
k_sem_give(&tx_cb->sem);
|
k_sem_give(&tx_cb->sem);
|
||||||
}
|
}
|
||||||
|
@ -494,7 +494,7 @@ static int can_rcar_leave_sleep_mode(const struct can_rcar_cfg *config)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int can_rcar_enter_reset_mode(const struct can_rcar_cfg *config, bool force)
|
static int can_rcar_enter_reset_mode(const struct can_rcar_cfg *config, bool force)
|
||||||
|
@ -514,7 +514,7 @@ static int can_rcar_enter_reset_mode(const struct can_rcar_cfg *config, bool for
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int can_rcar_enter_halt_mode(const struct can_rcar_cfg *config)
|
static int can_rcar_enter_halt_mode(const struct can_rcar_cfg *config)
|
||||||
|
@ -532,7 +532,7 @@ static int can_rcar_enter_halt_mode(const struct can_rcar_cfg *config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int can_rcar_enter_operation_mode(const struct can_rcar_cfg *config)
|
static int can_rcar_enter_operation_mode(const struct can_rcar_cfg *config)
|
||||||
|
@ -552,7 +552,7 @@ static int can_rcar_enter_operation_mode(const struct can_rcar_cfg *config)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i == MAX_STR_READS) {
|
if (i == MAX_STR_READS) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable Rx and Tx FIFO */
|
/* Enable Rx and Tx FIFO */
|
||||||
|
@ -688,7 +688,7 @@ int can_rcar_recover(const struct device *dev, k_timeout_t timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k_mutex_lock(&data->inst_mutex, K_FOREVER)) {
|
if (k_mutex_lock(&data->inst_mutex, K_FOREVER)) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
start_time = k_uptime_ticks();
|
start_time = k_uptime_ticks();
|
||||||
|
@ -700,7 +700,7 @@ int can_rcar_recover(const struct device *dev, k_timeout_t timeout)
|
||||||
|
|
||||||
if (!K_TIMEOUT_EQ(timeout, K_FOREVER) &&
|
if (!K_TIMEOUT_EQ(timeout, K_FOREVER) &&
|
||||||
k_uptime_ticks() - start_time >= timeout.ticks) {
|
k_uptime_ticks() - start_time >= timeout.ticks) {
|
||||||
ret = CAN_TIMEOUT;
|
ret = -EAGAIN;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,12 +736,12 @@ int can_rcar_send(const struct device *dev, const struct zcan_frame *frame,
|
||||||
if (frame->dlc > CAN_MAX_DLC) {
|
if (frame->dlc > CAN_MAX_DLC) {
|
||||||
LOG_ERR("DLC of %d exceeds maximum (%d)",
|
LOG_ERR("DLC of %d exceeds maximum (%d)",
|
||||||
frame->dlc, CAN_MAX_DLC);
|
frame->dlc, CAN_MAX_DLC);
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for a slot into the tx FIFO */
|
/* Wait for a slot into the tx FIFO */
|
||||||
if (k_sem_take(&data->tx_sem, timeout) != 0) {
|
if (k_sem_take(&data->tx_sem, timeout) != 0) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||||
|
@ -788,7 +788,7 @@ int can_rcar_send(const struct device *dev, const struct zcan_frame *frame,
|
||||||
k_sem_take(&tx_cb->sem, K_FOREVER);
|
k_sem_take(&tx_cb->sem, K_FOREVER);
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_TX_OK;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int can_rcar_attach(const struct device *dev,
|
static inline int can_rcar_attach(const struct device *dev,
|
||||||
|
@ -809,7 +809,7 @@ static inline int can_rcar_attach(const struct device *dev,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
int can_rcar_attach_isr(const struct device *dev, can_rx_callback_t isr,
|
int can_rcar_attach_isr(const struct device *dev, can_rx_callback_t isr,
|
||||||
|
|
|
@ -371,7 +371,7 @@ static int cmd_attach(const struct shell *shell, size_t argc, char **argv)
|
||||||
ret = can_attach_workq(can_dev, &k_sys_work_q, &work, print_frame,
|
ret = can_attach_workq(can_dev, &k_sys_work_q, &work, print_frame,
|
||||||
(void *)shell, &filter);
|
(void *)shell, &filter);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
if (ret == CAN_NO_FREE_FILTER) {
|
if (ret == -ENOSPC) {
|
||||||
shell_error(shell, "Can't attach, no free filter left");
|
shell_error(shell, "Can't attach, no free filter left");
|
||||||
} else {
|
} else {
|
||||||
shell_error(shell, "Failed to attach filter [%d]", ret);
|
shell_error(shell, "Failed to attach filter [%d]", ret);
|
||||||
|
|
|
@ -152,11 +152,11 @@ void can_stm32_tx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
|
||||||
|
|
||||||
if ((can->TSR & CAN_TSR_RQCP0) | bus_off) {
|
if ((can->TSR & CAN_TSR_RQCP0) | bus_off) {
|
||||||
data->mb0.error_flags =
|
data->mb0.error_flags =
|
||||||
can->TSR & CAN_TSR_TXOK0 ? CAN_TX_OK :
|
can->TSR & CAN_TSR_TXOK0 ? 0 :
|
||||||
can->TSR & CAN_TSR_TERR0 ? CAN_TX_ERR :
|
can->TSR & CAN_TSR_TERR0 ? -EIO :
|
||||||
can->TSR & CAN_TSR_ALST0 ? CAN_TX_ARB_LOST :
|
can->TSR & CAN_TSR_ALST0 ? -EBUSY :
|
||||||
bus_off ? CAN_TX_BUS_OFF :
|
bus_off ? -ENETDOWN :
|
||||||
CAN_TX_UNKNOWN;
|
-EIO;
|
||||||
/* clear the request. */
|
/* clear the request. */
|
||||||
can->TSR |= CAN_TSR_RQCP0;
|
can->TSR |= CAN_TSR_RQCP0;
|
||||||
can_stm32_signal_tx_complete(&data->mb0);
|
can_stm32_signal_tx_complete(&data->mb0);
|
||||||
|
@ -164,11 +164,11 @@ void can_stm32_tx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
|
||||||
|
|
||||||
if ((can->TSR & CAN_TSR_RQCP1) | bus_off) {
|
if ((can->TSR & CAN_TSR_RQCP1) | bus_off) {
|
||||||
data->mb1.error_flags =
|
data->mb1.error_flags =
|
||||||
can->TSR & CAN_TSR_TXOK1 ? CAN_TX_OK :
|
can->TSR & CAN_TSR_TXOK1 ? 0 :
|
||||||
can->TSR & CAN_TSR_TERR1 ? CAN_TX_ERR :
|
can->TSR & CAN_TSR_TERR1 ? -EIO :
|
||||||
can->TSR & CAN_TSR_ALST1 ? CAN_TX_ARB_LOST :
|
can->TSR & CAN_TSR_ALST1 ? -EBUSY :
|
||||||
bus_off ? CAN_TX_BUS_OFF :
|
bus_off ? -ENETDOWN :
|
||||||
CAN_TX_UNKNOWN;
|
-EIO;
|
||||||
/* clear the request. */
|
/* clear the request. */
|
||||||
can->TSR |= CAN_TSR_RQCP1;
|
can->TSR |= CAN_TSR_RQCP1;
|
||||||
can_stm32_signal_tx_complete(&data->mb1);
|
can_stm32_signal_tx_complete(&data->mb1);
|
||||||
|
@ -176,11 +176,11 @@ void can_stm32_tx_isr_handler(CAN_TypeDef *can, struct can_stm32_data *data)
|
||||||
|
|
||||||
if ((can->TSR & CAN_TSR_RQCP2) | bus_off) {
|
if ((can->TSR & CAN_TSR_RQCP2) | bus_off) {
|
||||||
data->mb2.error_flags =
|
data->mb2.error_flags =
|
||||||
can->TSR & CAN_TSR_TXOK2 ? CAN_TX_OK :
|
can->TSR & CAN_TSR_TXOK2 ? 0 :
|
||||||
can->TSR & CAN_TSR_TERR2 ? CAN_TX_ERR :
|
can->TSR & CAN_TSR_TERR2 ? -EIO :
|
||||||
can->TSR & CAN_TSR_ALST2 ? CAN_TX_ARB_LOST :
|
can->TSR & CAN_TSR_ALST2 ? -EBUSY :
|
||||||
bus_off ? CAN_TX_BUS_OFF :
|
bus_off ? -ENETDOWN :
|
||||||
CAN_TX_UNKNOWN;
|
-EIO;
|
||||||
/* clear the request. */
|
/* clear the request. */
|
||||||
can->TSR |= CAN_TSR_RQCP2;
|
can->TSR |= CAN_TSR_RQCP2;
|
||||||
can_stm32_signal_tx_complete(&data->mb2);
|
can_stm32_signal_tx_complete(&data->mb2);
|
||||||
|
@ -270,7 +270,7 @@ static int can_enter_init_mode(CAN_TypeDef *can)
|
||||||
while ((can->MSR & CAN_MSR_INAK) == 0U) {
|
while ((can->MSR & CAN_MSR_INAK) == 0U) {
|
||||||
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
||||||
can->MCR &= ~CAN_MCR_INRQ;
|
can->MCR &= ~CAN_MCR_INRQ;
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ static int can_leave_init_mode(CAN_TypeDef *can)
|
||||||
|
|
||||||
while ((can->MSR & CAN_MSR_INAK) != 0U) {
|
while ((can->MSR & CAN_MSR_INAK) != 0U) {
|
||||||
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +302,7 @@ static int can_leave_sleep_mode(CAN_TypeDef *can)
|
||||||
|
|
||||||
while ((can->MSR & CAN_MSR_SLAK) != 0) {
|
while ((can->MSR & CAN_MSR_SLAK) != 0) {
|
||||||
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -570,7 +570,7 @@ int can_stm32_recover(const struct device *dev, k_timeout_t timeout)
|
||||||
const struct can_stm32_config *cfg = DEV_CFG(dev);
|
const struct can_stm32_config *cfg = DEV_CFG(dev);
|
||||||
struct can_stm32_data *data = DEV_DATA(dev);
|
struct can_stm32_data *data = DEV_DATA(dev);
|
||||||
CAN_TypeDef *can = cfg->can;
|
CAN_TypeDef *can = cfg->can;
|
||||||
int ret = CAN_TIMEOUT;
|
int ret = -EAGAIN;
|
||||||
int64_t start_time;
|
int64_t start_time;
|
||||||
|
|
||||||
if (!(can->ESR & CAN_ESR_BOFF)) {
|
if (!(can->ESR & CAN_ESR_BOFF)) {
|
||||||
|
@ -578,7 +578,7 @@ int can_stm32_recover(const struct device *dev, k_timeout_t timeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (k_mutex_lock(&data->inst_mutex, K_FOREVER)) {
|
if (k_mutex_lock(&data->inst_mutex, K_FOREVER)) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = can_enter_init_mode(can);
|
ret = can_enter_init_mode(can);
|
||||||
|
@ -631,11 +631,11 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *frame,
|
||||||
|
|
||||||
if (frame->dlc > CAN_MAX_DLC) {
|
if (frame->dlc > CAN_MAX_DLC) {
|
||||||
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
LOG_ERR("DLC of %d exceeds maximum (%d)", frame->dlc, CAN_MAX_DLC);
|
||||||
return CAN_TX_EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (can->ESR & CAN_ESR_BOFF) {
|
if (can->ESR & CAN_ESR_BOFF) {
|
||||||
return CAN_TX_BUS_OFF;
|
return -ENETDOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||||
|
@ -643,7 +643,7 @@ int can_stm32_send(const struct device *dev, const struct zcan_frame *frame,
|
||||||
k_mutex_unlock(&data->inst_mutex);
|
k_mutex_unlock(&data->inst_mutex);
|
||||||
LOG_DBG("Transmit buffer full");
|
LOG_DBG("Transmit buffer full");
|
||||||
if (k_sem_take(&data->tx_int_sem, timeout)) {
|
if (k_sem_take(&data->tx_int_sem, timeout)) {
|
||||||
return CAN_TIMEOUT;
|
return -EAGAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
k_mutex_lock(&data->inst_mutex, K_FOREVER);
|
||||||
|
@ -717,7 +717,7 @@ static int can_stm32_shift_arr(void **arr, int start, int count)
|
||||||
size_t cnt;
|
size_t cnt;
|
||||||
|
|
||||||
if (start > CONFIG_CAN_MAX_FILTER) {
|
if (start > CONFIG_CAN_MAX_FILTER) {
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
|
@ -726,7 +726,7 @@ static int can_stm32_shift_arr(void **arr, int start, int count)
|
||||||
/* Check if nothing used will be overwritten */
|
/* Check if nothing used will be overwritten */
|
||||||
if (!can_stm32_check_free(arr, CONFIG_CAN_MAX_FILTER - count,
|
if (!can_stm32_check_free(arr, CONFIG_CAN_MAX_FILTER - count,
|
||||||
CONFIG_CAN_MAX_FILTER - 1)) {
|
CONFIG_CAN_MAX_FILTER - 1)) {
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* No need to shift. Destination is already outside the arr*/
|
/* No need to shift. Destination is already outside the arr*/
|
||||||
|
@ -742,7 +742,7 @@ static int can_stm32_shift_arr(void **arr, int start, int count)
|
||||||
count = -count;
|
count = -count;
|
||||||
|
|
||||||
if (start - count < 0) {
|
if (start - count < 0) {
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
cnt = (CONFIG_CAN_MAX_FILTER - start) * sizeof(void *);
|
cnt = (CONFIG_CAN_MAX_FILTER - start) * sizeof(void *);
|
||||||
|
@ -889,7 +889,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter,
|
||||||
uint32_t mask = 0U;
|
uint32_t mask = 0U;
|
||||||
uint32_t id = 0U;
|
uint32_t id = 0U;
|
||||||
int filter_nr = 0;
|
int filter_nr = 0;
|
||||||
int filter_index_new = CAN_NO_FREE_FILTER;
|
int filter_index_new = -ENOSPC;
|
||||||
int bank_nr;
|
int bank_nr;
|
||||||
uint32_t bank_bit;
|
uint32_t bank_bit;
|
||||||
int register_demand;
|
int register_demand;
|
||||||
|
@ -952,7 +952,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter,
|
||||||
|
|
||||||
if (!usage_shifted) {
|
if (!usage_shifted) {
|
||||||
LOG_INF("No free filter bank found");
|
LOG_INF("No free filter bank found");
|
||||||
return CAN_NO_FREE_FILTER;
|
return -ENOSPC;
|
||||||
}
|
}
|
||||||
} while (filter_nr < CAN_MAX_NUMBER_OF_FILTERS);
|
} while (filter_nr < CAN_MAX_NUMBER_OF_FILTERS);
|
||||||
|
|
||||||
|
@ -988,7 +988,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter,
|
||||||
|
|
||||||
if (filter_index_new >= CONFIG_CAN_MAX_FILTER || res) {
|
if (filter_index_new >= CONFIG_CAN_MAX_FILTER || res) {
|
||||||
LOG_INF("No space for a new filter!");
|
LOG_INF("No space for a new filter!");
|
||||||
filter_nr = CAN_NO_FREE_FILTER;
|
filter_nr = -ENOSPC;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -999,7 +999,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter,
|
||||||
filter_index_new = can_calc_filter_index(filter_nr, can->FM1R,
|
filter_index_new = can_calc_filter_index(filter_nr, can->FM1R,
|
||||||
can->FS1R);
|
can->FS1R);
|
||||||
if (filter_index_new >= CAN_MAX_NUMBER_OF_FILTERS) {
|
if (filter_index_new >= CAN_MAX_NUMBER_OF_FILTERS) {
|
||||||
filter_nr = CAN_NO_FREE_FILTER;
|
filter_nr = -ENOSPC;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1027,7 @@ static inline int can_stm32_attach(const struct device *dev,
|
||||||
int filter_nr;
|
int filter_nr;
|
||||||
|
|
||||||
filter_nr = can_stm32_set_filter(filter, data, can, &filter_index);
|
filter_nr = can_stm32_set_filter(filter, data, can, &filter_index);
|
||||||
if (filter_nr != CAN_NO_FREE_FILTER) {
|
if (filter_nr != -ENOSPC) {
|
||||||
data->rx_cb[filter_index] = cb;
|
data->rx_cb[filter_index] = cb;
|
||||||
data->cb_arg[filter_index] = cb_arg;
|
data->cb_arg[filter_index] = cb_arg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ static inline int socket_can_setsockopt(const struct device *dev, void *obj,
|
||||||
|
|
||||||
ret = can_attach_msgq(socket_context->can_dev, socket_context->msgq,
|
ret = can_attach_msgq(socket_context->can_dev, socket_context->msgq,
|
||||||
optval);
|
optval);
|
||||||
if (ret == CAN_NO_FREE_FILTER) {
|
if (ret == -ENOSPC) {
|
||||||
errno = ENOSPC;
|
errno = ENOSPC;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,25 +93,28 @@ extern "C" {
|
||||||
* `CAN_NO_FREE_FILTER` is returned by `can_attach_*()` if no free filters are
|
* `CAN_NO_FREE_FILTER` is returned by `can_attach_*()` if no free filters are
|
||||||
* available. `CAN_TIMEOUT` indicates that @a can_recover() timed out.
|
* available. `CAN_TIMEOUT` indicates that @a can_recover() timed out.
|
||||||
*
|
*
|
||||||
|
* @warning These definitions are deprecated. Use the corresponding errno
|
||||||
|
* definitions instead.
|
||||||
|
*
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** Transmitted successfully. */
|
/** Transmitted successfully. */
|
||||||
#define CAN_TX_OK (0)
|
#define CAN_TX_OK (0) __DEPRECATED_MACRO
|
||||||
/** General transmit error. */
|
/** General transmit error. */
|
||||||
#define CAN_TX_ERR (-2)
|
#define CAN_TX_ERR (-EIO) __DEPRECATED_MACRO
|
||||||
/** Bus arbitration lost during transmission. */
|
/** Bus arbitration lost during transmission. */
|
||||||
#define CAN_TX_ARB_LOST (-3)
|
#define CAN_TX_ARB_LOST (-EBUSY) __DEPRECATED_MACRO
|
||||||
/** CAN controller is in bus off state. */
|
/** CAN controller is in bus off state. */
|
||||||
#define CAN_TX_BUS_OFF (-4)
|
#define CAN_TX_BUS_OFF (-ENETDOWN) __DEPRECATED_MACRO
|
||||||
/** Unknown error. */
|
/** Unknown error. */
|
||||||
#define CAN_TX_UNKNOWN (-5)
|
#define CAN_TX_UNKNOWN (CAN_TX_ERR) __DEPRECATED_MACRO
|
||||||
/** Invalid parameter. */
|
/** Invalid parameter. */
|
||||||
#define CAN_TX_EINVAL (-22)
|
#define CAN_TX_EINVAL (-EINVAL) __DEPRECATED_MACRO
|
||||||
/** No free filters available. */
|
/** No free filters available. */
|
||||||
#define CAN_NO_FREE_FILTER (-1)
|
#define CAN_NO_FREE_FILTER (-ENOSPC) __DEPRECATED_MACRO
|
||||||
/** Operation timed out. */
|
/** Operation timed out. */
|
||||||
#define CAN_TIMEOUT (-1)
|
#define CAN_TIMEOUT (-EAGAIN) __DEPRECATED_MACRO
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
@ -294,7 +297,8 @@ struct can_timing {
|
||||||
* @typedef can_tx_callback_t
|
* @typedef can_tx_callback_t
|
||||||
* @brief Defines the application callback handler function signature
|
* @brief Defines the application callback handler function signature
|
||||||
*
|
*
|
||||||
* @param error_flags Status of the performed send operation.
|
* @param error_flags Status of the performed send operation. See the list of
|
||||||
|
* return values for @a can_send() for value descriptions.
|
||||||
* @param user_data User data provided when the frame was sent.
|
* @param user_data User data provided when the frame was sent.
|
||||||
*/
|
*/
|
||||||
typedef void (*can_tx_callback_t)(uint32_t error_flags, void *user_data);
|
typedef void (*can_tx_callback_t)(uint32_t error_flags, void *user_data);
|
||||||
|
@ -697,8 +701,12 @@ __deprecated static inline int can_configure(const struct device *dev, enum can_
|
||||||
* if called from user mode.
|
* if called from user mode.
|
||||||
* @param user_data User data to pass to callback function.
|
* @param user_data User data to pass to callback function.
|
||||||
*
|
*
|
||||||
* @retval 0 If successful.
|
* @retval 0 if successful.
|
||||||
* @retval CAN_TX_* on failure.
|
* @retval -EINVAL if an invalid parameter was passed to the function.
|
||||||
|
* @retval -ENETDOWN if the CAN controller is in bus-off state.
|
||||||
|
* @retval -EBUSY if CAN bus arbitration was lost.
|
||||||
|
* @retval -EIO if a general transmit error occurred.
|
||||||
|
* @retval -EAGAIN on timeout.
|
||||||
*/
|
*/
|
||||||
__syscall int can_send(const struct device *dev, const struct zcan_frame *frame,
|
__syscall int can_send(const struct device *dev, const struct zcan_frame *frame,
|
||||||
k_timeout_t timeout, can_tx_callback_t callback,
|
k_timeout_t timeout, can_tx_callback_t callback,
|
||||||
|
@ -727,10 +735,12 @@ static inline int z_impl_can_send(const struct device *dev, const struct zcan_fr
|
||||||
* @param rtr Write as data frame or Remote Transmission Request (RTR) frame.
|
* @param rtr Write as data frame or Remote Transmission Request (RTR) frame.
|
||||||
* @param timeout Timeout waiting for an empty TX mailbox or ``K_FOREVER``.
|
* @param timeout Timeout waiting for an empty TX mailbox or ``K_FOREVER``.
|
||||||
*
|
*
|
||||||
* @retval 0 If successful.
|
* @retval 0 if successful.
|
||||||
* @retval -EIO General input/output error.
|
* @retval -EINVAL if an invalid parameter was passed to the function.
|
||||||
* @retval -EINVAL if length > 8.
|
* @retval -ENETDOWN if the CAN controller is in bus-off state.
|
||||||
* @retval CAN_TX_* on failure.
|
* @retval -EBUSY if CAN bus arbitration was lost.
|
||||||
|
* @retval -EIO if a general transmit error occurred.
|
||||||
|
* @retval -EAGAIN on timeout.
|
||||||
*/
|
*/
|
||||||
static inline int can_write(const struct device *dev, const uint8_t *data, uint8_t length,
|
static inline int can_write(const struct device *dev, const uint8_t *data, uint8_t length,
|
||||||
uint32_t id, enum can_rtr rtr, k_timeout_t timeout)
|
uint32_t id, enum can_rtr rtr, k_timeout_t timeout)
|
||||||
|
@ -783,7 +793,7 @@ static inline int can_write(const struct device *dev, const uint8_t *data, uint8
|
||||||
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
||||||
*
|
*
|
||||||
* @retval filter_id on success.
|
* @retval filter_id on success.
|
||||||
* @retval CAN_NO_FREE_FILTER if there are no free filters.
|
* @retval -ENOSPC if there are no free filters.
|
||||||
*/
|
*/
|
||||||
static inline int can_attach_isr(const struct device *dev, can_rx_callback_t callback,
|
static inline int can_attach_isr(const struct device *dev, can_rx_callback_t callback,
|
||||||
void *user_data, const struct zcan_filter *filter)
|
void *user_data, const struct zcan_filter *filter)
|
||||||
|
@ -818,7 +828,7 @@ static inline int can_attach_isr(const struct device *dev, can_rx_callback_t cal
|
||||||
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
||||||
*
|
*
|
||||||
* @retval filter_id on success.
|
* @retval filter_id on success.
|
||||||
* @retval CAN_NO_FREE_FILTER if there are no free filters.
|
* @retval -ENOSPC if there are no free filters.
|
||||||
*/
|
*/
|
||||||
int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
||||||
struct zcan_work *work, can_rx_callback_t callback, void *user_data,
|
struct zcan_work *work, can_rx_callback_t callback, void *user_data,
|
||||||
|
@ -855,7 +865,7 @@ int can_attach_workq(const struct device *dev, struct k_work_q *work_q,
|
||||||
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
* @param filter Pointer to a @a zcan_filter structure defining the filter.
|
||||||
*
|
*
|
||||||
* @retval filter_id on success.
|
* @retval filter_id on success.
|
||||||
* @retval CAN_NO_FREE_FILTER if there are no free filters.
|
* @retval -ENOSPC if there are no free filters.
|
||||||
*/
|
*/
|
||||||
__syscall int can_attach_msgq(const struct device *dev, struct k_msgq *msg_q,
|
__syscall int can_attach_msgq(const struct device *dev, struct k_msgq *msg_q,
|
||||||
const struct zcan_filter *filter);
|
const struct zcan_filter *filter);
|
||||||
|
@ -945,7 +955,7 @@ static inline enum can_state z_impl_can_get_state(const struct device *dev,
|
||||||
* @param timeout Timeout for waiting for the recovery or ``K_FOREVER``.
|
* @param timeout Timeout for waiting for the recovery or ``K_FOREVER``.
|
||||||
*
|
*
|
||||||
* @retval 0 on success.
|
* @retval 0 on success.
|
||||||
* @retval CAN_TIMEOUT on timeout.
|
* @retval -EAGAIN on timeout.
|
||||||
*/
|
*/
|
||||||
#if !defined(CONFIG_CAN_AUTO_BUS_OFF_RECOVERY) || defined(__DOXYGEN__)
|
#if !defined(CONFIG_CAN_AUTO_BUS_OFF_RECOVERY) || defined(__DOXYGEN__)
|
||||||
__syscall int can_recover(const struct device *dev, k_timeout_t timeout);
|
__syscall int can_recover(const struct device *dev, k_timeout_t timeout);
|
||||||
|
|
|
@ -70,10 +70,10 @@ static void canopen_detach_all_rx_filters(CO_CANmodule_t *CANmodule)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0U; i < CANmodule->rx_size; i++) {
|
for (i = 0U; i < CANmodule->rx_size; i++) {
|
||||||
if (CANmodule->rx_array[i].filter_id != CAN_NO_FREE_FILTER) {
|
if (CANmodule->rx_array[i].filter_id != -ENOSPC) {
|
||||||
can_detach(CANmodule->dev,
|
can_detach(CANmodule->dev,
|
||||||
CANmodule->rx_array[i].filter_id);
|
CANmodule->rx_array[i].filter_id);
|
||||||
CANmodule->rx_array[i].filter_id = CAN_NO_FREE_FILTER;
|
CANmodule->rx_array[i].filter_id = -ENOSPC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,7 @@ static void canopen_tx_isr_callback(uint32_t error_flags, void *arg)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error_flags == CAN_TX_OK) {
|
if (error_flags == 0) {
|
||||||
CANmodule->first_tx_msg = false;
|
CANmodule->first_tx_msg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,9 +133,9 @@ static void canopen_tx_retry(struct k_work *item)
|
||||||
|
|
||||||
err = can_send(CANmodule->dev, &msg, K_NO_WAIT,
|
err = can_send(CANmodule->dev, &msg, K_NO_WAIT,
|
||||||
canopen_tx_isr_callback, CANmodule);
|
canopen_tx_isr_callback, CANmodule);
|
||||||
if (err == CAN_TIMEOUT) {
|
if (err == -EAGAIN) {
|
||||||
break;
|
break;
|
||||||
} else if (err != CAN_TX_OK) {
|
} else if (err != 0) {
|
||||||
LOG_ERR("failed to send CAN frame (err %d)",
|
LOG_ERR("failed to send CAN frame (err %d)",
|
||||||
err);
|
err);
|
||||||
CO_errorReport(CANmodule->em,
|
CO_errorReport(CANmodule->em,
|
||||||
|
@ -210,7 +210,7 @@ CO_ReturnError_t CO_CANmodule_init(CO_CANmodule_t *CANmodule,
|
||||||
for (i = 0U; i < rxSize; i++) {
|
for (i = 0U; i < rxSize; i++) {
|
||||||
rxArray[i].ident = 0U;
|
rxArray[i].ident = 0U;
|
||||||
rxArray[i].pFunct = NULL;
|
rxArray[i].pFunct = NULL;
|
||||||
rxArray[i].filter_id = CAN_NO_FREE_FILTER;
|
rxArray[i].filter_id = -ENOSPC;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0U; i < txSize; i++) {
|
for (i = 0U; i < txSize; i++) {
|
||||||
|
@ -284,14 +284,14 @@ CO_ReturnError_t CO_CANrxBufferInit(CO_CANmodule_t *CANmodule, uint16_t index,
|
||||||
filter.rtr = (rtr ? 1 : 0);
|
filter.rtr = (rtr ? 1 : 0);
|
||||||
filter.rtr_mask = 1;
|
filter.rtr_mask = 1;
|
||||||
|
|
||||||
if (buffer->filter_id != CAN_NO_FREE_FILTER) {
|
if (buffer->filter_id != -ENOSPC) {
|
||||||
can_detach(CANmodule->dev, buffer->filter_id);
|
can_detach(CANmodule->dev, buffer->filter_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer->filter_id = can_attach_isr(CANmodule->dev,
|
buffer->filter_id = can_attach_isr(CANmodule->dev,
|
||||||
canopen_rx_isr_callback,
|
canopen_rx_isr_callback,
|
||||||
buffer, &filter);
|
buffer, &filter);
|
||||||
if (buffer->filter_id == CAN_NO_FREE_FILTER) {
|
if (buffer->filter_id == -ENOSPC) {
|
||||||
LOG_ERR("failed to attach CAN rx isr, no free filter");
|
LOG_ERR("failed to attach CAN rx isr, no free filter");
|
||||||
CO_errorReport(CANmodule->em, CO_EM_MEMORY_ALLOCATION_ERROR,
|
CO_errorReport(CANmodule->em, CO_EM_MEMORY_ALLOCATION_ERROR,
|
||||||
CO_EMC_SOFTWARE_INTERNAL, 0);
|
CO_EMC_SOFTWARE_INTERNAL, 0);
|
||||||
|
@ -357,9 +357,9 @@ CO_ReturnError_t CO_CANsend(CO_CANmodule_t *CANmodule, CO_CANtx_t *buffer)
|
||||||
|
|
||||||
err = can_send(CANmodule->dev, &msg, K_NO_WAIT, canopen_tx_isr_callback,
|
err = can_send(CANmodule->dev, &msg, K_NO_WAIT, canopen_tx_isr_callback,
|
||||||
CANmodule);
|
CANmodule);
|
||||||
if (err == CAN_TIMEOUT) {
|
if (err == -EAGAIN) {
|
||||||
buffer->bufferFull = true;
|
buffer->bufferFull = true;
|
||||||
} else if (err != CAN_TX_OK) {
|
} else if (err != 0) {
|
||||||
LOG_ERR("failed to send CAN frame (err %d)", err);
|
LOG_ERR("failed to send CAN frame (err %d)", err);
|
||||||
CO_errorReport(CANmodule->em, CO_EM_GENERIC_SOFTWARE_ERROR,
|
CO_errorReport(CANmodule->em, CO_EM_GENERIC_SOFTWARE_ERROR,
|
||||||
CO_EMC_COMMUNICATION, 0);
|
CO_EMC_COMMUNICATION, 0);
|
||||||
|
|
|
@ -218,7 +218,7 @@ void main(void)
|
||||||
|
|
||||||
ret = can_attach_workq(can_dev, &k_sys_work_q, &rx_work, change_led,
|
ret = can_attach_workq(can_dev, &k_sys_work_q, &rx_work, change_led,
|
||||||
NULL, &change_led_filter);
|
NULL, &change_led_filter);
|
||||||
if (ret == CAN_NO_FREE_FILTER) {
|
if (ret == -ENOSPC) {
|
||||||
printk("Error, no filter available!\n");
|
printk("Error, no filter available!\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -969,7 +969,7 @@ static inline int send_cf(struct isotp_send_ctx *ctx)
|
||||||
|
|
||||||
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A),
|
ret = can_send(ctx->can_dev, &frame, K_MSEC(ISOTP_A),
|
||||||
send_can_tx_isr, ctx);
|
send_can_tx_isr, ctx);
|
||||||
if (ret == CAN_TX_OK) {
|
if (ret == 0) {
|
||||||
ctx->sn++;
|
ctx->sn++;
|
||||||
pull_data_ctx(ctx, len);
|
pull_data_ctx(ctx, len);
|
||||||
ctx->bs--;
|
ctx->bs--;
|
||||||
|
@ -1051,7 +1051,7 @@ static void send_state_machine(struct isotp_send_ctx *ctx)
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
LOG_ERR("Failed to send CF");
|
LOG_ERR("Failed to send CF");
|
||||||
send_report_error(ctx, ret == CAN_TIMEOUT ?
|
send_report_error(ctx, ret == -EAGAIN ?
|
||||||
ISOTP_N_TIMEOUT_A :
|
ISOTP_N_TIMEOUT_A :
|
||||||
ISOTP_N_ERROR);
|
ISOTP_N_ERROR);
|
||||||
break;
|
break;
|
||||||
|
@ -1181,7 +1181,7 @@ static int send(struct isotp_send_ctx *ctx, const struct device *can_dev,
|
||||||
ret = send_sf(ctx);
|
ret = send_sf(ctx);
|
||||||
ctx->state = ISOTP_TX_WAIT_FIN;
|
ctx->state = ISOTP_TX_WAIT_FIN;
|
||||||
if (ret) {
|
if (ret) {
|
||||||
return ret == CAN_TIMEOUT ?
|
return ret == -EAGAIN ?
|
||||||
ISOTP_N_TIMEOUT_A : ISOTP_N_ERROR;
|
ISOTP_N_TIMEOUT_A : ISOTP_N_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -730,7 +730,7 @@ static inline int canbus_send_cf(struct net_pkt *pkt)
|
||||||
net_pkt_read(pkt, &frame.data[1], len);
|
net_pkt_read(pkt, &frame.data[1], len);
|
||||||
ret = api->send(net_can_dev, &frame, canbus_tx_frame_isr,
|
ret = api->send(net_can_dev, &frame, canbus_tx_frame_isr,
|
||||||
pkt, K_NO_WAIT);
|
pkt, K_NO_WAIT);
|
||||||
if (ret == CAN_TX_OK) {
|
if (ret == 0) {
|
||||||
ctx->sn++;
|
ctx->sn++;
|
||||||
ctx->rem_len -= len;
|
ctx->rem_len -= len;
|
||||||
ctx->act_block_nr--;
|
ctx->act_block_nr--;
|
||||||
|
@ -760,7 +760,7 @@ static void canbus_tx_work(struct net_pkt *pkt)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret < 0 && ret != CAN_TIMEOUT) {
|
if (ret < 0 && ret != -EAGAIN) {
|
||||||
NET_ERR("Failed to send CF. CTX: %p", ctx);
|
NET_ERR("Failed to send CF. CTX: %p", ctx);
|
||||||
canbus_tx_report_err(pkt);
|
canbus_tx_report_err(pkt);
|
||||||
break;
|
break;
|
||||||
|
@ -939,7 +939,7 @@ static inline int canbus_send_ff(struct net_pkt *pkt, size_t len, bool mcast,
|
||||||
pkt->canbus_tx_ctx->rem_len -= NET_CAN_DL - index;
|
pkt->canbus_tx_ctx->rem_len -= NET_CAN_DL - index;
|
||||||
|
|
||||||
ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER);
|
ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER);
|
||||||
if (ret != CAN_TX_OK) {
|
if (ret != 0) {
|
||||||
NET_ERR("Sending FF failed [%d]. CTX: %p",
|
NET_ERR("Sending FF failed [%d]. CTX: %p",
|
||||||
ret, pkt->canbus_tx_ctx);
|
ret, pkt->canbus_tx_ctx);
|
||||||
}
|
}
|
||||||
|
@ -977,7 +977,7 @@ static inline int canbus_send_single_frame(struct net_pkt *pkt, size_t len,
|
||||||
canbus_set_frame_datalength(&frame, len + index);
|
canbus_set_frame_datalength(&frame, len + index);
|
||||||
|
|
||||||
ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER);
|
ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER);
|
||||||
if (ret != CAN_TX_OK) {
|
if (ret != 0) {
|
||||||
NET_ERR("Sending SF failed [%d]", ret);
|
NET_ERR("Sending SF failed [%d]", ret);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -1018,7 +1018,7 @@ static int canbus_send_multiple_frames(struct net_pkt *pkt, size_t len,
|
||||||
tx_ctx->tx_backlog = 0;
|
tx_ctx->tx_backlog = 0;
|
||||||
|
|
||||||
ret = canbus_send_ff(pkt, len, mcast, dest_addr);
|
ret = canbus_send_ff(pkt, len, mcast, dest_addr);
|
||||||
if (ret != CAN_TX_OK) {
|
if (ret != 0) {
|
||||||
NET_ERR("Failed to send FF [%d]", ret);
|
NET_ERR("Failed to send FF [%d]", ret);
|
||||||
canbus_tx_report_err(pkt);
|
canbus_tx_report_err(pkt);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
@ -1520,7 +1520,7 @@ static inline int canbus_send_dad_request(const struct device *net_can_dev,
|
||||||
sys_rand32_get() & CAN_NET_IF_ADDR_MASK);
|
sys_rand32_get() & CAN_NET_IF_ADDR_MASK);
|
||||||
|
|
||||||
ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER);
|
ret = api->send(net_can_dev, &frame, NULL, NULL, K_FOREVER);
|
||||||
if (ret != CAN_TX_OK) {
|
if (ret != 0) {
|
||||||
NET_ERR("Sending DAD request failed [%d]", ret);
|
NET_ERR("Sending DAD request failed [%d]", ret);
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
@ -1535,7 +1535,7 @@ static void canbus_send_dad_resp_cb(uint32_t err_flags, void *cb_arg)
|
||||||
|
|
||||||
if (err_flags) {
|
if (err_flags) {
|
||||||
NET_ERR("Failed to send dad response [%u]", err_flags);
|
NET_ERR("Failed to send dad response [%u]", err_flags);
|
||||||
if (err_flags != CAN_TX_BUS_OFF &&
|
if (err_flags != -ENETDOWN &&
|
||||||
fail_cnt < NET_CAN_DAD_SEND_RETRY) {
|
fail_cnt < NET_CAN_DAD_SEND_RETRY) {
|
||||||
k_work_submit_to_queue(&net_canbus_workq, work);
|
k_work_submit_to_queue(&net_canbus_workq, work);
|
||||||
}
|
}
|
||||||
|
@ -1565,7 +1565,7 @@ static inline void canbus_send_dad_response(struct k_work *item)
|
||||||
|
|
||||||
ret = api->send(net_can_dev, &frame, canbus_send_dad_resp_cb, item,
|
ret = api->send(net_can_dev, &frame, canbus_send_dad_resp_cb, item,
|
||||||
K_FOREVER);
|
K_FOREVER);
|
||||||
if (ret != CAN_TX_OK) {
|
if (ret != 0) {
|
||||||
NET_ERR("Sending SF failed [%d]", ret);
|
NET_ERR("Sending SF failed [%d]", ret);
|
||||||
} else {
|
} else {
|
||||||
NET_INFO("DAD response sent");
|
NET_INFO("DAD response sent");
|
||||||
|
@ -1605,7 +1605,7 @@ int canbus_attach_dad_resp_filter(const struct device *net_can_dev,
|
||||||
|
|
||||||
filter_id = api->attach_filter(net_can_dev, canbus_dad_resp_cb,
|
filter_id = api->attach_filter(net_can_dev, canbus_dad_resp_cb,
|
||||||
dad_sem, &filter);
|
dad_sem, &filter);
|
||||||
if (filter_id == CAN_NO_FREE_FILTER) {
|
if (filter_id == -ENOSPC) {
|
||||||
NET_ERR("Can't attach dad response filter");
|
NET_ERR("Can't attach dad response filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1636,7 +1636,7 @@ static inline int canbus_attach_dad_filter(const struct device *net_can_dev,
|
||||||
|
|
||||||
filter_id = api->attach_filter(net_can_dev, canbus_dad_request_cb,
|
filter_id = api->attach_filter(net_can_dev, canbus_dad_request_cb,
|
||||||
dad_work, &filter);
|
dad_work, &filter);
|
||||||
if (filter_id == CAN_NO_FREE_FILTER) {
|
if (filter_id == -ENOSPC) {
|
||||||
NET_ERR("Can't attach dad filter");
|
NET_ERR("Can't attach dad filter");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -339,9 +339,9 @@ static void send_test_msg(const struct device *can_dev,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, NULL, NULL);
|
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, NULL, NULL);
|
||||||
zassert_not_equal(ret, CAN_TX_ARB_LOST,
|
zassert_not_equal(ret, -EBUSY,
|
||||||
"Arbitration though in loopback mode");
|
"Arbitration though in loopback mode");
|
||||||
zassert_equal(ret, CAN_TX_OK, "Can't send a message. Err: %d", ret);
|
zassert_equal(ret, 0, "Can't send a message. Err: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_test_msg_nowait(const struct device *can_dev,
|
static void send_test_msg_nowait(const struct device *can_dev,
|
||||||
|
@ -351,9 +351,9 @@ static void send_test_msg_nowait(const struct device *can_dev,
|
||||||
int ret;
|
int ret;
|
||||||
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, cb,
|
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, cb,
|
||||||
(struct zcan_frame *)msg);
|
(struct zcan_frame *)msg);
|
||||||
zassert_not_equal(ret, CAN_TX_ARB_LOST,
|
zassert_not_equal(ret, -EBUSY,
|
||||||
"Arbitration though in loopback mode");
|
"Arbitration though in loopback mode");
|
||||||
zassert_equal(ret, CAN_TX_OK, "Can't send a message. Err: %d", ret);
|
zassert_equal(ret, 0, "Can't send a message. Err: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int attach_msgq(const struct device *can_dev,
|
static inline int attach_msgq(const struct device *can_dev,
|
||||||
|
@ -362,7 +362,7 @@ static inline int attach_msgq(const struct device *can_dev,
|
||||||
int filter_id;
|
int filter_id;
|
||||||
|
|
||||||
filter_id = can_attach_msgq(can_dev, &can_msgq, filter);
|
filter_id = can_attach_msgq(can_dev, &can_msgq, filter);
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number");
|
zassert_true((filter_id >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
@ -379,7 +379,7 @@ static inline int attach_workq(const struct device *can_dev,
|
||||||
filter_id = can_attach_workq(can_dev, &k_sys_work_q, work, cb,
|
filter_id = can_attach_workq(can_dev, &k_sys_work_q, work, cb,
|
||||||
(void *)filter, filter);
|
(void *)filter, filter);
|
||||||
|
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number");
|
zassert_true((filter_id >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
@ -395,7 +395,7 @@ static inline int attach_isr(const struct device *can_dev,
|
||||||
k_sem_reset(&rx_isr_sem);
|
k_sem_reset(&rx_isr_sem);
|
||||||
|
|
||||||
filter_id = can_attach_isr(can_dev, isr, (void *)filter, filter);
|
filter_id = can_attach_isr(can_dev, isr, (void *)filter, filter);
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number");
|
zassert_true((filter_id >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
@ -713,7 +713,7 @@ static void test_send_receive_wrong_id(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if a call with dlc > CAN_MAX_DLC returns CAN_TX_EINVAL
|
* Check if a call with dlc > CAN_MAX_DLC returns -EINVAL
|
||||||
*/
|
*/
|
||||||
static void test_send_invalid_dlc(void)
|
static void test_send_invalid_dlc(void)
|
||||||
{
|
{
|
||||||
|
@ -723,8 +723,8 @@ static void test_send_invalid_dlc(void)
|
||||||
frame.dlc = CAN_MAX_DLC + 1;
|
frame.dlc = CAN_MAX_DLC + 1;
|
||||||
|
|
||||||
ret = can_send(can_dev, &frame, TEST_SEND_TIMEOUT, tx_std_isr_1, NULL);
|
ret = can_send(can_dev, &frame, TEST_SEND_TIMEOUT, tx_std_isr_1, NULL);
|
||||||
zassert_equal(ret, CAN_TX_EINVAL,
|
zassert_equal(ret, -EINVAL,
|
||||||
"ret [%d] not equal to %d", ret, CAN_TX_EINVAL);
|
"ret [%d] not equal to %d", ret, -EINVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_main(void)
|
void test_main(void)
|
||||||
|
|
|
@ -203,9 +203,9 @@ static void send_test_msg(const struct device *can_dev,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, NULL, NULL);
|
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, NULL, NULL);
|
||||||
zassert_not_equal(ret, CAN_TX_ARB_LOST,
|
zassert_not_equal(ret, -EBUSY,
|
||||||
"Arbitration though in loopback mode");
|
"Arbitration though in loopback mode");
|
||||||
zassert_equal(ret, CAN_TX_OK, "Can't send a message. Err: %d", ret);
|
zassert_equal(ret, 0, "Can't send a message. Err: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void send_test_msg_nowait(const struct device *can_dev,
|
static void send_test_msg_nowait(const struct device *can_dev,
|
||||||
|
@ -216,9 +216,9 @@ static void send_test_msg_nowait(const struct device *can_dev,
|
||||||
|
|
||||||
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, cb,
|
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, cb,
|
||||||
(struct zcan_frame *)msg);
|
(struct zcan_frame *)msg);
|
||||||
zassert_not_equal(ret, CAN_TX_ARB_LOST,
|
zassert_not_equal(ret, -EBUSY,
|
||||||
"Arbitration though in loopback mode");
|
"Arbitration though in loopback mode");
|
||||||
zassert_equal(ret, CAN_TX_OK, "Can't send a message. Err: %d", ret);
|
zassert_equal(ret, 0, "Can't send a message. Err: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int attach_msgq(const struct device *can_dev,
|
static inline int attach_msgq(const struct device *can_dev,
|
||||||
|
@ -227,7 +227,7 @@ static inline int attach_msgq(const struct device *can_dev,
|
||||||
int filter_id;
|
int filter_id;
|
||||||
|
|
||||||
filter_id = can_attach_msgq(can_dev, &can_msgq, filter);
|
filter_id = can_attach_msgq(can_dev, &can_msgq, filter);
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number");
|
zassert_true((filter_id >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
@ -244,7 +244,7 @@ static inline int attach_workq(const struct device *can_dev,
|
||||||
filter_id = can_attach_workq(can_dev, &k_sys_work_q, work, cb,
|
filter_id = can_attach_workq(can_dev, &k_sys_work_q, work, cb,
|
||||||
(void *)filter, filter);
|
(void *)filter, filter);
|
||||||
|
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number");
|
zassert_true((filter_id >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
@ -260,7 +260,7 @@ static inline int attach_isr(const struct device *can_dev,
|
||||||
k_sem_reset(&rx_isr_sem);
|
k_sem_reset(&rx_isr_sem);
|
||||||
|
|
||||||
filter_id = can_attach_isr(can_dev, isr, (void *)filter, filter);
|
filter_id = can_attach_isr(can_dev, isr, (void *)filter, filter);
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number");
|
zassert_true((filter_id >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
|
|
@ -109,9 +109,9 @@ static void send_test_msg(const struct device *can_dev,
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, NULL, NULL);
|
ret = can_send(can_dev, msg, TEST_SEND_TIMEOUT, NULL, NULL);
|
||||||
zassert_not_equal(ret, CAN_TX_ARB_LOST,
|
zassert_not_equal(ret, -EBUSY,
|
||||||
"Arbitration though in loopback mode");
|
"Arbitration though in loopback mode");
|
||||||
zassert_equal(ret, CAN_TX_OK, "Can't send a message. Err: %d", ret);
|
zassert_equal(ret, 0, "Can't send a message. Err: %d", ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -131,18 +131,18 @@ static void test_filter_handling(void)
|
||||||
ret = can_set_mode(can_dev, CAN_LOOPBACK_MODE);
|
ret = can_set_mode(can_dev, CAN_LOOPBACK_MODE);
|
||||||
|
|
||||||
filter_id_1 = can_attach_msgq(can_dev, &can_msgq, &test_ext_masked_filter);
|
filter_id_1 = can_attach_msgq(can_dev, &can_msgq, &test_ext_masked_filter);
|
||||||
zassert_not_equal(filter_id_1, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id_1, -ENOSPC,
|
||||||
"Filter full even for a single one");
|
"Filter full even for a single one");
|
||||||
zassert_true((filter_id_1 >= 0), "Negative filter number");
|
zassert_true((filter_id_1 >= 0), "Negative filter number");
|
||||||
|
|
||||||
filter_id_2 = can_attach_msgq(can_dev, &can_msgq, &test_std_filter);
|
filter_id_2 = can_attach_msgq(can_dev, &can_msgq, &test_std_filter);
|
||||||
zassert_not_equal(filter_id_2, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id_2, -ENOSPC,
|
||||||
"Filter full when attaching the second one");
|
"Filter full when attaching the second one");
|
||||||
zassert_true((filter_id_2 >= 0), "Negative filter number");
|
zassert_true((filter_id_2 >= 0), "Negative filter number");
|
||||||
|
|
||||||
can_detach(can_dev, filter_id_1);
|
can_detach(can_dev, filter_id_1);
|
||||||
filter_id_1 = can_attach_msgq(can_dev, &can_msgq, &test_std_some_filter);
|
filter_id_1 = can_attach_msgq(can_dev, &can_msgq, &test_std_some_filter);
|
||||||
zassert_not_equal(filter_id_1, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id_1, -ENOSPC,
|
||||||
"Filter full when overriding the first one");
|
"Filter full when overriding the first one");
|
||||||
zassert_true((filter_id_1 >= 0), "Negative filter number");
|
zassert_true((filter_id_1 >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ static void test_filter_handling(void)
|
||||||
|
|
||||||
can_detach(can_dev, filter_id_1);
|
can_detach(can_dev, filter_id_1);
|
||||||
filter_id_1 = can_attach_msgq(can_dev, &can_msgq, &test_ext_filter);
|
filter_id_1 = can_attach_msgq(can_dev, &can_msgq, &test_ext_filter);
|
||||||
zassert_not_equal(filter_id_1, CAN_NO_FREE_FILTER,
|
zassert_not_equal(filter_id_1, -ENOSPC,
|
||||||
"Filter full when overriding the first one");
|
"Filter full when overriding the first one");
|
||||||
zassert_true((filter_id_1 >= 0), "Negative filter number");
|
zassert_true((filter_id_1 >= 0), "Negative filter number");
|
||||||
|
|
||||||
|
|
|
@ -250,7 +250,7 @@ static void send_frame_series(struct frame_desired *frames, size_t length,
|
||||||
frame.dlc = desired->length;
|
frame.dlc = desired->length;
|
||||||
memcpy(frame.data, desired->data, desired->length);
|
memcpy(frame.data, desired->data, desired->length);
|
||||||
ret = can_send(can_dev, &frame, K_MSEC(500), NULL, NULL);
|
ret = can_send(can_dev, &frame, K_MSEC(500), NULL, NULL);
|
||||||
zassert_equal(ret, CAN_TX_OK, "Sending msg %d failed.", i);
|
zassert_equal(ret, 0, "Sending msg %d failed.", i);
|
||||||
desired++;
|
desired++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -298,7 +298,7 @@ static int attach_msgq(uint32_t id, uint32_t mask)
|
||||||
};
|
};
|
||||||
|
|
||||||
filter_id = can_attach_msgq(can_dev, &frame_msgq, &filter);
|
filter_id = can_attach_msgq(can_dev, &frame_msgq, &filter);
|
||||||
zassert_not_equal(filter_id, CAN_NO_FREE_FILTER, "Filter full");
|
zassert_not_equal(filter_id, -ENOSPC, "Filter full");
|
||||||
zassert_true((filter_id >= 0), "Negative filter number [%d]",
|
zassert_true((filter_id >= 0), "Negative filter number [%d]",
|
||||||
filter_id);
|
filter_id);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue