summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lock/Client.Makefile3
-rw-r--r--lock/Server.Makefile4
-rw-r--r--lock/nrfm.c60
-rw-r--r--lock/nrfm.h2
-rw-r--r--lock/server.c6
-rw-r--r--lock/uart.c37
6 files changed, 4 insertions, 108 deletions
diff --git a/lock/Client.Makefile b/lock/Client.Makefile
index abb8567..a6758fd 100644
--- a/lock/Client.Makefile
+++ b/lock/Client.Makefile
@@ -3,7 +3,7 @@ MCU = atmega328p
PORT = /dev/cuaU0
TARGET = client
-SRC = client.c fpm.c uart.c nrfm.c util.c
+SRC = client.c fpm.c nrfm.c util.c
OBJ = $(SRC:.c=.o)
CFLAGS = -std=gnu99
@@ -12,7 +12,6 @@ CFLAGS += -Wall
CFLAGS += -mmcu=$(MCU)
CFLAGS += -DBAUD=57600
CFLAGS += -DF_CPU=16000000UL
-CFLAGS += -DDEBUG=0
CFLAGS += -DFPM_PWD=$(FPM_PWD)
CFLAGS += -ffunction-sections -fdata-sections
diff --git a/lock/Server.Makefile b/lock/Server.Makefile
index 0071e8d..f853a34 100644
--- a/lock/Server.Makefile
+++ b/lock/Server.Makefile
@@ -3,15 +3,13 @@ MCU = atmega328p
PORT = /dev/cuaU0
TARGET = server
-SRC = server.c uart.c nrfm.c util.c
+SRC = server.c nrfm.c util.c
OBJ = $(SRC:.c=.o)
CFLAGS = -std=gnu99
CFLAGS += -Os
CFLAGS += -Wall
CFLAGS += -mmcu=$(MCU)
-CFLAGS += -DBAUD=115200
-CFLAGS += -DDEBUG=1
CFLAGS += -DF_CPU=16000000UL
CFLAGS += -ffunction-sections -fdata-sections
diff --git a/lock/nrfm.c b/lock/nrfm.c
index c6769fb..a82135b 100644
--- a/lock/nrfm.c
+++ b/lock/nrfm.c
@@ -6,7 +6,6 @@
#include <util/delay.h>
#include "nrfm.h"
-#include "uart.h"
#define SPI_SS PB2
#define SPI_SCK PB5
@@ -176,32 +175,6 @@ static inline uint8_t rx_pdlen(void)
return SPDR;
}
-void radio_print_config(void)
-{
-#if DEBUG
- char s[22];
- uint8_t i, rv, addr[ADDRLEN];
-
- uint8_t regs[] = {
- 0x00, 0x01, 0x02, 0x03, 0x04,
- 0x05, 0x06, 0x07, 0x11, 0x1C, 0x1D
- };
-
- uart_write_line("NRF24L01 config:");
-
- for (i = 0; i < LEN(regs); i++) {
- rv = read_reg(regs[i]);
- snprintf(s, LEN(s), "\t0x%02X: 0x%02X %s%s",
- regs[i], rv, bittab[rv >> 4], bittab[rv & 0x0F]);
- uart_write_line(s);
- }
-
- read_reg_bulk(0x0B, addr, ADDRLEN);
- snprintf(s, LEN(s), "\r\n\t0x0B: %d.%d.%d", addr[2], addr[1], addr[0]);
- uart_write_line(s);
-#endif
-}
-
void radio_init(const uint8_t rxaddr[ADDRLEN])
{
SPI_DDR |= (1 << SPI_SS) | (1 << SPI_SCK) | (1 << SPI_MOSI);
@@ -259,16 +232,6 @@ uint8_t radio_sendto(const uint8_t addr[ADDRLEN], const char *msg, uint8_t n)
setaddr(0x10, addr);
setaddr(0x0A, addr);
-#if DEBUG
- char s[4];
- uart_write("DEBUG: sending to ");
- uart_write(itoa(addr[0], s, 10));
- uart_write(".");
- uart_write(itoa(addr[1], s, 10));
- uart_write(".");
- uart_write_line(itoa(addr[2], s, 10));
-#endif
-
imax = n < MAXPDLEN ? n : MAXPDLEN;
SPI_PORT &= ~(1 << SPI_SS);
@@ -293,16 +256,8 @@ uint8_t radio_sendto(const uint8_t addr[ADDRLEN], const char *msg, uint8_t n)
maxrt = rv & (1 << 4);
} while (txds == 0 && maxrt == 0);
-#if DEBUG
- if (txds)
- uart_write_line("DEBUG: packet sent");
-#endif
- if (maxrt) {
+ if (maxrt)
flush_tx();
-#if DEBUG
- uart_write_line("ERROR: sendto() failed: MAX_RT");
-#endif
- }
// restore config, typically rx mode
write_reg(0x00, cfg);
@@ -320,24 +275,11 @@ uint8_t radio_recv(char *buf, uint8_t n)
pdlen = rx_pdlen();
if (pdlen == 0) {
radio_flush_rx();
-#if DEBUG
- uart_write_line("ERROR: PDLEN = 0, abort read");
-#endif
return 0;
}
-#if DEBUG
- char s[3];
- itoa(pdlen, s, 10);
- uart_write("DEBUG: PDLEN=");
- uart_write_line(s);
-#endif
-
if (pdlen > MAXPDLEN) {
radio_flush_rx();
-#if DEBUG
- uart_write_line("ERROR: PDLEN > MAXPDLEN, abort read");
-#endif
return 0;
}
diff --git a/lock/nrfm.h b/lock/nrfm.h
index 009832f..52d4edb 100644
--- a/lock/nrfm.h
+++ b/lock/nrfm.h
@@ -8,8 +8,6 @@
void radio_init(const uint8_t rxaddr[ADDRLEN]);
-void radio_print_config(void);
-
void radio_listen(void);
void radio_pwr_dwn(void);
diff --git a/lock/server.c b/lock/server.c
index 12c5569..8274f81 100644
--- a/lock/server.c
+++ b/lock/server.c
@@ -9,7 +9,6 @@
#include <util/delay.h>
#include "nrfm.h"
-#include "uart.h"
#include "util.h"
#define PWM_MIN 500
@@ -74,7 +73,7 @@ static inline void init_wdt(void)
wdt_reset();
WDTCSR |= (1 << WDCE) | ( 1 << WDE);
- WDTCSR = (1 << WDP2) | (1 << WDP1);
+ WDTCSR = (1 << WDE) | (1 << WDP2) | (1 << WDP1);
WDTCSR |= (1 << WDIE);
}
@@ -132,10 +131,8 @@ int main(void)
init_btns();
init_servo();
- uart_init();
led_init();
radio_init(rxaddr);
- radio_print_config();
sei();
radio_listen();
@@ -169,7 +166,6 @@ int main(void)
sleep_bod_disable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_mode();
- radio_listen();
}
}
return 0;
diff --git a/lock/uart.c b/lock/uart.c
deleted file mode 100644
index a6d6674..0000000
--- a/lock/uart.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <avr/io.h>
-#include <util/setbaud.h>
-
-#include "uart.h"
-
-void uart_init(void)
-{
- UBRR0H = UBRRH_VALUE;
- UBRR0L = UBRRL_VALUE;
-#if USE_2X
- UCSR0A |= (1 << U2X0);
-#else
- UCSR0A &= ~(1 << U2X0);
-#endif
- UCSR0B = (1 << TXEN0) | (1 << RXEN0);
- UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
-}
-
-static inline void uart_write_char(char c)
-{
- while (!(UCSR0A & (1 << UDRE0)))
- ;
- UDR0 = c;
-}
-
-void uart_write(const char *s)
-{
- for (; *s; s++)
- uart_write_char(*s);
-}
-
-void uart_write_line(const char *s)
-{
- uart_write(s);
- uart_write_char('\r');
- uart_write_char('\n');
-}