diff --git a/components/sx127x_driver/sx127x_driver.c b/components/sx127x_driver/sx127x_driver.c index 5f53aa6..02ae641 100644 --- a/components/sx127x_driver/sx127x_driver.c +++ b/components/sx127x_driver/sx127x_driver.c @@ -63,6 +63,7 @@ esp_err_t sx127x_init(const sx127x_config_t *config, sx127x_t **handle_ptr) { SX127X_CHECK(hndl != NULL, "malloc error", ESP_ERR_NO_MEM); *handle_ptr = hndl; + hndl->spi_mutex = xSemaphoreCreateMutex(); hndl->task_handle = NULL; atomic_init(&hndl->task_state, SX127X_TASK_STOPPED); memcpy(&hndl->config, config, sizeof(sx127x_config_t)); @@ -76,8 +77,6 @@ esp_err_t sx127x_init(const sx127x_config_t *config, sx127x_t **handle_ptr) { gpio_set_level(config->rst_io_num, 1); vTaskDelay(SX127X_RESET_DELAY); - hndl->spi_mutex = xSemaphoreCreateMutex(); - spi_bus_config_t bus_config = { .mosi_io_num = config->mosi_io_num, .miso_io_num = config->miso_io_num, diff --git a/main/ugv_comms.c b/main/ugv_comms.c index c028ed6..a2ee390 100644 --- a/main/ugv_comms.c +++ b/main/ugv_comms.c @@ -21,6 +21,8 @@ static void ugv_comms_handle_command(ugv_comms_state_t * st, void ugv_comms_init() { ugv_comms_state_t *st = &ugv_comms_state; + st->mutex = xSemaphoreCreateMutex(); + sx127x_config_t lora_config = SX127X_CONFIG_DEFAULT; lora_config.sck_io_num = LORA_SCK; lora_config.miso_io_num = LORA_MISO; @@ -35,9 +37,7 @@ void ugv_comms_init() { lora_config.sync_word = 0x34; lora_config.crc = SX127X_CRC_ENABLED; - esp_err_t ret; - - st->mutex = xSemaphoreCreateMutex(); + esp_err_t ret; uas_ugv_Location loc = uas_ugv_Location_init_default; memcpy(&st->location, &loc, sizeof(loc)); st->ugv_state = uas_ugv_UGV_State_IDLE; diff --git a/main/ugv_io_gps.cc b/main/ugv_io_gps.cc index f38be92..b649eb9 100644 --- a/main/ugv_io_gps.cc +++ b/main/ugv_io_gps.cc @@ -47,6 +47,9 @@ UART_GPS::~UART_GPS() {} void UART_GPS::Init() { esp_err_t ret; + mutex_ = xSemaphoreCreateMutex(); + data_ = GpsData{}; + uart_config_t gps_uart_config; gps_uart_config.baud_rate = GPS_UART_BAUD; gps_uart_config.data_bits = UART_DATA_8_BITS; @@ -70,9 +73,6 @@ void UART_GPS::Init() { } ESP_LOGI(TAG, "gps uart configured"); - mutex_ = xSemaphoreCreateMutex(); - data_ = GpsData{}; - BaseType_t xRet = xTaskCreate(UART_GPS::GPS_Task, "ugv_io_gps", 2 * 1024, this, 1, &this->task_); if (xRet != pdTRUE) { diff --git a/main/ugv_io_mpu.cc b/main/ugv_io_mpu.cc index 90695be..07ab8ed 100644 --- a/main/ugv_io_mpu.cc +++ b/main/ugv_io_mpu.cc @@ -25,6 +25,9 @@ MPU::MPU() { mpu_ = new mpud::MPU(); } MPU::~MPU() { delete mpu_; } void MPU::Init() { + mutex_ = xSemaphoreCreateMutex(); + mpu_data_ = MpuData{}; + esp_err_t ret; ret = mpu_->testConnection(); if (ret != ESP_OK) { @@ -39,9 +42,6 @@ void MPU::Init() { mpu_->setAccelFullScale(MPU_ACCEL_FS); mpu_->setGyroFullScale(MPU_GYRO_FS); - mutex_ = xSemaphoreCreateMutex(); - mpu_data_ = MpuData{}; - BaseType_t xRet = xTaskCreate(MPU::MPU_Task, "ugv_io_mpu", 2 * 1024, this, 3, &this->task_); if (xRet != pdTRUE) {