forked from tonton81/WDT_T4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Watchdog_t4.h
66 lines (56 loc) · 1.58 KB
/
Watchdog_t4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#if !defined(_WATCHDOG_T4_H_)
#define _WATCHDOG_T4_H_
#include "Arduino.h"
typedef void (*watchdog_class_ptr)();
typedef enum WDT_DEV_TABLE {
WDT1 = (uint32_t)0x400B8000,
WDT2 = (uint32_t)0x400D0000,
WDT3 = (uint32_t)0x400BC000,
EWM = (uint32_t)0x400B4000
} WDT_DEV_TABLE;
typedef enum RTWDOG_CLK_TABLE {
BUS_CLK = 0,
LPO_CLK = 1,
INT_CLK = 2,
ER_CLK = 3
} RTWDOG_CLK_TABLE;
typedef struct WDT_timings_t {
double trigger = 5;
double timeout = 10;
double window = 0;
uint8_t pin = 0;
RTWDOG_CLK_TABLE clock = LPO_CLK; /* default clock, 32KHz */
bool lp_suspend = 0;
uint8_t input = 0;
bool update = 1;
bool cmd32en = 1;
watchdog_class_ptr callback = nullptr;
} WDT_timings_t;
#define WDT_CLASS template<WDT_DEV_TABLE _device>
#define WDT_FUNC template<WDT_DEV_TABLE _device>
#define WDT_OPT WDT_T4<_device>
class WDT_T4_Base {
public:
virtual void watchdog_isr() = 0;
virtual void ewatchdog_isr() = 0;
watchdog_class_ptr watchdog_class_handler = 0;
private:
};
static WDT_T4_Base* _WDT1 = nullptr;
static WDT_T4_Base* _WDT2 = nullptr;
static WDT_T4_Base* _WDT3 = nullptr;
static WDT_T4_Base* _EWM = nullptr;
WDT_CLASS class WDT_T4 : public WDT_T4_Base {
public:
void begin(WDT_timings_t config);
void callback(watchdog_class_ptr handler) { watchdog_class_handler = handler; }
void reset();
void feed();
bool expired();
private:
watchdog_class_ptr watchdog_class_handler;
void watchdog_isr();
void ewatchdog_isr();
};
#include "Watchdog_t4.tpp"
#endif