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)
42 uart_putchar('\r', stream);
43 loop_until_bit_is_set(UCSR0A, UDRE0);
48 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
51 volatile uint8_t bindex = 0;
53 volatile uint8_t done = 0;
58 GPIOR1 = b; // for the trace file
67 // this tell simavr to put the UART in loopback mode
68 GPIOR0 = SIMAVR_CMD_UART_LOOPBACK;
72 UCSR0C |= (3 << UCSZ00); // 8 bits
73 // see http://www.nongnu.org/avr-libc/user-manual/group__util__setbaud.html
75 #include <util/setbaud.h>
79 UCSR0A |= (1 << U2X0);
81 UCSR0A &= ~(1 << U2X0);
84 // enable receiver & transmitter
85 UCSR0B |= (1 << RXCIE0) | (1 << RXEN0) | (1 << TXEN0);
87 // this tells simavr to start the trace
88 GPIOR0 = SIMAVR_CMD_VCD_START_TRACE;
90 printf("Hey there, this should be received back\n");
96 printf("Received: %s", buffer);
98 // this quits the simulator, since interupts are off
99 // this is a "feature" that allows running tests cases and exit