Skip to content

Commit 051ff4b

Browse files
committed
Merge branch 'fix/fix_panic_reent' into 'master'
Fix panic reenter See merge request sdk/ESP8266_RTOS_SDK!455
2 parents 52e3992 + 1c92913 commit 051ff4b

File tree

1 file changed

+89
-28
lines changed
  • components/freertos/port/esp8266

1 file changed

+89
-28
lines changed

components/freertos/port/esp8266/panic.c

+89-28
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,70 @@ typedef struct task_info
5757
StackType_t *pxEndOfStack;
5858
} task_info_t;
5959

60-
static void IRAM_ATTR panic_stack(StackType_t *start_stk, StackType_t *end_stk)
60+
static void panic_data32(uint32_t data, int hex)
61+
{
62+
char buf[12];
63+
size_t off = 0;
64+
65+
if (!data)
66+
buf[off++] = '0';
67+
else {
68+
while (data) {
69+
char tmp = data % hex;
70+
71+
if (tmp >= 10)
72+
tmp = tmp - 10 + 'a';
73+
else
74+
tmp = tmp + '0';
75+
76+
data = data / hex;
77+
78+
buf[off++] = tmp;
79+
}
80+
}
81+
82+
if (hex == 16) {
83+
while (off < 8)
84+
buf[off++] = '0';
85+
}
86+
87+
while (off)
88+
ets_putc(buf[--off]);
89+
}
90+
91+
static void panic_str(const char *s)
92+
{
93+
while (*s)
94+
ets_putc(*s++);
95+
}
96+
97+
static void panic_stack(StackType_t *start_stk, StackType_t *end_stk)
6198
{
6299
uint32_t *start = (uint32_t *)start_stk, *end = (uint32_t *)end_stk;
63100
size_t i, j;
64101
size_t size = end - start + 1;
65102

66-
ets_printf("%10s", " ");
103+
panic_str(" ");
67104
for (i = 0; i < STACK_VOL_NUM; i++) {
68-
ets_printf("%-8x ", i * sizeof(StackType_t));
105+
panic_data32(i * sizeof(StackType_t), 16);
106+
panic_str(" ");
69107
}
70-
ets_printf("\n\n");
108+
panic_str("\r\n\r\n");
71109

72110
for (i = 0; i < size; i += STACK_VOL_NUM) {
73111
size_t len = size > i ? size - i : STACK_VOL_NUM - (i - size);
74112

75113
if (len > STACK_VOL_NUM)
76114
len = STACK_VOL_NUM;
77115

78-
ets_printf("%-10x", &start[i]);
116+
panic_data32((uint32_t)&start[i], 16);
117+
panic_str(" ");
79118

80119
for (j = 0; j < len; j++) {
81-
ets_printf("%08x ",start[i + j]);
120+
panic_data32((uint32_t)start[i + j], 16);
121+
panic_str(" ");
82122
}
83-
ets_printf("\n");
123+
panic_str("\r\n");
84124
}
85125
}
86126

@@ -91,54 +131,59 @@ static void IRAM_ATTR panic_stack(StackType_t *start_stk, StackType_t *end_stk)
91131
*
92132
* @return none
93133
*/
94-
void IRAM_ATTR panicHandler(void *frame)
134+
void panic_info(void *frame)
95135
{
96-
// for panic the function that disable cache
97-
Cache_Read_Enable_New();
98-
99136
task_info_t *task;
100137
int *regs = (int *)frame;
101138
int x, y;
102139
const char *sdesc[] = {
103-
"PC", "PS", "A0", "A1",
104-
"A2", "A3", "A4", "A5",
105-
"A6", "A7", "A8", "A9",
106-
"A10", "A11", "A12", "A13",
107-
"A14", "A15", "SAR", "EXCCAUSE"
140+
" PC", " PS", " A0", " A1",
141+
" A2", " A3", " A4", " A5",
142+
" A6", " A7", " A8", " A9",
143+
" A10", " A11", " A12", " A13",
144+
" A14", " A15", " SAR", "EXCCAUSE"
108145
};
109146

110147
extern int _Pri_3_NMICount;
111148

112-
/* NMI can interrupt exception. */
113-
ETS_INTR_LOCK();
114-
115-
ets_printf("\r\n\r\n");
149+
panic_str("\r\n\r\n");
116150

117151
if (_Pri_3_NMICount == -1) {
118-
ets_printf("Soft watch dog triggle:\r\n\r\n");
152+
panic_str("Soft watch dog triggle:\r\n\r\n");
119153
show_critical_info();
120154
} else if (xPortInIsrContext())
121-
ets_printf("Core 0 was running in ISR context:\r\n\r\n");
155+
panic_str("Core 0 was running in ISR context:\r\n\r\n");
122156

123157
if ((task = (task_info_t *)xTaskGetCurrentTaskHandle())) {
124158
StackType_t *pdata = task->pxStack;
125159
StackType_t *end = task->pxEndOfStack + 4;
126160

127-
ets_printf("Task stack [%s] stack from [%p] to [%p], total [%d] size\r\n\r\n",
128-
task->pcTaskName, pdata, end, end - pdata + 4);
161+
// "Task stack [%s] stack from [%p] to [%p], total [%d] size\r\n\r\n"
162+
panic_str("Task stack [");
163+
panic_str(task->pcTaskName);
164+
panic_str("] stack from [");
165+
panic_data32((uint32_t)pdata, 16);
166+
panic_str("] to [");
167+
panic_data32((uint32_t)end, 16);
168+
panic_str("], total [");
169+
panic_data32((uint32_t)(end - pdata + 4), 10);
170+
panic_str("] size\r\n\r\n");
129171

130172
panic_stack(pdata, end);
131173

132-
ets_printf("\r\n\r\n");
174+
panic_str("\r\n\r\n");
133175
} else {
134-
ets_printf("No task\r\n\r\n");
176+
panic_str("No task\r\n\r\n");
135177
}
136178

137179
for (x = 0; x < 20; x += 4) {
138180
for (y = 0; y < 4; y++) {
139-
ets_printf("%8s: 0x%08x ", sdesc[x + y], regs[x + y + 1]);
181+
panic_str(sdesc[x + y]);
182+
panic_str(": 0x");
183+
panic_data32((uint32_t)regs[x + y + 1], 16);
184+
panic_str(" ");
140185
}
141-
ets_printf("\r\n");
186+
panic_str("\r\n");
142187
}
143188

144189
/*
@@ -150,6 +195,22 @@ void IRAM_ATTR panicHandler(void *frame)
150195
while (1);
151196
}
152197

198+
void IRAM_ATTR panicHandler(void *frame)
199+
{
200+
int cnt = 10;
201+
202+
/* NMI can interrupt exception. */
203+
vPortEnterCritical();
204+
while (cnt--) {
205+
REG_WRITE(INT_ENA_WDEV, 0);
206+
}
207+
208+
// for panic the function that disable cache
209+
Cache_Read_Enable_New();
210+
211+
panic_info(frame);
212+
}
213+
153214
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
154215
{
155216
printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x at %p\n", rc, __builtin_return_address(0));

0 commit comments

Comments
 (0)