fix logs while canup + make curr_can_state volatile

This commit is contained in:
Данила Горнушко 2023-11-28 08:21:04 +03:00
parent 4315b513d7
commit c3594ab41e
3 changed files with 6 additions and 2 deletions

View file

@ -14,7 +14,7 @@ static const char* LOG_TAG = "can";
bool is_error_passive = false;
SemaphoreHandle_t can_mutex;
can_status_t curr_can_state = { 0 };
volatile can_status_t curr_can_state = { 0 };
static can_status_t get_can_state() {
can_status_t result;

View file

@ -51,7 +51,7 @@ static const twai_general_config_t g_config = {
};
extern SemaphoreHandle_t can_mutex;
extern can_status_t curr_can_state;
extern volatile can_status_t curr_can_state;
// functions

View file

@ -1,4 +1,5 @@
#include "cmd_can.h"
#include "esp_log.h"
#include "freertos/portmacro.h"
#include "inttypes.h"
#include "driver/twai.h"
@ -116,6 +117,8 @@ static int canstats(int argc, char **argv) {
static int canup(int argc, char **argv) {
esp_err_t res;
esp_log_level_t prev_gpio_lvl = esp_log_level_get("gpio");
esp_log_level_set("gpio", ESP_LOG_ERROR);
xSemaphoreTake(can_mutex, portMAX_DELAY);
// Install CAN driver
// TODO: add CAN filtering
@ -130,6 +133,7 @@ static int canup(int argc, char **argv) {
res = twai_start();
printf("CAN driver started\n");
xSemaphoreGive(can_mutex);
esp_log_level_set("gpio", prev_gpio_lvl);
return 0;
}