Prosper Van / Mbed 2 deprecated quadCommand7v2

Dependencies:   mbed PID Sensorv2 xbeeCom

quadCommand/KL25Z_Watchdog.h

Committer:
oprospero
Date:
2014-11-02
Revision:
1:e4439be6e1b9
Parent:
0:853ffcef6c67

File content as of revision 1:e4439be6e1b9:

//The section commented out is the ideal way to set the actual Watchdog timer.

#ifdef _DEBUG_WATCHDOG
    #include "mbed.h"
    Serial wd(USBTX, USBRX);
    #define NL "\n\r"
    #define PRINTF wd.printf   //Serial.print(x, y)
    #define PRINTLN(x) PRINT(x);PRINT(NL)
#else
//    #define PRINTF(...)
    #define PRINTLN(x)
#endif

class Watchdog {
public:
    Ticker dog;
    int hang;
    int check;
    Watchdog(float time)
    {
        check = 1;
        hang = 0;
    }
    Watchdog()
    {
        check = 1;
        hang = 0;
    }
    
    void enable(float time)
    {
        dog.attach(this,&Watchdog::checker, time);
        kick();
    }

    void kick() 
    {
        hang = rand();
        //reset timer
//        SIM->SRVCOP = 0x55;
//        SIM->SRVCOP = 0xAA;
    }
    
    void kick(float s) {
//        SIM->COPC = 0xCu;
        kick();
    }
    
    void disable()
    {
//        SIM->COPC = 0;
    }
    
    void checker()
    {
        if (hang == check)
        {
            
            NVIC_SystemReset();
        }
        check = hang;
    }
};