refactor logger
[simavr] / examples / board_simduino / atmega328p_dummy_blinky.c
1 /*
2         atmega328p_dummy_blinky.c
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22
23 #ifdef F_CPU
24 #undef F_CPU
25 #endif
26
27 #define F_CPU 16000000
28
29 #include <avr/io.h>
30 #include <stdio.h>
31 #include <avr/interrupt.h>
32 #include <avr/eeprom.h>
33 #include <avr/sleep.h>
34
35 /*
36  * This demonstrate how to use the avr_mcu_section.h file
37  * The macro adds a section to the ELF file with useful
38  * information for the simulator
39  */
40 #include "avr_mcu_section.h"
41 AVR_MCU(F_CPU, "atmega328p");
42
43 static int uart_putchar(char c, FILE *stream) {
44   if (c == '\n')
45     uart_putchar('\r', stream);
46   loop_until_bit_is_set(UCSR0A, UDRE0);
47   UDR0 = c;
48   return 0;
49 }
50
51 static FILE mystdout = FDEV_SETUP_STREAM(uart_putchar, NULL,
52                                          _FDEV_SETUP_WRITE);
53
54
55 int main()
56 {
57         stdout = &mystdout;
58
59         printf("Bootloader properly programmed, and ran me! Huzzah!\n");
60
61         // this quits the simulator, since interrupts are off
62         // this is a "feature" that allows running tests cases and exit
63         sleep_cpu();
64 }
65