Revision e775590e
Made the watchdog library. Tested and runs. Remember to hate function pointers :)
arduino/RadioBuggyMega/watchdog.c | ||
---|---|---|
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 |
} |
arduino/RadioBuggyMega/watchdog.h | ||
---|---|---|
1 |
/** |
|
2 |
* @file watchdog.h |
|
3 |
* @brief Headers for Receiver |
|
4 |
* |
|
5 |
* @authod: Audrey Yeoh (ayeoh) |
|
6 |
*/ |
|
7 |
|
|
8 |
#ifndef _WATCHDOG_H_ |
|
9 |
#define _WATCHDOG_H_ |
|
10 |
|
|
11 |
#ifdef __cplusplus |
|
12 |
extern "C"{ |
|
13 |
#endif |
|
14 |
|
|
15 |
typedef void (*fail_function_ptr)(void); |
|
16 |
|
|
17 |
void watchdog_init(int timeThresh, fail_function_ptr f); |
|
18 |
|
|
19 |
void watchdog_feed(); |
|
20 |
|
|
21 |
void watchdog_loop(); |
|
22 |
|
|
23 |
#ifdef __cplusplus |
|
24 |
} // extern "C" |
|
25 |
#endif /* __cplusplus */ |
|
26 |
|
|
27 |
#endif /* _WATCHDOG_H_ */ |
Also available in: Unified diff