]>
Commit | Line | Data |
---|---|---|
2d3643ee | 1 | /* $Id: main.c,v 1.1 2010/06/26 12:28:08 simimeie Exp $ |
2 | * Main file for the HaWo moodlight. | |
3 | * This is the main file that glues it all together. It also contains all | |
4 | * functionality that is too small to require an extra file. | |
5 | * (C) Michael "Fox" Meier 2010 | |
6 | */ | |
7 | ||
8 | #include <avr/io.h> | |
9 | #include <avr/interrupt.h> | |
10 | #include <avr/wdt.h> | |
11 | #include <avr/eeprom.h> | |
12 | #include <avr/power.h> | |
13 | #include <avr/sleep.h> | |
14 | #include <stdio.h> | |
15 | #include <string.h> | |
16 | #include <util/delay.h> | |
17 | ||
18 | #include "console.h" | |
19 | /* #include "eepromdata.h" */ | |
20 | ||
21 | uint8_t mcusr_mirror __attribute__ ((section (".noinit"))); | |
22 | ||
23 | /* This is needed to recover from a watchdog reset, as the watchdog | |
24 | * stays active after the reset. | |
25 | * The variable is just to make the reason of the last reset accessible | |
26 | * later. */ | |
27 | void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3"))); | |
28 | void get_mcusr(void) { | |
29 | mcusr_mirror = MCUSR; | |
30 | MCUSR = 0; | |
31 | wdt_disable(); | |
32 | } | |
33 | ||
34 | int main(void) | |
35 | { | |
36 | uint8_t i; | |
37 | ||
38 | /* Load settings from EEPROM */ | |
39 | #if 0 | |
40 | something = eeprom_read_byte(&ee_something); | |
41 | #endif /* LEDMODULE */ | |
42 | ||
43 | /* Initialize stuff */ | |
44 | console_init(); | |
45 | ||
46 | wdt_enable(WDTO_2S); | |
47 | ||
48 | /* Prepare sleep mode */ | |
49 | //set_sleep_mode(SLEEP_MODE_IDLE); | |
50 | //sleep_enable(); | |
51 | ||
52 | /* All set up, enable interrupts and go. */ | |
53 | sei(); | |
54 | ||
55 | if (mcusr_mirror & _BV(WDRF)) { | |
56 | console_printpgm_P(PSTR("NOTE: last reset was from Watchdog Timer.")); | |
57 | } | |
58 | if (mcusr_mirror & _BV(BORF)) { | |
59 | console_printpgm_P(PSTR("NOTE: last reset was from Brownout.")); | |
60 | } | |
61 | ||
62 | while (1) { /* We should never exit */ | |
63 | wdt_reset(); | |
64 | } | |
65 | } |