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,33 +327,31 @@ 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
#if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED) #if (HAS_LED != NOT_A_PIN) || defined(HAS_RGB_LED)
led_loop(); led_loop();
#endif #endif
#ifdef HAS_BUTTON #ifdef HAS_BUTTON
readButton(); readButton();
#endif #endif
#ifdef HAS_DISPLAY #ifdef HAS_DISPLAY
updateDisplay(); updateDisplay();
#endif #endif
// check housekeeping cycle and if expired do homework // check housekeeping cycle and if expired do homework
checkHousekeeping(); checkHousekeeping();
// check send queue and process it // check send queue and process it
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
} }