diff options
| author | sakimisu <[email protected]> | 2023-01-15 16:51:28 +0800 |
|---|---|---|
| committer | sakimisu <[email protected]> | 2023-01-15 16:55:29 +0800 |
| commit | 2c24b54bf103cabd01890dc1a4f2583b1fadf64d (patch) | |
| tree | 6afc2e774467067dca203b5262f6e0df3d806e2a /core | |
| parent | e475dd730b1b544f0e57f9011d744af4ccc10db0 (diff) | |
split tx_rx_thread into tx_thread and rx_thread
Diffstat (limited to 'core')
| -rw-r--r-- | core/usbd_core.c | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/core/usbd_core.c b/core/usbd_core.c index cd91ea00..cbe7a97b 100644 --- a/core/usbd_core.c +++ b/core/usbd_core.c @@ -6,7 +6,7 @@ * SPDX-License-Identifier: Apache-2.0 */ #include "usbd_core.h" -#ifdef CONFIG_USBDEV_TX_RX_THREAD +#if defined(CONFIG_USBDEV_TX_THREAD) || defined(CONFIG_USBDEV_RX_THREAD) #include "usb_osal.h" #endif @@ -72,9 +72,13 @@ static struct usb_bos_descriptor *bos_desc; struct usbd_tx_rx_msg tx_msg[USB_EP_IN_NUM]; struct usbd_tx_rx_msg rx_msg[USB_EP_OUT_NUM]; -#ifdef CONFIG_USBDEV_TX_RX_THREAD -usb_osal_mq_t usbd_tx_rx_mq; -usb_osal_thread_t usbd_tx_rx_thread; +#if defined(CONFIG_USBDEV_TX_THREAD) +usb_osal_mq_t usbd_tx_mq; +usb_osal_thread_t usbd_tx_thread; +#endif +#if defined(CONFIG_USBDEV_RX_THREAD) +usb_osal_mq_t usbd_rx_mq; +usb_osal_thread_t usbd_rx_thread; #endif static void usbd_class_event_notify_handler(uint8_t event, void *arg); @@ -1094,36 +1098,55 @@ void usbd_event_ep0_out_complete_handler(uint8_t ep, uint32_t nbytes) void usbd_event_ep_in_complete_handler(uint8_t ep, uint32_t nbytes) { -#ifndef CONFIG_USBDEV_TX_RX_THREAD +#ifndef CONFIG_USBDEV_TX_THREAD if (tx_msg[ep & 0x7f].cb) { tx_msg[ep & 0x7f].cb(ep, nbytes); } #else tx_msg[ep & 0x7f].nbytes = nbytes; - usb_osal_mq_send(usbd_tx_rx_mq, (uint32_t)&tx_msg[ep & 0x7f]); + usb_osal_mq_send(usbd_tx_mq, (uint32_t)&tx_msg[ep & 0x7f]); #endif } void usbd_event_ep_out_complete_handler(uint8_t ep, uint32_t nbytes) { -#ifndef CONFIG_USBDEV_TX_RX_THREAD +#ifndef CONFIG_USBDEV_RX_THREAD if (rx_msg[ep & 0x7f].cb) { rx_msg[ep & 0x7f].cb(ep, nbytes); } #else rx_msg[ep & 0x7f].nbytes = nbytes; - usb_osal_mq_send(usbd_tx_rx_mq, (uint32_t)&rx_msg[ep & 0x7f]); + usb_osal_mq_send(usbd_rx_mq, (uint32_t)&rx_msg[ep & 0x7f]); #endif } -#ifdef CONFIG_USBDEV_TX_RX_THREAD -static void usbdev_tx_rx_thread(void *argument) +#ifdef CONFIG_USBDEV_TX_THREAD +static void usbdev_tx_thread(void *argument) +{ + struct usbd_tx_rx_msg *msg; + int ret; + + while (1) { + ret = usb_osal_mq_recv(usbd_tx_mq, (uint32_t *)&msg, 0xffffffff); + if (ret < 0) { + continue; + } + + if (msg->cb) { + msg->cb(msg->ep, msg->nbytes); + } + } +} +#endif + +#ifdef CONFIG_USBDEV_RX_THREAD +static void usbdev_rx_thread(void *argument) { struct usbd_tx_rx_msg *msg; int ret; while (1) { - ret = usb_osal_mq_recv(usbd_tx_rx_mq, (uint32_t *)&msg, 0xffffffff); + ret = usb_osal_mq_recv(usbd_rx_mq, (uint32_t *)&msg, 0xffffffff); if (ret < 0) { continue; } @@ -1199,13 +1222,23 @@ bool usb_device_is_configured(void) int usbd_initialize(void) { -#ifdef CONFIG_USBDEV_TX_RX_THREAD - usbd_tx_rx_mq = usb_osal_mq_create(32); - if (usbd_tx_rx_mq == NULL) { +#ifdef CONFIG_USBDEV_TX_THREAD + usbd_tx_mq = usb_osal_mq_create(16); + if (usbd_tx_mq == NULL) { + return -1; + } + usbd_tx_thread = usb_osal_thread_create("usbd_tx", CONFIG_USBDEV_TX_STACKSIZE, CONFIG_USBDEV_TX_PRIO, usbdev_tx_thread, NULL); + if (usbd_tx_thread == NULL) { + return -1; + } +#endif +#ifdef CONFIG_USBDEV_RX_THREAD + usbd_rx_mq = usb_osal_mq_create(16); + if (usbd_rx_mq == NULL) { return -1; } - usbd_tx_rx_thread = usb_osal_thread_create("usbd_tx_rx", CONFIG_USBDEV_TX_RX_STACKSIZE, CONFIG_USBDEV_TX_RX_PRIO, usbdev_tx_rx_thread, NULL); - if (usbd_tx_rx_thread == NULL) { + usbd_rx_thread = usb_osal_thread_create("usbd_rx", CONFIG_USBDEV_RX_STACKSIZE, CONFIG_USBDEV_RX_PRIO, usbdev_rx_thread, NULL); + if (usbd_rx_thread == NULL) { return -1; } #endif @@ -1217,7 +1250,7 @@ int usbd_deinitialize(void) usbd_core_cfg.intf_offset = 0; usb_slist_init(&usbd_intf_head); usb_dc_deinit(); -#ifdef CONFIG_USBDEV_TX_RX_THREAD +#if defined(CONFIG_USBDEV_TX_THREAD) || defined(CONFIG_USBDEV_RX_THREAD) #endif return 0; } |
