altos/lpc: Enable brown-out-detector
authorKeith Packard <keithp@keithp.com>
Sat, 22 Jun 2013 02:39:27 +0000 (19:39 -0700)
committerKeith Packard <keithp@keithp.com>
Sat, 22 Jun 2013 07:49:59 +0000 (00:49 -0700)
Make sure the processor does something sensible when the power disappears.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lpc/ao_timer_lpc.c
src/lpc/lpc.h

index c0de90a3ab483343b7c3748ef40fc97b6a403ec9..44fb410e7f522b642d1a68f965f46681690a3d74 100644 (file)
@@ -100,6 +100,15 @@ ao_clock_init(void)
                                 (1 << LPC_SCB_SYSAHBCLKCTRL_GPIO) |
                                 (1 << LPC_SCB_SYSAHBCLKCTRL_IOCON));
                                 
+       /* Enable the brown-out detection at the highest voltage to
+        * make sure the flash part remains happy
+        */
+
+       lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_BOD_PD);
+       lpc_scb.bodctrl = ((LPC_SCB_BOD_BODRSTLEV_2_63 << LPC_SCB_BOD_BODRSTLEV) |
+                          (LPC_SCB_BOD_BODINTVAL_RESERVED << LPC_SCB_BOD_BODINTVAL) |
+                          (1 << LPC_SCB_BOD_BODRSTENA));
+
        /* Turn the IRC clock back on */
        lpc_scb.pdruncfg &= ~(1 << LPC_SCB_PDRUNCFG_IRC_PD);
        ao_clock_delay();
@@ -194,7 +203,7 @@ ao_clock_init(void)
        /* Power down everything we don't need */
        lpc_scb.pdruncfg = ((1 << LPC_SCB_PDRUNCFG_IRCOUT_PD) |
                            (1 << LPC_SCB_PDRUNCFG_IRC_PD) |
-                           (1 << LPC_SCB_PDRUNCFG_BOD_PD) |
+                           (0 << LPC_SCB_PDRUNCFG_BOD_PD) |
                            (1 << LPC_SCB_PDRUNCFG_ADC_PD) |
                            (1 << LPC_SCB_PDRUNCFG_WDTOSC_PD) |
                            (1 << LPC_SCB_PDRUNCFG_USBPLL_PD) |
index d66f0dd00bdf2b98d328a6a06713bfbe62be0b8b..f13ec61529860876c0b5217fa90e92a38dc4ba89 100644 (file)
@@ -609,6 +609,18 @@ extern struct lpc_scb lpc_scb;
 
 #define LPC_SCB_CLKOUTUEN_ENA          0
 
+#define LPC_SCB_BOD_BODRSTLEV          0
+# define LPC_SCB_BOD_BODRSTLEV_1_46            0
+# define LPC_SCB_BOD_BODRSTLEV_2_06            1
+# define LPC_SCB_BOD_BODRSTLEV_2_35            2
+# define LPC_SCB_BOD_BODRSTLEV_2_63            3
+#define LPC_SCB_BOD_BODINTVAL          2
+# define LPC_SCB_BOD_BODINTVAL_RESERVED                0
+# define LPC_SCB_BOD_BODINTVAL_2_22            1
+# define LPC_SCB_BOD_BODINTVAL_2_52            2
+# define LPC_SCB_BOD_BODINTVAL_2_80            3
+#define LPC_SCB_BOD_BODRSTENA          4
+
 #define LPC_SCB_PDRUNCFG_IRCOUT_PD     0
 #define LPC_SCB_PDRUNCFG_IRC_PD                1
 #define LPC_SCB_PDRUNCFG_FLASH_PD      2