diff options
| -rw-r--r-- | lock/bend.c | 26 | ||||
| -rw-r--r-- | lock/nrfm.c | 10 | ||||
| -rw-r--r-- | lock/nrfm.h | 2 |
3 files changed, 38 insertions, 0 deletions
diff --git a/lock/bend.c b/lock/bend.c index 3957c55..03934d1 100644 --- a/lock/bend.c +++ b/lock/bend.c @@ -3,6 +3,8 @@ #include <stdint.h> #include <string.h> +#include <avr/wdt.h> +#include <avr/sleep.h> #include <avr/interrupt.h> #include <util/delay.h> @@ -63,6 +65,15 @@ static inline void keydel(char *buf, uint8_t n) buf[i] = 0; } +static inline void init_wdt(void) +{ + cli(); + wdt_reset(); + WDTCSR |= (1 << WDCE) | ( 1 << WDE); + WDTCSR = (1 << WDP2) | (1 << WDP1) | (1 << WDP0); + WDTCSR |= (1 << WDIE); +} + static inline void init_rx(void) { RX_DDR &= ~(1 << RX_PIN); @@ -112,6 +123,7 @@ int main(void) char buf[WDLEN], key[WDLEN], msg[WDLEN]; + init_wdt(); init_rx(); init_btns(); init_servo(); @@ -124,6 +136,9 @@ int main(void) radio_listen(); for (;;) { + if (!rxd) + _delay_ms(250); + if (rxd) { radio_recv(buf, WDLEN); rxd = 0; @@ -142,6 +157,13 @@ int main(void) keydel(key, WDLEN); } } + } else { + radio_pwr_dwn(); + sleep_enable(); + sleep_bod_disable(); + sleep_cpu(); + sleep_disable(); + radio_listen(); } } return 0; @@ -163,3 +185,7 @@ ISR(INT1_vect) if (is_btn_pressed(PIND, UNLOCK_PIN)) unlock(); } + +ISR(WDT_vect) +{ +} diff --git a/lock/nrfm.c b/lock/nrfm.c index edffb87..253c6ce 100644 --- a/lock/nrfm.c +++ b/lock/nrfm.c @@ -232,6 +232,16 @@ void radio_listen(void) enable_chip(); } +void radio_pwr_dwn(void) +{ + uint8_t rv; + + disable_chip(); + rv = read_reg(0x00); + rv &= ~(1 << PWR_UP); + write_reg(0x00, rv); +} + uint8_t radio_sendto(const uint8_t addr[ADDRLEN], const char *msg, uint8_t n) { char s[4]; diff --git a/lock/nrfm.h b/lock/nrfm.h index 7c38031..009832f 100644 --- a/lock/nrfm.h +++ b/lock/nrfm.h @@ -12,6 +12,8 @@ void radio_print_config(void); void radio_listen(void); +void radio_pwr_dwn(void); + uint8_t radio_recv(char *buf, uint8_t n); void radio_flush_rx(void); |
