Skip to content

Commit

Permalink
ESP8266: Allow nested mgos_ints_disable/enable calls
Browse files Browse the repository at this point in the history
Keep track of the previous int level and the nesting level
  • Loading branch information
rojer committed Jun 15, 2021
1 parent 102d9ee commit f268d12
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions platforms/esp8266/src/esp_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,33 @@ void mgos_msleep(uint32_t msecs) {
mgos_usleep(msecs * 1000);
}

static uint8_t prev_intlevel = 0, nest_level = 0;

IRAM void mgos_ints_disable(void) {
__asm volatile("rsil a2, 3" : : : "a2");
uint32_t prev_ps;
asm volatile("rsil %0, 3 \n" : "=a"(prev_ps) : :);
if (nest_level == 0) {
prev_intlevel = (prev_ps & 0xf);
}
nest_level++;
}

IRAM void mgos_ints_enable(void) {
__asm volatile("rsil a2, 0" : : : "a2");
nest_level--;
if (nest_level != 0) return;
switch (prev_intlevel) {
case 0:
asm volatile("rsil a2, 0" : : : "a2");
break;
case 1:
asm volatile("rsil a2, 1" : : : "a2");
break;
case 2:
asm volatile("rsil a2, 2" : : : "a2");
break;
default:
asm volatile("rsil a2, 3" : : : "a2");
}
}

#ifdef RTOS_SDK
Expand Down

0 comments on commit f268d12

Please sign in to comment.