Arianna autonomous DAQ firmware

Dependencies:   mbed SDFileSystemFilinfo AriSnProtocol NetServicesMin AriSnComm MODSERIAL PowerControlClkPatch DS1820OW

Watchdog.h

Committer:
uci1
Date:
2012-10-16
Revision:
22:f957c4f840ad
Parent:
12:d472f9811262
Child:
40:1324da35afd4

File content as of revision 22:f957c4f840ad:

#ifndef MB_Watchdog
#define MB_Watchdog

#define WDFAILSAFE  (1200u)

// Simon's Watchdog code from
// http://mbed.org/forum/mbed/topic/508/
namespace Watchdog {
    
    // "kick" or "feed" the dog - reset the watchdog timer
    // by writing this required bit pattern
    inline
    void kick() {
        LPC_WDT->WDFEED = 0xAA;
        LPC_WDT->WDFEED = 0x55;
    }
    
    // Load timeout value in watchdog timer and enable
    inline
    void kick(const float s) {
        LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
        // WD has a fixed /4 prescaler, PCLK default is /4
        static const float clk = static_cast<float>(SystemCoreClock / 16);
        LPC_WDT->WDTC = s * clk;
        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
        kick();
    }
    
    struct SnKickStarter {
        SnKickStarter(const float s) {
            Watchdog::kick(s);
        }
    };
 
};


#endif // MB_Watchdog