summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--osal/usb_osal_freertos.c29
-rw-r--r--port/ch32/ch58x/usb_ch585_usbhs_dc.c6
2 files changed, 28 insertions, 7 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)
diff --git a/port/ch32/ch58x/usb_ch585_usbhs_dc.c b/port/ch32/ch58x/usb_ch585_usbhs_dc.c
index 2e6724c2..1f33a36d 100644
--- a/port/ch32/ch58x/usb_ch585_usbhs_dc.c
+++ b/port/ch32/ch58x/usb_ch585_usbhs_dc.c
@@ -41,7 +41,7 @@
* @brief Endpoint information structure
*/
typedef struct _usbd_ep_info {
- uint8_t mps; /* Maximum packet length of endpoint */
+ uint16_t mps; /* Maximum packet length of endpoint */
uint8_t eptype; /* Endpoint Type */
uint8_t ep_enable; /* Endpoint enable */
uint8_t *xfer_buf;
@@ -143,7 +143,7 @@ int usbd_ep_open(uint8_t busid, const struct usb_endpoint_descriptor *ep)
return -1;
}
- uint8_t mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
+ uint16_t mps = USB_GET_MAXPACKETSIZE(ep->wMaxPacketSize);
USB_SET_MAX_LEN(epid, mps);
if (USB_EP_DIR_IS_IN(ep->bEndpointAddress)) {
@@ -523,4 +523,4 @@ void USB2_DEVICE_IRQHandler(void)
{
extern void USBD_IRQHandler(uint8_t busid);
USBD_IRQHandler(0);
-} \ No newline at end of file
+}