From a31e56f13eba2a3761b994189a4fd7f892d2ba42 Mon Sep 17 00:00:00 2001 From: sakumisu <1203593632@qq.com> Date: Tue, 14 Jun 2022 22:08:04 +0800 Subject: [PATCH] rename struct name --- port/fsdev/usb_dc_fsdev.c | 68 +++++++-------- port/musb/usb_dc_musb.c | 68 +++++++-------- port/musb/usb_hc_musb.c | 174 ++++++++++++++++++++------------------ port/template/usb_dc.c | 18 ++-- port/template/usb_hc.c | 13 ++- 5 files changed, 176 insertions(+), 165 deletions(-) diff --git a/port/fsdev/usb_dc_fsdev.c b/port/fsdev/usb_dc_fsdev.c index f853bd3c..ed85228b 100644 --- a/port/fsdev/usb_dc_fsdev.c +++ b/port/fsdev/usb_dc_fsdev.c @@ -25,7 +25,7 @@ static void USB_WritePMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufA static void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes); /* Endpoint state */ -struct usb_dc_ep_state { +struct fsdev_ep_state { /** Endpoint max packet size */ uint16_t ep_mps; /** Endpoint Transfer Type. @@ -38,12 +38,12 @@ struct usb_dc_ep_state { }; /* Driver state */ -struct usb_dc_config_priv { +struct fsdev_udc { volatile uint8_t dev_addr; /*!< USB Address */ volatile uint32_t pma_offset; /*!< pma offset */ - struct usb_dc_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ - struct usb_dc_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */ -} usb_dc_cfg; + struct fsdev_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ + struct fsdev_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */ +} g_fsdev_udc; __WEAK void usb_dc_low_level_init(void) { @@ -55,9 +55,9 @@ __WEAK void usb_dc_low_level_deinit(void) int usb_dc_init(void) { - memset(&usb_dc_cfg, 0, sizeof(struct usb_dc_config_priv)); + memset(&g_fsdev_udc, 0, sizeof(struct fsdev_udc)); - usb_dc_cfg.pma_offset = USB_BTABLE_SIZE; + g_fsdev_udc.pma_offset = USB_BTABLE_SIZE; usb_dc_low_level_init(); @@ -110,7 +110,7 @@ int usbd_set_address(const uint8_t addr) USB->DADDR = (uint16_t)USB_DADDR_EF; } - usb_dc_cfg.dev_addr = addr; + g_fsdev_udc.dev_addr = addr; return 0; } @@ -150,17 +150,17 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) PCD_SET_EP_ADDRESS(USB, ep_idx, ep_idx); if (USB_EP_DIR_IS_OUT(ep_cfg->ep_addr)) { - usb_dc_cfg.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; - usb_dc_cfg.out_ep[ep_idx].ep_type = ep_cfg->ep_type; - if (usb_dc_cfg.out_ep[ep_idx].ep_mps > usb_dc_cfg.out_ep[ep_idx].ep_pma_buf_len) { - if (usb_dc_cfg.pma_offset + usb_dc_cfg.out_ep[ep_idx].ep_mps >= USB_RAM_SIZE) { + g_fsdev_udc.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; + g_fsdev_udc.out_ep[ep_idx].ep_type = ep_cfg->ep_type; + if (g_fsdev_udc.out_ep[ep_idx].ep_mps > g_fsdev_udc.out_ep[ep_idx].ep_pma_buf_len) { + if (g_fsdev_udc.pma_offset + g_fsdev_udc.out_ep[ep_idx].ep_mps >= USB_RAM_SIZE) { return -1; } - usb_dc_cfg.out_ep[ep_idx].ep_pma_buf_len = ep_cfg->ep_mps; - usb_dc_cfg.out_ep[ep_idx].ep_pma_addr = usb_dc_cfg.pma_offset; + g_fsdev_udc.out_ep[ep_idx].ep_pma_buf_len = ep_cfg->ep_mps; + g_fsdev_udc.out_ep[ep_idx].ep_pma_addr = g_fsdev_udc.pma_offset; /*Set the endpoint Receive buffer address */ - PCD_SET_EP_RX_ADDRESS(USB, ep_idx, usb_dc_cfg.pma_offset); - usb_dc_cfg.pma_offset += ep_cfg->ep_mps; + PCD_SET_EP_RX_ADDRESS(USB, ep_idx, g_fsdev_udc.pma_offset); + g_fsdev_udc.pma_offset += ep_cfg->ep_mps; } /*Set the endpoint Receive buffer counter*/ PCD_SET_EP_RX_CNT(USB, ep_idx, ep_cfg->ep_mps); @@ -169,17 +169,17 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) /* Configure VALID status for the Endpoint*/ PCD_SET_EP_RX_STATUS(USB, ep_idx, USB_EP_RX_VALID); } else { - usb_dc_cfg.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; - usb_dc_cfg.in_ep[ep_idx].ep_type = ep_cfg->ep_type; - if (usb_dc_cfg.in_ep[ep_idx].ep_mps > usb_dc_cfg.in_ep[ep_idx].ep_pma_buf_len) { - if (usb_dc_cfg.pma_offset + usb_dc_cfg.in_ep[ep_idx].ep_mps >= USB_RAM_SIZE) { + g_fsdev_udc.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; + g_fsdev_udc.in_ep[ep_idx].ep_type = ep_cfg->ep_type; + if (g_fsdev_udc.in_ep[ep_idx].ep_mps > g_fsdev_udc.in_ep[ep_idx].ep_pma_buf_len) { + if (g_fsdev_udc.pma_offset + g_fsdev_udc.in_ep[ep_idx].ep_mps >= USB_RAM_SIZE) { return -1; } - usb_dc_cfg.in_ep[ep_idx].ep_pma_buf_len = ep_cfg->ep_mps; - usb_dc_cfg.in_ep[ep_idx].ep_pma_addr = usb_dc_cfg.pma_offset; + g_fsdev_udc.in_ep[ep_idx].ep_pma_buf_len = ep_cfg->ep_mps; + g_fsdev_udc.in_ep[ep_idx].ep_pma_addr = g_fsdev_udc.pma_offset; /*Set the endpoint Transmit buffer address */ - PCD_SET_EP_TX_ADDRESS(USB, ep_idx, usb_dc_cfg.pma_offset); - usb_dc_cfg.pma_offset += ep_cfg->ep_mps; + PCD_SET_EP_TX_ADDRESS(USB, ep_idx, g_fsdev_udc.pma_offset); + g_fsdev_udc.pma_offset += ep_cfg->ep_mps; } PCD_CLEAR_TX_DTOG(USB, ep_idx); @@ -235,7 +235,7 @@ int usbd_ep_clear_stall(const uint8_t ep) } else { PCD_CLEAR_TX_DTOG(USB, ep_idx); - if (usb_dc_cfg.in_ep[ep_idx].ep_type != USB_ENDPOINT_TYPE_ISOCHRONOUS) { + if (g_fsdev_udc.in_ep[ep_idx].ep_type != USB_ENDPOINT_TYPE_ISOCHRONOUS) { /* Configure NAK status for the Endpoint */ PCD_SET_EP_TX_STATUS(USB, ep_idx, USB_EP_TX_NAK); } @@ -268,11 +268,11 @@ int usbd_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint return 0; } - if (data_len > usb_dc_cfg.in_ep[ep_idx].ep_mps) { - data_len = usb_dc_cfg.in_ep[ep_idx].ep_mps; + if (data_len > g_fsdev_udc.in_ep[ep_idx].ep_mps) { + data_len = g_fsdev_udc.in_ep[ep_idx].ep_mps; } - USB_WritePMA(USB, (uint8_t *)data, usb_dc_cfg.in_ep[ep_idx].ep_pma_addr, (uint16_t)data_len); + USB_WritePMA(USB, (uint8_t *)data, g_fsdev_udc.in_ep[ep_idx].ep_pma_addr, (uint16_t)data_len); PCD_SET_EP_TX_CNT(USB, ep_idx, (uint16_t)data_len); PCD_SET_EP_TX_STATUS(USB, ep_idx, USB_EP_TX_VALID); @@ -301,7 +301,7 @@ int usbd_ep_read(const uint8_t ep, uint8_t *data, uint32_t max_data_len, uint32_ read_count = PCD_GET_EP_RX_CNT(USB, ep_idx); read_count = MIN(read_count, max_data_len); - USB_ReadPMA(USB, (uint8_t *)data, usb_dc_cfg.out_ep[ep_idx].ep_pma_addr, (uint16_t)read_count); + USB_ReadPMA(USB, (uint8_t *)data, g_fsdev_udc.out_ep[ep_idx].ep_pma_addr, (uint16_t)read_count); if (read_bytes) { *read_bytes = read_count; @@ -335,9 +335,9 @@ void USBD_IRQHandler(void) /* DIR = 0 implies that (EP_CTR_TX = 1) always */ PCD_CLEAR_TX_EP_CTR(USB, 0); usbd_event_notify_handler(USBD_EVENT_EP0_IN_NOTIFY, NULL); - if ((usb_dc_cfg.dev_addr > 0U) && (PCD_GET_EP_TX_CNT(USB, 0) == 0U)) { - USB->DADDR = ((uint16_t)usb_dc_cfg.dev_addr | USB_DADDR_EF); - usb_dc_cfg.dev_addr = 0U; + if ((g_fsdev_udc.dev_addr > 0U) && (PCD_GET_EP_TX_CNT(USB, 0) == 0U)) { + USB->DADDR = ((uint16_t)g_fsdev_udc.dev_addr | USB_DADDR_EF); + g_fsdev_udc.dev_addr = 0U; } } else { /* DIR = 1 */ @@ -381,8 +381,8 @@ void USBD_IRQHandler(void) } } if (wIstr & USB_ISTR_RESET) { - memset(&usb_dc_cfg, 0, sizeof(struct usb_dc_config_priv)); - usb_dc_cfg.pma_offset = USB_BTABLE_SIZE; + memset(&g_fsdev_udc, 0, sizeof(struct fsdev_udc)); + g_fsdev_udc.pma_offset = USB_BTABLE_SIZE; usbd_event_notify_handler(USBD_EVENT_RESET, NULL); USB->ISTR &= (uint16_t)(~USB_ISTR_RESET); } diff --git a/port/musb/usb_dc_musb.c b/port/musb/usb_dc_musb.c index 846eb2f4..4f5faca6 100644 --- a/port/musb/usb_dc_musb.c +++ b/port/musb/usb_dc_musb.c @@ -103,7 +103,7 @@ typedef enum { } ep0_state_t; /* Endpoint state */ -struct usb_dc_ep_state { +struct musb_ep_state { /** Endpoint max packet size */ uint16_t ep_mps; /** Endpoint Transfer Type. @@ -114,13 +114,13 @@ struct usb_dc_ep_state { }; /* Driver state */ -struct usb_dc_config_priv { +struct musb_udc { volatile uint8_t dev_addr; volatile uint32_t fifo_size_offset; struct usb_setup_packet setup; - struct usb_dc_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ - struct usb_dc_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */ -} usb_dc_cfg; + struct musb_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ + struct musb_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */ +} g_musb_udc; static volatile uint8_t usb_ep0_state = USB_EP0_STATE_SETUP; volatile uint16_t ep0_last_size = 0; @@ -225,13 +225,13 @@ __WEAK void usb_dc_low_level_deinit(void) int usb_dc_init(void) { - memset(&usb_dc_cfg, 0, sizeof(struct usb_dc_config_priv)); + memset(&g_musb_udc, 0, sizeof(struct musb_udc)); - usb_dc_cfg.out_ep[0].ep_mps = USB_CTRL_EP_MPS; - usb_dc_cfg.out_ep[0].ep_type = 0x00; - usb_dc_cfg.in_ep[0].ep_mps = USB_CTRL_EP_MPS; - usb_dc_cfg.in_ep[0].ep_type = 0x00; - usb_dc_cfg.fifo_size_offset = USB_CTRL_EP_MPS; + g_musb_udc.out_ep[0].ep_mps = USB_CTRL_EP_MPS; + g_musb_udc.out_ep[0].ep_type = 0x00; + g_musb_udc.in_ep[0].ep_mps = USB_CTRL_EP_MPS; + g_musb_udc.in_ep[0].ep_type = 0x00; + g_musb_udc.fifo_size_offset = USB_CTRL_EP_MPS; usb_dc_low_level_init(); @@ -266,7 +266,7 @@ int usbd_set_address(const uint8_t addr) HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = 0; } - usb_dc_cfg.dev_addr = addr; + g_musb_udc.dev_addr = addr; return 0; } @@ -287,8 +287,8 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) USBC_SelectActiveEp(ep_idx); if (USB_EP_DIR_IS_OUT(ep_cfg->ep_addr)) { - usb_dc_cfg.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; - usb_dc_cfg.out_ep[ep_idx].ep_type = ep_cfg->ep_type; + g_musb_udc.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; + g_musb_udc.out_ep[ep_idx].ep_type = ep_cfg->ep_type; HWREGH(USB_BASE + MUSB_RXIE_OFFSET) |= (1 << ep_idx); @@ -335,12 +335,12 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) fifo_size = usb_musb_get_fifo_size(ep_cfg->ep_mps, &used); HWREGB(USB_BASE + MUSB_RXFIFOSZ_OFFSET) = fifo_size & 0x0f; - HWREGH(USB_BASE + MUSB_RXFIFOADD_OFFSET) = (usb_dc_cfg.fifo_size_offset >> 3); + HWREGH(USB_BASE + MUSB_RXFIFOADD_OFFSET) = (g_musb_udc.fifo_size_offset >> 3); - usb_dc_cfg.fifo_size_offset += used; + g_musb_udc.fifo_size_offset += used; } else { - usb_dc_cfg.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; - usb_dc_cfg.in_ep[ep_idx].ep_type = ep_cfg->ep_type; + g_musb_udc.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; + g_musb_udc.in_ep[ep_idx].ep_type = ep_cfg->ep_type; HWREGH(USB_BASE + MUSB_TXIE_OFFSET) |= (1 << ep_idx); @@ -381,9 +381,9 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) fifo_size = usb_musb_get_fifo_size(ep_cfg->ep_mps, &used); HWREGB(USB_BASE + MUSB_TXFIFOSZ_OFFSET) = fifo_size & 0x0f; - HWREGH(USB_BASE + MUSB_TXFIFOADD_OFFSET) = (usb_dc_cfg.fifo_size_offset >> 3); + HWREGH(USB_BASE + MUSB_TXFIFOADD_OFFSET) = (g_musb_udc.fifo_size_offset >> 3); - usb_dc_cfg.fifo_size_offset += used; + g_musb_udc.fifo_size_offset += used; } USBC_SelectActiveEp(old_ep_idx); @@ -499,8 +499,8 @@ int usbd_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint ep0_last_size = data_len; - if (data_len > usb_dc_cfg.in_ep[ep_idx].ep_mps) { - data_len = usb_dc_cfg.in_ep[ep_idx].ep_mps; + if (data_len > g_musb_udc.in_ep[ep_idx].ep_mps) { + data_len = g_musb_udc.in_ep[ep_idx].ep_mps; } usb_musb_write_packet(ep_idx, (uint8_t *)data, data_len); @@ -542,7 +542,7 @@ int usbd_ep_read(const uint8_t ep, uint8_t *data, uint32_t max_data_len, uint32_ if (ep_idx == 0x00) { if (usb_ep0_state == USB_EP0_STATE_SETUP) { - memcpy(data, (uint8_t *)&usb_dc_cfg.setup, 8); + memcpy(data, (uint8_t *)&g_musb_udc.setup, 8); } else { read_count = HWREGH(USB_BASE + MUSB_IND_RXCOUNT_OFFSET); read_count = MIN(read_count, max_data_len); @@ -577,9 +577,9 @@ static void handle_ep0(void) HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_SETENDC; } - if (usb_dc_cfg.dev_addr > 0) { - HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = usb_dc_cfg.dev_addr; - usb_dc_cfg.dev_addr = 0; + if (g_musb_udc.dev_addr > 0) { + HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = g_musb_udc.dev_addr; + g_musb_udc.dev_addr = 0; } switch (usb_ep0_state) { @@ -591,8 +591,8 @@ static void handle_ep0(void) return; } - usb_musb_read_packet(0, (uint8_t *)&usb_dc_cfg.setup, 8); - if (usb_dc_cfg.setup.wLength) { + usb_musb_read_packet(0, (uint8_t *)&g_musb_udc.setup, 8); + if (g_musb_udc.setup.wLength) { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_RXRDYC; } else { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_RXRDYC | USB_CSRL0_DATAEND); @@ -601,10 +601,10 @@ static void handle_ep0(void) usbd_event_notify_handler(USBD_EVENT_SETUP_NOTIFY, NULL); if (usb_ep0_state != USB_EP0_STATE_STALL) { - if (usb_dc_cfg.setup.wLength) { - if (usb_dc_cfg.setup.bmRequestType & 0x80) { + if (g_musb_udc.setup.wLength) { + if (g_musb_udc.setup.bmRequestType & 0x80) { usb_ep0_state = USB_EP0_STATE_IN_DATA; - if (ep0_last_size > usb_dc_cfg.in_ep[0].ep_mps) { + if (ep0_last_size > g_musb_udc.in_ep[0].ep_mps) { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_TXRDY; } else { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_TXRDY | USB_CSRL0_DATAEND); @@ -623,7 +623,7 @@ static void handle_ep0(void) case USB_EP0_STATE_IN_DATA: usbd_event_notify_handler(USBD_EVENT_EP0_IN_NOTIFY, NULL); - if (ep0_last_size > usb_dc_cfg.in_ep[0].ep_mps) { + if (ep0_last_size > g_musb_udc.in_ep[0].ep_mps) { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_TXRDY; } else { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_TXRDY | USB_CSRL0_DATAEND); @@ -636,7 +636,7 @@ static void handle_ep0(void) case USB_EP0_STATE_OUT_DATA: if (ep0_status & USB_CSRL0_RXRDY) { usbd_event_notify_handler(USBD_EVENT_EP0_OUT_NOTIFY, NULL); - if (usb_dc_cfg.setup.wLength > usb_dc_cfg.out_ep[0].ep_mps) { + if (g_musb_udc.setup.wLength > g_musb_udc.out_ep[0].ep_mps) { HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_RXRDYC; } else { usb_ep0_state = USB_EP0_STATE_IN_STATUS; @@ -678,7 +678,7 @@ void USBD_IRQHandler(void) HWREGB(USB_BASE + MUSB_RXFIFOSZ_OFFSET) = 0; HWREGH(USB_BASE + MUSB_RXFIFOADD_OFFSET) = 0; } - usb_dc_cfg.fifo_size_offset = USB_CTRL_EP_MPS; + g_musb_udc.fifo_size_offset = USB_CTRL_EP_MPS; } if (is & USB_IS_SOF) { diff --git a/port/musb/usb_hc_musb.c b/port/musb/usb_hc_musb.c index d93d7cfc..5c461f14 100644 --- a/port/musb/usb_hc_musb.c +++ b/port/musb/usb_hc_musb.c @@ -143,7 +143,7 @@ typedef enum { USB_EP0_STATE_IN_STATUS_C, /**< IN DATA */ } ep0_state_t; -struct usb_musb_chan { +struct musb_pipe { uint8_t ep_idx; bool inuse; /* True: This channel is "in use" */ bool in; /* True: IN endpoint */ @@ -154,20 +154,20 @@ struct usb_musb_chan { volatile uint32_t buflen; volatile uint16_t xfrd; /* Bytes transferred (at end of transfer) */ volatile int result; /* The result of the transfer */ - struct usbh_hubport *hport; volatile bool waiter; /* True: Thread is waiting for a channel event */ usb_osal_sem_t waitsem; /* Channel wait semaphore */ #ifdef CONFIG_USBHOST_ASYNCH usbh_asynch_callback_t callback; /* Transfer complete callback */ void *arg; /* Argument that accompanies the callback */ #endif + struct usbh_hubport *hport; }; -struct usb_musb_priv { - struct usb_musb_chan chan[CONIFG_USB_MUSB_EP_NUM][CONFIG_USBHOST_PIPE_NUM]; - volatile struct usb_musb_chan *active_chan[CONIFG_USB_MUSB_EP_NUM]; +struct musb_hcd { + struct musb_pipe chan[CONIFG_USB_MUSB_EP_NUM][CONFIG_USBHOST_PIPE_NUM]; + volatile struct musb_pipe *active_chan[CONIFG_USB_MUSB_EP_NUM]; usb_osal_mutex_t exclsem[CONIFG_USB_MUSB_EP_NUM]; /* Support mutually exclusive access */ -} g_usbhost; +} g_musb_hcd; static volatile uint8_t usb_ep0_state = USB_EP0_STATE_SETUP; volatile uint8_t ep0_outlen = 0; @@ -264,13 +264,13 @@ static void usb_musb_read_packet(uint8_t ep_idx, uint8_t *buffer, uint16_t len) } /**************************************************************************** - * Name: usb_synopsys_chan_alloc + * Name: musb_pipe_alloc * * Description: * Allocate a channel. * ****************************************************************************/ -static int usb_musb_chan_alloc(uint8_t ep_idx) +static int musb_pipe_alloc(uint8_t ep_idx) { int chidx; @@ -278,10 +278,10 @@ static int usb_musb_chan_alloc(uint8_t ep_idx) for (chidx = 0; chidx < CONFIG_USBHOST_PIPE_NUM; chidx++) { /* Is this channel available? */ - if (!g_usbhost.chan[ep_idx][chidx].inuse) { + if (!g_musb_hcd.chan[ep_idx][chidx].inuse) { /* Yes... make it "in use" and return the index */ - g_usbhost.chan[ep_idx][chidx].inuse = true; + g_musb_hcd.chan[ep_idx][chidx].inuse = true; return chidx; } } @@ -292,20 +292,20 @@ static int usb_musb_chan_alloc(uint8_t ep_idx) } /**************************************************************************** - * Name: usb_synopsys_chan_free + * Name: musb_pipe_free * * Description: * Free a previoiusly allocated channel. * ****************************************************************************/ -static void usb_musb_chan_free(struct usb_musb_chan *chan) +static void musb_pipe_free(struct musb_pipe *chan) { /* Mark the channel available */ chan->inuse = false; } /**************************************************************************** - * Name: usb_musb_chan_waitsetup + * Name: musb_pipe_waitsetup * * Description: * Set the request for the transfer complete event well BEFORE enabling @@ -319,7 +319,7 @@ static void usb_musb_chan_free(struct usb_musb_chan *chan) * ****************************************************************************/ -static int usb_musb_chan_waitsetup(struct usb_musb_chan *chan) +static int musb_pipe_waitsetup(struct musb_pipe *chan) { size_t flags; int ret = -ENODEV; @@ -333,7 +333,7 @@ static int usb_musb_chan_waitsetup(struct usb_musb_chan *chan) * when either (1) the device is disconnected, or (2) the transfer * completed. */ - g_usbhost.active_chan[chan->ep_idx] = chan; + g_musb_hcd.active_chan[chan->ep_idx] = chan; chan->waiter = true; chan->result = -EBUSY; chan->xfrd = 0; @@ -348,7 +348,7 @@ static int usb_musb_chan_waitsetup(struct usb_musb_chan *chan) } /**************************************************************************** - * Name: usb_musb_chan_asynchsetup + * Name: musb_pipe_asynchsetup * * Description: * Set the request for the transfer complete event well BEFORE enabling @@ -363,7 +363,7 @@ static int usb_musb_chan_waitsetup(struct usb_musb_chan *chan) ****************************************************************************/ #ifdef CONFIG_USBHOST_ASYNCH -static int usb_musb_chan_asynchsetup(struct usb_musb_chan *chan, usbh_asynch_callback_t callback, void *arg) +static int musb_pipe_asynchsetup(struct musb_pipe *chan, usbh_asynch_callback_t callback, void *arg) { size_t flags; int ret = -ENODEV; @@ -376,7 +376,7 @@ static int usb_musb_chan_asynchsetup(struct usb_musb_chan *chan, usbh_asynch_cal * when either (1) the device is disconnected, or (2) the transfer * completed. */ - g_usbhost.active_chan[chan->ep_idx] = chan; + g_musb_hcd.active_chan[chan->ep_idx] = chan; chan->waiter = false; chan->result = -EBUSY; chan->xfrd = 0; @@ -391,7 +391,7 @@ static int usb_musb_chan_asynchsetup(struct usb_musb_chan *chan, usbh_asynch_cal #endif /**************************************************************************** - * Name: usb_musb_chan_wait + * Name: musb_pipe_wait * * Description: * Wait for a transfer on a channel to complete. @@ -401,7 +401,7 @@ static int usb_musb_chan_asynchsetup(struct usb_musb_chan *chan, usbh_asynch_cal * ****************************************************************************/ -static int usb_musb_chan_wait(struct usb_musb_chan *chan, uint32_t timeout) +static int musb_pipe_wait(struct musb_pipe *chan, uint32_t timeout) { int ret; @@ -429,7 +429,7 @@ static int usb_musb_chan_wait(struct usb_musb_chan *chan, uint32_t timeout) } /**************************************************************************** - * Name: usb_musb_chan_wakeup + * Name: musb_pipe_wakeup * * Description: * A channel transfer has completed... wakeup any threads waiting for the @@ -441,13 +441,13 @@ static int usb_musb_chan_wait(struct usb_musb_chan *chan, uint32_t timeout) * ****************************************************************************/ -static void usb_musb_chan_wakeup(struct usb_musb_chan *chan) +static void musb_pipe_wakeup(struct musb_pipe *chan) { usbh_asynch_callback_t callback; void *arg; int nbytes; - g_usbhost.active_chan[chan->ep_idx] = NULL; + g_musb_hcd.active_chan[chan->ep_idx] = NULL; /* Is the transfer complete? */ if (chan->waiter) { @@ -478,7 +478,17 @@ __WEAK void usb_hc_low_level_init(void) { } -int usb_hc_init(void) +int usb_hc_sw_init(void) +{ + memset(&g_musb_hcd, 0, sizeof(struct musb_hcd)); + for (uint8_t i = 0; i < CONIFG_USB_MUSB_EP_NUM; i++) { + g_musb_hcd.exclsem[i] = usb_osal_mutex_create(); + } + + return 0; +} + +int usb_hc_hw_init(void) { uint8_t regval; uint32_t fifo_offset = 0; @@ -502,10 +512,6 @@ int usb_hc_init(void) fifo_offset += 512; } - for (uint8_t i = 0; i < CONIFG_USB_MUSB_EP_NUM; i++) { - g_usbhost.exclsem[i] = usb_osal_mutex_create(); - } - /* Enable USB interrupts */ regval = USB_IE_RESET | USB_IE_CONN | USB_IE_DISCON | USB_IE_RESUME | USB_IE_SUSPND | @@ -562,9 +568,9 @@ uint8_t usbh_get_port_speed(const uint8_t port) int usbh_ep0_reconfigure(usbh_epinfo_t ep, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) { int ret; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; - ret = usb_osal_mutex_take(g_usbhost.exclsem[0]); + ret = usb_osal_mutex_take(g_musb_hcd.exclsem[0]); if (ret < 0) { return ret; } @@ -580,14 +586,14 @@ int usbh_ep0_reconfigure(usbh_epinfo_t ep, uint8_t dev_addr, uint8_t ep_mps, uin chan->speed = USB_TYPE0_SPEED_LOW; } - usb_osal_mutex_give(g_usbhost.exclsem[0]); + usb_osal_mutex_give(g_musb_hcd.exclsem[0]); return ret; } int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg) { struct usbh_hubport *hport; - struct usb_musb_chan *chan; + struct musb_pipe *chan; uint32_t chidx; uint8_t ep_idx = 0; uint8_t old_ep_index; @@ -599,9 +605,9 @@ int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg) USBC_SelectActiveEp(ep_idx); if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) { - chidx = usb_musb_chan_alloc(0); - chan = &g_usbhost.chan[0][chidx]; - memset(chan, 0, sizeof(struct usb_musb_chan)); + chidx = musb_pipe_alloc(0); + chan = &g_musb_hcd.chan[0][chidx]; + memset(chan, 0, sizeof(struct musb_pipe)); chan->inuse = true; chan->ep_idx = 0; chan->interval = 0; @@ -612,10 +618,10 @@ int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg) *ep = (usbh_epinfo_t)chan; } else { - chidx = usb_musb_chan_alloc(ep_idx); + chidx = musb_pipe_alloc(ep_idx); - chan = &g_usbhost.chan[ep_idx][chidx]; - memset(chan, 0, sizeof(struct usb_musb_chan)); + chan = &g_musb_hcd.chan[ep_idx][chidx]; + memset(chan, 0, sizeof(struct musb_pipe)); chan->inuse = true; chan->in = ep_cfg->ep_addr & 0x80 ? 1 : 0; chan->ep_idx = ep_idx; @@ -649,8 +655,8 @@ int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg) int usbh_ep_free(usbh_epinfo_t ep) { - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; - usb_musb_chan_free(chan); + struct musb_pipe *chan = (struct musb_pipe *)ep; + musb_pipe_free(chan); usb_osal_sem_delete(chan->waitsem); return 0; } @@ -659,14 +665,14 @@ int usbh_control_transfer(usbh_epinfo_t ep, struct usb_setup_packet *setup, uint { int ret; uint32_t old_ep_index; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; - ret = usb_osal_mutex_take(g_usbhost.exclsem[0]); + ret = usb_osal_mutex_take(g_musb_hcd.exclsem[0]); if (ret < 0) { return ret; } - ret = usb_musb_chan_waitsetup(chan); + ret = musb_pipe_waitsetup(chan); if (ret < 0) { goto errout_with_mutex; } @@ -701,16 +707,16 @@ int usbh_control_transfer(usbh_epinfo_t ep, struct usb_setup_packet *setup, uint HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_TXRDY | USB_CSRL0_SETUP; USBC_SelectActiveEp(old_ep_index); - ret = usb_musb_chan_wait(chan, CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT); + ret = musb_pipe_wait(chan, CONFIG_USBHOST_CONTROL_TRANSFER_TIMEOUT); if (ret < 0) { goto errout_with_mutex; } - usb_osal_mutex_give(g_usbhost.exclsem[0]); + usb_osal_mutex_give(g_musb_hcd.exclsem[0]); return ret; errout_with_mutex: chan->waiter = false; - usb_osal_mutex_give(g_usbhost.exclsem[0]); + usb_osal_mutex_give(g_musb_hcd.exclsem[0]); return ret; } @@ -718,14 +724,14 @@ int usbh_ep_bulk_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t buflen, ui { int ret; uint32_t old_ep_index; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; - ret = usb_osal_mutex_take(g_usbhost.exclsem[chan->ep_idx]); + ret = usb_osal_mutex_take(g_musb_hcd.exclsem[chan->ep_idx]); if (ret < 0) { return ret; } - ret = usb_musb_chan_waitsetup(chan); + ret = musb_pipe_waitsetup(chan); if (ret < 0) { goto errout_with_mutex; } @@ -774,16 +780,16 @@ int usbh_ep_bulk_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t buflen, ui } USBC_SelectActiveEp(old_ep_index); - ret = usb_musb_chan_wait(chan, timeout); + ret = musb_pipe_wait(chan, timeout); if (ret < 0) { goto errout_with_mutex; } - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; errout_with_mutex: chan->waiter = false; - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; } @@ -791,14 +797,14 @@ int usbh_ep_intr_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t buflen, ui { int ret; uint32_t old_ep_index; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; - ret = usb_osal_mutex_take(g_usbhost.exclsem[chan->ep_idx]); + ret = usb_osal_mutex_take(g_musb_hcd.exclsem[chan->ep_idx]); if (ret < 0) { return ret; } - ret = usb_musb_chan_waitsetup(chan); + ret = musb_pipe_waitsetup(chan); if (ret < 0) { goto errout_with_mutex; } @@ -847,16 +853,16 @@ int usbh_ep_intr_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t buflen, ui } USBC_SelectActiveEp(old_ep_index); - ret = usb_musb_chan_wait(chan, timeout); + ret = musb_pipe_wait(chan, timeout); if (ret < 0) { goto errout_with_mutex; } - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; errout_with_mutex: chan->waiter = false; - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; } @@ -864,18 +870,18 @@ int usbh_ep_bulk_async_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t bufl { int ret; uint32_t old_ep_index; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; - if (g_usbhost.active_chan[chan->ep_idx]) { + if (g_musb_hcd.active_chan[chan->ep_idx]) { return -EINVAL; } - ret = usb_osal_mutex_take(g_usbhost.exclsem[chan->ep_idx]); + ret = usb_osal_mutex_take(g_musb_hcd.exclsem[chan->ep_idx]); if (ret < 0) { return ret; } - ret = usb_musb_chan_asynchsetup(chan, callback, arg); + ret = musb_pipe_asynchsetup(chan, callback, arg); if (ret < 0) { goto errout_with_mutex; } @@ -924,11 +930,11 @@ int usbh_ep_bulk_async_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t bufl } USBC_SelectActiveEp(old_ep_index); - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; errout_with_mutex: - g_usbhost.active_chan[chan->ep_idx] = NULL; - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + g_musb_hcd.active_chan[chan->ep_idx] = NULL; + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; } @@ -936,18 +942,18 @@ int usbh_ep_intr_async_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t bufl { int ret; uint32_t old_ep_index; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; - if (g_usbhost.active_chan[chan->ep_idx]) { + if (g_musb_hcd.active_chan[chan->ep_idx]) { return -EINVAL; } - ret = usb_osal_mutex_take(g_usbhost.exclsem[chan->ep_idx]); + ret = usb_osal_mutex_take(g_musb_hcd.exclsem[chan->ep_idx]); if (ret < 0) { return ret; } - ret = usb_musb_chan_asynchsetup(chan, callback, arg); + ret = musb_pipe_asynchsetup(chan, callback, arg); if (ret < 0) { goto errout_with_mutex; } @@ -996,18 +1002,18 @@ int usbh_ep_intr_async_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t bufl } USBC_SelectActiveEp(old_ep_index); - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; errout_with_mutex: - g_usbhost.active_chan[chan->ep_idx] = NULL; - usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); + g_musb_hcd.active_chan[chan->ep_idx] = NULL; + usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]); return ret; } int usb_ep_cancel(usbh_epinfo_t ep) { size_t flags; - struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; + struct musb_pipe *chan = (struct musb_pipe *)ep; #ifdef CONFIG_USBHOST_ASYNCH usbh_asynch_callback_t callback; void *arg; @@ -1025,7 +1031,7 @@ int usb_ep_cancel(usbh_epinfo_t ep) chan->xfrd = 0; #endif - g_usbhost.active_chan[chan->ep_idx] = NULL; + g_musb_hcd.active_chan[chan->ep_idx] = NULL; usb_osal_leave_critical_section(flags); /* Is there a thread waiting for this transfer to complete? */ @@ -1047,10 +1053,10 @@ int usb_ep_cancel(usbh_epinfo_t ep) void handle_ep0(void) { uint8_t ep0_status; - struct usb_musb_chan *chan; + struct musb_pipe *chan; int result = 0; - chan = (struct usb_musb_chan *)g_usbhost.active_chan[0]; + chan = (struct musb_pipe *)g_musb_hcd.active_chan[0]; USBC_SelectActiveEp(0); ep0_status = HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET); @@ -1155,7 +1161,7 @@ void handle_ep0(void) chan_wait: if (chan) { chan->result = result; - usb_musb_chan_wakeup(chan); + musb_pipe_wakeup(chan); } } @@ -1166,7 +1172,7 @@ void USBH_IRQHandler(void) uint32_t rxis; uint8_t ep_csrl_status; // uint8_t ep_csrh_status; - struct usb_musb_chan *chan; + struct musb_pipe *chan; uint8_t ep_idx; uint8_t old_ep_idx; int result = 0; @@ -1188,10 +1194,10 @@ void USBH_IRQHandler(void) if (is & USB_IS_DISCON) { if (usbh_get_port_connect_status(0) == false) { for (uint8_t ep_index = 0; ep_index < CONIFG_USB_MUSB_EP_NUM; ep_index++) { - if (g_usbhost.active_chan[ep_index]) { - chan = (struct usb_musb_chan *)g_usbhost.active_chan[ep_index]; + if (g_musb_hcd.active_chan[ep_index]) { + chan = (struct musb_pipe *)g_musb_hcd.active_chan[ep_index]; chan->result = -ENXIO; - usb_musb_chan_wakeup(chan); + musb_pipe_wakeup(chan); } } @@ -1230,7 +1236,7 @@ void USBH_IRQHandler(void) txis &= ~(1 << ep_idx); HWREGH(USB_BASE + MUSB_TXIS_OFFSET) = (1 << ep_idx); - chan = (struct usb_musb_chan *)g_usbhost.active_chan[ep_idx]; + chan = (struct musb_pipe *)g_musb_hcd.active_chan[ep_idx]; USBC_SelectActiveEp(ep_idx); @@ -1275,7 +1281,7 @@ void USBH_IRQHandler(void) rxis &= ~(1 << ep_idx); HWREGH(USB_BASE + MUSB_RXIS_OFFSET) = (1 << ep_idx); // clear isr flag - chan = (struct usb_musb_chan *)g_usbhost.active_chan[ep_idx]; + chan = (struct musb_pipe *)g_musb_hcd.active_chan[ep_idx]; USBC_SelectActiveEp(ep_idx); @@ -1322,6 +1328,6 @@ chan_wait: USBC_SelectActiveEp(old_ep_idx); if (chan) { chan->result = result; - usb_musb_chan_wakeup(chan); + musb_pipe_wakeup(chan); } } \ No newline at end of file diff --git a/port/template/usb_dc.c b/port/template/usb_dc.c index 943bf926..a42390c6 100644 --- a/port/template/usb_dc.c +++ b/port/template/usb_dc.c @@ -20,11 +20,11 @@ struct usb_dc_ep_state { }; /* Driver state */ -struct usb_dc_config_priv { +struct xxx_udc { volatile uint8_t dev_addr; struct usb_dc_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ struct usb_dc_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */ -} usb_dc_cfg; +} g_xxx_udc; __WEAK void usb_dc_low_level_init(void) { @@ -36,7 +36,7 @@ __WEAK void usb_dc_low_level_deinit(void) int usb_dc_init(void) { - memset(&usb_dc_cfg, 0, sizeof(struct usb_dc_config_priv)); + memset(&g_xxx_udc, 0, sizeof(struct xxx_udc)); usb_dc_low_level_init(); return 0; @@ -57,11 +57,11 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg) uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr); if (USB_EP_DIR_IS_OUT(ep_cfg->ep_addr)) { - usb_dc_cfg.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; - usb_dc_cfg.out_ep[ep_idx].ep_type = ep_cfg->ep_type; + g_xxx_udc.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps; + g_xxx_udc.out_ep[ep_idx].ep_type = ep_cfg->ep_type; } else { - usb_dc_cfg.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; - usb_dc_cfg.in_ep[ep_idx].ep_type = ep_cfg->ep_type; + g_xxx_udc.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; + g_xxx_udc.in_ep[ep_idx].ep_type = ep_cfg->ep_type; } return 0; } @@ -98,8 +98,8 @@ int usbd_ep_write(const uint8_t ep, const uint8_t *data, uint32_t data_len, uint return 0; } - if (data_len > usb_dc_cfg.in_ep[ep_idx].ep_mps) { - data_len = usb_dc_cfg.in_ep[ep_idx].ep_mps; + if (data_len > g_xxx_udc.in_ep[ep_idx].ep_mps) { + data_len = g_xxx_udc.in_ep[ep_idx].ep_mps; } if (ret_bytes) { diff --git a/port/template/usb_hc.c b/port/template/usb_hc.c index 62122352..3de99f65 100644 --- a/port/template/usb_hc.c +++ b/port/template/usb_hc.c @@ -4,20 +4,25 @@ #define USBH_IRQHandler OTG_FS_IRQHandler #endif -struct usb_xxx_priv { +struct xxx_hcd { volatile bool connected; /* Connected to device */ volatile bool pscwait; /* True: Thread is waiting for a port event */ usb_osal_sem_t exclsem; /* Support mutually exclusive access */ -} g_usbhost; +} g_xxx_hcd; __WEAK void usb_hc_low_level_init(void) { } -int usb_hc_init(void) +int usb_hc_sw_init(void) { - memset(&g_usbhost, 0, sizeof(struct usb_xxx_priv)); + memset(&g_usbhost, 0, sizeof(struct xxx_hcd)); + return 0; +} + +int usb_hc_hw_init(void) +{ usb_hc_low_level_init(); return 0;