mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(driver_twai): fixed TWAI arbitration lost event handling
Merges https://github.com/espressif/esp-idf/pull/18100
This commit is contained in:
@@ -280,7 +280,9 @@ twai_error_state_t twai_hal_get_err_state(twai_hal_context_t *hal_ctx);
|
||||
__attribute__((always_inline))
|
||||
static inline twai_error_flags_t twai_hal_get_err_flags(twai_hal_context_t *hal_ctx)
|
||||
{
|
||||
return hal_ctx->errors;
|
||||
twai_error_flags_t error_flags = hal_ctx->errors;
|
||||
hal_ctx->errors.val = 0; // clear ctx for next errors
|
||||
return error_flags;
|
||||
}
|
||||
|
||||
/* ------------------------------- TX and RX -------------------------------- */
|
||||
|
||||
@@ -276,13 +276,10 @@ uint32_t twai_hal_get_events(twai_hal_context_t *hal_ctx)
|
||||
twai_ll_err_dir_t dir;
|
||||
twai_ll_err_seg_t seg;
|
||||
twai_ll_parse_err_code_cap(hal_ctx->dev, &type, &dir, &seg); //Decode error interrupt
|
||||
twai_error_flags_t errors = {
|
||||
.bit_err = (type == TWAI_LL_ERR_BIT),
|
||||
.form_err = (type == TWAI_LL_ERR_FORM),
|
||||
.stuff_err = (type == TWAI_LL_ERR_STUFF),
|
||||
.ack_err = (type == TWAI_LL_ERR_OTHER) && (seg == TWAI_LL_ERR_SEG_ACK_SLOT),
|
||||
};
|
||||
hal_ctx->errors = errors;
|
||||
hal_ctx->errors.bit_err = (type == TWAI_LL_ERR_BIT);
|
||||
hal_ctx->errors.form_err = (type == TWAI_LL_ERR_FORM);
|
||||
hal_ctx->errors.stuff_err = (type == TWAI_LL_ERR_STUFF);
|
||||
hal_ctx->errors.ack_err = (type == TWAI_LL_ERR_OTHER) && (seg == TWAI_LL_ERR_SEG_ACK_SLOT);
|
||||
#if TWAI_LL_HAS_RX_FRAME_ISSUE
|
||||
//Check for errata condition (RX message has bus error at particular segments)
|
||||
if (dir == TWAI_LL_ERR_DIR_RX &&
|
||||
@@ -293,6 +290,7 @@ uint32_t twai_hal_get_events(twai_hal_context_t *hal_ctx)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
hal_ctx->errors.arb_lost = !!(events & TWAI_HAL_EVENT_ARB_LOST);
|
||||
if (events & TWAI_HAL_EVENT_ARB_LOST) {
|
||||
twai_ll_clear_arb_lost_cap(hal_ctx->dev);
|
||||
}
|
||||
|
||||
@@ -218,6 +218,7 @@ uint32_t twai_hal_get_events(twai_hal_context_t *hal_ctx)
|
||||
hal_ctx->errors = twaifd_ll_get_err_reason(hal_ctx->dev);
|
||||
hal_events |= TWAI_HAL_EVENT_BUS_ERR;
|
||||
}
|
||||
hal_ctx->errors.arb_lost = !!(int_stat & TWAIFD_LL_INTR_ARBIT_LOST);
|
||||
if (int_stat & TWAIFD_LL_INTR_ARBIT_LOST) {
|
||||
hal_events |= TWAI_HAL_EVENT_ARB_LOST;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user