Skip to content

Commit

Permalink
feat(osal): add argument macro for different os, especially for nuttx
Browse files Browse the repository at this point in the history
  • Loading branch information
sakumisu committed Jan 20, 2025
1 parent 646e84b commit 0200f0f
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions class/cdc/usbh_cdc_ecm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion class/cdc/usbh_cdc_ecm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions class/cdc/usbh_cdc_ncm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion class/cdc/usbh_cdc_ncm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions class/hub/usbh_hub.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions class/msc/usbd_msc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions class/vendor/net/usbh_asix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion class/vendor/net/usbh_asix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions class/vendor/net/usbh_rtl8152.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion class/vendor/net/usbh_rtl8152.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions class/vendor/wifi/usbh_bl616.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion class/vendor/wifi/usbh_bl616.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions class/wireless/usbh_bluetooth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions class/wireless/usbh_bluetooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions class/wireless/usbh_rndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion class/wireless/usbh_rndis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 9 additions & 1 deletion common/usb_osal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions demo/usb_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -222,10 +222,10 @@ int usb_msc_fatfs_test()

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
Expand Down

0 comments on commit 0200f0f

Please sign in to comment.