From 01011013fc0659ed3b9f0201edd39e3fa46110f1 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Wed, 9 Feb 2022 12:24:11 +0100 Subject: [PATCH] adjust task prios & delays & time cal cycle --- src/cyclic.cpp | 8 ++++++++ src/gpsread.cpp | 12 +++--------- src/lorawan.cpp | 2 +- src/main.cpp | 10 +++++----- src/rcommand.cpp | 2 +- 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/cyclic.cpp b/src/cyclic.cpp index 45bac2f2..42556acf 100644 --- a/src/cyclic.cpp +++ b/src/cyclic.cpp @@ -34,6 +34,7 @@ void doHousekeeping() { if (rcmdTask != NULL) ESP_LOGD(TAG, "Rcommand interpreter %d bytes left | Taskstate = %d", uxTaskGetStackHighWaterMark(rcmdTask), eTaskGetState(rcmdTask)); + #if (HAS_LORA) if (lmicTask != NULL) ESP_LOGD(TAG, "LMiCtask %d bytes left | Taskstate = %d", @@ -43,11 +44,18 @@ void doHousekeeping() { uxTaskGetStackHighWaterMark(lorasendTask), eTaskGetState(lorasendTask)); #endif + #if (HAS_GPS) if (GpsTask != NULL) ESP_LOGD(TAG, "Gpsloop %d bytes left | Taskstate = %d", uxTaskGetStackHighWaterMark(GpsTask), eTaskGetState(GpsTask)); + // (only) while device time is not set or unsynched, and we have a valid + // GPS time, we call calibrateTime to poll time immeditately from GPS + if ((timeSource == _unsynced || timeSource == _set) && + (gpstime.isUpdated() && gpstime.isValid() && gpstime.age() < 1000)) + calibrateTime(); #endif + #ifdef HAS_SPI if (spiTask != NULL) ESP_LOGD(TAG, "spiloop %d bytes left | Taskstate = %d", diff --git a/src/gpsread.cpp b/src/gpsread.cpp index aecef475..6aef95b0 100644 --- a/src/gpsread.cpp +++ b/src/gpsread.cpp @@ -273,23 +273,17 @@ void gps_loop(void *pvParameters) { // feed GPS decoder with serial NMEA data from GPS device while (GPS_Serial.available()) if (gps.encode(GPS_Serial.read())) - break; // NMEA sentence complete - - // (only) while device time is not set or unsynched, and we have a valid - // GPS time, we call calibrateTime to poll time immeditately from GPS - if ((timeSource == _unsynced || timeSource == _set) && - (gpstime.isUpdated() && gpstime.isValid() && gpstime.age() < 1000)) - calibrateTime(); + break; // leave encode loop after each NMEA complete sentence // show NMEA data, very noisy, useful only for debugging GPS // ESP_LOGV(TAG, "GPS NMEA data: passed %u / failed: %u / with fix: // %u", gps.passedChecksum(), gps.failedChecksum(), gps // .sentencesWithFix()); - delay(2); + delay(5); } // inner while loop - delay(2); + delay(1000); } // outer while loop } // gps_loop() diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 403cf19f..ab5b2fe7 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -305,7 +305,7 @@ esp_err_t lmic_init(void) { "lmictask", // name of task 4096, // stack size of task (void *)1, // parameter of the task - 8, // priority of the task + 1, // priority of the task &lmicTask, // task handle 1); // CPU core diff --git a/src/main.cpp b/src/main.cpp index 9cd922fc..b1d12fbb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,16 +29,16 @@ Task Core Prio Purpose ------------------------------------------------------------------------------- ledloop* 0 1 blinks LEDs spiloop# 0 2 reads/writes data on spi interface -lmictask* 1 8 MCCI LMiC LORAWAN stack +lmictask* 1 1 MCCI LMiC LORAWAN stack clockloop# 1 6 generates realtime telegrams for external clock mqttloop# 1 5 reads/writes data on ETH interface timesync_proc# 1 7 processes realtime time sync requests -irqhandler# 1 4 cyclic tasks (i.e. displayrefresh) triggered by -gpsloop* 1 3 reads data from GPS via serial or i2c +irqhandler# 1 4 application IRQ (i.e. displayrefresh) +gpsloop* 1 1 reads data from GPS via serial or i2c lorasendtask# 1 2 feeds data from lora sendqueue to lmcic rmcd_process# 1 1 Remote command interpreter loop -* spinning task +* spinning task, always ready # blocked/waiting task Low priority numbers denote low priority tasks. @@ -322,7 +322,7 @@ void setup() { "gpsloop", // name of task 8192, // stack size of task (void *)1, // parameter of the task - 3, // priority of the task + 1, // priority of the task &GpsTask, // task handle 1); // CPU core } diff --git a/src/rcommand.cpp b/src/rcommand.cpp index ecaadca7..fe333b1f 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -484,7 +484,7 @@ void rcmd_process(void *pvParameters) { rcmd_execute(RcmdBuffer.cmd, RcmdBuffer.cmdLen); } - delay(2); // yield to CPU + delay(5); // yield to CPU } // rcmd_process() // enqueue remote command