From 6dd3b665dde8fae96e60353df5176078ef9f3555 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 30 Apr 2025 11:11:53 +0800 Subject: Front end sleep. --- lock/fend.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'lock/fend.c') diff --git a/lock/fend.c b/lock/fend.c index 966bfde..7177e72 100644 --- a/lock/fend.c +++ b/lock/fend.c @@ -3,6 +3,8 @@ #include #include +#include +#include #include #include @@ -26,6 +28,15 @@ static volatile uint8_t sync = 0; static volatile uint8_t islock = 0; static volatile uint8_t isunlock = 0; +static inline void wdt_off(void) +{ + cli(); + wdt_reset(); + MCUSR &= ~(1 << WDRF); + WDTCSR |= (1 << WDCE) | (1 << WDE); + WDTCSR = 0x00; +} + static inline void init_rx(void) { RX_DDR &= ~(1 << RX_PIN); @@ -45,12 +56,12 @@ static inline void init_btns(void) int main(void) { - uint8_t n; uint8_t rxaddr[ADDRLEN] = { 194, 178, 82 }; uint8_t txaddr[ADDRLEN] = { 194, 178, 83 }; char buf[WDLEN], key[WDLEN]; + wdt_off(); init_rx(); init_btns(); @@ -68,11 +79,10 @@ int main(void) sync = radio_sendto(txaddr, buf, WDLEN); _delay_ms(50); } while (!sync); - uart_write_line("sent SYN"); } if (rxd) { - n = radio_recv(buf, WDLEN); + radio_recv(buf, WDLEN); rxd = 0; if (sync && (islock || isunlock)) { sync = 0; @@ -87,6 +97,15 @@ int main(void) radio_sendto(txaddr, buf, WDLEN); } } + + if (!sync) { + radio_pwr_dwn(); + sleep_enable(); + sleep_bod_disable(); + sleep_cpu(); + sleep_disable(); + radio_listen(); + } } return 0; } -- cgit v1.2.3