4 This test case enables uart RX interupts, does a "printf" and then receive characters
5 via the interupt handler until it reaches a \r.
7 This tests the uart reception fifo system. It relies on the uart "irq" input and output
8 to be wired together (see simavr.c)
13 #include <avr/interrupt.h>
14 #include <avr/eeprom.h>
15 #include <avr/sleep.h>
18 * This demonstrate how to use the avr_mcu_section.h file
19 * The macro adds a section to the ELF file with useful
20 * information for the simulator
22 #include "avr_mcu_section.h"
23 AVR_MCU(F_CPU, "atmega88");
24 // tell simavr to listen to commands written in this (unused) register
25 AVR_MCU_SIMAVR_COMMAND(&GPIOR0);
28 * This small section tells simavr to generate a VCD trace dump with changes to these
30 * Opening it with gtkwave will show you the data being pumped out into the data register
31 * UDR0, and the UDRE0 bit being set, then cleared
33 const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = {
34 { AVR_MCU_VCD_SYMBOL("UDR0"), .what = (void*)&UDR0, },
35 { AVR_MCU_VCD_SYMBOL("UDRE0"), .mask = (1 << UDRE0), .what = (void*)&UCSR0A, },
36 { AVR_MCU_VCD_SYMBOL("GPIOR1"), .what = (void*)&GPIOR1, },
39 static int uart_putchar(char c, FILE *stream) {
40 #if 0 // don't want character translation for this test
42 uart_putchar('\r', stream);
44 loop_until_bit_is_set(UCSR0A, UDRE0);
49 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
52 volatile uint8_t bindex = 0;
54 volatile uint8_t done = 0;
59 GPIOR1 = b; // for the trace file
68 // this tell simavr to put the UART in loopback mode
69 GPIOR0 = SIMAVR_CMD_UART_LOOPBACK;
73 UCSR0C |= (3 << UCSZ00); // 8 bits
74 // see http://www.nongnu.org/avr-libc/user-manual/group__util__setbaud.html
76 #include <util/setbaud.h>
80 UCSR0A |= (1 << U2X0);
82 UCSR0A &= ~(1 << U2X0);
85 // enable receiver & transmitter
86 UCSR0B |= (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0);
88 // this tells simavr to start the trace
89 GPIOR0 = SIMAVR_CMD_VCD_START_TRACE;
91 printf("Hey there, this should be received back\n");
97 printf("Received: %s", buffer);
99 // this quits the simulator, since interupts are off
100 // this is a "feature" that allows running tests cases and exit