DERPS

Dependencies:   BMP280 BNO055_fusion PowerControl mbed

Fork of STRAIGHT_DRIVE_NO_SEP by Antoine Laurens

Revision:
23:455f7da3dd7a
Parent:
6:0602a9e8118b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SAFETY.cpp	Sun Apr 03 07:08:18 2016 +0000
@@ -0,0 +1,38 @@
+#include "SAFETY.h"
+
+#define USR_POWERDOWN   (0x104)
+
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+void SAFETY::kick(void)
+{
+    LPC_WDT->WDFEED = 0xAA;
+    LPC_WDT->WDFEED = 0x55;
+}
+
+void SAFETY::kick(float s)
+{
+    LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+    uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+    LPC_WDT->WDTC = s * (float)clk;
+    LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+    kick();
+}
+
+int SAFETY::semihost_powerdown()
+{
+    uint32_t arg;
+    return __semihost(USR_POWERDOWN, &arg);
+}
+
+void SAFETY::init(uint32_t brownOutRoutine)
+{
+    //Power Down Ethernet
+    PHY_PowerDown();
+    //Power Down USB Chip
+    semihost_powerdown();
+    //Setup Brown Out Interrupt
+    NVIC_SetVector(BOD_IRQn, brownOutRoutine);
+    //Enable Brown Out Interrupt
+    NVIC_EnableIRQ(BOD_IRQn);
+}
\ No newline at end of file