From dd3104c4a159e88c6cfd628a47ba767ddb4ffd15 Mon Sep 17 00:00:00 2001 From: songyanguang <345810377@qq.com> Date: Fri, 16 Aug 2024 18:05:19 +0800 Subject: [PATCH] Modify the usb main function. --- .../drivers/usb/components/core/usbh_core.c | 4 ++ .../usb/components/port/xhci/usb_hc_xhci.c | 1 + .../usb/components/port/xhci/usb_hc_xhci.h | 1 + .../drivers/usb/usb_service/usb_host.c | 55 +++++++++++++++++-- 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c index 7e5535504..038a26258 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c @@ -884,6 +884,10 @@ int usbh_control_transfer_xiuos(struct usbh_hubport *hport, usbh_pipe_t pipe, st int ret; urb = usb_malloc(sizeof(struct usbh_urb)); + if (NULL == urb) { + USB_LOG_ERR("No memory to alloc for usbh_urb\r\n"); + return -ENOMEM; + } memset(urb, 0, sizeof(struct usbh_urb)); usbh_control_urb_fill_xiuos(urb, hport, pipe, setup, buffer, setup->wLength, CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT, NULL, NULL); diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.c index 8ccf71ace..c0d7df4da 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.c @@ -869,6 +869,7 @@ int xhci_usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_c struct usb_mem_page ring_page; if (NULL == ppipe) { + USB_LOG_ERR("XHCI %s could not allocate xhci endpoint\n", xhci->name ); return -ENOMEM; } diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.h b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.h index eaef45fea..15a0a2ec1 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.h +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/xhci/usb_hc_xhci.h @@ -54,6 +54,7 @@ extern "C" { * USB3_ADDR_OFFSET_UPPER_BOUND can be found in Part 2, * Table 16-1 USB3 Address Mapping. */ +#define USB3_NUM 2 #define USB3_0_ID 0 #define USB3_1_ID 1 #define USB3_0_BASE_ADDR 0xFCC00000 diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c index 336b0a142..709b2097c 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/usb_host.c @@ -1,9 +1,13 @@ #include "usb_host.h" #include "usb_mem.h" +#include "usb_hc_xhci.h" #include "usyscall.h" #include "libipc.h" #include "rndis_service.h" #include "lwip_rndis_service.h" +#include + +static struct usbh_bus usb[USB3_NUM]; /* IPC rndis server */ int IPC_DO_SERVE_FUNC(Ipc_usbh_rndis_eth_tx)(void *dataptr, size_t *tot_len){ @@ -19,7 +23,7 @@ IPC_SERVER_INTERFACE(Ipc_usbh_rndis_eth_control, 3); IPC_SERVER_REGISTER_INTERFACES(IpcRndisServer, 2, Ipc_usbh_rndis_eth_tx, Ipc_usbh_rndis_eth_control); -int ipc_rndis_server_init(void) +int ipc_rndis_server_init(void *para) { if (register_server("RndisServer") < 0) { printf("register server name: %s failed.\n", "RndisServer"); @@ -38,8 +42,12 @@ int ipc_lwip_client_init(void) struct Session *session; session = usb_malloc(sizeof(struct Session)); + if (NULL == session) { + printf("No memory to alloc for LWIPServer session\r\n"); + return -ENOMEM; + } if(connect_session(session, "LWIPServer", 4096) < 0) { - printf("connect session failed\n"); + printf("connect LWIPServer session failed\n"); return -1; } g_session_lwip = session; @@ -53,10 +61,47 @@ int lwip_rndis_data_recv(void *dataptr, size_t len) return ipc_lwip_rndis_data_recv(session, dataptr, len); } -/* usb main*/ -int main(){ +void ipc_rndis_init(void){ + int tid; + ipc_lwip_client_init(); - ipc_rndis_server_init(); + tid = thread(ipc_rndis_server_init, "ipc_rndis_server", NULL); + if(tid < 0){ + printf("create thread ipc_rndis_server failed.\r\n"); + } +} + +static void usb_init(int id) +{ + if (0 == usbh_initialize(id, &usb[id])){ + printf("Init cherryusb host successfully.\r\n"); + } + else{ + printf("Init cherryusb host failed.\r\n"); + } +} + +/* usb main*/ +int main(int argc, char* argv[]) +{ + int id = USB3_0_ID; + + if (argc >= 2) { + id = atoi(argv[1]); + if (id >= USB3_NUM) { + printf("Invalid usb3 id(%d).\r\n", id); + return -EINVAL; + } + } + printf("usb3 id % init.\n", id); + usb_init(id); + + ipc_rndis_init(); + + while (1){ + usb_osal_msleep(1000); + } + return 0; }