Browse Source

Initialize in better order to avoid errors

ugv_io
Alex Mikhalev 6 years ago
parent
commit
d34b7679f2
  1. 3
      components/sx127x_driver/sx127x_driver.c
  2. 6
      main/ugv_comms.c
  3. 6
      main/ugv_io_gps.cc
  4. 6
      main/ugv_io_mpu.cc

3
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); SX127X_CHECK(hndl != NULL, "malloc error", ESP_ERR_NO_MEM);
*handle_ptr = hndl; *handle_ptr = hndl;
hndl->spi_mutex = xSemaphoreCreateMutex();
hndl->task_handle = NULL; hndl->task_handle = NULL;
atomic_init(&hndl->task_state, SX127X_TASK_STOPPED); atomic_init(&hndl->task_state, SX127X_TASK_STOPPED);
memcpy(&hndl->config, config, sizeof(sx127x_config_t)); 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); gpio_set_level(config->rst_io_num, 1);
vTaskDelay(SX127X_RESET_DELAY); vTaskDelay(SX127X_RESET_DELAY);
hndl->spi_mutex = xSemaphoreCreateMutex();
spi_bus_config_t bus_config = { spi_bus_config_t bus_config = {
.mosi_io_num = config->mosi_io_num, .mosi_io_num = config->mosi_io_num,
.miso_io_num = config->miso_io_num, .miso_io_num = config->miso_io_num,

6
main/ugv_comms.c

@ -21,6 +21,8 @@ static void ugv_comms_handle_command(ugv_comms_state_t * st,
void ugv_comms_init() { void ugv_comms_init() {
ugv_comms_state_t *st = &ugv_comms_state; ugv_comms_state_t *st = &ugv_comms_state;
st->mutex = xSemaphoreCreateMutex();
sx127x_config_t lora_config = SX127X_CONFIG_DEFAULT; sx127x_config_t lora_config = SX127X_CONFIG_DEFAULT;
lora_config.sck_io_num = LORA_SCK; lora_config.sck_io_num = LORA_SCK;
lora_config.miso_io_num = LORA_MISO; lora_config.miso_io_num = LORA_MISO;
@ -35,9 +37,7 @@ void ugv_comms_init() {
lora_config.sync_word = 0x34; lora_config.sync_word = 0x34;
lora_config.crc = SX127X_CRC_ENABLED; lora_config.crc = SX127X_CRC_ENABLED;
esp_err_t ret; esp_err_t ret;
st->mutex = xSemaphoreCreateMutex();
uas_ugv_Location loc = uas_ugv_Location_init_default; uas_ugv_Location loc = uas_ugv_Location_init_default;
memcpy(&st->location, &loc, sizeof(loc)); memcpy(&st->location, &loc, sizeof(loc));
st->ugv_state = uas_ugv_UGV_State_IDLE; st->ugv_state = uas_ugv_UGV_State_IDLE;

6
main/ugv_io_gps.cc

@ -47,6 +47,9 @@ UART_GPS::~UART_GPS() {}
void UART_GPS::Init() { void UART_GPS::Init() {
esp_err_t ret; esp_err_t ret;
mutex_ = xSemaphoreCreateMutex();
data_ = GpsData{};
uart_config_t gps_uart_config; uart_config_t gps_uart_config;
gps_uart_config.baud_rate = GPS_UART_BAUD; gps_uart_config.baud_rate = GPS_UART_BAUD;
gps_uart_config.data_bits = UART_DATA_8_BITS; gps_uart_config.data_bits = UART_DATA_8_BITS;
@ -70,9 +73,6 @@ void UART_GPS::Init() {
} }
ESP_LOGI(TAG, "gps uart configured"); ESP_LOGI(TAG, "gps uart configured");
mutex_ = xSemaphoreCreateMutex();
data_ = GpsData{};
BaseType_t xRet = xTaskCreate(UART_GPS::GPS_Task, "ugv_io_gps", 2 * 1024, BaseType_t xRet = xTaskCreate(UART_GPS::GPS_Task, "ugv_io_gps", 2 * 1024,
this, 1, &this->task_); this, 1, &this->task_);
if (xRet != pdTRUE) { if (xRet != pdTRUE) {

6
main/ugv_io_mpu.cc

@ -25,6 +25,9 @@ MPU::MPU() { mpu_ = new mpud::MPU(); }
MPU::~MPU() { delete mpu_; } MPU::~MPU() { delete mpu_; }
void MPU::Init() { void MPU::Init() {
mutex_ = xSemaphoreCreateMutex();
mpu_data_ = MpuData{};
esp_err_t ret; esp_err_t ret;
ret = mpu_->testConnection(); ret = mpu_->testConnection();
if (ret != ESP_OK) { if (ret != ESP_OK) {
@ -39,9 +42,6 @@ void MPU::Init() {
mpu_->setAccelFullScale(MPU_ACCEL_FS); mpu_->setAccelFullScale(MPU_ACCEL_FS);
mpu_->setGyroFullScale(MPU_GYRO_FS); mpu_->setGyroFullScale(MPU_GYRO_FS);
mutex_ = xSemaphoreCreateMutex();
mpu_data_ = MpuData{};
BaseType_t xRet = BaseType_t xRet =
xTaskCreate(MPU::MPU_Task, "ugv_io_mpu", 2 * 1024, this, 3, &this->task_); xTaskCreate(MPU::MPU_Task, "ugv_io_mpu", 2 * 1024, this, 3, &this->task_);
if (xRet != pdTRUE) { if (xRet != pdTRUE) {

Loading…
Cancel
Save