Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Committer:
uci1
Date:
Thu Nov 27 03:12:32 2014 +0000
Revision:
62:4b59c1eb429f
Parent:
40:1324da35afd4
Child:
63:4820a4460f00
add debug to watchdog. set watchdog to config value at main() start

Who changed what in which revision?

UserRevisionLine numberNew contents of line
uci1 0:664899e0b988 1 #ifndef MB_Watchdog
uci1 0:664899e0b988 2 #define MB_Watchdog
uci1 0:664899e0b988 3
uci1 22:f957c4f840ad 4 #define WDFAILSAFE (1200u)
uci1 22:f957c4f840ad 5
uci1 62:4b59c1eb429f 6 //#define DEBUG
uci1 62:4b59c1eb429f 7
uci1 40:1324da35afd4 8 // Adapted from Simon's Watchdog code from
uci1 0:664899e0b988 9 // http://mbed.org/forum/mbed/topic/508/
uci1 0:664899e0b988 10 namespace Watchdog {
uci1 0:664899e0b988 11
uci1 0:664899e0b988 12 // "kick" or "feed" the dog - reset the watchdog timer
uci1 0:664899e0b988 13 // by writing this required bit pattern
uci1 12:d472f9811262 14 inline
uci1 0:664899e0b988 15 void kick() {
uci1 0:664899e0b988 16 LPC_WDT->WDFEED = 0xAA;
uci1 0:664899e0b988 17 LPC_WDT->WDFEED = 0x55;
uci1 0:664899e0b988 18 }
uci1 0:664899e0b988 19
uci1 0:664899e0b988 20 // Load timeout value in watchdog timer and enable
uci1 12:d472f9811262 21 inline
uci1 0:664899e0b988 22 void kick(const float s) {
uci1 62:4b59c1eb429f 23 #ifdef DEBUG
uci1 62:4b59c1eb429f 24 printf("WDkick s=[%g] \r\n",s);
uci1 62:4b59c1eb429f 25 #endif
uci1 0:664899e0b988 26 LPC_WDT->WDCLKSEL = 0x1; // Set CLK src to PCLK
uci1 0:664899e0b988 27 // WD has a fixed /4 prescaler, PCLK default is /4
uci1 0:664899e0b988 28 static const float clk = static_cast<float>(SystemCoreClock / 16);
uci1 0:664899e0b988 29 LPC_WDT->WDTC = s * clk;
uci1 40:1324da35afd4 30 // LPC_WDT->WDMOD = 0x3; // Enabled and Reset
uci1 40:1324da35afd4 31 LPC_WDT->WDMOD |= 0x3; // Enabled and Reset
uci1 0:664899e0b988 32 kick();
uci1 0:664899e0b988 33 }
uci1 22:f957c4f840ad 34
uci1 40:1324da35afd4 35 inline
uci1 40:1324da35afd4 36 bool didWatchdogReset() {
uci1 40:1324da35afd4 37 return ( (LPC_WDT->WDMOD) & 0x4 );
uci1 40:1324da35afd4 38 }
uci1 40:1324da35afd4 39
uci1 40:1324da35afd4 40 inline
uci1 40:1324da35afd4 41 void clearResetFlag() {
uci1 40:1324da35afd4 42 LPC_WDT->WDMOD &= ~(0x4);
uci1 40:1324da35afd4 43 }
uci1 40:1324da35afd4 44
uci1 22:f957c4f840ad 45 struct SnKickStarter {
uci1 22:f957c4f840ad 46 SnKickStarter(const float s) {
uci1 22:f957c4f840ad 47 Watchdog::kick(s);
uci1 22:f957c4f840ad 48 }
uci1 22:f957c4f840ad 49 };
uci1 0:664899e0b988 50
uci1 0:664899e0b988 51 };
uci1 0:664899e0b988 52
uci1 0:664899e0b988 53
uci1 0:664899e0b988 54 #endif // MB_Watchdog