Skip to content

Commit c77c4cc

Browse files
committed
Merge branch 'bugfix/twai_assert_program_logic' into 'master'
TWAI: Remove asserts used for program logic Closes IDFGH-3729 See merge request espressif/esp-idf!9834
2 parents 570629d + f790e0c commit c77c4cc

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

components/driver/twai.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@ static inline void twai_handle_bus_off(int *alert_req)
130130
static inline void twai_handle_recovery_complete(int *alert_req)
131131
{
132132
//Bus recovery complete.
133-
assert(twai_hal_handle_bus_recov_cplt(&twai_context));
133+
bool recov_cplt = twai_hal_handle_bus_recov_cplt(&twai_context);
134+
assert(recov_cplt);
134135

135136
//Reset and set flags to the equivalent of the stopped state
136137
TWAI_RESET_FLAG(p_twai_obj->control_flags, CTRL_FLAG_RECOVERING | CTRL_FLAG_ERR_WARN |
@@ -221,7 +222,7 @@ static inline void twai_handle_tx_buffer_frame(BaseType_t *task_woken, int *aler
221222

222223
//Update TX message count
223224
p_twai_obj->tx_msg_count--;
224-
assert(p_twai_obj->tx_msg_count >= 0); //Sanity check
225+
assert(p_twai_obj->tx_msg_count >= 0); //Sanity check
225226

226227
//Check if there are more frames to transmit
227228
if (p_twai_obj->tx_msg_count > 0 && p_twai_obj->tx_queue != NULL) {
@@ -381,7 +382,8 @@ esp_err_t twai_driver_install(const twai_general_config_t *g_config, const twai_
381382
}
382383
periph_module_reset(PERIPH_TWAI_MODULE);
383384
periph_module_enable(PERIPH_TWAI_MODULE); //Enable APB CLK to TWAI peripheral
384-
assert(twai_hal_init(&twai_context));
385+
bool init = twai_hal_init(&twai_context);
386+
assert(init);
385387
twai_hal_configure(&twai_context, t_config, f_config, DRIVER_DEFAULT_INTERRUPTS, g_config->clkout_divider);
386388
//Todo: Allow interrupt to be registered to specified CPU
387389
TWAI_EXIT_CRITICAL();
@@ -467,7 +469,8 @@ esp_err_t twai_start(void)
467469
//Todo: Add assert to see if in reset mode. //Should already be in bus-off mode, set again to make sure
468470

469471
//Currently in listen only mode, need to set to mode specified by configuration
470-
assert(twai_hal_start(&twai_context, p_twai_obj->mode));
472+
bool started = twai_hal_start(&twai_context, p_twai_obj->mode);
473+
assert(started);
471474

472475
TWAI_RESET_FLAG(p_twai_obj->control_flags, CTRL_FLAG_STOPPED);
473476
TWAI_EXIT_CRITICAL();
@@ -481,7 +484,8 @@ esp_err_t twai_stop(void)
481484
TWAI_CHECK_FROM_CRIT(p_twai_obj != NULL, ESP_ERR_INVALID_STATE);
482485
TWAI_CHECK_FROM_CRIT(!(p_twai_obj->control_flags & (CTRL_FLAG_STOPPED | CTRL_FLAG_BUS_OFF)), ESP_ERR_INVALID_STATE);
483486

484-
assert(twai_hal_stop(&twai_context));
487+
bool stopped = twai_hal_stop(&twai_context);
488+
assert(stopped);
485489

486490
TWAI_RESET_FLAG(p_twai_obj->control_flags, CTRL_FLAG_TX_BUFF_OCCUPIED);
487491
TWAI_SET_FLAG(p_twai_obj->control_flags, CTRL_FLAG_STOPPED);
@@ -630,7 +634,8 @@ esp_err_t twai_initiate_recovery(void)
630634
TWAI_SET_FLAG(p_twai_obj->control_flags, CTRL_FLAG_RECOVERING);
631635

632636
//Trigger start of recovery process
633-
assert(twai_hal_start_bus_recovery(&twai_context));
637+
bool started = twai_hal_start_bus_recovery(&twai_context);
638+
assert(started);
634639
TWAI_EXIT_CRITICAL();
635640

636641
return ESP_OK;

0 commit comments

Comments
 (0)