Skip to content

Commit

Permalink
update(osal/freertos): update usb_osal_mq_recv and usb_osal_mq_send f…
Browse files Browse the repository at this point in the history
…or isr api
  • Loading branch information
sakumisu committed Nov 6, 2024
1 parent 037c2a8 commit 6ea1e2f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 12 deletions.
27 changes: 21 additions & 6 deletions osal/idf/usb_osal_idf.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,35 @@ int usb_osal_mq_send(usb_osal_mq_t mq, uintptr_t addr)
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
int ret;

ret = xQueueSendFromISR((usb_osal_mq_t)mq, &addr, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
if (xPortInIsrContext()) {
ret = xQueueSendFromISR((usb_osal_mq_t)mq, &addr, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xQueueSend((usb_osal_mq_t)mq, &addr, 0xffffffff);
}

return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
}

int usb_osal_mq_recv(usb_osal_mq_t mq, uintptr_t *addr, uint32_t timeout)
{
if (timeout == USB_OSAL_WAITING_FOREVER) {
return (xQueueReceive((usb_osal_mq_t)mq, addr, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
int ret;

if (xPortInIsrContext()) {
ret = xQueueReceiveFromISR((usb_osal_mq_t)mq, addr, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
} else {
return (xQueueReceive((usb_osal_mq_t)mq, addr, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
if (timeout == USB_OSAL_WAITING_FOREVER) {
return (xQueueReceive((usb_osal_mq_t)mq, addr, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
} else {
return (xQueueReceive((usb_osal_mq_t)mq, addr, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
}
}
}

Expand Down
27 changes: 21 additions & 6 deletions osal/usb_osal_freertos.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,35 @@ int usb_osal_mq_send(usb_osal_mq_t mq, uintptr_t addr)
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
int ret;

ret = xQueueSendFromISR((usb_osal_mq_t)mq, &addr, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
if (xPortIsInsideInterrupt()) {
ret = xQueueSendFromISR((usb_osal_mq_t)mq, &addr, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
} else {
ret = xQueueSend((usb_osal_mq_t)mq, &addr, 0xffffffff);
}

return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
}

int usb_osal_mq_recv(usb_osal_mq_t mq, uintptr_t *addr, uint32_t timeout)
{
if (timeout == USB_OSAL_WAITING_FOREVER) {
return (xQueueReceive((usb_osal_mq_t)mq, addr, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
int ret;

if (xPortIsInsideInterrupt()) {
ret = xQueueReceiveFromISR((usb_osal_mq_t)mq, addr, &xHigherPriorityTaskWoken);
if (ret == pdPASS) {
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
return (ret == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
} else {
return (xQueueReceive((usb_osal_mq_t)mq, addr, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
if (timeout == USB_OSAL_WAITING_FOREVER) {
return (xQueueReceive((usb_osal_mq_t)mq, addr, portMAX_DELAY) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
} else {
return (xQueueReceive((usb_osal_mq_t)mq, addr, pdMS_TO_TICKS(timeout)) == pdPASS) ? 0 : -USB_ERR_TIMEOUT;
}
}
}

Expand Down

0 comments on commit 6ea1e2f

Please sign in to comment.