Add a watchdog module to meshsolar. (#9337)

* add watchdog module

* Restore the code in power.h

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
This commit is contained in:
Quency-D
2026-01-29 10:41:27 +08:00
committed by GitHub
parent df400850c1
commit b2f2f6b305
4 changed files with 75 additions and 7 deletions

View File

@@ -91,6 +91,9 @@
#include "modules/DropzoneModule.h" #include "modules/DropzoneModule.h"
#endif #endif
#if defined(HAS_HARDWARE_WATCHDOG)
#include "watchdog/watchdogThread.h"
#endif
/** /**
* Create module instances here. If you are adding a new module, you must 'new' it here (or somewhere else) * Create module instances here. If you are adding a new module, you must 'new' it here (or somewhere else)
*/ */
@@ -229,6 +232,9 @@ void setupModules()
#if !MESHTASTIC_EXCLUDE_RANGETEST && !MESHTASTIC_EXCLUDE_GPS #if !MESHTASTIC_EXCLUDE_RANGETEST && !MESHTASTIC_EXCLUDE_GPS
if (moduleConfig.has_range_test && moduleConfig.range_test.enabled) if (moduleConfig.has_range_test && moduleConfig.range_test.enabled)
new RangeTestModule(); new RangeTestModule();
#endif
#if defined(HAS_HARDWARE_WATCHDOG)
watchdogThread = new WatchdogThread();
#endif #endif
// NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra // NOTE! This module must be added LAST because it likes to check for replies from other modules and avoid sending extra
// acks // acks

View File

@@ -0,0 +1,37 @@
#include "watchdogThread.h"
#include "configuration.h"
#ifdef HAS_HARDWARE_WATCHDOG
WatchdogThread *watchdogThread;
WatchdogThread::WatchdogThread() : OSThread("Watchdog")
{
setup();
}
void WatchdogThread::feedDog(void)
{
digitalWrite(HARDWARE_WATCHDOG_DONE, HIGH);
delay(1);
digitalWrite(HARDWARE_WATCHDOG_DONE, LOW);
}
int32_t WatchdogThread::runOnce()
{
LOG_DEBUG("Feeding hardware watchdog");
feedDog();
return HARDWARE_WATCHDOG_TIMEOUT_MS;
}
bool WatchdogThread::setup()
{
LOG_DEBUG("init hardware watchdog");
pinMode(HARDWARE_WATCHDOG_WAKE, INPUT);
pinMode(HARDWARE_WATCHDOG_DONE, OUTPUT);
delay(1);
digitalWrite(HARDWARE_WATCHDOG_DONE, LOW);
delay(1);
feedDog();
return true;
}
#endif

View File

@@ -0,0 +1,19 @@
#pragma once
#include <stdint.h>
#include "concurrency/OSThread.h"
#ifdef HAS_HARDWARE_WATCHDOG
class WatchdogThread : private concurrency::OSThread
{
public:
WatchdogThread();
void feedDog(void);
virtual bool setup();
virtual int32_t runOnce() override;
};
extern WatchdogThread *watchdogThread;
#endif

View File

@@ -39,15 +39,15 @@ extern "C" {
#define NUM_ANALOG_INPUTS (1) #define NUM_ANALOG_INPUTS (1)
#define NUM_ANALOG_OUTPUTS (0) #define NUM_ANALOG_OUTPUTS (0)
#define PIN_LED1 (0 + 4) // green (confirmed on 1.0 board) #define PIN_LED1 (32 + 15) // green (confirmed on 1.0 board)
#define LED_BLUE PIN_LED1 // fake for bluefruit library #define LED_BLUE PIN_LED1 // fake for bluefruit library
#define LED_GREEN PIN_LED1 #define LED_GREEN PIN_LED1
#define LED_STATE_ON 0 // State when LED is lit #define LED_STATE_ON 0 // State when LED is lit
#define HAS_NEOPIXEL // Enable the use of neopixels // #define HAS_NEOPIXEL // Enable the use of neopixels
#define NEOPIXEL_COUNT 1 // How many neopixels are connected // #define NEOPIXEL_COUNT 1 // How many neopixels are connected
#define NEOPIXEL_DATA (32 + 15) // gpio pin used to send data to the neopixels // #define NEOPIXEL_DATA (32 + 15) // gpio pin used to send data to the neopixels
#define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800) // type of neopixels in use // #define NEOPIXEL_TYPE (NEO_GRB + NEO_KHZ800) // type of neopixels in use
/* /*
* Buttons * Buttons
@@ -59,8 +59,8 @@ extern "C" {
/* /*
No longer populated on PCB No longer populated on PCB
*/ */
#define PIN_SERIAL2_RX (0 + 9) #define PIN_SERIAL2_RX (-1)
#define PIN_SERIAL2_TX (0 + 10) #define PIN_SERIAL2_TX (-1)
/* /*
* I2C * I2C
@@ -137,6 +137,12 @@ No longer populated on PCB
// To debug via the segger JLINK console rather than the CDC-ACM serial device // To debug via the segger JLINK console rather than the CDC-ACM serial device
// #define USE_SEGGER // #define USE_SEGGER
// Hardware watchdog
#define HAS_HARDWARE_WATCHDOG
#define HARDWARE_WATCHDOG_DONE (0 + 9)
#define HARDWARE_WATCHDOG_WAKE (0 + 10)
#define HARDWARE_WATCHDOG_TIMEOUT_MS (6*60*1000) // 6 minute watchdog
#define BQ4050_SDA_PIN (32 + 1) // I2C data line pin #define BQ4050_SDA_PIN (32 + 1) // I2C data line pin
#define BQ4050_SCL_PIN (32 + 0) // I2C clock line pin #define BQ4050_SCL_PIN (32 + 0) // I2C clock line pin
#define BQ4050_EMERGENCY_SHUTDOWN_PIN (32 + 3) // Emergency shutdown pin #define BQ4050_EMERGENCY_SHUTDOWN_PIN (32 + 3) // Emergency shutdown pin