feat(class): add usb_osal_thread_schedule_other to allow the applications which use the struct usbh_xxx to exit properly before free struct usbh_xxx

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu
2025-06-03 17:31:31 +08:00
parent a8bf2687bd
commit bff8a632a9
25 changed files with 111 additions and 0 deletions

View File

@@ -594,6 +594,7 @@ static int usbh_audio_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister Audio Class:%s\r\n", hport->config.intf[intf].devname);
usbh_audio_stop(audio_class);
}

View File

@@ -193,6 +193,7 @@ static int usbh_cdc_acm_disconnect(struct usbh_hubport *hport, uint8_t intf)
#endif
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister CDC ACM Class:%s\r\n", hport->config.intf[intf].devname);
usbh_cdc_acm_stop(cdc_acm_class);
}

View File

@@ -221,6 +221,7 @@ static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister CDC ECM Class:%s\r\n", hport->config.intf[intf].devname);
usbh_cdc_ecm_stop(cdc_ecm_class);
}

View File

@@ -239,6 +239,7 @@ static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister CDC NCM Class:%s\r\n", hport->config.intf[intf].devname);
usbh_cdc_ncm_stop(cdc_ncm_class);
}

View File

@@ -299,6 +299,7 @@ int usbh_hid_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister HID Class:%s\r\n", hport->config.intf[intf].devname);
usbh_hid_stop(hid_class);
}

View File

@@ -342,6 +342,7 @@ static int usbh_msc_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister MSC Class:%s\r\n", hport->config.intf[intf].devname);
usbh_msc_stop(msc_class);
}

View File

@@ -638,6 +638,7 @@ static int usbh_asix_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister ASIX Class:%s\r\n", hport->config.intf[intf].devname);
usbh_asix_stop(asix_class);
}

View File

@@ -2121,6 +2121,7 @@ static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister rtl8152 Class:%s\r\n", hport->config.intf[intf].devname);
usbh_rtl8152_stop(rtl8152_class);
}

View File

@@ -311,6 +311,7 @@ static int usbh_ch34x_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister CH34X Class:%s\r\n", hport->config.intf[intf].devname);
usbh_ch34x_stop(ch34x_class);
}

View File

@@ -260,6 +260,7 @@ static int usbh_cp210x_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister CP210X Class:%s\r\n", hport->config.intf[intf].devname);
usbh_cp210x_stop(cp210x_class);
}

View File

@@ -440,6 +440,7 @@ static int usbh_ftdi_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister FTDI Class:%s\r\n", hport->config.intf[intf].devname);
usbh_ftdi_stop(ftdi_class);
}

View File

@@ -375,6 +375,7 @@ static int usbh_pl2303_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister PL2303 Class:%s\r\n", hport->config.intf[intf].devname);
usbh_pl2303_stop(pl2303_class);
}

View File

@@ -337,6 +337,7 @@ static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister BL616 WIFI Class:%s\r\n", hport->config.intf[intf].devname);
usbh_bl616_stop(bl616_class);
}

View File

@@ -86,6 +86,7 @@ int usbh_xbox_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister XBOX Class:%s\r\n", hport->config.intf[intf].devname);
usbh_xbox_stop(xbox_class);
}

View File

@@ -483,6 +483,7 @@ static int usbh_video_ctrl_disconnect(struct usbh_hubport *hport, uint8_t intf)
}
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister Video Class:%s\r\n", hport->config.intf[intf].devname);
usbh_video_stop(video_class);
}

View File

@@ -134,6 +134,7 @@ static int usbh_bluetooth_disconnect(struct usbh_hubport *hport, uint8_t intf)
// }
#endif
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister Bluetooth Class:%s\r\n", hport->config.intf[intf].devname);
usbh_bluetooth_stop(bluetooth_class);
}

View File

@@ -438,6 +438,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
// }
if (hport->config.intf[intf].devname[0] != '\0') {
usb_osal_thread_schedule_other();
USB_LOG_INFO("Unregister RNDIS Class:%s\r\n", hport->config.intf[intf].devname);
usbh_rndis_stop(rndis_class);
}

View File

