Browse Source

Fixed Interrupt WDT Reset

pull/1687/head
Kevin Le 2 months ago
parent
commit
f4c43f7eb7
  1. 34
      src/helpers/ESP32Board.h

34
src/helpers/ESP32Board.h

@ -19,11 +19,12 @@ class ESP32Board : public mesh::MainBoard {
protected: protected:
uint8_t startup_reason; uint8_t startup_reason;
bool inhibit_sleep = false; bool inhibit_sleep = false;
static inline portMUX_TYPE sleepMux = portMUX_INITIALIZER_UNLOCKED;
public: public:
void begin() { void begin() {
// for future use, sub-classes SHOULD call this from their begin() // for future use, sub-classes SHOULD call this from their begin()
startup_reason = BD_STARTUP_NORMAL; startup_reason = BD_STARTUP_NORMAL;
#ifdef ESP32_CPU_FREQ #ifdef ESP32_CPU_FREQ
setCpuFrequencyMhz(ESP32_CPU_FREQ); setCpuFrequencyMhz(ESP32_CPU_FREQ);
@ -46,7 +47,7 @@ public:
#endif #endif
#else #else
Wire.begin(); Wire.begin();
#endif #endif
} }
// Temperature from ESP32 MCU // Temperature from ESP32 MCU
@ -84,10 +85,8 @@ public:
} }
#endif #endif
// Configure GPIO wakeup // Set GPIO wakeup
gpio_num_t wakeupPin = (gpio_num_t)getIRQGpio(); gpio_num_t wakeupPin = (gpio_num_t)getIRQGpio();
esp_sleep_enable_gpio_wakeup();
gpio_wakeup_enable((gpio_num_t)wakeupPin, GPIO_INTR_HIGH_LEVEL); // Wake up when receiving a LoRa packet
// Configure timer wakeup // Configure timer wakeup
if (secs > 0) { if (secs > 0) {
@ -95,14 +94,19 @@ public:
} }
// Disable CPU interrupt servicing // Disable CPU interrupt servicing
noInterrupts(); portENTER_CRITICAL(&sleepMux);
// Skip sleep if there is a LoRa packet // Skip sleep if there is a LoRa packet
if (digitalRead(wakeupPin) == HIGH) { if (gpio_get_level(wakeupPin) == HIGH) {
interrupts(); portEXIT_CRITICAL(&sleepMux);
delay(1);
return; return;
} }
// Configure GPIO wakeup
esp_sleep_enable_gpio_wakeup();
gpio_wakeup_enable((gpio_num_t)wakeupPin, GPIO_INTR_HIGH_LEVEL); // Wake up when receiving a LoRa packet
// MCU enters light sleep // MCU enters light sleep
esp_light_sleep_start(); esp_light_sleep_start();
@ -111,7 +115,7 @@ public:
gpio_set_intr_type(wakeupPin, GPIO_INTR_POSEDGE); gpio_set_intr_type(wakeupPin, GPIO_INTR_POSEDGE);
// Enable CPU interrupt servicing // Enable CPU interrupt servicing
interrupts(); portEXIT_CRITICAL(&sleepMux);
} }
uint8_t getStartupReason() const override { return startup_reason; } uint8_t getStartupReason() const override { return startup_reason; }
@ -135,7 +139,7 @@ public:
#endif #endif
uint16_t getBattMilliVolts() override { uint16_t getBattMilliVolts() override {
#ifdef PIN_VBAT_READ #ifdef PIN_VBAT_READ
analogReadResolution(12); analogReadResolution(12);
uint32_t raw = 0; uint32_t raw = 0;
@ -174,16 +178,16 @@ public:
// start with some date/time in the recent past // start with some date/time in the recent past
struct timeval tv; struct timeval tv;
tv.tv_sec = 1715770351; // 15 May 2024, 8:50pm tv.tv_sec = 1715770351; // 15 May 2024, 8:50pm
tv.tv_usec = 0; tv.tv_usec = 0;
settimeofday(&tv, NULL); settimeofday(&tv, NULL);
} }
} }
uint32_t getCurrentTime() override { uint32_t getCurrentTime() override {
time_t _now; time_t _now;
time(&_now); time(&_now);
return _now; return _now;
} }
void setCurrentTime(uint32_t time) override { void setCurrentTime(uint32_t time) override {
struct timeval tv; struct timeval tv;
tv.tv_sec = time; tv.tv_sec = time;
tv.tv_usec = 0; tv.tv_usec = 0;

Loading…
Cancel
Save