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

Signed-off-by: sakumisu <1203593632@qq.com>
This commit is contained in:
sakumisu
2025-01-20 18:23:00 +08:00
parent 646e84bedc
commit 6769eac6e0
18 changed files with 44 additions and 36 deletions

View File

@@ -231,12 +231,12 @@ static int usbh_cdc_ecm_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret; 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; uint32_t g_cdc_ecm_rx_length;
int ret; int ret;
(void)argument; (void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create cdc ecm rx thread\r\n"); USB_LOG_INFO("Create cdc ecm rx thread\r\n");
// clang-format off // clang-format off
find_class: find_class:

View File

@@ -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); uint8_t *usbh_cdc_ecm_get_eth_txbuf(void);
int usbh_cdc_ecm_eth_output(uint32_t buflen); 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_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 #ifdef __cplusplus
} }

View File

@@ -249,7 +249,7 @@ static int usbh_cdc_ncm_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret; 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; uint32_t g_cdc_ncm_rx_length;
int ret; int ret;
@@ -259,7 +259,7 @@ void usbh_cdc_ncm_rx_thread(void *argument)
uint32_t transfer_size = (16 * 1024); uint32_t transfer_size = (16 * 1024);
#endif #endif
(void)argument; (void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create cdc ncm rx thread\r\n"); USB_LOG_INFO("Create cdc ncm rx thread\r\n");
// clang-format off // clang-format off
find_class: find_class:

View File

@@ -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); uint8_t *usbh_cdc_ncm_get_eth_txbuf(void);
int usbh_cdc_ncm_eth_output(uint32_t buflen); 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_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 #ifdef __cplusplus
} }

View File

