From cda16639cbf19d6eb5c11f05f1045e54b3fdaba9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Tue, 30 Oct 2018 12:07:58 +0100 Subject: [avr] Add test program for IO and basic usart --- sw-avr/rom-loader/main.c | 34 +++++++++++++++++++++++++++++++++- sw-avr/rom-loader/makefile | 25 ++++++++++++++++--------- sw-avr/rom-loader/pinmap.h | 19 +++++++++++++++++++ sw-avr/rom-loader/rom-loader.bin | Bin 6352 -> 0 bytes sw-avr/rom-loader/usart.c | 37 +++++++++++++++++++++++++++++++++++++ sw-avr/rom-loader/usart.h | 10 ++++++++++ 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 sw-avr/rom-loader/pinmap.h delete mode 100755 sw-avr/rom-loader/rom-loader.bin create mode 100644 sw-avr/rom-loader/usart.c create mode 100644 sw-avr/rom-loader/usart.h (limited to 'sw-avr/rom-loader') 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 +#include "usart.h" +#include "pinmap.h" + +// TODO: remove +#include + + +inline void io_init(void) +{ + ADDRL_DDR |= (_BV(ADDRL_bitE) | _BV(ADDRL_bitD)); + ADDRL_DDR |= (0x7< +#include + +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 + +void usart_init(void); +void usart_send(uint8_t c); +uint8_t usart_recv(void); + +#endif -- cgit v1.2.1