diff --git a/main/can.c b/main/can.c index c39efa4..e0e1cee 100644 --- a/main/can.c +++ b/main/can.c @@ -1,4 +1,5 @@ #include "can.h" +#include "esp_err.h" #include "esp_log.h" #include "freertos/portmacro.h" #include "freertos/projdefs.h" @@ -96,7 +97,8 @@ void can_task(void* arg) { print_w_clr_time("CAN recovered!", LOG_COLOR_BLUE, false); if (auto_recovery) { print_w_clr_time("Starting CAN...", LOG_COLOR_GREEN, false); - twai_start(); + ESP_ERROR_CHECK(twai_start()); + is_error_passive = false; } } } diff --git a/main/can.h b/main/can.h index 82775b7..acf088e 100644 --- a/main/can.h +++ b/main/can.h @@ -41,6 +41,7 @@ extern SemaphoreHandle_t can_mutex; extern volatile can_status_t curr_can_state; extern bool timestamp_enabled; extern bool auto_recovery; +extern bool is_error_passive; // functions diff --git a/main/cmd_can.c b/main/cmd_can.c index c57dcc4..0b2342d 100644 --- a/main/cmd_can.c +++ b/main/cmd_can.c @@ -237,6 +237,7 @@ static int canup(int argc, char **argv) { esp_restart(); } ESP_ERROR_CHECK(twai_start()); + is_error_passive = false; print_w_clr_time("CAN driver started", LOG_COLOR_BLUE, true); free_exit: xSemaphoreGive(can_mutex); @@ -247,8 +248,10 @@ free_exit: static int canstart(int argc, char **argv) { xSemaphoreTake(can_mutex, portMAX_DELAY); esp_err_t res = twai_start(); - if (res == ESP_OK) print_w_clr_time("CAN driver started", LOG_COLOR_GREEN, true); - else print_w_clr_time("Driver is not in stopped state, or is not installed.", LOG_COLOR_RED, true); + if (res == ESP_OK) { + print_w_clr_time("CAN driver started", LOG_COLOR_GREEN, true); + is_error_passive = false; + } else print_w_clr_time("Driver is not in stopped state, or is not installed.", LOG_COLOR_RED, true); xSemaphoreGive(can_mutex); return 0; }