From bc8503b73e89e25cae293d3893afd5e227dc4bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 10 Apr 2019 11:52:35 +0200 Subject: [PATCH] organized tests --- avr_tests/Makefile | 7 +++ avr_tests/io_test.c | 19 +++++++ avr_tests/usart_test.c | 71 +++++++++++++++++++++++++++ {test => x86_tests}/Makefile | 0 {test => x86_tests}/test_ringbuffer.c | 0 5 files changed, 97 insertions(+) create mode 100644 avr_tests/Makefile create mode 100644 avr_tests/io_test.c create mode 100644 avr_tests/usart_test.c rename {test => x86_tests}/Makefile (100%) rename {test => x86_tests}/test_ringbuffer.c (100%) diff --git a/avr_tests/Makefile b/avr_tests/Makefile new file mode 100644 index 0000000..d45aad0 --- /dev/null +++ b/avr_tests/Makefile @@ -0,0 +1,7 @@ +tests= usart_test.elf io_test.elf + +all: $(tests) + +%.elf:%.c + avr-gcc $< -mmcu=atmega168 -O -o $@ + avrdude -p m168 -c avrispmkii -U flash:w:$@:a diff --git a/avr_tests/io_test.c b/avr_tests/io_test.c new file mode 100644 index 0000000..b2351f3 --- /dev/null +++ b/avr_tests/io_test.c @@ -0,0 +1,19 @@ +#include +#define F_CPU 18000000UL +#include + +int main(void) +{ +// CLKPR |= _BV(CLKPCE); +// CLKPR &= ~(_BV(CLKPS0) +// | _BV(CLKPS1) +// | _BV(CLKPS2) +// | _BV(CLKPS3)); + DDRC |= _BV(PC5); + while(1) + { + PORTC ^= _BV(PC5); + _delay_ms(4000); + } + return 0; +} diff --git a/avr_tests/usart_test.c b/avr_tests/usart_test.c new file mode 100644 index 0000000..b0ea092 --- /dev/null +++ b/avr_tests/usart_test.c @@ -0,0 +1,71 @@ +#include +#include +#include + +//#define USART_U2X_EN + +#define F_CPU 20000000UL +#include +#define USART_BAUD 2400 +#define UBRR_VALUE_DS 520 + +#ifndef USART_U2X_EN +#define UBRR_VALUE (F_CPU/16/USART_BAUD-1) +#else +#define UBRR_VALUE (F_CPU/8/USART_BAUD-1) +#endif + +#if !(UBRR_VALUE == UBRR_VALUE_DS) +#warning "Calculated UBRR value differs from the value given in the datasheet: " +#define UBRR_VALUE UBRR_VALUE_DS +#endif + +int cnt; + +void +usart_init(void) +{ + UBRR0H = (unsigned char)(UBRR_VALUE >> 8); + UBRR0L = (unsigned char)UBRR_VALUE; +#ifdef USART_U2X_EN + UCSR0A |= _BV(U2X0); +#endif + UCSR0B = _BV(TXEN0) | _BV(TXCIE0); + UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); + //UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); + cnt = 0; + sei(); +} + + +ISR(USART_TX_vect) +{ + if(!cnt) + { + UDR0 = '\n'; + cnt++; + } + else + { + cnt = (cnt + 1) % 10; + UDR0 = '0' + cnt; + } +} + +int main(void) +{ + DDRC |= _BV(PC5); + usart_init(); + while(!(UCSR0A & _BV(UDRE0))); + UDR0 = '0'; + while(1) + { + PORTC ^= _BV(PC5); + _delay_ms(500); + PORTC ^= _BV(PC5); + _delay_ms(1000); + PORTC ^= _BV(PC5); + _delay_ms(500); + } + return 0; +} diff --git a/test/Makefile b/x86_tests/Makefile similarity index 100% rename from test/Makefile rename to x86_tests/Makefile diff --git a/test/test_ringbuffer.c b/x86_tests/test_ringbuffer.c similarity index 100% rename from test/test_ringbuffer.c rename to x86_tests/test_ringbuffer.c