Timer bugfix (issue #145 #148)

This commit is contained in:
Klaus K Wilting 2018-09-21 12:25:52 +02:00
parent ebc3aac991
commit 67832da09d
4 changed files with 23 additions and 22 deletions

View File

@ -63,7 +63,7 @@ void gps_loop(void *pvParameters) {
#endif #endif
} // if (cfg.gpsmode) } // if (cfg.gpsmode)
vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
} // end of infinite loop } // end of infinite loop

View File

@ -248,7 +248,7 @@ void lorawan_loop(void *pvParameters) {
while (1) { while (1) {
os_runloop_once(); // execute LMIC jobs os_runloop_once(); // execute LMIC jobs
vTaskDelay(2 / portTICK_PERIOD_MS); // reset watchdog vTaskDelay(2 / portTICK_PERIOD_MS); // yield to CPU
} }
} }

View File

@ -236,19 +236,22 @@ void setup() {
channelSwitch = timerBegin(1, 800, true); channelSwitch = timerBegin(1, 800, true);
timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true); timerAttachInterrupt(channelSwitch, &ChannelSwitchIRQ, true);
timerAlarmWrite(channelSwitch, cfg.wifichancycle * 1000, 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 // setup send cycle trigger IRQ using esp32 hardware timer 2
sendCycle = timerBegin(2, 8000, true); sendCycle = timerBegin(2, 8000, true);
timerAttachInterrupt(sendCycle, &SendCycleIRQ, true); timerAttachInterrupt(sendCycle, &SendCycleIRQ, true);
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true); timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
timerAlarmEnable(sendCycle);
// setup house keeping cycle trigger IRQ using esp32 hardware timer 3 // setup house keeping cycle trigger IRQ using esp32 hardware timer 3
homeCycle = timerBegin(3, 8000, true); homeCycle = timerBegin(3, 8000, true);
timerAttachInterrupt(homeCycle, &homeCycleIRQ, true); timerAttachInterrupt(homeCycle, &homeCycleIRQ, true);
timerAlarmWrite(homeCycle, HOMECYCLE * 10000, true); timerAlarmWrite(homeCycle, HOMECYCLE * 10000, true);
//enable timers, caution: order is critical here
timerAlarmEnable(homeCycle); timerAlarmEnable(homeCycle);
timerAlarmEnable(sendCycle);
timerAlarmEnable(channelSwitch);
// show payload encoder // show payload encoder
#if PAYLOAD_ENCODER == 1 #if PAYLOAD_ENCODER == 1
@ -324,7 +327,6 @@ void setup() {
void loop() { void loop() {
while (1) {
// state machine for switching display, LED, button, housekeeping, // state machine for switching display, LED, button, housekeeping,
// senddata // senddata
@ -346,11 +348,10 @@ void loop() {
processSendBuffer(); processSendBuffer();
// check send cycle and enqueue payload if cycle is expired // check send cycle and enqueue payload if cycle is expired
sendPayload(); sendPayload();
// reset watchdog // yield to CPU
vTaskDelay(2 / portTICK_PERIOD_MS); vTaskDelay(2 / portTICK_PERIOD_MS);
} // loop() } // loop()
}
/* end Arduino main loop /* end Arduino main loop
* ------------------------------------------------------------ */ * ------------------------------------------------------------ */

View File

@ -58,10 +58,10 @@ void wifi_channel_loop(void *pvParameters) {
channel = (channel % WIFI_CHANNEL_MAX) + 1; channel = (channel % WIFI_CHANNEL_MAX) + 1;
esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE); esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
ESP_LOGD(TAG, "Wifi set channel %d", channel); 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 } // end of infinite wifi channel rotation loop
} }