watchdog test (not working for now)
This commit is contained in:
parent
85b27248b0
commit
65807c648c
|
@ -40,6 +40,7 @@
|
|||
/* variables */
|
||||
bool query_pzem004 = false; // flag to query the PZEM-004 power meter
|
||||
volatile uint8_t timer_seconds = 0; // how many seconds have passed
|
||||
volatile bool watchdog = true; // set when watchdog interrupt occurred
|
||||
|
||||
/* disable watchdog when booting */
|
||||
void wdt_init(void) __attribute__((naked)) __attribute__((section(".init3")));
|
||||
|
@ -74,7 +75,7 @@ int main(void)
|
|||
{
|
||||
io_init(); // initialize IOs
|
||||
|
||||
//printf(PSTR("welcome to the spar counter power meter monitor\n"));
|
||||
printf(PSTR("welcome to the spar counter power meter monitor\n"));
|
||||
|
||||
struct configuration conf; // node configuration
|
||||
// read configuration data from EEPROM + CRC-8-iButton value
|
||||
|
@ -109,8 +110,24 @@ int main(void)
|
|||
bool send_values = false; // set to true to send out the values
|
||||
|
||||
bool action = false; // to know if we performed any king of action during which some other activity could have happened
|
||||
|
||||
/* start watchdog */
|
||||
wdt_enable(WDTO_4S);
|
||||
while (true);
|
||||
WDTCSR = (1<<WDCE); // change settings
|
||||
//WDTCSR = (0<<WDP3)|(1<<WDP2)|(1<<WDP1)|(1<<WDP0); // set time-out to 2s
|
||||
WDTCSR = (1<<WDP3)|(0<<WDP2)|(0<<WDP1)|(1<<WDP0);
|
||||
WDTCSR = (1<<WDCE); // change settings
|
||||
WDTCSR = (1<<WDE)|(1<<WDIE); // enable interrupt than system reset mode
|
||||
while (true);
|
||||
|
||||
while (true) { // endless loop for micro-controller
|
||||
action = false; // new cycle of actions
|
||||
if (watchdog) { // watchdog interrupt trigger. clear before system reset
|
||||
WDTCSR = (1<<WDCE); // change settings
|
||||
WDTCSR = (1<<WDE)|(1<<WDIE); // enable interrupt than system reset mode
|
||||
watchdog = false;
|
||||
}
|
||||
if (timer_seconds!=0 && timer_seconds==conf.request_period) {
|
||||
action = true; // an action is performed
|
||||
timer_seconds = 0; // restart timer
|
||||
|
@ -247,3 +264,9 @@ ISR(TIMER1_COMPA_vect)
|
|||
{
|
||||
timer_seconds++; // count seconds
|
||||
}
|
||||
|
||||
/* watchdog interrupt */
|
||||
ISR(WDT_vect)
|
||||
{
|
||||
watchdog = true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue