diff options
| author | Zhihong Chen <[email protected]> | 2026-09-02 11:02:51 +0800 |
|---|---|---|
| committer | sakumisu <[email protected]> | 2026-09-02 13:54:10 +0800 |
| commit | 1fd876d0986bb62f39abb0b4d2f8d6c0b884e5f6 (patch) | |
| tree | 1228ca7509c5307e6836861ffeacbbab8114b332 | |
| parent | 4b3e95217be54c92759bb12e8334b1c0baa27e20 (diff) | |
Signed-off-by: Zhihong Chen <[email protected]>
| -rw-r--r-- | osal/usb_osal_freertos.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/osal/usb_osal_freertos.c b/osal/usb_osal_freertos.c index f1ebf7fc..ed145291 100644 --- a/osal/usb_osal_freertos.c +++ b/osal/usb_osal_freertos.c @@ -57,11 +57,22 @@ void usb_osal_sem_delete(usb_osal_sem_t sem) int usb_osal_sem_take(usb_osal_sem_t sem, uint32_t timeout) { - if (timeout == USB_OSAL_WAITING_FOREVER) { - return (xSemaphoreTake((SemaphoreHandle_t)sem, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT; + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + int ret; + + if (xPortIsInsideInterrupt()) { + /* ISR context: only non-blocking take is allowed */ + ret = xSemaphoreTakeFromISR((SemaphoreHandle_t)sem, &xHigherPriorityTaskWoken); + if (ret == pdPASS) { + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + } else if (timeout == USB_OSAL_WAITING_FOREVER) { + ret = xSemaphoreTake((SemaphoreHandle_t)sem, portMAX_DELAY); } else { - return (xSemaphoreTake((SemaphoreHandle_t)sem, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT; + ret = xSemaphoreTake((SemaphoreHandle_t)sem, pdMS_TO_TICKS(timeout)); } + + return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT; } int usb_osal_sem_give(usb_osal_sem_t sem) @@ -206,7 +217,17 @@ void usb_osal_timer_start(struct usb_osal_timer *timer) void usb_osal_timer_stop(struct usb_osal_timer *timer) { - xTimerStop(timer->timer, 0); + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + int ret; + + if (xPortIsInsideInterrupt()) { + ret = xTimerStopFromISR(timer->timer, &xHigherPriorityTaskWoken); + if (ret == pdPASS) { + portYIELD_FROM_ISR(xHigherPriorityTaskWoken); + } + } else { + xTimerStop(timer->timer, 0); + } } size_t usb_osal_enter_critical_section(void) |
