11 #include <avr/interrupt.h>
12 #include <avr/eeprom.h>
13 #include <avr/sleep.h>
16 * This demonstrate how to use the avr_mcu_section.h file
17 * The macro adds a section to the ELF file with useful
18 * information for the simulator
20 #include "avr_mcu_section.h"
21 AVR_MCU(F_CPU, "atmega88");
24 * This small section tells simavr to generate a VCD trace dump with changes to these
26 * Opening it with gtkwave will show you the data being pumped out into the data register
27 * UDR0, and the UDRE0 bit being set, then cleared
29 const struct avr_mmcu_vcd_trace_t _mytrace[] _MMCU_ = {
30 { AVR_MCU_VCD_SYMBOL("UDR0"), .what = (void*)&UDR0, },
31 { AVR_MCU_VCD_SYMBOL("UDRE0"), .mask = (1 << UDRE0), .what = (void*)&UCSR0A, },
35 /* declare this in a .eeprom ELF section */
36 uint32_t value EEMEM = 0xdeadbeef;
38 static int uart_putchar(char c, FILE *stream) {
40 uart_putchar('\r', stream);
41 loop_until_bit_is_set(UCSR0A, UDRE0);
46 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
54 // read the eeprom value
55 uint32_t c = eeprom_read_dword((void*)&value);
56 printf("Read from eeprom 0x%08lx -- should be 0xdeadbeef\n", c);
58 eeprom_write_dword((void*)&value, 0xcafef00d);
60 c = eeprom_read_dword((void*)&value);
61 printf("Read from eeprom 0x%08lx -- should be 0xcafef00d\n", c);
63 // this quits the simulator, since interupts are off
64 // this is a "feature" that allows running tests cases and exit