diff --git a/components/esp8266/driver/i2s.c b/components/esp8266/driver/i2s.c index 1de17aa9..f965469a 100644 --- a/components/esp8266/driver/i2s.c +++ b/components/esp8266/driver/i2s.c @@ -43,7 +43,6 @@ static const char *I2S_TAG = "i2s"; return (ret_val); \ } -#define portYIELD_FROM_ISR() taskYIELD() #define dma_intr_enable() _xt_isr_unmask(1 << ETS_SLC_INUM) #define dma_intr_disable() _xt_isr_mask(1 << ETS_SLC_INUM) #define dma_intr_register(a, b) _xt_isr_attach(ETS_SLC_INUM, (a), (b)) diff --git a/components/esp8266/driver/spi.c b/components/esp8266/driver/spi.c index a197c120..a5a3ed4b 100644 --- a/components/esp8266/driver/spi.c +++ b/components/esp8266/driver/spi.c @@ -41,8 +41,6 @@ } \ } while(0) -#define portYIELD_FROM_ISR() taskYIELD() - #ifndef CONFIG_ESP8266_HSPI_HIGH_THROUGHPUT #define ENTER_CRITICAL_HIGH_THROUGHPUT() ENTER_CRITICAL() #define EXIT_CRITICAL_HIGH_THROUGHPUT() EXIT_CRITICAL() diff --git a/components/esp8266/driver/uart.c b/components/esp8266/driver/uart.c index 728c8458..96fa0622 100644 --- a/components/esp8266/driver/uart.c +++ b/components/esp8266/driver/uart.c @@ -35,8 +35,6 @@ #include "driver/uart.h" #include "driver/uart_select.h" -#define portYIELD_FROM_ISR() taskYIELD() - #define UART_ENTER_CRITICAL() portENTER_CRITICAL() #define UART_EXIT_CRITICAL() portEXIT_CRITICAL() diff --git a/components/freertos/port/esp8266/include/freertos/portmacro.h b/components/freertos/port/esp8266/include/freertos/portmacro.h index b3fabfdb..5d24707d 100644 --- a/components/freertos/port/esp8266/include/freertos/portmacro.h +++ b/components/freertos/port/esp8266/include/freertos/portmacro.h @@ -111,6 +111,7 @@ extern void vTaskSwitchContext( void ); \ } \ } +void portYIELD_FROM_ISR(void); /*-----------------------------------------------------------*/ extern unsigned cpu_sr; diff --git a/components/freertos/port/esp8266/port.c b/components/freertos/port/esp8266/port.c index 0a0c3457..4f3721b4 100644 --- a/components/freertos/port/esp8266/port.c +++ b/components/freertos/port/esp8266/port.c @@ -53,7 +53,6 @@ #define PORT_ASSERT(x) do { if (!(x)) {ets_printf("%s %u\n", "rtos_port", __LINE__); while(1){}; }} while (0) extern uint8_t NMIIrqIsOn; -static int SWReq = 0; uint32_t cpu_sr; @@ -68,9 +67,15 @@ uint64_t g_esp_os_ticks; uint64_t g_esp_os_us; uint64_t g_esp_os_cpu_clk; +static uint32_t s_switch_ctx_flag; + void vPortEnterCritical(void); void vPortExitCritical(void); +void IRAM_ATTR portYIELD_FROM_ISR(void) +{ + s_switch_ctx_flag = 1; +} uint8_t *__cpu_init_stk(uint8_t *stack_top, void (*_entry)(void *), void *param, void (*_exit)(void)) { @@ -112,7 +117,7 @@ void IRAM_ATTR PendSV(int req) { if (req == 1) { vPortEnterCritical(); - SWReq = 1; + s_switch_ctx_flag = 1; xthal_set_intset(1 << ETS_SOFT_INUM); vPortExitCritical(); } else if (req == 2) { @@ -120,13 +125,12 @@ void IRAM_ATTR PendSV(int req) } } -void TASK_SW_ATTR SoftIsrHdl(void* arg) +void IRAM_ATTR SoftIsrHdl(void* arg) { extern int MacIsrSigPostDefHdl(void); - if (MacIsrSigPostDefHdl() || (SWReq == 1)) { - vTaskSwitchContext(); - SWReq = 0; + if (MacIsrSigPostDefHdl()) { + portYIELD_FROM_ISR(); } } @@ -165,7 +169,7 @@ void IRAM_ATTR xPortSysTickHandle(void *p) g_esp_os_ticks++; if (xTaskIncrementTick() != pdFALSE) { - vTaskSwitchContext(); + portYIELD_FROM_ISR(); } } @@ -259,7 +263,7 @@ void IRAM_ATTR vPortExitCritical(void) void show_critical_info(void) { ets_printf("ShowCritical:%u\n", uxCriticalNesting); - ets_printf("SWReq:%u\n", SWReq); + ets_printf("s_switch_ctx_flag:%u\n", s_switch_ctx_flag); } #ifdef ESP_DPORT_CLOSE_NMI @@ -345,6 +349,11 @@ void IRAM_ATTR _xt_isr_handler(void) mask &= ~bit; } } while (soc_get_int_mask()); + + if (s_switch_ctx_flag) { + vTaskSwitchContext(); + s_switch_ctx_flag = 0; + } } int xPortInIsrContext(void) diff --git a/components/newlib/newlib/port/locks.c b/components/newlib/newlib/port/locks.c index 1c709fd5..11972a60 100644 --- a/components/newlib/newlib/port/locks.c +++ b/components/newlib/newlib/port/locks.c @@ -20,8 +20,6 @@ #include "semphr.h" #include "task.h" -#define portYIELD_FROM_ISR portYIELD - /* Initialize the given lock by allocating a new mutex semaphore as the _lock_t value.