Skip to content

Commit 00fafb8

Browse files
committed
Merge branch 'feature/add_nmi_panic_wd' into 'master'
feat(esp8266): add non-mask watch dog to panic critical function See merge request sdk/ESP8266_RTOS_SDK!1327
2 parents ad7fd54 + f7b83db commit 00fafb8

File tree

6 files changed

+105
-22
lines changed

6 files changed

+105
-22
lines changed

components/esp8266/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
menu "ESP8266-specific"
22

3+
config ESP8266_NMI_WDT
4+
bool "Enable non-mask watch dog"
5+
default y
6+
help
7+
Important: this non-mask watch dog is registered to non-mask timer0,
8+
so it can not work together with PWM.
9+
10+
Enable this non-mask watch dog can help users to debug blocking code
11+
when CPU is at critical state(disable interrupt).
12+
313
choice ESP8266_DEFAULT_CPU_FREQ_MHZ
414
prompt "CPU frequency"
515
default ESP8266_DEFAULT_CPU_FREQ_160

components/esp8266/driver/ir_tx.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@
2929

3030
static const char *TAG = "ir tx";
3131

32-
#define WDEVTSF0_TIME_LO 0x3ff21004
33-
#define WDEVTSF0_TIME_HI 0x3ff21008
34-
#define WDEVTSFSW0_LO 0x3ff21018
35-
#define WDEVTSFSW0_HI 0x3ff2101C
36-
#define WDEVTSF0_TIMER_LO 0x3ff2109c
37-
#define WDEVTSF0_TIMER_HI 0x3ff210a0
38-
#define WDEVTSF0TIMER_ENA 0x3ff21098
39-
#define WDEV_TSF0TIMER_ENA BIT(31)
40-
4132
int wDev_MacTimSetFunc(void (*handle)(void));
4233

4334
#define IR_TX_CHECK(a, str, ret_val) \

components/esp8266/driver/pwm.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,6 @@ static const char *TAG = "pwm";
5555
#define AHEAD_TICKS3 2
5656
#define MAX_TICKS 10000000ul
5757

58-
#define WDEVTSF0_TIME_LO 0x3ff21004
59-
#define WDEVTSF0_TIME_HI 0x3ff21008
60-
#define WDEVTSFSW0_LO 0x3ff21018
61-
#define WDEVTSFSW0_HI 0x3ff2101C
62-
#define WDEVTSF0_TIMER_LO 0x3ff2109c
63-
#define WDEVTSF0_TIMER_HI 0x3ff210a0
64-
#define WDEVTSF0TIMER_ENA 0x3ff21098
65-
#define WDEV_TSF0TIMER_ENA BIT(31)
66-
6758
#define PWM_VERSION "PWM v3.2"
6859

6960
typedef struct {

components/esp8266/include/esp8266/eagle_soc.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@
146146

147147
#define WDEV_COUNT_REG (0x3ff20c00)
148148

149+
#define WDEVTSF0_TIME_LO 0x3ff21004
150+
#define WDEVTSF0_TIME_HI 0x3ff21008
151+
#define WDEVTSFSW0_LO 0x3ff21018
152+
#define WDEVTSFSW0_HI 0x3ff2101C
153+
#define WDEVTSF0_TIMER_LO 0x3ff2109c
154+
#define WDEVTSF0_TIMER_HI 0x3ff210a0
155+
#define WDEVTSF0TIMER_ENA 0x3ff21098
156+
#define WDEV_TSF0TIMER_ENA BIT(31)
157+
149158
//Watch dog reg {{
150159
#define PERIPHS_WDT_BASEADDR 0x60000900
151160

components/esp8266/source/task_wdt.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include "esp_log.h"
1818
#include "esp_libc.h"
1919
#include "esp_task_wdt.h"
20+
#include "esp_attr.h"
2021
#include "portmacro.h"
22+
#include "esp8266/rom_functions.h"
2123
#include "esp8266/eagle_soc.h"
2224
#include "driver/soc.h"
2325

@@ -36,6 +38,73 @@ static void esp_task_wdt_isr(void *param)
3638
}
3739
#endif
3840

