diff --git a/src/gps.cpp b/src/gps.cpp index 15dd9638..849ca30e 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -63,7 +63,7 @@ void gps_loop(void *pvParameters) { #endif } // if (cfg.gpsmode) - vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog + vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU } // end of infinite loop diff --git a/src/lorawan.cpp b/src/lorawan.cpp index a9939893..95babc37 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -248,7 +248,7 @@ void lorawan_loop(void *pvParameters) { while (1) { os_runloop_once(); // execute LMIC jobs - vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog + vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU } } diff --git a/src/main.cpp b/src/main.cpp index aeb9ffd4..7b207d71 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -236,19 +236,22 @@ void setup() { channelSwitch = timerBegin(1, 800, true); timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); timerAlarmWrite(channelSwitch, cfg.wifichancycle * 1000, true); - timerAlarmEnable(channelSwitch); + //ESP_LOGI(TAG, "chanelswitch alarm threshold %d", cfg.wifichancycle * 1000); // setup send cycle trigger IRQ using esp32 hardware timer 2 sendCycle = timerBegin(2, 8000, true); timerAttachInterrupt(sendCycle, &SendCycleIRQ, true); timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true); - timerAlarmEnable(sendCycle); // setup house keeping cycle trigger IRQ using esp32 hardware timer 3 homeCycle = timerBegin(3, 8000, true); timerAttachInterrupt(homeCycle, &homeCycleIRQ, true); timerAlarmWrite(homeCycle, HOMECYCLE * 10000, true); + + //enable timers, caution: order is critical here timerAlarmEnable(homeCycle); + timerAlarmEnable(sendCycle); + timerAlarmEnable(channelSwitch); // show payload encoder #if PAYLOAD_ENCODER == 1 @@ -324,33 +327,31 @@ void setup() { void loop() { - while (1) { - // state machine for switching display, LED, button, housekeeping, - // senddata + // state machine for switching display, LED, button, housekeeping, + // senddata #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) - led_loop(); + led_loop(); #endif #ifdef HAS_BUTTON - readButton(); + readButton(); #endif #ifdef HAS_DISPLAY - updateDisplay(); + updateDisplay(); #endif - // check housekeeping cycle and if expired do homework - checkHousekeeping(); - // check send queue and process it - processSendBuffer(); - // check send cycle and enqueue payload if cycle is expired - sendPayload(); - // reset watchdog - vTaskDelay(2 / portTICK_PERIOD_MS); + // check housekeeping cycle and if expired do homework + checkHousekeeping(); + // check send queue and process it + processSendBuffer(); + // check send cycle and enqueue payload if cycle is expired + sendPayload(); + // yield to CPU + vTaskDelay(2 / portTICK_PERIOD_MS); - } // loop() -} +} // loop() /* end Arduino main loop * ------------------------------------------------------------ */ diff --git a/src/wifiscan.cpp b/src/wifiscan.cpp index ed3a84ee..4c240738 100644 --- a/src/wifiscan.cpp +++ b/src/wifiscan.cpp @@ -58,10 +58,10 @@ void wifi_channel_loop(void *pvParameters) { channel = (channel % WIFI_CHANNEL_MAX) + 1; esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); ESP_LOGD(TAG, "Wifi set channel %d", channel); - - vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog } + vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU + } // end of infinite wifi channel rotation loop }