Project

General

Profile

Statistics
| Branch: | Revision:

robobuggy / arduino / RadioBuggyMega / watchdog.c @ e775590e

History | View | Annotate | Download (1.12 KB)

1
/* Watchdog Library. Woof! woof!
2
 *         Cats beware! Meow.
3
 * 
4
 * The watchdog library checks everytime its called how long time has passed
5
 * between change in signals. If the time passed between signals is more than
6
 * the threshold initialized in the begining, it enters the fail case. In the case
7
 * of buggy, it drops the brakes. 
8
 * 
9
 * The watchdog can be fed, preferably with a bone, everytime a signal is made. 
10
 * ie. rc_available is true. If the dog has been fed recently, then the time last fed
11
 * is reset to the current time. 
12
 *
13
 * @author: Audrey Yeoh (ayeoh)
14
 * 
15
 */
16
 
17
#include <Arduino.h>
18
#include "watchdog.h" 
19

    
20
static fail_function_ptr fail_mode = NULL;
21
static unsigned long time;
22
static int thresh;
23

    
24
/* Initializes the watchdog.
25
 * Sets the threshold of the maximum time to wait for a new signal
26
 * Sets the fail case function if the time passed between signals is more
27
 * than the threshold. 
28
 */
29
void watchdog_init(int timeThresh, fail_function_ptr f ){
30
        thresh = timeThresh;
31
        fail_mode = f;
32
        time = 0;
33
}
34

    
35
void watchdog_feed(){
36
        time = millis();
37
}
38

    
39
void watchdog_loop(){
40
        if(millis() - time > thresh){
41
                fail_mode();
42
        }
43
}