-
Notifications
You must be signed in to change notification settings - Fork 60
/
watchdog.c
54 lines (43 loc) · 1.07 KB
/
watchdog.c
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
// Base on esp_hw_wdt in github
/*
* Copyright (c) 2014-2017 Cesanta Software Limited
* All rights reserved
* Changed:
* 2017 Alexander Epstine ([email protected])
*/
#if defined(ARDUINO) && defined(ESP8266)
#include "watchdog.h"
#include "Arduino.h"
#include "stdint.h"
#include "user_interface.h"
#define REG_WDT_BASE 0x60000900
#define WDT_CTL (REG_WDT_BASE + 0x0)
#define WDT_CTL_ENABLE (BIT(0))
#define WDT_RESET (REG_WDT_BASE + 0x14)
#define WDT_RESET_VALUE 0x73
void esp_hw_wdt_enable() {
SET_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE);
}
void esp_hw_wdt_disable() {
CLEAR_PERI_REG_MASK(WDT_CTL, WDT_CTL_ENABLE);
}
void esp_hw_wdt_feed() {
WRITE_PERI_REG(WDT_RESET, WDT_RESET_VALUE);
}
void watchdog_disable_all() {
system_soft_wdt_stop();
esp_hw_wdt_disable();
}
void watchdog_enable_all() {
esp_hw_wdt_enable();
system_soft_wdt_restart();
}
static uint32_t wdt_checkpoint;
void watchdog_check_begin() {
wdt_checkpoint = millis();
}
void watchdog_check_end(const char *message) {
uint32_t d = millis() - wdt_checkpoint;
//printf("=== %s took: %dms\n", message, d);
}
#endif