Skip to content

Commit

Permalink
never yield within an ISR
Browse files Browse the repository at this point in the history
  • Loading branch information
Makuna committed Jul 15, 2015
1 parent d815c36 commit 0b2fb8d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cores/esp8266/core_esp8266_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ extern "C" void __yield() {
extern "C" void yield(void) __attribute__ ((weak, alias("__yield")));

extern "C" void optimistic_yield() {
if (system_get_time() - g_micros_at_last_task_yield > OPTIMISTIC_YIELD_TIME_US)
if (!ETS_INTR_WITHINISR() &&
(system_get_time() - g_micros_at_last_task_yield) > OPTIMISTIC_YIELD_TIME_US)
{
__yield();
}
Expand Down
8 changes: 8 additions & 0 deletions tools/sdk/include/ets_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ typedef void (*int_handler_t)(void*);
#define ETS_INTR_DISABLE(inum) \
ets_isr_mask((1<<inum))

inline bool ETS_INTR_WITHINISR()
{
uint32_t ps;
__asm__ __volatile__("rsr %0,ps":"=a" (ps));
// PS.EXCM and PS.UM bit checks
return ((ps & ((1 << 4) | (1 << 5))) > 0);
}

inline uint32_t ETS_INTR_ENABLED(void)
{
uint32_t enabled;
Expand Down

0 comments on commit 0b2fb8d

Please sign in to comment.