From 88f710458c01c33760e3f9e672064ce2430b03ee Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Fri, 12 Aug 2022 19:42:02 +0800 Subject: [PATCH] delete workq --- SConscript | 2 - core/usbh_core.c | 2 - core/usbh_core.h | 2 - .../MDK-ARM/stm32f429igt6.uvoptx | 44 ++----- .../MDK-ARM/stm32f429igt6.uvprojx | 7 +- .../MDK-ARM/stm32h743xih6.uvoptx | 18 +-- .../MDK-ARM/stm32h743xih6.uvprojx | 7 +- osal/usb_workq.c | 120 ------------------ osal/usb_workq.h | 49 ------- port/dwc2/usb_hc_dwc2.c | 106 +++------------- usb_config.h | 14 -- 11 files changed, 34 insertions(+), 337 deletions(-) delete mode 100644 osal/usb_workq.c delete mode 100644 osal/usb_workq.h diff --git a/SConscript b/SConscript index 34c2bbc2..f27a4ad0 100644 --- a/SConscript +++ b/SConscript @@ -81,7 +81,6 @@ if GetDepend(['PKG_CHERRYUSB_HOST']): path += [cwd + '/class/hub'] src += Glob('core/usbh_core.c') src += Glob('osal/usb_osal_rtthread.c') - src += Glob('osal/usb_workq.c') if GetDepend(['PKG_CHERRYUSB_HOST_CDC']): path += [cwd + '/class/cdc'] @@ -101,7 +100,6 @@ if GetDepend(['PKG_CHERRYUSB_HOST']): if GetDepend(['PKG_CHERRYUSB_HOST_DWC2']): src += Glob('port/dwc2/usb_hc_dwc2.c') - CPPDEFINES += ['CONFIG_USBHOST_HIGH_WORKQ'] if GetDepend(['PKG_CHERRYUSB_HOST_MUSB']): src += Glob('port/musb/usb_hc_musb.c') diff --git a/core/usbh_core.c b/core/usbh_core.c index 45b4daf8..2a61f0c6 100644 --- a/core/usbh_core.c +++ b/core/usbh_core.c @@ -830,8 +830,6 @@ int usbh_initialize(void) usbh_class_info_table_end = (struct usbh_class_info *)&_usbh_class_info_end; #endif - usbh_workq_initialize(); - usbh_core_cfg.pscevent = usb_osal_event_create(); if (usbh_core_cfg.pscevent == NULL) { return -1; diff --git a/core/usbh_core.h b/core/usbh_core.h index b4d867a3..05687250 100644 --- a/core/usbh_core.h +++ b/core/usbh_core.h @@ -36,7 +36,6 @@ #include "usb_log.h" #include "usb_hc.h" #include "usb_osal.h" -#include "usb_workq.h" #include "usbh_hub.h" #ifdef __cplusplus @@ -129,7 +128,6 @@ typedef struct usbh_hub { struct usb_hub_descriptor hub_desc; struct usbh_hubport child[CONFIG_USBHOST_EHPORTS]; struct usbh_hubport *parent; /* Parent hub port */ - struct usb_work work; } usbh_hub_t; void usbh_event_notify_handler(uint8_t event, uint8_t rhport); diff --git a/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvoptx b/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvoptx index 3de13968..bc0bd9a9 100644 --- a/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvoptx +++ b/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvoptx @@ -173,22 +173,6 @@ 1 0 - 819 - 1 -
0
- 0 - 0 - 0 - 0 - 0 - 0 - ..\..\..\..\..\core\usbh_core.c - - -
- - 2 - 0 1027 1
0
@@ -203,7 +187,7 @@
- 3 + 2 0 1030 1 @@ -219,7 +203,7 @@ - 4 + 3 0 1309 1 @@ -235,7 +219,7 @@ - 5 + 4 0 1314 1 @@ -839,18 +823,6 @@ 0 0 - - 6 - 40 - 1 - 0 - 0 - 0 - ..\..\..\..\..\osal\usb_workq.c - usb_workq.c - 0 - 0 - @@ -861,7 +833,7 @@ 0 7 - 41 + 40 1 0 0 @@ -873,7 +845,7 @@ 7 - 42 + 41 1 0 0 @@ -885,7 +857,7 @@ 7 - 43 + 42 1 0 0 @@ -897,7 +869,7 @@ 7 - 44 + 43 1 0 0 @@ -909,7 +881,7 @@ 7 - 45 + 44 1 0 0 diff --git a/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvprojx b/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvprojx index 872fcc6f..fbb4c041 100644 --- a/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvprojx +++ b/demo/stm32/usb_host/stm32f429igt6/MDK-ARM/stm32f429igt6.uvprojx @@ -338,7 +338,7 @@ 0 - USE_HAL_DRIVER,STM32F429xx,CONFIG_USBHOST_HIGH_WORKQ + USE_HAL_DRIVER,STM32F429xx ../Core/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc;../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32F4xx/Include;../Drivers/CMSIS/Include;..\..\..\..\..\common;..\..\..\..\..\core;..\..\..\..\..\class\cdc;..\..\..\..\..\class\hub;..\..\..\..\..\class\hid;..\..\..\..\..\class\msc;..\..\..\..\..\osal;..\..\..\..\..\third_party\FreeRTOS-10.4\include;..\..\..\..\..\third_party\FreeRTOS-10.4\portable\GCC\ARM_CM4F;..\..\..\..\..\third_party\fatfs-0.14\source @@ -604,11 +604,6 @@ 1 ..\..\..\..\..\port\dwc2\usb_hc_dwc2.c - - usb_workq.c - 1 - ..\..\..\..\..\osal\usb_workq.c - diff --git a/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvoptx b/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvoptx index 2a14c094..0db1921f 100644 --- a/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvoptx +++ b/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvoptx @@ -812,18 +812,6 @@ 0 0 0 - ..\..\..\..\..\osal\usb_workq.c - usb_workq.c - 0 - 0 - - - 6 - 40 - 1 - 0 - 0 - 0 ..\..\..\..\..\class\cdc\usbh_cdc_acm.c usbh_cdc_acm.c 0 @@ -831,7 +819,7 @@ 6 - 41 + 40 1 0 0 @@ -843,7 +831,7 @@ 6 - 42 + 41 1 0 0 @@ -855,7 +843,7 @@ 6 - 43 + 42 1 0 0 diff --git a/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvprojx b/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvprojx index 37ccb48e..939819a2 100644 --- a/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvprojx +++ b/demo/stm32/usb_host/stm32h743xih6/MDK-ARM/stm32h743xih6.uvprojx @@ -338,7 +338,7 @@ 0 - USE_HAL_DRIVER,STM32H743xx,STM32H7,CONFIG_USBHOST_HIGH_WORKQ,CONFIG_USB_DCACHE_ENABLE,CONFIG_USB_ALIGN_SIZE=32 + USE_HAL_DRIVER,STM32H743xx,STM32H7,CONFIG_USB_DCACHE_ENABLE,CONFIG_USB_ALIGN_SIZE=32 ../Core/Inc;../Drivers/STM32H7xx_HAL_Driver/Inc;../Drivers/STM32H7xx_HAL_Driver/Inc/Legacy;../Drivers/CMSIS/Device/ST/STM32H7xx/Include;../Drivers/CMSIS/Include;..\..\..\..\..\core;..\..\..\..\..\common;..\..\..\..\..\osal;..\..\..\..\..\class\cdc;..\..\..\..\..\class\hid;..\..\..\..\..\class\msc;..\..\..\..\..\class\hub;..\..\..\..\..\third_party\FreeRTOS-10.4\include;..\..\..\..\..\third_party\FreeRTOS-10.4\portable\GCC\ARM_CM7\r0p1 @@ -599,11 +599,6 @@ 1 ..\..\..\..\..\osal\usb_osal_freertos.c - - usb_workq.c - 1 - ..\..\..\..\..\osal\usb_workq.c - usbh_cdc_acm.c 1 diff --git a/osal/usb_workq.c b/osal/usb_workq.c deleted file mode 100644 index 99dfd112..00000000 --- a/osal/usb_workq.c +++ /dev/null @@ -1,120 +0,0 @@ -/** - * @file usb_workq.c - * @brief - * - * Copyright (c) 2022 sakumisu - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -#include "usb_list.h" -#include "usb_osal.h" -#include "usb_workq.h" -#include "usb_config.h" - -void usb_workqueue_submit(struct usb_workqueue *queue, struct usb_work *work, usb_worker_t worker, void *arg, uint32_t ticks) -{ - size_t flags; - flags = usb_osal_enter_critical_section(); - usb_dlist_remove(&work->list); - work->worker = worker; - work->arg = arg; - - if (ticks == 0) { - usb_dlist_insert_after(&queue->work_list, &work->list); - usb_osal_sem_give(queue->sem); - } - - usb_osal_leave_critical_section(flags); -} - -struct usb_workqueue g_hpworkq = { NULL }; -struct usb_workqueue g_lpworkq = { NULL }; - -#ifdef CONFIG_USBHOST_HIGH_WORKQ -static void usbh_hpwork_thread(void *argument) -{ - struct usb_work *work; - size_t flags; - int ret; - struct usb_workqueue *queue = (struct usb_workqueue *)argument; - while (1) { - ret = usb_osal_sem_take(queue->sem, 0xffffffff); - if (ret < 0) { - continue; - } - flags = usb_osal_enter_critical_section(); - if (usb_dlist_isempty(&queue->work_list)) { - usb_osal_leave_critical_section(flags); - continue; - } - work = usb_dlist_first_entry(&queue->work_list, struct usb_work, list); - usb_dlist_remove(&work->list); - usb_osal_leave_critical_section(flags); - work->worker(work->arg); - } -} -#endif -#ifdef CONFIG_USBHOST_LOW_WORKQ -static void usbh_lpwork_thread(void *argument) -{ - struct usb_work *work; - size_t flags; - int ret; - struct usb_workqueue *queue = (struct usb_workqueue *)argument; - while (1) { - ret = usb_osal_sem_take(queue->sem, 0xffffffff); - if (ret < 0) { - continue; - } - flags = usb_osal_enter_critical_section(); - if (usb_dlist_isempty(&queue->work_list)) { - usb_osal_leave_critical_section(flags); - continue; - } - work = usb_dlist_first_entry(&queue->work_list, struct usb_work, list); - usb_dlist_remove(&work->list); - usb_osal_leave_critical_section(flags); - work->worker(work->arg); - } -} -#endif - -int usbh_workq_initialize(void) -{ -#ifdef CONFIG_USBHOST_HIGH_WORKQ - g_hpworkq.sem = usb_osal_sem_create(0); - if (g_hpworkq.sem == NULL) { - return -1; - } - g_hpworkq.thread = usb_osal_thread_create("usbh_hpworkq", CONFIG_USBHOST_HPWORKQ_STACKSIZE, CONFIG_USBHOST_HPWORKQ_PRIO, usbh_hpwork_thread, &g_hpworkq); - if (g_hpworkq.thread == NULL) { - return -1; - } -#endif -#ifdef CONFIG_USBHOST_LOW_WORKQ - g_lpworkq.sem = usb_osal_sem_create(0); - if (g_lpworkq.sem == NULL) { - return -1; - } - - g_lpworkq.thread = usb_osal_thread_create("usbh_lpworkq", CONFIG_USBHOST_LPWORKQ_STACKSIZE, CONFIG_USBHOST_LPWORKQ_PRIO, usbh_lpwork_thread, &g_lpworkq); - if (g_lpworkq.thread == NULL) { - return -1; - } -#endif - return 0; -} diff --git a/osal/usb_workq.h b/osal/usb_workq.h deleted file mode 100644 index 0c3707dd..00000000 --- a/osal/usb_workq.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * @file usb_workq.h - * @brief - * - * Copyright (c) 2022 sakumisu - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - */ -#ifndef _USB_WORKQUEUE_H -#define _USB_WORKQUEUE_H - -/* Defines the work callback */ -typedef void (*usb_worker_t)(void *arg); - -struct usb_work -{ - usb_dlist_t list; - usb_worker_t worker; - void *arg; -}; - -struct usb_workqueue -{ - usb_dlist_t work_list; - usb_dlist_t delay_work_list; - usb_osal_sem_t sem; - usb_osal_thread_t thread; -}; - -extern struct usb_workqueue g_hpworkq; -extern struct usb_workqueue g_lpworkq; - -void usb_workqueue_submit(struct usb_workqueue *queue, struct usb_work *work, usb_worker_t worker, void *arg, uint32_t ticks); -int usbh_workq_initialize(); -#endif diff --git a/port/dwc2/usb_hc_dwc2.c b/port/dwc2/usb_hc_dwc2.c index 89cb5032..cae495c9 100644 --- a/port/dwc2/usb_hc_dwc2.c +++ b/port/dwc2/usb_hc_dwc2.c @@ -1,10 +1,6 @@ #include "usbh_core.h" #include "usb_dwc2_reg.h" -#ifndef CONFIG_USBHOST_HIGH_WORKQ -#error "dwc2 host must use high workq" -#endif - #if defined(STM32F7) || defined(STM32H7) #ifndef CONFIG_USB_DCACHE_ENABLE #warning "if you enable dcache,please enable this macro" @@ -65,7 +61,7 @@ struct dwc2_pipe { struct dwc2_hcd { volatile bool connected; - struct usb_work work; + volatile bool port_enable; struct dwc2_pipe chan[CONFIG_USB_DWC2_PIPE_NUM]; } g_dwc2_hcd; @@ -624,8 +620,8 @@ int usb_hc_hw_init(void) USB_OTG_GLB->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN; USB_OTG_GLB->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN; #endif + /*!< FS/LS PHY clock select */ USB_OTG_HOST->HCFG |= USB_OTG_HCFG_FSLSPCS_0; - usbh_reset_port(1); /* Set default Max speed support */ USB_OTG_HOST->HCFG &= ~(USB_OTG_HCFG_FSLSS); @@ -694,6 +690,10 @@ int usbh_reset_port(const uint8_t port) usb_osal_msleep(100U); /* See Note #1 */ USB_OTG_HPRT = ((~USB_OTG_HPRT_PRST) & hprt0); usb_osal_msleep(10U); + + while (!g_dwc2_hcd.port_enable) { + } + return 0; } @@ -1098,56 +1098,6 @@ int usb_ep_cancel(usbh_epinfo_t ep) return 0; } -//static void usb_dwc2_rxqlvl_irq_handler(void) -//{ -// uint32_t pktsts; -// uint32_t pktcnt; -// uint32_t GrxstspReg; -// uint32_t xferSizePktCnt; -// uint32_t tmpreg; -// uint32_t ch_num; -// uint32_t len32b; -// uint32_t *pdest; -// struct dwc2_pipe *chan; - -// GrxstspReg = USB_OTG_GLB->GRXSTSP; -// ch_num = GrxstspReg & USB_OTG_GRXSTSP_EPNUM; -// pktsts = (GrxstspReg & USB_OTG_GRXSTSP_PKTSTS) >> 17; -// pktcnt = (GrxstspReg & USB_OTG_GRXSTSP_BCNT) >> 4; - -// chan = &g_dwc2_hcd.chan[ch_num]; -// switch (pktsts) { -// case GRXSTS_PKTSTS_IN: -// /* Read the data into the host buffer. */ -// if ((pktcnt > 0U) && (chan->buffer != NULL)) { -// len32b = ((uint32_t)pktcnt + 3U) / 4U; - -// pdest = (uint32_t *)chan->buffer; - -// for (uint8_t i = 0U; i < len32b; i++) { -// *pdest = USB_OTG_FIFO(0U); -// pdest++; -// } - -// chan->buffer += pktcnt; -// chan->xfrd += pktcnt; -// chan->buflen -= pktcnt; - -// if (chan->buflen == 0) { -// } -// } -// break; - -// case GRXSTS_PKTSTS_DATA_TOGGLE_ERR: -// break; - -// case GRXSTS_PKTSTS_IN_XFER_COMP: -// case GRXSTS_PKTSTS_CH_HALTED: -// default: -// break; -// } -//} - static void dwc2_inchan_irq_handler(uint8_t ch_num) { uint32_t chan_intstatus; @@ -1333,16 +1283,9 @@ static void dwc2_outchan_irq_handler(uint8_t ch_num) } } -void dwc2_reset_handler(void *arg) -{ - usb_osal_msleep(300); /* let the usb host power keep stable */ - usbh_reset_port(1); -} - static void dwc2_port_irq_handler(void) { __IO uint32_t hprt0, hprt0_dup, regval; - bool reset = false; /* Handle Host Port Interrupts */ hprt0 = USB_OTG_HPRT; @@ -1354,7 +1297,7 @@ static void dwc2_port_irq_handler(void) /* Check whether Port Connect detected */ if ((hprt0 & USB_OTG_HPRT_PCDET) == USB_OTG_HPRT_PCDET) { if ((hprt0 & USB_OTG_HPRT_PCSTS) == USB_OTG_HPRT_PCSTS) { - reset = true; + usbh_event_notify_handler(USBH_EVENT_CONNECTED, 1); } hprt0_dup |= USB_OTG_HPRT_PCDET; } @@ -1373,7 +1316,6 @@ static void dwc2_port_irq_handler(void) regval &= ~USB_OTG_HCFG_FSLSPCS; regval |= USB_OTG_HCFG_FSLSPCS_1; USB_OTG_HOST->HCFG = regval; - reset = true; } } else { USB_OTG_HOST->HFIR = 48000U; @@ -1382,22 +1324,14 @@ static void dwc2_port_irq_handler(void) regval &= ~USB_OTG_HCFG_FSLSPCS; regval |= USB_OTG_HCFG_FSLSPCS_0; USB_OTG_HOST->HCFG = regval; - reset = true; } } #endif - usbh_event_notify_handler(USBH_EVENT_CONNECTED, 1); - } else { - for (int chidx = 0; chidx < CONFIG_USB_DWC2_PIPE_NUM; chidx++) { - struct dwc2_pipe *chan; - chan = &g_dwc2_hcd.chan[chidx]; - if (chan->waiter) { - chan->waiter = false; - chan->result = -ENXIO; - usb_osal_sem_give(chan->waitsem); - } + for (uint32_t i = 0; i < 1000; i++) { } - usbh_event_notify_handler(USBH_EVENT_DISCONNECTED, 1); + g_dwc2_hcd.port_enable = true; + } else { + g_dwc2_hcd.port_enable = false; } } @@ -1407,9 +1341,6 @@ static void dwc2_port_irq_handler(void) } /* Clear Port Interrupts */ USB_OTG_HPRT = hprt0_dup; - if (reset) { - usb_workqueue_submit(&g_hpworkq, &g_dwc2_hcd.work, dwc2_reset_handler, NULL, 0); - } } void USBH_IRQHandler(void) @@ -1426,13 +1357,18 @@ void USBH_IRQHandler(void) dwc2_port_irq_handler(); } if (gint_status & USB_OTG_GINTSTS_DISCINT) { + for (int chidx = 0; chidx < CONFIG_USB_DWC2_PIPE_NUM; chidx++) { + struct dwc2_pipe *chan; + chan = &g_dwc2_hcd.chan[chidx]; + if (chan->waiter) { + chan->waiter = false; + chan->result = -ENXIO; + usb_osal_sem_give(chan->waitsem); + } + } + usbh_event_notify_handler(USBH_EVENT_DISCONNECTED, 1); USB_OTG_GLB->GINTSTS = USB_OTG_GINTSTS_DISCINT; } - // if (gint_status & USB_OTG_GINTSTS_RXFLVL) { - // USB_MASK_INTERRUPT(USB_OTG_GLB, USB_OTG_GINTSTS_RXFLVL); - // usb_dwc2_rxqlvl_irq_handler(); - // USB_UNMASK_INTERRUPT(USB_OTG_GLB, USB_OTG_GINTSTS_RXFLVL); - // } if (gint_status & USB_OTG_GINTSTS_HCINT) { chan_int = (USB_OTG_HOST->HAINT & USB_OTG_HOST->HAINTMSK) & 0xFFFFU; for (uint8_t i = 0U; i < CONFIG_USB_DWC2_PIPE_NUM; i++) { diff --git a/usb_config.h b/usb_config.h index ca8ebd01..76ab984f 100644 --- a/usb_config.h +++ b/usb_config.h @@ -89,20 +89,6 @@ #define CONFIG_USBHOST_MSC_TIMEOUT 5000 #endif -#ifndef CONFIG_USBHOST_HPWORKQ_PRIO -#define CONFIG_USBHOST_HPWORKQ_PRIO 5 -#endif -#ifndef CONFIG_USBHOST_HPWORKQ_STACKSIZE -#define CONFIG_USBHOST_HPWORKQ_STACKSIZE 2048 -#endif - -#ifndef CONFIG_USBHOST_LPWORKQ_PRIO -#define CONFIG_USBHOST_LPWORKQ_PRIO 1 -#endif -#ifndef CONFIG_USBHOST_LPWORKQ_STACKSIZE -#define CONFIG_USBHOST_LPWORKQ_STACKSIZE 2048 -#endif - #ifndef CONFIG_USBHOST_PSC_PRIO #define CONFIG_USBHOST_PSC_PRIO 4 #endif