diff options
| author | Jeff Epler <jepler@gmail.com> | 2020-10-06 10:31:38 -0500 |
|---|---|---|
| committer | Jeff Epler <jepler@gmail.com> | 2020-10-06 20:12:10 -0500 |
| commit | eed3387f4e625335a5d2f6582946ec75d1c1ed10 (patch) | |
| tree | 2857e3093f440e842bda8c5b51e0244d1709bf70 | |
| parent | abe0405d6e643614557edd65995b61c04c656c44 (diff) | |
stm32: canio: Fix message cancellation
.. it's necessary to wait for a cancellation request to actually free
the respective Tx mailbox
| -rw-r--r-- | ports/stm/common-hal/canio/CAN.c | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/ports/stm/common-hal/canio/CAN.c b/ports/stm/common-hal/canio/CAN.c index 62c4e9935..fe1c3f2b1 100644 --- a/ports/stm/common-hal/canio/CAN.c +++ b/ports/stm/common-hal/canio/CAN.c @@ -241,13 +241,21 @@ void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in) // // We don't strictly guarantee that we abort the oldest Tx request, // rather we just abort a different index each time. This permits us - // to avoid tracking this information altogether. + // to just track a single cancel index HAL_CAN_AbortTxRequest(&self->handle, 1 << (self->cancel_mailbox)); self->cancel_mailbox = (self->cancel_mailbox + 1) % 3; + // The abort request may not have completed immediately, so wait for + // the Tx mailbox to become free + do { + free_level = HAL_CAN_GetTxMailboxesFreeLevel(&self->handle); + } while (!free_level); } HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(&self->handle, &header, message->data, &mailbox); if (status != HAL_OK) { - mp_raise_OSError(MP_ENOMEM); + // this is a "shouldn't happen" condition. we don't throw because the + // contract of send() is that it queues the packet to be sent if + // possible and does not signal success or failure to actually send. + return; } // wait 8ms (hard coded for now) for TX to occur |
