diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-11 11:54:06 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2025-04-11 11:54:06 +0800 |
| commit | 00efdf295efb4da45e2e65807ea127c2193f993b (patch) | |
| tree | 8f6b04aad8d0c5eb0cd670741dff4f7e4a3e9775 | |
| parent | 94ebd8da9b256dea2f30dc33c40a1494e39152f8 (diff) | |
| download | smart-home-00efdf295efb4da45e2e65807ea127c2193f993b.tar.gz | |
WDT control code.
| -rw-r--r-- | lock/scan.c | 4 | ||||
| -rw-r--r-- | lock/servo.c | 4 | ||||
| -rw-r--r-- | lock/util.c | 8 | ||||
| -rw-r--r-- | lock/util.h | 2 |
4 files changed, 17 insertions, 1 deletions
diff --git a/lock/scan.c b/lock/scan.c index e375111..6784e9a 100644 --- a/lock/scan.c +++ b/lock/scan.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <avr/interrupt.h> +#include <avr/wdt.h> #include <util/delay.h> #include "nrfm.h" @@ -22,6 +23,7 @@ int main(void) TCCR1B |= (1 << WGM13) | (1 << CS11); ICR1 = 20000; + wdt_init(); uart_init(); radio_init(rxaddr); radio_print_config(); @@ -29,6 +31,8 @@ int main(void) sei(); for (;;) { + wdt_reset(); + _delay_ms(2000); } return 0; diff --git a/lock/servo.c b/lock/servo.c index fedc706..9b735ea 100644 --- a/lock/servo.c +++ b/lock/servo.c @@ -3,8 +3,8 @@ #include <stdint.h> #include <string.h> -#include <avr/io.h> #include <avr/interrupt.h> +#include <avr/wdt.h> #include <util/delay.h> #include "nrfm.h" @@ -55,6 +55,7 @@ int main(void) PCICR |= (1 << RX_PCIE); RX_PCMSK |= (1 << RX_PCINT); + wdt_init(); uart_init(); servo_init(); radio_init(rxaddr); @@ -64,6 +65,7 @@ int main(void) radio_listen(); for (;;) { + wdt_reset(); if (rxdr) { } else { _delay_ms(2000); diff --git a/lock/util.c b/lock/util.c index bc62438..dda35a2 100644 --- a/lock/util.c +++ b/lock/util.c @@ -1,5 +1,6 @@ #include <avr/io.h> #include <avr/interrupt.h> +#include <avr/wdt.h> #include "util.h" @@ -14,6 +15,13 @@ static char tab[] = { static uint16_t tablen = sizeof(tab) / sizeof(tab[0]); +void wdt_init(void) +{ + wdt_reset(); + WDTCSR |= (1 << WDCE) | (1 << WDE); + WDTCSR = (1 << WDE) | (1 << WDP3) | (1 << WDP0); +} + void keygen(char *buf, uint8_t n) { int i, imax; diff --git a/lock/util.h b/lock/util.h index 54dc66b..cb4e86f 100644 --- a/lock/util.h +++ b/lock/util.h @@ -9,6 +9,8 @@ #define WDLEN 32 +void wdt_init(void); + void keygen(char *buf, uint8_t n); void xor(const char *k, const char *s, char *d, uint8_t n); |
