Skip to content

Commit 8ee1612

Browse files
committed
never yield within an ISR
1 parent cbc1ef6 commit 8ee1612

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

hardware/esp8266com/esp8266/cores/esp8266/core_esp8266_main.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ extern "C" void __yield() {
8888
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));
8989

9090
extern "C" void optimistic_yield() {
91-
if (system_get_time() - g_micros_at_last_task_yield > OPTIMISTIC_YIELD_TIME_US)
91+
if (!ETS_INTR_WITHINISR() &&
92+
(system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US)
9293
{
9394
__yield();
9495
}

hardware/esp8266com/esp8266/tools/sdk/include/ets_sys.h

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ typedef void (*int_handler_t)(void*);
6161
#define ETS_INTR_DISABLE(inum) \
6262
ets_isr_mask((1<<inum))
6363

64+
inline bool ETS_INTR_WITHINISR()
65+
{
66+
uint32_t ps;
67+
__asm__ __volatile__("rsr %0,ps":"=a" (ps));
68+
// PS.EXCM and PS.UM bit checks
69+
return ((ps & ((1 << 4) | (1 << 5))) > 0);
70+
}
71+
6472
inline uint32_t ETS_INTR_ENABLED(void)
6573
{
6674
uint32_t enabled;

0 commit comments

Comments
 (0)