From: Michel Pollet Date: Tue, 15 Mar 2011 13:37:09 +0000 (+0000) Subject: test: Updated uart_echo X-Git-Tag: v1.0a8~8 X-Git-Url: https://git.htl-mechatronik.at/public/?a=commitdiff_plain;h=613903e9fc0d7c809650909a68fc519b1731537e;p=sx%2Fsimavr.git test: Updated uart_echo Now set a baud rate, to excersize the new logic in the uart simulator. Also added a VCD file Signed-off-by: Michel Pollet --- diff --git a/tests/atmega88_uart_echo.c b/tests/atmega88_uart_echo.c index b0ea04c..17be737 100644 --- a/tests/atmega88_uart_echo.c +++ b/tests/atmega88_uart_echo.c @@ -24,6 +24,18 @@ AVR_MCU(F_CPU, "atmega88"); // tell simavr to listen to commands written in this (unused) register AVR_MCU_SIMAVR_COMMAND(&GPIOR0); +/* + * This small section tells simavr to generate a VCD trace dump with changes to these + * registers. + * Opening it with gtkwave will show you the data being pumped out into the data register + * UDR0, and the UDRE0 bit being set, then cleared + */ +const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = { + { AVR_MCU_VCD_SYMBOL("UDR0"), .what = (void*)&UDR0, }, + { AVR_MCU_VCD_SYMBOL("UDRE0"), .mask = (1 << UDRE0), .what = (void*)&UCSR0A, }, + { AVR_MCU_VCD_SYMBOL("GPIOR1"), .what = (void*)&GPIOR1, }, +}; + static int uart_putchar(char c, FILE *stream) { if (c == '\r') uart_putchar('\r', stream); @@ -42,6 +54,7 @@ volatile uint8_t done = 0; ISR(USART_RX_vect) { uint8_t b = UDR0; + GPIOR1 = b; // for the trace file buffer[bindex++] = b; buffer[bindex] = 0; if (b == '\n') @@ -55,9 +68,23 @@ int main() stdout = &mystdout; - // enable receiver + UCSR0C |= (3 << UCSZ00); // 8 bits + // see http://www.nongnu.org/avr-libc/user-manual/group__util__setbaud.html +#define BAUD 38400 +#include + UBRR0H = UBRRH_VALUE; + UBRR0L = UBRRL_VALUE; +#if USE_2X + UCSR0A |= (1 << U2X0); +#else + UCSR0A &= ~(1 << U2X0); +#endif + + // enable receiver & transmitter UCSR0B |= (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0); + // this tells simavr to start the trace + GPIOR0 = SIMAVR_CMD_VCD_START_TRACE; sei(); printf("Hey there, this should be received back\n");