From bb583485108d99bbede50dc30937e078fb6198bb Mon Sep 17 00:00:00 2001 From: sakimisu <1203593632@qq.com> Date: Wed, 28 Jun 2023 21:12:50 +0800 Subject: [PATCH] check if current context is in irq when gives sem --- osal/usb_osal_freertos.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/osal/usb_osal_freertos.c b/osal/usb_osal_freertos.c index 8547a4c0..da8ccd60 100644 --- a/osal/usb_osal_freertos.c +++ b/osal/usb_osal_freertos.c @@ -38,9 +38,13 @@ int usb_osal_sem_give(usb_osal_sem_t sem) BaseType_t xHigherPriorityTaskWoken = pdFALSE; int ret; - ret = xSemaphoreGiveFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken); - if (ret == pdPASS) { - portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + if (xPortIsInsideInterrupt()) { + ret = xSemaphoreGiveFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken); + if (ret == pdPASS) { + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + } else { + ret = xSemaphoreGive((SemaphoreHandle_t)sem); } return (ret == pdPASS) ? 0 : -ETIMEDOUT;