Initialize in better order to avoid errors
This commit is contained in:
parent
87dc10cdc5
commit
d34b7679f2
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user