@@ -42,6 +42,7 @@ struct usb_osal_timer {
*/
usb_osal_thread_t usb_osal_thread_create(const char *name, uint32_t stack_size, uint32_t prio, usb_thread_entry_t entry, void *args);
void usb_osal_thread_delete(usb_osal_thread_t thread);
void usb_osal_thread_schedule_other(void);
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count);
void usb_osal_sem_delete(usb_osal_sem_t sem);

View File

@@ -25,6 +25,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
vTaskDelete(thread);
}
void usb_osal_thread_schedule_other(void)
{
TaskHandle_t xCurrentTask = xTaskGetCurrentTaskHandle();
const UBaseType_t old_priority = uxTaskPriorityGet(xCurrentTask);
vTaskPrioritySet(xCurrentTask, tskIDLE_PRIORITY);
taskYIELD();
vTaskPrioritySet(xCurrentTask, old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
return (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);

View File

@@ -30,6 +30,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
vTaskDelete(thread);
}
void usb_osal_thread_schedule_other(void)
{
TaskHandle_t xCurrentTask = xTaskGetCurrentTaskHandle();
const UBaseType_t old_priority = uxTaskPriorityGet(xCurrentTask);
vTaskPrioritySet(xCurrentTask, tskIDLE_PRIORITY);
taskYIELD();
vTaskPrioritySet(xCurrentTask, old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
usb_osal_sem_t sem = (usb_osal_sem_t)xSemaphoreCreateCounting(1, initial_count);

View File

@@ -55,6 +55,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
}
}
void usb_osal_thread_schedule_other(void)
{
UINT32 task_id = LOS_CurTaskIDGet();
const UINT16 old_priority = LOS_TaskPriGet(task_id);
LOS_TaskPriSet(task_id, OS_TASK_PRIORITY_LOWEST);
LOS_TaskYield();
LOS_TaskPriSet(task_id, old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
UINT32 sem_handle;

View File

@@ -63,6 +63,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
kthread_delete(pid);
}
void usb_osal_thread_schedule_other(void)
{
struct tcb_s *tcb = nxsched_self();
const int old_priority = tcb->sched_priority;
nxsched_set_priority(tcb, SCHED_PRIORITY_MIN);
sched_yield();
nxsched_set_priority(tcb, old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
int ret;

View File

@@ -34,6 +34,23 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
rt_thread_delete(thread);
}
void usb_osal_thread_schedule_other(void)
{
rt_thread_t self = rt_thread_self();
rt_uint8_t priority;
#if (RTTHREAD_VERSION >= RT_VERSION_CHECK(5, 0, 0))
const rt_uint8_t old_priority = RT_SCHED_PRIV(self).current_priority;
#else
const rt_uint8_t old_priority = self->current_priority;
#endif
priority = RT_THREAD_PRIORITY_MAX - 1;
rt_thread_control(self, RT_THREAD_CTRL_CHANGE_PRIORITY, (void *)&priority);
rt_thread_yield();
rt_thread_control(self, RT_THREAD_CTRL_CHANGE_PRIORITY, (void *)&old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
usb_osal_sem_t sem = (usb_osal_sem_t)rt_sem_create("usbh_sem", initial_count, RT_IPC_FLAG_FIFO);

View File

@@ -69,6 +69,18 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
tx_byte_release(thread);
}
void usb_osal_thread_schedule_other(void)
{
TX_THREAD *current_thread = tx_thread_identify();
const UINT old_priority = current_thread->tx_thread_priority;
tx_thread_priority_change(current_thread, TX_MAX_PRIORITIES - 1, &old_priority);
tx_thread_relinquish();
tx_thread_priority_change(current_thread, old_priority, &old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
TX_SEMAPHORE *sem_ptr = TX_NULL;

View File

@@ -74,6 +74,22 @@ void usb_osal_thread_delete(usb_osal_thread_t thread)
k_free(thread);
}
void usb_osal_thread_schedule_other(void)
{
#if (KERNELVERSION >= 0x3070000)
struct k_thread *current_thread = k_sched_current_thread_query();
#else
struct k_thread *current_thread = z_current_get();
#endif
const int old_priority = k_thread_priority_get(current_thread);
k_thread_priority_set(current_thread, K_LOWEST_APPLICATION_THREAD_PRIO);
k_yield();
k_thread_priority_set(current_thread, old_priority);
}
usb_osal_sem_t usb_osal_sem_create(uint32_t initial_count)
{
struct k_sem *sem;