2018-01-29 12:43:22 +00:00
|
|
|
// ======================================================================================================
|
|
|
|
|
2018-02-18 14:41:50 +00:00
|
|
|
#include "freertos/FreeRTOS.h" // FreeeRTOS
|
2018-01-29 12:43:22 +00:00
|
|
|
#include "freertos/task.h"
|
|
|
|
|
2018-02-18 14:41:50 +00:00
|
|
|
#include "hal.h" // Hardware Abstraction Layer
|
2018-01-29 12:43:22 +00:00
|
|
|
|
2018-02-18 14:41:50 +00:00
|
|
|
#include "rf.h" // RF control/transmission/reception task
|
|
|
|
#include "proc.h" // GPS/RF process taskk
|
|
|
|
#include "gps.h" // GPS control data acquisiton
|
2018-02-25 18:47:03 +00:00
|
|
|
#include "sens.h"
|
2020-04-30 22:23:17 +00:00
|
|
|
#include "imu.h"
|
2018-02-18 14:41:50 +00:00
|
|
|
#include "ctrl.h" // Control task
|
2019-01-22 00:08:19 +00:00
|
|
|
#include "log.h" // Data logging task
|
2020-02-24 21:54:21 +00:00
|
|
|
#include "knob.h" // potentiometer as rotary encoder
|
|
|
|
#include "sound.h" // sounds, warnings, alarms
|
|
|
|
#include "disp.h"
|
2019-01-22 00:08:19 +00:00
|
|
|
|
2020-05-06 16:31:43 +00:00
|
|
|
#ifdef WITH_SDLOG
|
|
|
|
#include "sdlog.h"
|
|
|
|
#endif
|
|
|
|
|
2019-05-08 17:03:54 +00:00
|
|
|
#ifdef WITH_AERO
|
|
|
|
#include "aero.h"
|
|
|
|
#endif
|
|
|
|
|
2020-08-29 11:49:46 +00:00
|
|
|
#ifdef WITH_STRATUX
|
|
|
|
#include "stratux.h"
|
|
|
|
#endif
|
|
|
|
|
2020-10-29 02:08:34 +00:00
|
|
|
#ifdef WITH_AP
|
|
|
|
#include "ap.h"
|
|
|
|
#endif
|
|
|
|
|
2020-10-27 23:45:07 +00:00
|
|
|
#ifdef WITH_APRS
|
|
|
|
#include "aprs.h" // APRS task
|
2019-01-22 00:08:19 +00:00
|
|
|
#endif
|
2018-01-29 12:43:22 +00:00
|
|
|
|
|
|
|
extern "C"
|
|
|
|
void app_main(void)
|
|
|
|
{
|
|
|
|
// printf("OGN Tracker on ESP32\n");
|
|
|
|
|
2020-09-21 00:42:12 +00:00
|
|
|
CONS_UART_Init();
|
2018-02-25 18:47:03 +00:00
|
|
|
CONS_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the writing to the console
|
2020-04-30 22:23:17 +00:00
|
|
|
I2C_Mutex = xSemaphoreCreateMutex(); // semaphore for sharing the I2C bus
|
2018-01-29 12:43:22 +00:00
|
|
|
|
2018-02-18 14:41:50 +00:00
|
|
|
NVS_Init(); // initialize Non-Volatile-Storage in Flash and read the tracker parameters
|
2018-01-29 12:43:22 +00:00
|
|
|
|
2018-02-18 14:41:50 +00:00
|
|
|
Parameters.setDefault(getUniqueAddress()); // set default parameter values
|
|
|
|
if(Parameters.ReadFromNVS()!=ESP_OK) // try to get parameters from NVS
|
|
|
|
{ Parameters.WriteToNVS(); } // if did not work: try to save (default) parameters to NVS
|
2020-10-08 01:30:52 +00:00
|
|
|
|
2019-01-22 00:08:19 +00:00
|
|
|
#ifdef WITH_SPIFFS
|
2018-02-18 14:41:50 +00:00
|
|
|
SPIFFS_Register(); // initialize the file system in the Flash
|
2019-01-22 00:08:19 +00:00
|
|
|
#endif
|
2018-03-09 13:11:21 +00:00
|
|
|
IO_Configuration(); // initialize the GPIO/UART/I2C/SPI for Radio, GPS, OLED, Baro
|
|
|
|
|
2020-02-24 21:54:21 +00:00
|
|
|
#ifdef WITH_SD
|
2020-04-19 19:19:32 +00:00
|
|
|
if(SD_isMounted()) // if SD card succesfully mounted at startup
|
2020-02-24 21:54:21 +00:00
|
|
|
{ Parameters.SaveToFlash=0;
|
2020-04-19 19:19:32 +00:00
|
|
|
if(Parameters.ReadFromFile("/sdcard/TRACKER.CFG")>0) // try to read parameters from the TRACKER.CFG file
|
|
|
|
{ if(Parameters.SaveToFlash) Parameters.WriteToNVS(); } // if succesfull and SaveToFlash==1 then save them to flash
|
|
|
|
// #ifdef WITH_SPIFFS
|
2020-08-29 11:52:29 +00:00
|
|
|
// FlashLog_CopyToSD(); // copy all flash log files to the SD card
|
2020-04-19 19:19:32 +00:00
|
|
|
// #endif
|
2020-02-24 21:54:21 +00:00
|
|
|
}
|
|
|
|
#endif
|
2020-10-09 13:08:50 +00:00
|
|
|
#ifdef WITH_LORAWAN
|
2020-10-19 23:35:45 +00:00
|
|
|
WANdev.Reset(getUniqueID(), Parameters.AppKey); // set default LoRaWAN config.
|
|
|
|
if(WANdev.ReadFromNVS()!=ESP_OK) // if can't read the LoRaWAN setup from NVS
|
|
|
|
{ WANdev.WriteToNVS(); } // then store the default
|
|
|
|
if(Parameters.hasAppKey())
|
|
|
|
{ if(!Parameters.sameAppKey(WANdev.AppKey)) // if LoRaWAN key different from the one in Parameters
|
|
|
|
{ WANdev.Reset(getUniqueID(), Parameters.AppKey); // then reset LoRaWAN to this key
|
|
|
|
WANdev.WriteToNVS(); } // and save LoRaWAN config. to NVS
|
|
|
|
Parameters.clrAppKey(); }
|
2020-10-09 13:08:50 +00:00
|
|
|
#endif
|
2020-02-24 21:54:21 +00:00
|
|
|
|
2020-04-19 19:19:32 +00:00
|
|
|
CONS_UART_SetBaudrate(Parameters.CONbaud);
|
|
|
|
|
2018-02-18 14:41:50 +00:00
|
|
|
#ifdef WITH_BT_SPP
|
2019-01-22 00:08:19 +00:00
|
|
|
{ int32_t Err=BT_SPP_Init(); // start BT SPP
|
|
|
|
// #ifdef DEBUG_PRINT
|
|
|
|
xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
|
|
|
|
Format_String(CONS_UART_Write, "BT_SPP_Init() => ");
|
|
|
|
Format_SignDec(CONS_UART_Write, Err);
|
|
|
|
Format_String(CONS_UART_Write, "\n");
|
|
|
|
xSemaphoreGive(CONS_Mutex);
|
|
|
|
// #endif
|
|
|
|
}
|
2018-02-18 14:41:50 +00:00
|
|
|
#endif
|
|
|
|
|
2020-05-06 16:31:43 +00:00
|
|
|
#ifdef WITH_SDLOG
|
|
|
|
Log_Mutex = xSemaphoreCreateMutex();
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskSDLOG, "SDLOG", 4000, 0, tskIDLE_PRIORITY+1, 0);
|
2019-01-22 00:08:19 +00:00
|
|
|
#endif
|
2020-09-26 01:00:23 +00:00
|
|
|
|
|
|
|
#ifdef WITH_LOG
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskLOG , "LOG", 5000, 0, tskIDLE_PRIORITY+1, 0);
|
2020-09-26 01:00:23 +00:00
|
|
|
#endif
|
|
|
|
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskRF, "RF", 2000, 0, tskIDLE_PRIORITY+5, 0);
|
|
|
|
xTaskCreate(vTaskPROC, "PROC", 2000, 0, tskIDLE_PRIORITY+3, 0);
|
2020-09-26 01:00:23 +00:00
|
|
|
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskGPS, "GPS", 2000, 0, tskIDLE_PRIORITY+4, 0);
|
2020-04-18 18:05:51 +00:00
|
|
|
#if defined(WITH_BMP180) || defined(WITH_BMP280) || defined(WITH_BME280) || defined(WITH_MS5607) || defined(WITH_MS5611)
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskSENS, "SENS", 2000, 0, tskIDLE_PRIORITY+4, 0);
|
2019-01-22 00:08:19 +00:00
|
|
|
#endif
|
2020-04-30 22:23:17 +00:00
|
|
|
#ifdef WITH_BMX055
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskIMU, "IMU", 2000, 0, tskIDLE_PRIORITY+4, 0);
|
2020-04-30 22:23:17 +00:00
|
|
|
#endif
|
2020-09-26 01:00:23 +00:00
|
|
|
|
2020-02-24 21:54:21 +00:00
|
|
|
#ifdef WITH_KNOB
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskKNOB, "KNOB", 2000, 0, tskIDLE_PRIORITY+3, 0);
|
2020-02-24 21:54:21 +00:00
|
|
|
#endif
|
2019-05-08 17:03:54 +00:00
|
|
|
#ifdef WITH_AERO
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskAERO, "AERO", 2000, 0, tskIDLE_PRIORITY+3, 0);
|
2019-05-08 17:03:54 +00:00
|
|
|
#endif
|
2020-10-27 23:45:07 +00:00
|
|
|
#ifdef WITH_APRS
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskAPRS, "APRS", 4000, 0, tskIDLE_PRIORITY+2, 0);
|
2020-02-24 21:54:21 +00:00
|
|
|
#endif
|
2020-08-29 17:54:47 +00:00
|
|
|
#ifdef WITH_STRATUX
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskSTX, "STX", 4000, 0, tskIDLE_PRIORITY+3, 0);
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_AP
|
|
|
|
xTaskCreate(vTaskAP, "AP", 4000, 0, tskIDLE_PRIORITY+3, 0);
|
2020-08-29 11:49:46 +00:00
|
|
|
#endif
|
2020-02-24 21:54:21 +00:00
|
|
|
#if defined(WITH_OLED) || defined(WITH_U8G2_OLED) || defined(WITH_ST7789) || defined(WITH_ILI9341)
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskDISP, "DISP", 3000, 0, tskIDLE_PRIORITY+2, 0);
|
2020-02-24 21:54:21 +00:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_SOUND
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskSOUND, "SOUND", 2000, 0, tskIDLE_PRIORITY+3, 0);
|
2018-02-25 19:33:58 +00:00
|
|
|
#endif
|
2020-10-29 02:08:34 +00:00
|
|
|
xTaskCreate(vTaskTICK , "TICK", 1000, 0, tskIDLE_PRIORITY+3, 0);
|
2018-01-29 12:43:22 +00:00
|
|
|
// xTaskCreate(vTaskCTRL, "CTRL", 1536, 0, tskIDLE_PRIORITY+2, 0);
|
|
|
|
vTaskCTRL(0); // run directly the CTRL task, instead of creating a separate one.
|
|
|
|
|
|
|
|
// while(1)
|
|
|
|
// { vTaskDelay(10000); }
|
|
|
|
}
|
|
|
|
|