17aea8ef |
1 | /* $Id: main.c,v 1.2 2010/06/26 19:08:18 simimeie Exp $ |
2d3643ee |
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" |
17aea8ef |
19 | #include "ledpwm.h" |
20 | #include "ircontrol.h" |
2d3643ee |
21 | /* #include "eepromdata.h" */ |
22 | |
23 | uint8_t mcusr_mirror __attribute__ ((section (".noinit"))); |
24 | |
25 | /* This is needed to recover from a watchdog reset, as the watchdog |
26 | * stays active after the reset. |
27 | * The variable is just to make the reason of the last reset accessible |
28 | * later. */ |
29 | void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3"))); |
30 | void get_mcusr(void) { |
31 | mcusr_mirror = MCUSR; |
32 | MCUSR = 0; |
33 | wdt_disable(); |
34 | } |
35 | |
36 | int main(void) |
37 | { |
17aea8ef |
38 | uint8_t i = 0; |
2d3643ee |
39 | |
40 | /* Load settings from EEPROM */ |
41 | #if 0 |
42 | something = eeprom_read_byte(&ee_something); |
43 | #endif /* LEDMODULE */ |
44 | |
45 | /* Initialize stuff */ |
46 | console_init(); |
17aea8ef |
47 | ledpwm_init(); |
48 | ircontrol_init(); |
2d3643ee |
49 | |
50 | wdt_enable(WDTO_2S); |
51 | |
52 | /* Prepare sleep mode */ |
53 | //set_sleep_mode(SLEEP_MODE_IDLE); |
54 | //sleep_enable(); |
55 | |
56 | /* All set up, enable interrupts and go. */ |
57 | sei(); |
58 | |
59 | if (mcusr_mirror & _BV(WDRF)) { |
60 | console_printpgm_P(PSTR("NOTE: last reset was from Watchdog Timer.")); |
61 | } |
62 | if (mcusr_mirror & _BV(BORF)) { |
63 | console_printpgm_P(PSTR("NOTE: last reset was from Brownout.")); |
64 | } |
65 | |
66 | while (1) { /* We should never exit */ |
67 | wdt_reset(); |
17aea8ef |
68 | /* i++; |
69 | console_printhex8(i); |
70 | ledpwm_setled(LEDPWM_REDLED, i); |
71 | ledpwm_setled(LEDPWM_GREENLED, i+128); |
72 | ledpwm_setled(LEDPWM_BLUELED, 255-i); |
73 | _delay_ms(500); */ |
2d3643ee |
74 | } |
75 | } |