41+
#ifdef CONFIG_ESP8266_NMI_WDT
42+
43+
#if CONFIG_ESP_TASK_WDT_TIMEOUT_S == 13
44+
#define NMI_WD_TOTAL_PERIOD (6553600)
45+
#elif CONFIG_ESP_TASK_WDT_TIMEOUT_S == 14
46+
#define NMI_WD_TOTAL_PERIOD (13107200)
47+
#elif CONFIG_ESP_TASK_WDT_TIMEOUT_S == 15
48+
#define NMI_WD_TOTAL_PERIOD (26214400)
49+
#endif
50+
51+
#define NMI_WD_CHECK_PERIOD (1 * 1000 * 1000)
52+
53+
static int s_nmi_wd_state;
54+
55+
static void nmi_panic_wd(void)
56+
{
57+
extern uint32_t _chip_nmi_cnt;
58+
extern uint8_t _chip_nmi_stk[];
59+
extern void panicHandler(void *frame, int wdt);
60+
uint32_t *p;
61+
62+
if (_chip_nmi_cnt == 1) {
63+
p = (uint32_t *)&_chip_nmi_stk[512];
64+
} else {
65+
p = (uint32_t *)&_chip_nmi_stk[512 + 124 + 256];
66+
}
67+
68+
panicHandler(p - 1, 1);
69+
}
70+
71+
static void IRAM_ATTR nmi_set_wd_time(uint32_t us)
72+
{
73+
REG_WRITE(WDEVTSF0TIMER_ENA, REG_READ(WDEVTSF0TIMER_ENA) & (~WDEV_TSF0TIMER_ENA));
74+
75+
REG_WRITE(WDEVTSFSW0_LO, 0);
76+
REG_WRITE(WDEVTSFSW0_HI, 0);
77+
REG_WRITE(WDEVTSFSW0_LO, 0);
78+
79+
REG_WRITE(WDEVTSF0_TIMER_LO, 0);
80+
REG_WRITE(WDEVTSF0_TIMER_HI, 0);
81+
82+
REG_WRITE(WDEVTSF0_TIMER_LO, us);
83+
84+
REG_WRITE(WDEVTSF0TIMER_ENA, WDEV_TSF0TIMER_ENA);
85+
}
86+
87+
static void IRAM_ATTR nmi_check_wd(void)
88+
{
89+
switch (s_nmi_wd_state) {
90+
case 0:
91+
s_nmi_wd_state = 1;
92+
nmi_set_wd_time(NMI_WD_CHECK_PERIOD);
93+
break;
94+
case 1:
95+
s_nmi_wd_state = 2;
96+
nmi_set_wd_time(NMI_WD_TOTAL_PERIOD - NMI_WD_CHECK_PERIOD);
97+
break;
98+
case 2:
99+
Cache_Read_Enable_New();
100+
nmi_panic_wd();
101+
break;
102+
default:
103+
break;
104+
}
105+
}
106+
#endif
107+
39108
/**
40109
* @brief Just for pass compiling and mark wdt calling line
41110
*/
@@ -72,6 +141,15 @@ esp_err_t esp_task_wdt_init(void)
72141

73142
WDT_FEED();
74143

144+
#ifdef CONFIG_ESP8266_NMI_WDT
145+
{
146+
extern void wDev_MacTimSetFunc(void *func);
147+
148+
wDev_MacTimSetFunc(nmi_check_wd);;
149+
nmi_set_wd_time(NMI_WD_CHECK_PERIOD);
150+
}
151+
#endif
152+
75153
return 0;
76154
}
77155

@@ -82,6 +160,10 @@ esp_err_t esp_task_wdt_init(void)
82160
void esp_task_wdt_reset(void)
83161
{
84162
WDT_FEED();
163+
164+
#ifdef CONFIG_ESP8266_NMI_WDT
165+
s_nmi_wd_state = 0;
166+
#endif
85167
}
86168

87169
/**

components/freertos/port/esp8266/xtensa_vectors.S

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ Add to compile passing.
8080
#define _INTERRUPT_LEVEL 3
8181

8282
STRUCT_BEGIN
83+
STRUCT_FIELD (long,4,HESF_,EPC3)
84+
STRUCT_FIELD (long,4,HESF_,EPS3)
85+
STRUCT_AFIELD(long,4,HESF_,AREG, 16) /* address registers ar0..ar15 */
8386
STRUCT_FIELD (long,4,HESF_,SAR)
84-
STRUCT_FIELD (long,4,HESF_,EPC1)
8587
STRUCT_FIELD (long,4,HESF_,EXCCAUSE)
88+
STRUCT_FIELD (long,4,HESF_,EPC1)
8689
STRUCT_FIELD (long,4,HESF_,EXCVADDR)
8790
STRUCT_FIELD (long,4,HESF_,EXCSAVE1)
88-
STRUCT_FIELD (long,4,HESF_,EPC3)
89-
STRUCT_FIELD (long,4,HESF_,EPS3)
90-
STRUCT_AFIELD(long,4,HESF_,AREG, 16) /* address registers ar0..ar15 */
9191
#define HESF_AR(n) HESF_AREG+((n)*4)
9292
STRUCT_END(HighPriFrame)
9393
#define HESF_TOTALSIZE HighPriFrameSize+32 /* 32 bytes for interrupted code's save areas under SP */

0 commit comments

Comments
 (0)