aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2012-03-15 15:37:46 +0000
committerDimitri Sokolyuk <demon@dim13.org>2012-03-15 15:37:46 +0000
commit5f069d4537f18a0db7608ff2e7ba531c9102745e (patch)
tree4ee7b6e82313bf5b33581502c5c366f871fa3417
parent2972db07e0058336e6d07cfc11320a57b16970d8 (diff)
ATmega328P port
-rw-r--r--bootloader/bootloader.c2
-rw-r--r--bootloader/bootloader.h9
-rw-r--r--firmware/Makefile7
-rw-r--r--firmware/firmware.c22
-rw-r--r--kernel/dmx/Makefile10
-rw-r--r--kernel/kernel.c2
-rw-r--r--kernel/uart.c38
7 files changed, 46 insertions, 44 deletions
diff --git a/bootloader/bootloader.c b/bootloader/bootloader.c
index 82ba04b..931d641 100644
--- a/bootloader/bootloader.c
+++ b/bootloader/bootloader.c
@@ -22,8 +22,6 @@
#include <string.h>
#include "bootloader.h"
-#define GUARDPAGE 120
-
int
transfer(int fd, struct page *p, int pages, int pagesize)
{
diff --git a/bootloader/bootloader.h b/bootloader/bootloader.h
index 5de5e8b..3c5f301 100644
--- a/bootloader/bootloader.h
+++ b/bootloader/bootloader.h
@@ -18,10 +18,11 @@
#ifndef __BOOTLOADER_H
#define __BOOTLOADER_H
-#define PAGESIZE 64
-#define PAGENUM 128
-#define RAMSTART 0x60
-#define RAMEND 0x45F
+#define PAGESIZE 128 /* 64 words */
+#define PAGENUM 256 /* Table 28-11 */
+#define GUARDPAGE (256 - 32)
+#define RAMSTART 0x100
+#define RAMEND 0x8FF
struct page {
unsigned char *data;
diff --git a/firmware/Makefile b/firmware/Makefile
index cd7975a..935980b 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -3,11 +3,10 @@
PROG= firmware
NOMAN=
-MCU_TARGET= atmega8
-F_CPU= 16000000
-PRESCALE= 8
+MCU_TARGET= atmega328p
+F_CPU= 20000000
BAUD= 9600
-ORG= 0x1e00
+ORG= 0x7e00 # Table 27-13, 4 Pages 265 words * 2
# You should not have to change anything below here.
diff --git a/firmware/firmware.c b/firmware/firmware.c
index 528c9e9..cb7ea6d 100644
--- a/firmware/firmware.c
+++ b/firmware/firmware.c
@@ -19,8 +19,10 @@
#include <avr/boot.h>
#include <util/setbaud.h> /* depends on BAUD & F_CPU env vars */
-#define TIMEOUT (F_CPU / PRESCALE) /* 1 sec */
-#define PUTCH(c) do { loop_until_bit_is_set(UCSRA, UDRE); UDR = (c); } while (0)
+#define TIMEOUT (F_CPU / 8) /* 1 sec */
+#define PUTCH(c) do { \
+ loop_until_bit_is_set(UCSR0A, UDRE0); UDR0 = (c); \
+} while (0)
union {
uint16_t word;
@@ -39,17 +41,21 @@ main(void)
uint8_t sum = 0;
uint8_t state = INIT;
- UCSRB = _BV(RXEN) | _BV(TXEN);
- UBRRH = UBRRH_VALUE;
- UBRRL = UBRRL_VALUE;
- UCSRA &= ~_BV(U2X);
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
+ UBRR0H = UBRRH_VALUE;
+ UBRR0L = UBRRL_VALUE;
+ #if USE_2X
+ UCSR0A |= _BV(U2X0);
+ #else
+ UCSR0A &= ~_BV(U2X0);
+ #endif
PUTCH('+'); /* say hallo */
for (;;) {
- for (c = 0; bit_is_clear(UCSRA, RXC); c++)
+ for (c = 0; bit_is_clear(UCSR0A, RXC0); c++)
if (c > TIMEOUT)
goto reboot;
- ch = UDR; /* GETCH */
+ ch = UDR0; /* GETCH */
switch (state) {
case INIT:
diff --git a/kernel/dmx/Makefile b/kernel/dmx/Makefile
index deb7b98..4ee69ca 100644
--- a/kernel/dmx/Makefile
+++ b/kernel/dmx/Makefile
@@ -1,14 +1,8 @@
# $Id$
-MCU= atmega8
-F_CPU= 16000000
-#F_CPU= 14745600
-#PRESCALE= 1 # res 62.5nsec cycle 4msec
+MCU= atmega328p
+F_CPU= 20000000
PRESCALE= 8 # res 0.5usec cycle 32.7msec
-#PRESCALE= 64 # res 4usec cycle 262msec
-#PRESCALE= 256 # res 16msec cycle 1 sec
-#PRESCALE= 1024 # res 64msec cycle 4 sec
-#STACK= 48
STACK= 80
TASKS= 11 # +1 idle = 12
SEMAPHORES= 2
diff --git a/kernel/kernel.c b/kernel/kernel.c
index eb79413..169108c 100644
--- a/kernel/kernel.c
+++ b/kernel/kernel.c
@@ -121,7 +121,7 @@ init(uint8_t stack)
TCNT1 = 0; /* reset timer */
TCCR1A = 0; /* normal operation */
TCCR1B = TIMER_FLAGS; /* prescale */
- TIMSK = (_BV(OCIE1A) | _BV(TOIE1)); /* enable interrupts */
+ TIMSK1 = (_BV(OCIE1A) | _BV(TOIE1)); /* enable interrupts */
OCR1A = 0; /* default overflow */
TAILQ_INIT(&kernel.runq);
diff --git a/kernel/uart.c b/kernel/uart.c
index ec015e5..ab17bb2 100644
--- a/kernel/uart.c
+++ b/kernel/uart.c
@@ -33,11 +33,11 @@
FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
#ifdef USE_RXCIE
-ISR(SIG_UART_RECV)
+ISR(USART_RX_vect)
{
uint8_t c, *p;
- switch ((c = UDR)) {
+ switch ((c = UDR0)) {
case 'Z': /* zero */
for (p = (uint8_t *)RAMSTART; p <= (uint8_t *)RAMEND; p++)
*p = 0;
@@ -51,10 +51,10 @@ ISR(SIG_UART_RECV)
uart_putchar(*p, NULL);
break;
case 'T':
- UCSRB |= _BV(UDRIE);
+ UCSR0B |= _BV(UDRIE0);
break;
case 't':
- UCSRB &= ~_BV(UDRIE);
+ UCSR0B &= ~_BV(UDRIE0);
break;
case '\r':
case '\n':
@@ -65,24 +65,28 @@ ISR(SIG_UART_RECV)
}
}
-ISR(SIG_UART_DATA)
+ISR(USART_UDRE_vect)
{
uint8_t r = running();
- UDR = r ? '0' + r : '.';
+ UDR0 = r ? '0' + r : '.';
}
#endif
void
uart_init(void)
{
- UCSRB = _BV(RXEN) | _BV(TXEN);
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
#ifdef USE_RXCIE
- UCSRB |= _BV(RXCIE);
+ UCSR0B |= _BV(RXCIE0);
#endif
- UBRRH = UBRRH_VALUE;
- UBRRL = UBRRL_VALUE;
- UCSRA &= ~_BV(U2X);
+ UBRR0H = UBRRH_VALUE;
+ UBRR0L = UBRRL_VALUE;
+ #if USE_U2X
+ UCSR0A |= _BV(U2X0);
+ #else
+ UCSR0A &= ~_BV(U2X0);
+ #endif
stdin = &uart_stream;
stdout = &uart_stream;
@@ -93,8 +97,8 @@ uart_putchar(char c, FILE *fd)
{
if (c == '\n')
uart_putchar('\r', fd);
- loop_until_bit_is_set(UCSRA, UDRE);
- UDR = c;
+ loop_until_bit_is_set(UCSR0A, UDRE0);
+ UDR0 = c;
return 0;
}
@@ -104,14 +108,14 @@ uart_getchar(FILE *fd)
{
char c;
- loop_until_bit_is_set(UCSRA, RXC);
+ loop_until_bit_is_set(UCSR0A, RXC0);
- if (bit_is_set(UCSRA, FE))
+ if (bit_is_set(UCSR0A, FE0))
return -2; /* EOF */
- if (bit_is_set(UCSRA, DOR))
+ if (bit_is_set(UCSR0A, DOR0))
return -1; /* ERR */
- c = UDR;
+ c = UDR0;
uart_putchar(c, fd); /* ECHO */
switch (c) {