summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sw-avr/rom-loader/main.c34
-rw-r--r--sw-avr/rom-loader/makefile25
-rw-r--r--sw-avr/rom-loader/pinmap.h19
-rwxr-xr-xsw-avr/rom-loader/rom-loader.binbin6352 -> 0 bytes
-rw-r--r--sw-avr/rom-loader/usart.c37
-rw-r--r--sw-avr/rom-loader/usart.h10
6 files changed, 115 insertions, 10 deletions
diff --git a/sw-avr/rom-loader/main.c b/sw-avr/rom-loader/main.c
index b178c06..784afb6 100644
--- a/sw-avr/rom-loader/main.c
+++ b/sw-avr/rom-loader/main.c
@@ -1,6 +1,38 @@
#include <avr/io.h>
+#include "usart.h"
+#include "pinmap.h"
+
+// TODO: remove
+#include <util/delay.h>
+
+
+inline void io_init(void)
+{
+ ADDRL_DDR |= (_BV(ADDRL_bitE) | _BV(ADDRL_bitD));
+ ADDRL_DDR |= (0x7<<ADDRL_bitA0); // 3 bits
+
+ ADDRH_DDR |= (_BV(ADDRH_bitE) | _BV(ADDRH_bitD));
+ ADDRH_DDR |= (0x7<<ADDRH_bitA0);
+
+ // all output
+ DATA_DDR = 0xFF;
+}
+
int main(void)
{
- return;
+ io_init();
+ usart_init();
+
+ // TODO: remove
+ DATA_PORT |= _BV(1);
+
+ while (1) {
+ DATA_PORT ^= _BV(1);
+ _delay_ms(500);
+
+ usart_send('c');
+ }
+
+ return 0;
}
diff --git a/sw-avr/rom-loader/makefile b/sw-avr/rom-loader/makefile
index e68174f..85222c8 100644
--- a/sw-avr/rom-loader/makefile
+++ b/sw-avr/rom-loader/makefile
@@ -1,17 +1,24 @@
-CC=avr-gcc
-CARGS=-Wall -mmcu=atmega328p -D__AVR_ATmega328p__ -Os -I.
+SOURCES := main.c usart.c
+OBJECTS := $(patsubst %.c,%.o,$(SOURCES))
-SOURCES=main.c
+CFLAGS := -Wall -mmcu=atmega328p -Os -I. \
+ -D__AVR_ATmega328p__ -DF_CPU=1000000UL -DBAUD=9600
+LDFLAGS :=
.PHONY: all flash clean
-all: rom-loader.bin
+all: rom-loader.hex
-flash: rom-loader.bin
- avrdude -c usbasp -p atmega328p
+flash: rom-loader.hex
+ avrdude -c usbasp -p atmega328p -U flash:w:$<
clean:
- rm rom-loader.bin
+ rm -f *.bin *.hex *.o
-rom-loader.bin: $(SOURCES)
- $(CC) $(CARGS) $< -o $@
+rom-loader.hex: rom-loader.bin
+ avr-objcopy -R .eeprom -O ihex $< $@
+rom-loader.bin: $(OBJECTS)
+ avr-gcc $(CFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)
+
+%.o: %.c
+ avr-gcc $(CFLAGS) $< -c -o $@ $(LDFLAGS)
diff --git a/sw-avr/rom-loader/pinmap.h b/sw-avr/rom-loader/pinmap.h
new file mode 100644
index 0000000..1149feb
--- /dev/null
+++ b/sw-avr/rom-loader/pinmap.h
@@ -0,0 +1,19 @@
+#ifndef PINMAP_H
+#define PINMAP_H
+
+#define ADDRL_DDR DDRC
+#define ADDRL_PORT PORTC
+#define ADDRL_bitE 3
+#define ADDRL_bitD 4
+#define ADDRL_bitA0 0
+
+#define ADDRH_DDR DDRD
+#define ADDRH_PORT PORTD
+#define ADDRH_bitE 7
+#define ADDRH_bitD 3
+#define ADDRH_bitA0 4
+
+#define DATA_DDR DDRB
+#define DATA_PORT PORTB
+
+#endif
diff --git a/sw-avr/rom-loader/rom-loader.bin b/sw-avr/rom-loader/rom-loader.bin
deleted file mode 100755
index 1feb241..0000000
--- a/sw-avr/rom-loader/rom-loader.bin
+++ /dev/null
Binary files differ
diff --git a/sw-avr/rom-loader/usart.c b/sw-avr/rom-loader/usart.c
new file mode 100644
index 0000000..5637d4f
--- /dev/null
+++ b/sw-avr/rom-loader/usart.c
@@ -0,0 +1,37 @@
+#include "usart.h"
+
+#include <avr/io.h>
+#include <util/setbaud.h>
+
+void usart_init(void)
+{
+ // automated by util/setbaud.h
+ UBRR0H = UBRRH_VALUE;
+ UBRR0L = UBRRL_VALUE;
+
+#if USE_2X
+ UCSR0A |= _BV(U2X0);
+#else
+ UCSR0A &= ~(_BV(U2X0));
+#endif
+
+ // 8 bit data
+ UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
+
+ // enable TX and RX pins
+ UCSR0B = _BV(RXEN0) | _BV(TXEN0);
+}
+
+void usart_send(uint8_t c)
+{
+ UDR0 = c;
+ // wait until transmission ready
+ loop_until_bit_is_set(UCSR0A, TXC0);
+}
+
+uint8_t usart_recv(void)
+{
+ // wait until data exists
+ loop_until_bit_is_set(UCSR0A, RXC0);
+ return UDR0;
+}
diff --git a/sw-avr/rom-loader/usart.h b/sw-avr/rom-loader/usart.h
new file mode 100644
index 0000000..f7d8806
--- /dev/null
+++ b/sw-avr/rom-loader/usart.h
@@ -0,0 +1,10 @@
+#ifndef USART_H
+#define USART_H
+
+#include <stdint.h>
+
+void usart_init(void);
+void usart_send(uint8_t c);
+uint8_t usart_recv(void);
+
+#endif