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