Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Br 5298fa76 #17

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/global_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
11 changes: 1 addition & 10 deletions src/hw_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/hw_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions src/hw_spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@

#include <avr/io.h>

#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
Expand Down
48 changes: 26 additions & 22 deletions src/hw_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <util/setbaud.h> /* 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
Expand All @@ -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<<RXC0)) != 0)
{
uint8_t c = UDR0;
console_rx_callback(c);
}
#elif __AVR_ATmega328P__
if ((UCSR0A&(1<<RXC0)) != 0)
{
uint8_t c = UDR0;
#elif __AVR_ATmega8__
if ((UCSRA&(1<<RXC)) != 0) {
uint8_t c = UDR;
console_rx_callback(c);
}
#elif __AVR_AT90USB162__
Expand All @@ -62,14 +66,14 @@ void hw_uart_tick(void)

void hw_uart_putc(char c)
{
#if __AVR_ATmega168__
#if __AVR_ATmega168__ || __AVR_ATmega328P__
while (bit_is_clear(UCSR0A, UDRE0))
watchdog_reset();
UDR0 = c;
#elif __AVR_ATmega328P__
while (bit_is_clear(UCSR0A, UDRE0))
#elif __AVR_ATmega8__
while (bit_is_clear(UCSRA, UDRE))
watchdog_reset();
UDR0 = c;
UDR = c;
#elif __AVR_AT90USB162__
while (bit_is_clear(UCSR1A, UDRE1))
watchdog_reset();
Expand Down
2 changes: 1 addition & 1 deletion src/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static const uint8_t led_seq_glow[] PROGMEM =
};


static const uint8_t *led_sequences[] PROGMEM =
static const uint8_t *const led_sequences[] PROGMEM =
{
[LED_SEQ_OFF] = led_seq_off,
[LED_SEQ_ON] = led_seq_on,
Expand Down
6 changes: 3 additions & 3 deletions src/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MENU
enum { MENU };
#undef X
#define X(sym,str) sym##_str,
const uint8_t *my_menu[] PROGMEM = { MENU NULL };
const uint8_t *const my_menu[] PROGMEM = { MENU NULL };
#endif
/*****************************************************************/
#if 1
Expand All @@ -42,7 +42,7 @@ MY_MENU2
enum { MY_MENU2 };
#undef X
#define X(sym,str) sym##_str,
const uint8_t *my_menu2[] PROGMEM = { MY_MENU2 NULL };
const uint8_t *const my_menu2[] PROGMEM = { MY_MENU2 NULL };

/*****************************************************************/
#endif
Expand All @@ -56,7 +56,7 @@ static void menu_print_item(uint8_t index, const uint8_t *str_P)
console_newline();
}

uint8_t menu_show(const uint8_t **menu_P)
uint8_t menu_show(const uint8_t *const *menu_P)
{
const uint8_t *str_P;
uint8_t index = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/menu.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MENU_H
#define MENU_H 1

uint8_t menu_show(const uint8_t **menu_P);
uint8_t menu_show(const uint8_t *const *menu_P);
uint8_t menu_pick_key(uint8_t max);

void mymenu(void);
Expand Down
10 changes: 10 additions & 0 deletions src/tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ ISR(TIMER0_OVF_vect)
void tick_init(void)
{
// setup clock divider. Timer0 overflows on counting to 256
#if __AVR_ATmega8__
TCCR0 |= _BV(CS00);
TIFR |= _BV(TOV0);

TCNT0 = 0x0;

// enable overflow interrupts
TIMSK |= _BV(TOIE0);
#else
TCCR0B |= _BV(CS00);
TIFR0 |= _BV(TOV0);

TCNT0 = 0x0;

// enable overflow interrupts
TIMSK0 |= _BV(TOIE0);
#endif
}

uint32_t tick_get(void)
Expand Down