diff --git a/src/cpu.c b/src/cpu.c index d2151f8..23bf9c1 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -6,8 +6,11 @@ void cpu_init(void) { + /* XXX an associated macro is checked, not the function */ +#ifdef clock_prescale_get /* Disable clock division */ clock_prescale_set(clock_div_1); +#endif } void cpu_reset(void) diff --git a/src/global_commands.h b/src/global_commands.h index 8909f50..6cb76bd 100644 --- a/src/global_commands.h +++ b/src/global_commands.h @@ -8,7 +8,7 @@ typedef BOOL (*global_command_func_t)(const uint8_t *tok_start, const uint8_t *l typedef struct { - const prog_char *name; + const char *name; global_command_func_t handler; } global_command_t; diff --git a/src/hw_i2c.c b/src/hw_i2c.c index 8ed2ad1..21b15ec 100644 --- a/src/hw_i2c.c +++ b/src/hw_i2c.c @@ -49,16 +49,7 @@ #else -#if __AVR_ATmega168__ -#define SDA PC4 // SDA pin -#define SCL PC5 // SCL pin -#define SDA_DDR DDRC -#define SCL_DDR DDRC -#define SDA_OUT PORTC -#define SCL_OUT PORTC -#define SDA_IN PINC -#define SCL_IN PINC -#elif __AVR_ATmega328P__ +#if __AVR_ATmega8__ || __AVR_ATmega168__ || __AVR_ATmega328P__ #define SDA PC4 // SDA pin #define SCL PC5 // SCL pin #define SDA_DDR DDRC diff --git a/src/hw_spi.c b/src/hw_spi.c index 60a4767..d68817f 100644 --- a/src/hw_spi.c +++ b/src/hw_spi.c @@ -3,7 +3,7 @@ void hw_spi_init(void) { - uint8_t tmp; + uint8_t tmp __attribute__ ((unused)); /* used to discard status */ // SCK and MOSI as output, SS as output - we're master SPI_DDR |= _BV(SPI_SCLK) | _BV(SPI_MOSI) | _BV(SPI_SS); diff --git a/src/hw_spi.h b/src/hw_spi.h index c3b3b44..25033cf 100644 --- a/src/hw_spi.h +++ b/src/hw_spi.h @@ -3,14 +3,7 @@ #include -#if __AVR_ATmega168__ -#define SPI_PORT PORTB -#define SPI_DDR DDRB -#define SPI_SS PB2 -#define SPI_MOSI PB3 -#define SPI_MISO PB4 -#define SPI_SCLK PB5 -#elif __AVR_ATmega328P__ +#if __AVR_ATmega8__ || __AVR_ATmega168__ || __AVR_ATmega328P__ #define SPI_PORT PORTB #define SPI_DDR DDRB #define SPI_SS PB2 diff --git a/src/hw_uart.c b/src/hw_uart.c index 7cb5a37..6401ff2 100644 --- a/src/hw_uart.c +++ b/src/hw_uart.c @@ -6,27 +6,32 @@ #include "console.h" #include "watchdog.h" -// When doing calculations per page 174 od atmega168 datasheet, -// make sure we use real numbers and round, not truncate -#define UBRR_VAL ((1.0 * F_CPU / (16.0 * BAUD)) + 0.5 - 1) -#define UBRR_DOUBLESPEED_VAL ((1.0 * F_CPU / (8.0 * BAUD)) + 0.5 - 1) +#include /* BAUD may be defined in hw_uart.h */ void hw_uart_init(void) { -#if __AVR_ATmega168__ -#if BAUD > 57600 - // Setup lower divider to get higher precision for high baud rate. +#if __AVR_ATmega168__ || __AVR_ATmega328P__ +#if USE_2X UCSR0A |= _BV(U2X0); - UBRR0 = UBRR_DOUBLESPEED_VAL; #else - UBRR0 = UBRR_VAL; + UCSR0A &= ~_BV(U2X0); #endif + UBRR0 = UBRR_VALUE; UCSR0B = _BV(TXEN0) | _BV(RXEN0); -#elif __AVR_ATmega328P__ - UBRR0 = (F_CPU / (16UL * BAUD)) - 1; - UCSR0B = _BV(TXEN0) | _BV(RXEN0); +#elif __AVR_ATmega8__ +#if USE_2X + UCSRA |= _BV(U2X); +#else + UCSRA &= ~_BV(U2X); +#endif + UBRRH = UBRRH_VALUE; + UBRRL = UBRRL_VALUE; + UCSRB = _BV(TXEN) | _BV(RXEN); #elif __AVR_AT90USB162__ - UBRR1 = UBRR_VAL; +#if USE_2X +#error U2X not supported on AT90USB162 +#endif + UBRR1 = UBRR_VALUE; UCSR1B = _BV(TXEN1) | _BV(RXEN1); #else #error Unsupported device, FIXME @@ -36,16 +41,15 @@ void hw_uart_init(void) void hw_uart_tick(void) { #ifdef CONFIG_HW_UART_CONSOLE -#if __AVR_ATmega168__ +#if __AVR_ATmega168__ || __AVR_ATmega328P__ if ((UCSR0A&(1<