From 6769eac6e0eda91357163d17e4075aac8a512d65 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Mon, 20 Jan 2025 18:23:00 +0800 Subject: [PATCH] feat(osal): add argument macro for different os, especially for nuttx Signed-off-by: sakumisu <1203593632@qq.com> --- class/cdc/usbh_cdc_ecm.c | 4 ++-- class/cdc/usbh_cdc_ecm.h | 2 +- class/cdc/usbh_cdc_ncm.c | 4 ++-- class/cdc/usbh_cdc_ncm.h | 2 +- class/hub/usbh_hub.c | 4 ++-- class/msc/usbd_msc.c | 6 +++--- class/vendor/net/usbh_asix.c | 4 ++-- class/vendor/net/usbh_asix.h | 2 +- class/vendor/net/usbh_rtl8152.c | 4 ++-- class/vendor/net/usbh_rtl8152.h | 2 +- class/vendor/wifi/usbh_bl616.c | 4 ++-- class/vendor/wifi/usbh_bl616.h | 2 +- class/wireless/usbh_bluetooth.c | 6 +++--- class/wireless/usbh_bluetooth.h | 6 +++--- class/wireless/usbh_rndis.c | 4 ++-- class/wireless/usbh_rndis.h | 2 +- common/usb_osal.h | 10 +++++++++- demo/usb_host.c | 12 ++++++------ 18 files changed, 44 insertions(+), 36 deletions(-) diff --git a/class/cdc/usbh_cdc_ecm.c b/class/cdc/usbh_cdc_ecm.c index c4743e56..5ca1ff33 100644 --- a/class/cdc/usbh_cdc_ecm.c +++ b/class/cdc/usbh_cdc_ecm.c @@ -231,12 +231,12 @@ static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf) return ret; } -void usbh_cdc_ecm_rx_thread(void *argument) +void usbh_cdc_ecm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { uint32_t g_cdc_ecm_rx_length; int ret; - (void)argument; + (void)CONFIG_USB_OSAL_THREAD_GET_ARGV; USB_LOG_INFO("Create cdc ecm rx thread\r\n"); // clang-format off find_class: diff --git a/class/cdc/usbh_cdc_ecm.h b/class/cdc/usbh_cdc_ecm.h index 6e8dbc7f..a3ab84a5 100644 --- a/class/cdc/usbh_cdc_ecm.h +++ b/class/cdc/usbh_cdc_ecm.h @@ -41,7 +41,7 @@ void usbh_cdc_ecm_stop(struct usbh_cdc_ecm *cdc_ecm_class); uint8_t *usbh_cdc_ecm_get_eth_txbuf(void); int usbh_cdc_ecm_eth_output(uint32_t buflen); void usbh_cdc_ecm_eth_input(uint8_t *buf, uint32_t buflen); -void usbh_cdc_ecm_rx_thread(void *argument); +void usbh_cdc_ecm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #ifdef __cplusplus } diff --git a/class/cdc/usbh_cdc_ncm.c b/class/cdc/usbh_cdc_ncm.c index f9f3c533..b3347695 100644 --- a/class/cdc/usbh_cdc_ncm.c +++ b/class/cdc/usbh_cdc_ncm.c @@ -249,7 +249,7 @@ static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf) return ret; } -void usbh_cdc_ncm_rx_thread(void *argument) +void usbh_cdc_ncm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { uint32_t g_cdc_ncm_rx_length; int ret; @@ -259,7 +259,7 @@ void usbh_cdc_ncm_rx_thread(void *argument) uint32_t transfer_size = (16 * 1024); #endif - (void)argument; + (void)CONFIG_USB_OSAL_THREAD_GET_ARGV; USB_LOG_INFO("Create cdc ncm rx thread\r\n"); // clang-format off find_class: diff --git a/class/cdc/usbh_cdc_ncm.h b/class/cdc/usbh_cdc_ncm.h index e9b3e8e0..b86122a2 100644 --- a/class/cdc/usbh_cdc_ncm.h +++ b/class/cdc/usbh_cdc_ncm.h @@ -45,7 +45,7 @@ void usbh_cdc_ncm_stop(struct usbh_cdc_ncm *cdc_ncm_class); uint8_t *usbh_cdc_ncm_get_eth_txbuf(void); int usbh_cdc_ncm_eth_output(uint32_t buflen); void usbh_cdc_ncm_eth_input(uint8_t *buf, uint32_t buflen); -void usbh_cdc_ncm_rx_thread(void *argument); +void usbh_cdc_ncm_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #ifdef __cplusplus } diff --git a/class/hub/usbh_hub.c b/class/hub/usbh_hub.c index 9dae3966..54377a74 100644 --- a/class/hub/usbh_hub.c +++ b/class/hub/usbh_hub.c @@ -648,12 +648,12 @@ static void usbh_hub_events(struct usbh_hub *hub) } } -static void usbh_hub_thread(void *argument) +static void usbh_hub_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { struct usbh_hub *hub; int ret = 0; - struct usbh_bus *bus = (struct usbh_bus *)argument; + struct usbh_bus *bus = (struct usbh_bus *)CONFIG_USB_OSAL_THREAD_GET_ARGV; usb_hc_init(bus); while (1) { diff --git a/class/msc/usbd_msc.c b/class/msc/usbd_msc.c index 1f84d02c..993617ab 100644 --- a/class/msc/usbd_msc.c +++ b/class/msc/usbd_msc.c @@ -60,7 +60,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv { } g_usbd_msc[CONFIG_USBDEV_MAX_BUS]; #ifdef CONFIG_USBDEV_MSC_THREAD -static void usbdev_msc_thread(void *argument); +static void usbdev_msc_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #endif static void usdb_msc_set_max_lun(uint8_t busid) @@ -911,11 +911,11 @@ void mass_storage_bulk_in(uint8_t busid, uint8_t ep, uint32_t nbytes) } #if defined(CONFIG_USBDEV_MSC_THREAD) -static void usbdev_msc_thread(void *argument) +static void usbdev_msc_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { uintptr_t event; int ret; - uint8_t busid = (uint8_t)(uint32_t)argument; + uint8_t busid = (uint8_t)CONFIG_USB_OSAL_THREAD_GET_ARGV; while (1) { ret = usb_osal_mq_recv(g_usbd_msc[busid].usbd_msc_mq, (uintptr_t *)&event, USB_OSAL_WAITING_FOREVER); diff --git a/class/vendor/net/usbh_asix.c b/class/vendor/net/usbh_asix.c index 66c1f078..f4976718 100644 --- a/class/vendor/net/usbh_asix.c +++ b/class/vendor/net/usbh_asix.c @@ -670,7 +670,7 @@ int usbh_asix_get_connect_status(struct usbh_asix *asix_class) return 0; } -void usbh_asix_rx_thread(void *argument) +void usbh_asix_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { uint32_t g_asix_rx_length; int ret; @@ -683,7 +683,7 @@ void usbh_asix_rx_thread(void *argument) uint32_t transfer_size = (16 * 1024); #endif - (void)argument; + (void)CONFIG_USB_OSAL_THREAD_GET_ARGV; USB_LOG_INFO("Create asix rx thread\r\n"); // clang-format off find_class: diff --git a/class/vendor/net/usbh_asix.h b/class/vendor/net/usbh_asix.h index 8b0b5d98..bdeb0e31 100644 --- a/class/vendor/net/usbh_asix.h +++ b/class/vendor/net/usbh_asix.h @@ -168,7 +168,7 @@ void usbh_asix_stop(struct usbh_asix *asix_class); uint8_t *usbh_asix_get_eth_txbuf(void); int usbh_asix_eth_output(uint32_t buflen); void usbh_asix_eth_input(uint8_t *buf, uint32_t buflen); -void usbh_asix_rx_thread(void *argument); +void usbh_asix_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #ifdef __cplusplus } diff --git a/class/vendor/net/usbh_rtl8152.c b/class/vendor/net/usbh_rtl8152.c index 10fc0483..4913389a 100644 --- a/class/vendor/net/usbh_rtl8152.c +++ b/class/vendor/net/usbh_rtl8152.c @@ -2130,7 +2130,7 @@ static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf) return ret; } -void usbh_rtl8152_rx_thread(void *argument) +void usbh_rtl8152_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { uint32_t g_rtl8152_rx_length; int ret; @@ -2142,7 +2142,7 @@ void usbh_rtl8152_rx_thread(void *argument) uint32_t transfer_size = (16 * 1024); #endif - (void)argument; + (void)CONFIG_USB_OSAL_THREAD_GET_ARGV; USB_LOG_INFO("Create rtl8152 rx thread\r\n"); // clang-format off find_class: diff --git a/class/vendor/net/usbh_rtl8152.h b/class/vendor/net/usbh_rtl8152.h index 9d593b91..171fa0bf 100644 --- a/class/vendor/net/usbh_rtl8152.h +++ b/class/vendor/net/usbh_rtl8152.h @@ -59,7 +59,7 @@ void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class); uint8_t *usbh_rtl8152_get_eth_txbuf(void); int usbh_rtl8152_eth_output(uint32_t buflen); void usbh_rtl8152_eth_input(uint8_t *buf, uint32_t buflen); -void usbh_rtl8152_rx_thread(void *argument); +void usbh_rtl8152_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #ifdef __cplusplus } diff --git a/class/vendor/wifi/usbh_bl616.c b/class/vendor/wifi/usbh_bl616.c index 9275faac..059086be 100644 --- a/class/vendor/wifi/usbh_bl616.c +++ b/class/vendor/wifi/usbh_bl616.c @@ -347,7 +347,7 @@ static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf) return ret; } -void usbh_bl616_rx_thread(void *argument) +void usbh_bl616_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; usb_data_t *usb_hdr; @@ -356,7 +356,7 @@ void usbh_bl616_rx_thread(void *argument) rnm_scan_ind_msg_t *scanmsg; uint8_t *data; - (void)argument; + (void)CONFIG_USB_OSAL_THREAD_GET_ARGV; USB_LOG_INFO("Create bl616 wifi rx thread\r\n"); while (1) { diff --git a/class/vendor/wifi/usbh_bl616.h b/class/vendor/wifi/usbh_bl616.h index 6ec5a7a8..2d247ae2 100644 --- a/class/vendor/wifi/usbh_bl616.h +++ b/class/vendor/wifi/usbh_bl616.h @@ -205,7 +205,7 @@ void usbh_bl616_sta_update_ip(uint8_t ip4_addr[4], uint8_t ip4_mask[4], uint8_t uint8_t *usbh_bl616_get_eth_txbuf(void); int usbh_bl616_eth_output(uint32_t buflen); void usbh_bl616_eth_input(uint8_t *buf, uint32_t buflen); -void usbh_bl616_rx_thread(void *argument); +void usbh_bl616_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); void usbh_bl616_run(struct usbh_bl616 *bl616_class); void usbh_bl616_stop(struct usbh_bl616 *bl616_class); diff --git a/class/wireless/usbh_bluetooth.c b/class/wireless/usbh_bluetooth.c index 991f0957..e507c7e6 100644 --- a/class/wireless/usbh_bluetooth.c +++ b/class/wireless/usbh_bluetooth.c @@ -189,7 +189,7 @@ int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen) return ret; } -void usbh_bluetooth_hci_rx_thread(void *argument) +void usbh_bluetooth_hci_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; uint32_t ep_mps; @@ -271,7 +271,7 @@ int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen) return ret; } -void usbh_bluetooth_hci_evt_rx_thread(void *argument) +void usbh_bluetooth_hci_evt_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; uint32_t ep_mps; @@ -320,7 +320,7 @@ delete : // clang-format on } -void usbh_bluetooth_hci_acl_rx_thread(void *argument) +void usbh_bluetooth_hci_acl_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; uint32_t ep_mps; diff --git a/class/wireless/usbh_bluetooth.h b/class/wireless/usbh_bluetooth.h index 868ff2c2..87eb02ac 100644 --- a/class/wireless/usbh_bluetooth.h +++ b/class/wireless/usbh_bluetooth.h @@ -40,10 +40,10 @@ extern "C" { int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen); void usbh_bluetooth_hci_read_callback(uint8_t *data, uint32_t len); #ifdef CONFIG_USBHOST_BLUETOOTH_HCI_H4 -void usbh_bluetooth_hci_rx_thread(void *argument); +void usbh_bluetooth_hci_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #else -void usbh_bluetooth_hci_evt_rx_thread(void *argument); -void usbh_bluetooth_hci_acl_rx_thread(void *argument); +void usbh_bluetooth_hci_evt_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); +void usbh_bluetooth_hci_acl_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #endif void usbh_bluetooth_run(struct usbh_bluetooth *bluetooth_class); diff --git a/class/wireless/usbh_rndis.c b/class/wireless/usbh_rndis.c index e9eaff01..2c250d9f 100644 --- a/class/wireless/usbh_rndis.c +++ b/class/wireless/usbh_rndis.c @@ -448,7 +448,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf) return ret; } -void usbh_rndis_rx_thread(void *argument) +void usbh_rndis_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { uint32_t g_rndis_rx_length; int ret; @@ -461,7 +461,7 @@ void usbh_rndis_rx_thread(void *argument) uint32_t transfer_size = (16 * 1024); #endif - (void)argument; + (void)CONFIG_USB_OSAL_THREAD_GET_ARGV; USB_LOG_INFO("Create rndis rx thread\r\n"); // clang-format off diff --git a/class/wireless/usbh_rndis.h b/class/wireless/usbh_rndis.h index 17a40006..505a07ae 100644 --- a/class/wireless/usbh_rndis.h +++ b/class/wireless/usbh_rndis.h @@ -46,7 +46,7 @@ void usbh_rndis_stop(struct usbh_rndis *rndis_class); uint8_t *usbh_rndis_get_eth_txbuf(void); int usbh_rndis_eth_output(uint32_t buflen); void usbh_rndis_eth_input(uint8_t *buf, uint32_t buflen); -void usbh_rndis_rx_thread(void *argument); +void usbh_rndis_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV); #ifdef __cplusplus } diff --git a/common/usb_osal.h b/common/usb_osal.h index a3380d13..aa2f1336 100644 --- a/common/usb_osal.h +++ b/common/usb_osal.h @@ -10,13 +10,21 @@ #include #include +#ifdef __INCLUDE_NUTTX_CONFIG_H +#define CONFIG_USB_OSAL_THREAD_SET_ARGV int argc, char **argv +#define CONFIG_USB_OSAL_THREAD_GET_ARGV ((uintptr_t)strtoul(argv[1], NULL, 16)) +#else +#define CONFIG_USB_OSAL_THREAD_SET_ARGV void *argument +#define CONFIG_USB_OSAL_THREAD_GET_ARGV ((uintptr_t)argument) +#endif + #define USB_OSAL_WAITING_FOREVER (0xFFFFFFFFU) typedef void *usb_osal_thread_t; typedef void *usb_osal_sem_t; typedef void *usb_osal_mutex_t; typedef void *usb_osal_mq_t; -typedef void (*usb_thread_entry_t)(void *argument); +typedef void (*usb_thread_entry_t)(CONFIG_USB_OSAL_THREAD_SET_ARGV); typedef void (*usb_timer_handler_t)(void *argument); struct usb_osal_timer { usb_timer_handler_t handler; diff --git a/demo/usb_host.c b/demo/usb_host.c index 817103d5..400d9889 100644 --- a/demo/usb_host.c +++ b/demo/usb_host.c @@ -58,10 +58,10 @@ void usbh_cdc_acm_callback(void *arg, int nbytes) } } -static void usbh_cdc_acm_thread(void *argument) +static void usbh_cdc_acm_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; - struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)argument; + struct usbh_cdc_acm *cdc_acm_class = (struct usbh_cdc_acm *)CONFIG_USB_OSAL_THREAD_GET_ARGV; /* test with only one buffer, if you have more cdc acm class, modify by yourself */ #if TEST_USBH_CDC_SPEED @@ -133,10 +133,10 @@ void usbh_hid_callback(void *arg, int nbytes) } } -static void usbh_hid_thread(void *argument) +static void usbh_hid_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; - struct usbh_hid *hid_class = (struct usbh_hid *)argument; + struct usbh_hid *hid_class = (struct usbh_hid *)CONFIG_USB_OSAL_THREAD_GET_ARGV; ; /* test with only one buffer, if you have more hid class, modify by yourself */ @@ -222,10 +222,10 @@ unmount: USB_NOCACHE_RAM_SECTION USB_MEM_ALIGNX uint8_t partition_table[512]; -static void usbh_msc_thread(void *argument) +static void usbh_msc_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV) { int ret; - struct usbh_msc *msc_class = (struct usbh_msc *)argument; + struct usbh_msc *msc_class = (struct usbh_msc *)CONFIG_USB_OSAL_THREAD_GET_ARGV; /* test with only one buffer, if you have more msc class, modify by yourself */ #if 1