task stack sizes tailored; semaphore controlled wifi task

This commit is contained in:
Klaus K Wilting 2018-09-27 15:13:15 +02:00
parent cb4870bce5
commit b22fd808b8
5 changed files with 36 additions and 11 deletions

View File

@ -6,13 +6,13 @@
; ---> SELECT TARGET PLATFORM HERE! <--- ; ---> SELECT TARGET PLATFORM HERE! <---
[platformio] [platformio]
;env_default = generic env_default = generic
;env_default = ebox ;env_default = ebox
;env_default = heltec ;env_default = heltec
;env_default = ttgov1 ;env_default = ttgov1
;env_default = ttgov2 ;env_default = ttgov2
;env_default = ttgov21old ;env_default = ttgov21old
env_default = ttgov21new ;env_default = ttgov21new
;env_default = ttgobeam ;env_default = ttgobeam
;env_default = lopy ;env_default = lopy
;env_default = lopy4 ;env_default = lopy4
@ -29,7 +29,7 @@ description = Paxcounter is a proof-of-concept ESP32 device for metering passeng
release_version = 1.5.7 release_version = 1.5.7
; DEBUG LEVEL: For production run set to 0, otherwise device will leak RAM while running! ; 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 ; 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 MODE: select esptool to flash via USB/UART, select custom to upload to cloud for OTA
upload_protocol = esptool upload_protocol = esptool
;upload_protocol = custom ;upload_protocol = custom

View File

@ -23,6 +23,19 @@ void doHousekeeping() {
if (cfg.runmode == 1) if (cfg.runmode == 1)
ESP.restart(); 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 // read battery voltage into global variable
#ifdef HAS_BATTERY_PROBE #ifdef HAS_BATTERY_PROBE
batt_voltage = read_voltage(); batt_voltage = read_voltage();

View File

@ -54,6 +54,7 @@ extern std::array<uint64_t, 0xff>::iterator it;
extern std::array<uint64_t, 0xff> beacons; extern std::array<uint64_t, 0xff> beacons;
extern SemaphoreHandle_t xWifiChannelSwitchSemaphore; extern SemaphoreHandle_t xWifiChannelSwitchSemaphore;
extern TaskHandle_t stateMachineTask, wifiSwitchTask;
#ifdef HAS_GPS #ifdef HAS_GPS
extern TaskHandle_t GpsTask; extern TaskHandle_t GpsTask;

View File

@ -59,7 +59,7 @@ hw_timer_t *channelSwitch, *displaytimer, *sendCycle, *homeCycle;
uint8_t volatile ButtonPressedIRQ = 0, ChannelTimerIRQ = 0, uint8_t volatile ButtonPressedIRQ = 0, ChannelTimerIRQ = 0,
SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, HomeCycleIRQ = 0; SendCycleTimerIRQ = 0, DisplayTimerIRQ = 0, HomeCycleIRQ = 0;
TaskHandle_t stateMachineTask = NULL; TaskHandle_t stateMachineTask, wifiSwitchTask;
SemaphoreHandle_t xWifiChannelSwitchSemaphore; SemaphoreHandle_t xWifiChannelSwitchSemaphore;
@ -308,8 +308,13 @@ void setup() {
// https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/ // https://techtutorialsx.com/2017/05/09/esp32-get-task-execution-core/
ESP_LOGI(TAG, "Starting Lora..."); ESP_LOGI(TAG, "Starting Lora...");
xTaskCreatePinnedToCore(lorawan_loop, "loraloop", 2048, (void *)1, 1, xTaskCreatePinnedToCore(lorawan_loop, /* task function */
&LoraTask, 1); "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 #endif
// if device has GPS and it is enabled, start GPS reader task on core 0 with // 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 // streaming NMEA data
#ifdef HAS_GPS #ifdef HAS_GPS
ESP_LOGI(TAG, "Starting 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 #endif
// start BLE scan callback if BLE function is enabled in NVRAM configuration // start BLE scan callback if BLE function is enabled in NVRAM configuration
@ -339,10 +350,10 @@ void setup() {
// start wifi channel rotation task // start wifi channel rotation task
xTaskCreatePinnedToCore(switchWifiChannel, /* task function */ xTaskCreatePinnedToCore(switchWifiChannel, /* task function */
"wifiloop", /* name of task */ "wifiloop", /* name of task */
3048, /* stack size of task */ 1024, /* stack size of task */
NULL, /* parameter of the task */ NULL, /* parameter of the task */
4, /* priority of the task */ 4, /* priority of the task */
NULL, /* task handle*/ &wifiSwitchTask, /* task handle*/
0); /* CPU core */ 0); /* CPU core */
// start state machine // start state machine

View File

@ -57,7 +57,7 @@ void ChannelSwitchIRQ() {
// Wifi channel rotation task // Wifi channel rotation task
void switchWifiChannel(void * parameter) { void switchWifiChannel(void * parameter) {
while (1) { 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); xSemaphoreTake(xWifiChannelSwitchSemaphore, portMAX_DELAY);
// rotates variable channel 1..WIFI_CHANNEL_MAX // rotates variable channel 1..WIFI_CHANNEL_MAX
channel = (channel % WIFI_CHANNEL_MAX) + 1; channel = (channel % WIFI_CHANNEL_MAX) + 1;