Jump to reset vector when program exceeds specified watchdog timeout

This commit is contained in:
2024-09-05 17:55:05 +02:00
parent 7eaacf4abf
commit 0bd4866816
5 changed files with 31 additions and 18 deletions

View File

@@ -7,13 +7,14 @@
#include <avr/interrupt.h>
// TODO: Convert raw data from ADS1115 to usable values.
// TODO: Implement optional sensor value check with CRC8.
// TODO: Set timeouts for polling based things like I2C.
// TODO: Write an improved serial parser (low priority).
// TODO: Implement optional CRC8 sensor measurement check.
// TODO: Either implement software PWM for the FAN03 timer
// (which will be quite complicated) or pick a chip with
// more than two 16-bit PWM outputs like the ATmega328PB.
// https://www.mikrocontroller.net/articles/Soft-PWM
// TODO: Check if FAN02 is receiving the right frequency.
// TODO: Write an improved command parser (low priority).
// TODO: Proper error handling and recovery (after testing).
int Init(void)
{
@@ -48,8 +49,8 @@ int Init(void)
if (WDT_HasTriggered())
Info("Unexpected system reset.");
// WDT_Enable();
// WDT_SetTimeout(7);
WDT_Enable();
WDT_SetTimeoutFlag(0x7); // 2 seconds
// There is a possiblity to use interrupt signals
// for I2C communication but only as one large
@@ -98,8 +99,6 @@ void Update(void)
float temp[3], rhum[3];
short raw[4];
WDT_Reset(); // Reset watchdog
Info("Reading sensor values...");
I2C_SetChannel(AHT01);
@@ -128,7 +127,9 @@ int main(void)
Init();
for (;;) {
WDT_Reset();
Update();
WDT_Reset();
Sleep(1000);
}