diff options
author | iabdalkader <i.abdalkader@gmail.com> | 2020-06-30 23:13:57 +0200 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2020-07-09 00:38:56 +1000 |
commit | c299cc94e334a5a9576e15e0f046e24810c4c75a (patch) | |
tree | 4b7a8530f3321478f115f033baef7ca2496dbfce | |
parent | d07073f4e2f37d9614340f7544985dfee834532e (diff) |
stm32/pyb_can: Handle timeout arg for FDCAN in pyb_can_send.
Following the documented pyb can_send behavior in pyb.CAN docs.
-rw-r--r-- | ports/stm32/pyb_can.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ports/stm32/pyb_can.c b/ports/stm32/pyb_can.c index ad2efbef4..224b8f28b 100644 --- a/ports/stm32/pyb_can.c +++ b/ports/stm32/pyb_can.c @@ -432,6 +432,20 @@ STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t * HAL_StatusTypeDef status; #if MICROPY_HW_ENABLE_FDCAN + uint32_t timeout_ms = args[ARG_timeout].u_int; + uint32_t start = HAL_GetTick(); + while (HAL_FDCAN_GetTxFifoFreeLevel(&self->can) == 0) { + if (timeout_ms == 0) { + mp_raise_OSError(MP_ETIMEDOUT); + } + // Check for the Timeout + if (timeout_ms != HAL_MAX_DELAY) { + if (HAL_GetTick() - start >= timeout_ms) { + mp_raise_OSError(MP_ETIMEDOUT); + } + } + MICROPY_EVENT_POLL_HOOK + } status = HAL_FDCAN_AddMessageToTxFifoQ(&self->can, &tx_msg, tx_data); #else self->can.pTxMsg = &tx_msg; |