@@ -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; struct usbh_hub *hub;
int ret = 0; 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); usb_hc_init(bus);
while (1) { while (1) {

View File

@@ -60,7 +60,7 @@ USB_NOCACHE_RAM_SECTION struct usbd_msc_priv {
} g_usbd_msc[CONFIG_USBDEV_MAX_BUS]; } g_usbd_msc[CONFIG_USBDEV_MAX_BUS];
#ifdef CONFIG_USBDEV_MSC_THREAD #ifdef CONFIG_USBDEV_MSC_THREAD
static void usbdev_msc_thread(void *argument); static void usbdev_msc_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
#endif #endif
static void usdb_msc_set_max_lun(uint8_t busid) 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) #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; uintptr_t event;
int ret; int ret;
uint8_t busid = (uint8_t)(uint32_t)argument; uint8_t busid = (uint8_t)CONFIG_USB_OSAL_THREAD_GET_ARGV;
while (1) { while (1) {
ret = usb_osal_mq_recv(g_usbd_msc[busid].usbd_msc_mq, (uintptr_t *)&event, USB_OSAL_WAITING_FOREVER); ret = usb_osal_mq_recv(g_usbd_msc[busid].usbd_msc_mq, (uintptr_t *)&event, USB_OSAL_WAITING_FOREVER);

View File

@@ -670,7 +670,7 @@ int usbh_asix_get_connect_status(struct usbh_asix *asix_class)
return 0; 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; uint32_t g_asix_rx_length;
int ret; int ret;
@@ -683,7 +683,7 @@ void usbh_asix_rx_thread(void *argument)
uint32_t transfer_size = (16 * 1024); uint32_t transfer_size = (16 * 1024);
#endif #endif
(void)argument; (void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create asix rx thread\r\n"); USB_LOG_INFO("Create asix rx thread\r\n");
// clang-format off // clang-format off
find_class: find_class:

View File

@@ -168,7 +168,7 @@ void usbh_asix_stop(struct usbh_asix *asix_class);
uint8_t *usbh_asix_get_eth_txbuf(void); uint8_t *usbh_asix_get_eth_txbuf(void);
int usbh_asix_eth_output(uint32_t buflen); int usbh_asix_eth_output(uint32_t buflen);
void usbh_asix_eth_input(uint8_t *buf, 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 #ifdef __cplusplus
} }

View File

@@ -2130,7 +2130,7 @@ static int usbh_rtl8152_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret; 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; uint32_t g_rtl8152_rx_length;
int ret; int ret;
@@ -2142,7 +2142,7 @@ void usbh_rtl8152_rx_thread(void *argument)
uint32_t transfer_size = (16 * 1024); uint32_t transfer_size = (16 * 1024);
#endif #endif
(void)argument; (void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create rtl8152 rx thread\r\n"); USB_LOG_INFO("Create rtl8152 rx thread\r\n");
// clang-format off // clang-format off
find_class: find_class:

View File

@@ -59,7 +59,7 @@ void usbh_rtl8152_stop(struct usbh_rtl8152 *rtl8152_class);
uint8_t *usbh_rtl8152_get_eth_txbuf(void); uint8_t *usbh_rtl8152_get_eth_txbuf(void);
int usbh_rtl8152_eth_output(uint32_t buflen); int usbh_rtl8152_eth_output(uint32_t buflen);
void usbh_rtl8152_eth_input(uint8_t *buf, 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 #ifdef __cplusplus
} }

View File

@@ -347,7 +347,7 @@ static int usbh_bl616_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret; return ret;
} }
void usbh_bl616_rx_thread(void *argument) void usbh_bl616_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
{ {
int ret; int ret;
usb_data_t *usb_hdr; usb_data_t *usb_hdr;
@@ -356,7 +356,7 @@ void usbh_bl616_rx_thread(void *argument)
rnm_scan_ind_msg_t *scanmsg; rnm_scan_ind_msg_t *scanmsg;
uint8_t *data; uint8_t *data;
(void)argument; (void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create bl616 wifi rx thread\r\n"); USB_LOG_INFO("Create bl616 wifi rx thread\r\n");
while (1) { while (1) {

View File

@@ -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); uint8_t *usbh_bl616_get_eth_txbuf(void);
int usbh_bl616_eth_output(uint32_t buflen); int usbh_bl616_eth_output(uint32_t buflen);
void usbh_bl616_eth_input(uint8_t *buf, 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_run(struct usbh_bl616 *bl616_class);
void usbh_bl616_stop(struct usbh_bl616 *bl616_class); void usbh_bl616_stop(struct usbh_bl616 *bl616_class);

View File

@@ -189,7 +189,7 @@ int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen)
return ret; return ret;
} }
void usbh_bluetooth_hci_rx_thread(void *argument) void usbh_bluetooth_hci_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV)
{ {
int ret; int ret;
uint32_t ep_mps; 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; 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; int ret;
uint32_t ep_mps; uint32_t ep_mps;
@@ -320,7 +320,7 @@ delete :
// clang-format on // 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; int ret;
uint32_t ep_mps; uint32_t ep_mps;

View File

@@ -40,10 +40,10 @@ extern "C" {
int usbh_bluetooth_hci_write(uint8_t hci_type, uint8_t *buffer, uint32_t buflen); 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); void usbh_bluetooth_hci_read_callback(uint8_t *data, uint32_t len);
#ifdef CONFIG_USBHOST_BLUETOOTH_HCI_H4 #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 #else
void usbh_bluetooth_hci_evt_rx_thread(void *argument); void usbh_bluetooth_hci_evt_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
void usbh_bluetooth_hci_acl_rx_thread(void *argument); void usbh_bluetooth_hci_acl_rx_thread(CONFIG_USB_OSAL_THREAD_SET_ARGV);
#endif #endif
void usbh_bluetooth_run(struct usbh_bluetooth *bluetooth_class); void usbh_bluetooth_run(struct usbh_bluetooth *bluetooth_class);

View File

@@ -448,7 +448,7 @@ static int usbh_rndis_disconnect(struct usbh_hubport *hport, uint8_t intf)
return ret; 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; uint32_t g_rndis_rx_length;
int ret; int ret;
@@ -461,7 +461,7 @@ void usbh_rndis_rx_thread(void *argument)
uint32_t transfer_size = (16 * 1024); uint32_t transfer_size = (16 * 1024);
#endif #endif
(void)argument; (void)CONFIG_USB_OSAL_THREAD_GET_ARGV;
USB_LOG_INFO("Create rndis rx thread\r\n"); USB_LOG_INFO("Create rndis rx thread\r\n");
// clang-format off // clang-format off

View File

@@ -46,7 +46,7 @@ void usbh_rndis_stop(struct usbh_rndis *rndis_class);
uint8_t *usbh_rndis_get_eth_txbuf(void); uint8_t *usbh_rndis_get_eth_txbuf(void);
int usbh_rndis_eth_output(uint32_t buflen); int usbh_rndis_eth_output(uint32_t buflen);
void usbh_rndis_eth_input(uint8_t *buf, 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 #ifdef __cplusplus
} }

View File

@@ -10,13 +10,21 @@
#include <string.h> #include <string.h>
#include <stdbool.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) #define USB_OSAL_WAITING_FOREVER (0xFFFFFFFFU)
typedef void *usb_osal_thread_t; typedef void *usb_osal_thread_t;
typedef void *usb_osal_sem_t; typedef void *usb_osal_sem_t;
typedef void *usb_osal_mutex_t; typedef void *usb_osal_mutex_t;
typedef void *usb_osal_mq_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); typedef void (*usb_timer_handler_t)(void *argument);
struct usb_osal_timer { struct usb_osal_timer {
usb_timer_handler_t handler; usb_timer_handler_t handler;

View File

@@ -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; 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 */ /* test with only one buffer, if you have more cdc acm class, modify by yourself */
#if TEST_USBH_CDC_SPEED #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; 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 */ /* 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]; 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; 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 */ /* test with only one buffer, if you have more msc class, modify by yourself */
#if 1 #if 1