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
|
@ -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) {
|
||||
data->mb0.error_flags =
|
||||
can->TSR & CAN_TSR_TXOK0 ? CAN_TX_OK :
|
||||
can->TSR & CAN_TSR_TERR0 ? CAN_TX_ERR :
|
||||
can->TSR & CAN_TSR_ALST0 ? CAN_TX_ARB_LOST :
|
||||
bus_off ? CAN_TX_BUS_OFF :
|
||||
CAN_TX_UNKNOWN;
|
||||
can->TSR & CAN_TSR_TXOK0 ? 0 :
|
||||
can->TSR & CAN_TSR_TERR0 ? -EIO :
|
||||
can->TSR & CAN_TSR_ALST0 ? -EBUSY :
|
||||
bus_off ? -ENETDOWN :
|
||||
-EIO;
|
||||
/* clear the request. */
|
||||
can->TSR |= CAN_TSR_RQCP0;
|
||||
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) {
|
||||
data->mb1.error_flags =
|
||||
can->TSR & CAN_TSR_TXOK1 ? CAN_TX_OK :
|
||||
can->TSR & CAN_TSR_TERR1 ? CAN_TX_ERR :
|
||||
can->TSR & CAN_TSR_ALST1 ? CAN_TX_ARB_LOST :
|
||||
bus_off ? CAN_TX_BUS_OFF :
|
||||
CAN_TX_UNKNOWN;
|
||||
can->TSR & CAN_TSR_TXOK1 ? 0 :
|
||||
can->TSR & CAN_TSR_TERR1 ? -EIO :
|
||||
can->TSR & CAN_TSR_ALST1 ? -EBUSY :
|
||||
bus_off ? -ENETDOWN :
|
||||
-EIO;
|
||||
/* clear the request. */
|
||||
can->TSR |= CAN_TSR_RQCP1;
|
||||
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) {
|
||||
data->mb2.error_flags =
|
||||
can->TSR & CAN_TSR_TXOK2 ? CAN_TX_OK :
|
||||
can->TSR & CAN_TSR_TERR2 ? CAN_TX_ERR :
|
||||
can->TSR & CAN_TSR_ALST2 ? CAN_TX_ARB_LOST :
|
||||
bus_off ? CAN_TX_BUS_OFF :
|
||||
CAN_TX_UNKNOWN;
|
||||
can->TSR & CAN_TSR_TXOK2 ? 0 :
|
||||
can->TSR & CAN_TSR_TERR2 ? -EIO :
|
||||
can->TSR & CAN_TSR_ALST2 ? -EBUSY :
|
||||
bus_off ? -ENETDOWN :
|
||||
-EIO;
|
||||
/* clear the request. */
|
||||
can->TSR |= CAN_TSR_RQCP2;
|
||||
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) {
|
||||
if (k_cycle_get_32() - start_time > CAN_INIT_TIMEOUT) {
|
||||
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) {
|
||||
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) {
|
||||
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);
|
||||
struct can_stm32_data *data = DEV_DATA(dev);
|
||||
CAN_TypeDef *can = cfg->can;
|
||||
int ret = CAN_TIMEOUT;
|
||||
int ret = -EAGAIN;
|
||||
int64_t start_time;
|
||||
|
||||
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)) {
|
||||
return CAN_TIMEOUT;
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
return CAN_TX_BUS_OFF;
|
||||
return -ENETDOWN;
|
||||
}
|
||||
|
||||
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);
|
||||
LOG_DBG("Transmit buffer full");
|
||||
if (k_sem_take(&data->tx_int_sem, timeout)) {
|
||||
return CAN_TIMEOUT;
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (start > CONFIG_CAN_MAX_FILTER) {
|
||||
return CAN_NO_FREE_FILTER;
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
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 */
|
||||
if (!can_stm32_check_free(arr, CONFIG_CAN_MAX_FILTER - count,
|
||||
CONFIG_CAN_MAX_FILTER - 1)) {
|
||||
return CAN_NO_FREE_FILTER;
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
/* 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;
|
||||
|
||||
if (start - count < 0) {
|
||||
return CAN_NO_FREE_FILTER;
|
||||
return -ENOSPC;
|
||||
}
|
||||
|
||||
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 id = 0U;
|
||||
int filter_nr = 0;
|
||||
int filter_index_new = CAN_NO_FREE_FILTER;
|
||||
int filter_index_new = -ENOSPC;
|
||||
int bank_nr;
|
||||
uint32_t bank_bit;
|
||||
int register_demand;
|
||||
|
@ -952,7 +952,7 @@ static inline int can_stm32_set_filter(const struct zcan_filter *filter,
|
|||
|
||||
if (!usage_shifted) {
|
||||
LOG_INF("No free filter bank found");
|
||||
return CAN_NO_FREE_FILTER;
|
||||
return -ENOSPC;
|
||||
}
|
||||
} 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) {
|
||||
LOG_INF("No space for a new filter!");
|
||||
filter_nr = CAN_NO_FREE_FILTER;
|
||||
filter_nr = -ENOSPC;
|
||||
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,
|
||||
can->FS1R);
|
||||
if (filter_index_new >= CAN_MAX_NUMBER_OF_FILTERS) {
|
||||
filter_nr = CAN_NO_FREE_FILTER;
|
||||
filter_nr = -ENOSPC;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
@ -1027,7 +1027,7 @@ static inline int can_stm32_attach(const struct device *dev,
|
|||
int filter_nr;
|
||||
|
||||
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->cb_arg[filter_index] = cb_arg;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue