Просмотр исходного кода

feat(osal): add argument macro for different os, especially for nuttx

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 11 месяцев назад
Родитель
Сommit
6769eac6e0

+ 2 - 2
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:

+ 1 - 1
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
 }

+ 2 - 2
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:

+ 1 - 1
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
 }

+ 2 - 2
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) {

+ 3 - 3
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);

+ 2 - 2
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:

+ 1 - 1
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
 }

+ 2 - 2
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:

+ 1 - 1
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
 }

+ 2 - 2
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) {

+ 1 - 1
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);

+ 3 - 3
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;

+ 3 - 3
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);

+ 2 - 2
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

+ 1 - 1
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
 }

+ 9 - 1
common/usb_osal.h

@@ -10,13 +10,21 @@
 #include <string.h>
 #include <stdbool.h>
 
+#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;

+ 6 - 6
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