From b22fd808b89b80121b025009644c821afe4acea9 Mon Sep 17 00:00:00 2001 From: Klaus K Wilting Date: Thu, 27 Sep 2018 15:13:15 +0200 Subject: [PATCH] task stack sizes tailored; semaphore controlled wifi task --- platformio.ini | 6 +++--- src/cyclic.cpp | 15 ++++++++++++++- src/globals.h | 1 + src/main.cpp | 23 +++++++++++++++++------ src/wifiscan.cpp | 2 +- 5 files changed, 36 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index 028ecd13..8e3d7397 100644 --- a/platformio.ini +++ b/platformio.ini @@ -6,13 +6,13 @@ ; ---> SELECT TARGET PLATFORM HERE! <--- [platformio] -;env_default = generic +env_default = generic ;env_default = ebox ;env_default = heltec ;env_default = ttgov1 ;env_default = ttgov2 ;env_default = ttgov21old -env_default = ttgov21new +;env_default = ttgov21new ;env_default = ttgobeam ;env_default = lopy ;env_default = lopy4 @@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng release_version = 1.5.7 ; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 0=None, 1=Error, 2=Warn, 3=Info, 4=Debug, 5=Verbose -debug_level = 3 +debug_level = 0 ; UPLOAD MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA upload_protocol = esptool ;upload_protocol = custom diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 0d5d1a3d..756c1a42 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -23,6 +23,19 @@ void doHousekeeping() { if (cfg.runmode == 1) ESP.restart(); +// task storage debugging // +#ifdef HAS_LORA + ESP_LOGD(TAG, "Loraloop %d bytes left", + uxTaskGetStackHighWaterMark(LoraTask)); +#endif + ESP_LOGD(TAG, "Wifiloop %d bytes left", + uxTaskGetStackHighWaterMark(wifiSwitchTask)); + ESP_LOGD(TAG, "Statemachine %d bytes left", + uxTaskGetStackHighWaterMark(stateMachineTask)); +#ifdef HAS_GPS + ESP_LOGD(TAG, "Gpsloop %d bytes left", uxTaskGetStackHighWaterMark(GpsTask)); +#endif + // read battery voltage into global variable #ifdef HAS_BATTERY_PROBE batt_voltage = read_voltage(); @@ -48,7 +61,7 @@ void doHousekeeping() { esp_get_minimum_free_heap_size(), ESP.getFreeHeap()); SendData(COUNTERPORT); // send data before clearing counters reset_counters(); // clear macs container and reset all counters - get_salt(); // get new salt for salting hashes + get_salt(); // get new salt for salting hashes if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again esp_restart(); // memory leak, reset device diff --git a/src/globals.h b/src/globals.h index e9412403..a63859e1 100644 --- a/src/globals.h +++ b/src/globals.h @@ -54,6 +54,7 @@ extern std::array::iterator it; extern std::array beacons; extern SemaphoreHandle_t xWifiChannelSwitchSemaphore; +extern TaskHandle_t stateMachineTask, wifiSwitchTask; #ifdef HAS_GPS extern TaskHandle_t GpsTask; diff --git a/src/main.cpp b/src/main.cpp index 27c5b8c5..15363f54 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -59,7 +59,7 @@ hw_timer_t *channelSwitch, *displaytimer, *sendCycle, *homeCycle; uint8_t volatile ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, HomeCycleIRQ = 0; -TaskHandle_t stateMachineTask = NULL; +TaskHandle_t stateMachineTask, wifiSwitchTask; SemaphoreHandle_t xWifiChannelSwitchSemaphore; @@ -308,8 +308,13 @@ void setup() { // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ ESP_LOGI(TAG, "Starting Lora..."); - xTaskCreatePinnedToCore(lorawan_loop, "loraloop", 2048, (void *)1, 1, - &LoraTask, 1); + xTaskCreatePinnedToCore(lorawan_loop, /* task function */ + "loraloop", /* name of task */ + 2560, /* stack size of task */ + (void *)1, /* parameter of the task */ + 1, /* priority of the task */ + &LoraTask, /* task handle*/ + 1); /* CPU core */ #endif // if device has GPS and it is enabled, start GPS reader task on core 0 with @@ -317,7 +322,13 @@ void setup() { // streaming NMEA data #ifdef HAS_GPS ESP_LOGI(TAG, "Starting GPS..."); - xTaskCreatePinnedToCore(gps_loop, "gpsloop", 2048, (void *)1, 2, &GpsTask, 0); + xTaskCreatePinnedToCore(gps_loop, /* task function */ + "gpsloop", /* name of task */ + 1024, /* stack size of task */ + (void *)1, /* parameter of the task */ + 2, /* priority of the task */ + &GpsTask, /* task handle*/ + 0); /* CPU core */ #endif // start BLE scan callback if BLE function is enabled in NVRAM configuration @@ -339,10 +350,10 @@ void setup() { // start wifi channel rotation task xTaskCreatePinnedToCore(switchWifiChannel, /* task function */ "wifiloop", /* name of task */ - 3048, /* stack size of task */ + 1024, /* stack size of task */ NULL, /* parameter of the task */ 4, /* priority of the task */ - NULL, /* task handle*/ + &wifiSwitchTask, /* task handle*/ 0); /* CPU core */ // start state machine diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index 04ebb3a7..21a5a95e 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -57,7 +57,7 @@ void ChannelSwitchIRQ() { // Wifi channel rotation task void switchWifiChannel(void * parameter) { while (1) { - // task in block state to wait for channel switch timer interrupt event + // task is remaining in block state waiting for channel switch timer interrupt event xSemaphoreTake(xWifiChannelSwitchSemaphore, portMAX_DELAY); // rotates variable channel 1..WIFI_CHANNEL_MAX channel = (channel % WIFI_CHANNEL_MAX) + 1;