starting implementation of the moodlight - by copying the console code
[moodlight.git] / main.c
diff --git a/main.c b/main.c
new file mode 100644 (file)
index 0000000..3073f33
--- /dev/null
+++ b/main.c
@@ -0,0 +1,65 @@
+/* $Id: main.c,v 1.1 2010/06/26 12:28:08 simimeie Exp $
+ * Main file for the HaWo moodlight.
+ * This is the main file that glues it all together. It also contains all
+ * functionality that is too small to require an extra file.
+ * (C) Michael "Fox" Meier 2010
+ */
+
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/wdt.h>
+#include <avr/eeprom.h>
+#include <avr/power.h>
+#include <avr/sleep.h>
+#include <stdio.h>
+#include <string.h>
+#include <util/delay.h>
+
+#include "console.h"
+/* #include "eepromdata.h" */
+
+uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
+
+/* This is needed to recover from a watchdog reset, as the watchdog
+ * stays active after the reset.
+ * The variable is just to make the reason of the last reset accessible
+ * later. */
+void get_mcusr(void) __attribute__((naked)) __attribute__((section(".init3")));
+void get_mcusr(void) {
+  mcusr_mirror = MCUSR;
+  MCUSR = 0;
+  wdt_disable();
+}
+
+int main(void)
+{
+  uint8_t i;
+  
+  /* Load settings from EEPROM */
+#if 0
+  something = eeprom_read_byte(&ee_something);
+#endif /* LEDMODULE */
+
+  /* Initialize stuff */
+  console_init();
+  
+  wdt_enable(WDTO_2S);
+
+  /* Prepare sleep mode */
+  //set_sleep_mode(SLEEP_MODE_IDLE);
+  //sleep_enable();
+
+  /* All set up, enable interrupts and go. */
+  sei();
+  
+  if (mcusr_mirror & _BV(WDRF)) {
+    console_printpgm_P(PSTR("NOTE: last reset was from Watchdog Timer."));
+  }
+  if (mcusr_mirror & _BV(BORF)) {
+    console_printpgm_P(PSTR("NOTE: last reset was from Brownout."));
+  }
+  
+  while (1) { /* We should never exit */
+    wdt_reset();
+  }
+}
This page took 0.043861 seconds and 4 git commands to generate.