check if current context is in irq when gives sem

This commit is contained in:
sakimisu
2023-06-28 21:12:50 +08:00
parent 8253f074ce
commit bb58348510

View File

@@ -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;