rename struct name

This commit is contained in:
sakumisu
2022-06-14 22:08:04 +08:00
parent 8d7ef730a2
commit a31e56f13e
5 changed files with 176 additions and 165 deletions

View File

@@ -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); static void USB_ReadPMA(USB_TypeDef *USBx, uint8_t *pbUsrBuf, uint16_t wPMABufAddr, uint16_t wNBytes);
/* Endpoint state */ /* Endpoint state */
struct usb_dc_ep_state { struct fsdev_ep_state {
/** Endpoint max packet size */ /** Endpoint max packet size */
uint16_t ep_mps; uint16_t ep_mps;
/** Endpoint Transfer Type. /** Endpoint Transfer Type.
@@ -38,12 +38,12 @@ struct usb_dc_ep_state {
}; };
/* Driver state */ /* Driver state */
struct usb_dc_config_priv { struct fsdev_udc {
volatile uint8_t dev_addr; /*!< USB Address */ volatile uint8_t dev_addr; /*!< USB Address */
volatile uint32_t pma_offset; /*!< pma offset */ volatile uint32_t pma_offset; /*!< pma offset */
struct usb_dc_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ struct fsdev_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 */ struct fsdev_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */
} usb_dc_cfg; } g_fsdev_udc;
__WEAK void usb_dc_low_level_init(void) __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) 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(); 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->DADDR = (uint16_t)USB_DADDR_EF;
} }
usb_dc_cfg.dev_addr = addr; g_fsdev_udc.dev_addr = addr;
return 0; 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); PCD_SET_EP_ADDRESS(USB, ep_idx, ep_idx);
if (USB_EP_DIR_IS_OUT(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; g_fsdev_udc.out_ep[ep_idx].ep_mps = ep_cfg->ep_mps;
usb_dc_cfg.out_ep[ep_idx].ep_type = ep_cfg->ep_type; g_fsdev_udc.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 (g_fsdev_udc.out_ep[ep_idx].ep_mps > g_fsdev_udc.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) { if (g_fsdev_udc.pma_offset + g_fsdev_udc.out_ep[ep_idx].ep_mps >= USB_RAM_SIZE) {
return -1; return -1;
} }
usb_dc_cfg.out_ep[ep_idx].ep_pma_buf_len = ep_cfg->ep_mps; g_fsdev_udc.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_addr = g_fsdev_udc.pma_offset;
/*Set the endpoint Receive buffer address */ /*Set the endpoint Receive buffer address */
PCD_SET_EP_RX_ADDRESS(USB, ep_idx, usb_dc_cfg.pma_offset); PCD_SET_EP_RX_ADDRESS(USB, ep_idx, g_fsdev_udc.pma_offset);
usb_dc_cfg.pma_offset += ep_cfg->ep_mps; g_fsdev_udc.pma_offset += ep_cfg->ep_mps;
} }
/*Set the endpoint Receive buffer counter*/ /*Set the endpoint Receive buffer counter*/
PCD_SET_EP_RX_CNT(USB, ep_idx, ep_cfg->ep_mps); 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*/ /* Configure VALID status for the Endpoint*/
PCD_SET_EP_RX_STATUS(USB, ep_idx, USB_EP_RX_VALID); PCD_SET_EP_RX_STATUS(USB, ep_idx, USB_EP_RX_VALID);
} else { } else {
usb_dc_cfg.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_fsdev_udc.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps;
usb_dc_cfg.in_ep[ep_idx].ep_type = ep_cfg->ep_type; g_fsdev_udc.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 (g_fsdev_udc.in_ep[ep_idx].ep_mps > g_fsdev_udc.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) { if (g_fsdev_udc.pma_offset + g_fsdev_udc.in_ep[ep_idx].ep_mps >= USB_RAM_SIZE) {
return -1; return -1;
} }
usb_dc_cfg.in_ep[ep_idx].ep_pma_buf_len = ep_cfg->ep_mps; g_fsdev_udc.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_addr = g_fsdev_udc.pma_offset;
/*Set the endpoint Transmit buffer address */ /*Set the endpoint Transmit buffer address */
PCD_SET_EP_TX_ADDRESS(USB, ep_idx, usb_dc_cfg.pma_offset); PCD_SET_EP_TX_ADDRESS(USB, ep_idx, g_fsdev_udc.pma_offset);
usb_dc_cfg.pma_offset += ep_cfg->ep_mps; g_fsdev_udc.pma_offset += ep_cfg->ep_mps;
} }
PCD_CLEAR_TX_DTOG(USB, ep_idx); PCD_CLEAR_TX_DTOG(USB, ep_idx);
@@ -235,7 +235,7 @@ int usbd_ep_clear_stall(const uint8_t ep)
} else { } else {
PCD_CLEAR_TX_DTOG(USB, ep_idx); 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 */ /* Configure NAK status for the Endpoint */
PCD_SET_EP_TX_STATUS(USB, ep_idx, USB_EP_TX_NAK); 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; return 0;
} }
if (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 = usb_dc_cfg.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_CNT(USB, ep_idx, (uint16_t)data_len);
PCD_SET_EP_TX_STATUS(USB, ep_idx, USB_EP_TX_VALID); 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 = PCD_GET_EP_RX_CNT(USB, ep_idx);
read_count = MIN(read_count, max_data_len); 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) { if (read_bytes) {
*read_bytes = read_count; *read_bytes = read_count;
@@ -335,9 +335,9 @@ void USBD_IRQHandler(void)
/* DIR = 0 implies that (EP_CTR_TX = 1) always */ /* DIR = 0 implies that (EP_CTR_TX = 1) always */
PCD_CLEAR_TX_EP_CTR(USB, 0); PCD_CLEAR_TX_EP_CTR(USB, 0);
usbd_event_notify_handler(USBD_EVENT_EP0_IN_NOTIFY, NULL); 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)) { if ((g_fsdev_udc.dev_addr > 0U) && (PCD_GET_EP_TX_CNT(USB, 0) == 0U)) {
USB->DADDR = ((uint16_t)usb_dc_cfg.dev_addr | USB_DADDR_EF); USB->DADDR = ((uint16_t)g_fsdev_udc.dev_addr | USB_DADDR_EF);
usb_dc_cfg.dev_addr = 0U; g_fsdev_udc.dev_addr = 0U;
} }
} else { } else {
/* DIR = 1 */ /* DIR = 1 */
@@ -381,8 +381,8 @@ void USBD_IRQHandler(void)
} }
} }
if (wIstr & USB_ISTR_RESET) { if (wIstr & USB_ISTR_RESET) {
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;
usbd_event_notify_handler(USBD_EVENT_RESET, NULL); usbd_event_notify_handler(USBD_EVENT_RESET, NULL);
USB->ISTR &= (uint16_t)(~USB_ISTR_RESET); USB->ISTR &= (uint16_t)(~USB_ISTR_RESET);
} }

View File

@@ -103,7 +103,7 @@ typedef enum {
} ep0_state_t; } ep0_state_t;
/* Endpoint state */ /* Endpoint state */
struct usb_dc_ep_state { struct musb_ep_state {
/** Endpoint max packet size */ /** Endpoint max packet size */
uint16_t ep_mps; uint16_t ep_mps;
/** Endpoint Transfer Type. /** Endpoint Transfer Type.
@@ -114,13 +114,13 @@ struct usb_dc_ep_state {
}; };
/* Driver state */ /* Driver state */
struct usb_dc_config_priv { struct musb_udc {
volatile uint8_t dev_addr; volatile uint8_t dev_addr;
volatile uint32_t fifo_size_offset; volatile uint32_t fifo_size_offset;
struct usb_setup_packet setup; struct usb_setup_packet setup;
struct usb_dc_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ struct musb_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 */ struct musb_ep_state out_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< OUT endpoint parameters */
} usb_dc_cfg; } g_musb_udc;
static volatile uint8_t usb_ep0_state = USB_EP0_STATE_SETUP; static volatile uint8_t usb_ep0_state = USB_EP0_STATE_SETUP;
volatile uint16_t ep0_last_size = 0; volatile uint16_t ep0_last_size = 0;
@@ -225,13 +225,13 @@ __WEAK void usb_dc_low_level_deinit(void)
int usb_dc_init(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; g_musb_udc.out_ep[0].ep_mps = USB_CTRL_EP_MPS;
usb_dc_cfg.out_ep[0].ep_type = 0x00; g_musb_udc.out_ep[0].ep_type = 0x00;
usb_dc_cfg.in_ep[0].ep_mps = USB_CTRL_EP_MPS; g_musb_udc.in_ep[0].ep_mps = USB_CTRL_EP_MPS;
usb_dc_cfg.in_ep[0].ep_type = 0x00; g_musb_udc.in_ep[0].ep_type = 0x00;
usb_dc_cfg.fifo_size_offset = USB_CTRL_EP_MPS; g_musb_udc.fifo_size_offset = USB_CTRL_EP_MPS;
usb_dc_low_level_init(); usb_dc_low_level_init();
@@ -266,7 +266,7 @@ int usbd_set_address(const uint8_t addr)
HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = 0; HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = 0;
} }
usb_dc_cfg.dev_addr = addr; g_musb_udc.dev_addr = addr;
return 0; return 0;
} }
@@ -287,8 +287,8 @@ int usbd_ep_open(const struct usbd_endpoint_cfg *ep_cfg)
USBC_SelectActiveEp(ep_idx); USBC_SelectActiveEp(ep_idx);
if (USB_EP_DIR_IS_OUT(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; g_musb_udc.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_type = ep_cfg->ep_type;
HWREGH(USB_BASE + MUSB_RXIE_OFFSET) |= (1 << ep_idx); 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); fifo_size = usb_musb_get_fifo_size(ep_cfg->ep_mps, &used);
HWREGB(USB_BASE + MUSB_RXFIFOSZ_OFFSET) = fifo_size & 0x0f; 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 { } else {
usb_dc_cfg.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_musb_udc.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_type = ep_cfg->ep_type;
HWREGH(USB_BASE + MUSB_TXIE_OFFSET) |= (1 << ep_idx); 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); fifo_size = usb_musb_get_fifo_size(ep_cfg->ep_mps, &used);
HWREGB(USB_BASE + MUSB_TXFIFOSZ_OFFSET) = fifo_size & 0x0f; 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); 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; ep0_last_size = data_len;
if (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 = usb_dc_cfg.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); 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 (ep_idx == 0x00) {
if (usb_ep0_state == USB_EP0_STATE_SETUP) { 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 { } else {
read_count = HWREGH(USB_BASE + MUSB_IND_RXCOUNT_OFFSET); read_count = HWREGH(USB_BASE + MUSB_IND_RXCOUNT_OFFSET);
read_count = MIN(read_count, max_data_len); 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; HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_SETENDC;
} }
if (usb_dc_cfg.dev_addr > 0) { if (g_musb_udc.dev_addr > 0) {
HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = usb_dc_cfg.dev_addr; HWREGB(USB_BASE + MUSB_FADDR_OFFSET) = g_musb_udc.dev_addr;
usb_dc_cfg.dev_addr = 0; g_musb_udc.dev_addr = 0;
} }
switch (usb_ep0_state) { switch (usb_ep0_state) {
@@ -591,8 +591,8 @@ static void handle_ep0(void)
return; return;
} }
usb_musb_read_packet(0, (uint8_t *)&usb_dc_cfg.setup, 8); usb_musb_read_packet(0, (uint8_t *)&g_musb_udc.setup, 8);
if (usb_dc_cfg.setup.wLength) { if (g_musb_udc.setup.wLength) {
HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_RXRDYC; HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_RXRDYC;
} else { } else {
HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_RXRDYC | USB_CSRL0_DATAEND); 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); usbd_event_notify_handler(USBD_EVENT_SETUP_NOTIFY, NULL);
if (usb_ep0_state != USB_EP0_STATE_STALL) { if (usb_ep0_state != USB_EP0_STATE_STALL) {
if (usb_dc_cfg.setup.wLength) { if (g_musb_udc.setup.wLength) {
if (usb_dc_cfg.setup.bmRequestType & 0x80) { if (g_musb_udc.setup.bmRequestType & 0x80) {
usb_ep0_state = USB_EP0_STATE_IN_DATA; 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; HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_TXRDY;
} else { } else {
HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_TXRDY | USB_CSRL0_DATAEND); 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: case USB_EP0_STATE_IN_DATA:
usbd_event_notify_handler(USBD_EVENT_EP0_IN_NOTIFY, NULL); 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; HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_TXRDY;
} else { } else {
HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = (USB_CSRL0_TXRDY | USB_CSRL0_DATAEND); 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: case USB_EP0_STATE_OUT_DATA:
if (ep0_status & USB_CSRL0_RXRDY) { if (ep0_status & USB_CSRL0_RXRDY) {
usbd_event_notify_handler(USBD_EVENT_EP0_OUT_NOTIFY, NULL); 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; HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_RXRDYC;
} else { } else {
usb_ep0_state = USB_EP0_STATE_IN_STATUS; usb_ep0_state = USB_EP0_STATE_IN_STATUS;
@@ -678,7 +678,7 @@ void USBD_IRQHandler(void)
HWREGB(USB_BASE + MUSB_RXFIFOSZ_OFFSET) = 0; HWREGB(USB_BASE + MUSB_RXFIFOSZ_OFFSET) = 0;
HWREGH(USB_BASE + MUSB_RXFIFOADD_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) { if (is & USB_IS_SOF) {

View File

@@ -143,7 +143,7 @@ typedef enum {
USB_EP0_STATE_IN_STATUS_C, /**< IN DATA */ USB_EP0_STATE_IN_STATUS_C, /**< IN DATA */
} ep0_state_t; } ep0_state_t;
struct usb_musb_chan { struct musb_pipe {
uint8_t ep_idx; uint8_t ep_idx;
bool inuse; /* True: This channel is "in use" */ bool inuse; /* True: This channel is "in use" */
bool in; /* True: IN endpoint */ bool in; /* True: IN endpoint */
@@ -154,20 +154,20 @@ struct usb_musb_chan {
volatile uint32_t buflen; volatile uint32_t buflen;
volatile uint16_t xfrd; /* Bytes transferred (at end of transfer) */ volatile uint16_t xfrd; /* Bytes transferred (at end of transfer) */
volatile int result; /* The result of the transfer */ volatile int result; /* The result of the transfer */
struct usbh_hubport *hport;
volatile bool waiter; /* True: Thread is waiting for a channel event */ volatile bool waiter; /* True: Thread is waiting for a channel event */
usb_osal_sem_t waitsem; /* Channel wait semaphore */ usb_osal_sem_t waitsem; /* Channel wait semaphore */
#ifdef CONFIG_USBHOST_ASYNCH #ifdef CONFIG_USBHOST_ASYNCH
usbh_asynch_callback_t callback; /* Transfer complete callback */ usbh_asynch_callback_t callback; /* Transfer complete callback */
void *arg; /* Argument that accompanies the callback */ void *arg; /* Argument that accompanies the callback */
#endif #endif
struct usbh_hubport *hport;
}; };
struct usb_musb_priv { struct musb_hcd {
struct usb_musb_chan chan[CONIFG_USB_MUSB_EP_NUM][CONFIG_USBHOST_PIPE_NUM]; struct musb_pipe chan[CONIFG_USB_MUSB_EP_NUM][CONFIG_USBHOST_PIPE_NUM];
volatile struct usb_musb_chan *active_chan[CONIFG_USB_MUSB_EP_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 */ 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; static volatile uint8_t usb_ep0_state = USB_EP0_STATE_SETUP;
volatile uint8_t ep0_outlen = 0; 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: * Description:
* Allocate a channel. * Allocate a channel.
* *
****************************************************************************/ ****************************************************************************/
static int usb_musb_chan_alloc(uint8_t ep_idx) static int musb_pipe_alloc(uint8_t ep_idx)
{ {
int chidx; 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++) { for (chidx = 0; chidx < CONFIG_USBHOST_PIPE_NUM; chidx++) {
/* Is this channel available? */ /* 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 */ /* 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; 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: * Description:
* Free a previoiusly allocated channel. * 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 */ /* Mark the channel available */
chan->inuse = false; chan->inuse = false;
} }
/**************************************************************************** /****************************************************************************
* Name: usb_musb_chan_waitsetup * Name: musb_pipe_waitsetup
* *
* Description: * Description:
* Set the request for the transfer complete event well BEFORE enabling * 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; size_t flags;
int ret = -ENODEV; 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 * when either (1) the device is disconnected, or (2) the transfer
* completed. * completed.
*/ */
g_usbhost.active_chan[chan->ep_idx] = chan; g_musb_hcd.active_chan[chan->ep_idx] = chan;
chan->waiter = true; chan->waiter = true;
chan->result = -EBUSY; chan->result = -EBUSY;
chan->xfrd = 0; 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: * Description:
* Set the request for the transfer complete event well BEFORE enabling * 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 #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; size_t flags;
int ret = -ENODEV; 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 * when either (1) the device is disconnected, or (2) the transfer
* completed. * completed.
*/ */
g_usbhost.active_chan[chan->ep_idx] = chan; g_musb_hcd.active_chan[chan->ep_idx] = chan;
chan->waiter = false; chan->waiter = false;
chan->result = -EBUSY; chan->result = -EBUSY;
chan->xfrd = 0; chan->xfrd = 0;
@@ -391,7 +391,7 @@ static int usb_musb_chan_asynchsetup(struct usb_musb_chan *chan, usbh_asynch_cal
#endif #endif
/**************************************************************************** /****************************************************************************
* Name: usb_musb_chan_wait * Name: musb_pipe_wait
* *
* Description: * Description:
* Wait for a transfer on a channel to complete. * 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; 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: * Description:
* A channel transfer has completed... wakeup any threads waiting for the * 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; usbh_asynch_callback_t callback;
void *arg; void *arg;
int nbytes; int nbytes;
g_usbhost.active_chan[chan->ep_idx] = NULL; g_musb_hcd.active_chan[chan->ep_idx] = NULL;
/* Is the transfer complete? */ /* Is the transfer complete? */
if (chan->waiter) { 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; uint8_t regval;
uint32_t fifo_offset = 0; uint32_t fifo_offset = 0;
@@ -502,10 +512,6 @@ int usb_hc_init(void)
fifo_offset += 512; 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 */ /* Enable USB interrupts */
regval = USB_IE_RESET | USB_IE_CONN | USB_IE_DISCON | regval = USB_IE_RESET | USB_IE_CONN | USB_IE_DISCON |
USB_IE_RESUME | USB_IE_SUSPND | 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 usbh_ep0_reconfigure(usbh_epinfo_t ep, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed)
{ {
int ret; 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) { if (ret < 0) {
return ret; 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; 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; return ret;
} }
int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg) int usbh_ep_alloc(usbh_epinfo_t *ep, const struct usbh_endpoint_cfg *ep_cfg)
{ {
struct usbh_hubport *hport; struct usbh_hubport *hport;
struct usb_musb_chan *chan; struct musb_pipe *chan;
uint32_t chidx; uint32_t chidx;
uint8_t ep_idx = 0; uint8_t ep_idx = 0;
uint8_t old_ep_index; 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); USBC_SelectActiveEp(ep_idx);
if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) { if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) {
chidx = usb_musb_chan_alloc(0); chidx = musb_pipe_alloc(0);
chan = &g_usbhost.chan[0][chidx]; chan = &g_musb_hcd.chan[0][chidx];
memset(chan, 0, sizeof(struct usb_musb_chan)); memset(chan, 0, sizeof(struct musb_pipe));
chan->inuse = true; chan->inuse = true;
chan->ep_idx = 0; chan->ep_idx = 0;
chan->interval = 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; *ep = (usbh_epinfo_t)chan;
} else { } else {
chidx = usb_musb_chan_alloc(ep_idx); chidx = musb_pipe_alloc(ep_idx);
chan = &g_usbhost.chan[ep_idx][chidx]; chan = &g_musb_hcd.chan[ep_idx][chidx];
memset(chan, 0, sizeof(struct usb_musb_chan)); memset(chan, 0, sizeof(struct musb_pipe));
chan->inuse = true; chan->inuse = true;
chan->in = ep_cfg->ep_addr & 0x80 ? 1 : 0; chan->in = ep_cfg->ep_addr & 0x80 ? 1 : 0;
chan->ep_idx = ep_idx; 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) int usbh_ep_free(usbh_epinfo_t ep)
{ {
struct usb_musb_chan *chan = (struct usb_musb_chan *)ep; struct musb_pipe *chan = (struct musb_pipe *)ep;
usb_musb_chan_free(chan); musb_pipe_free(chan);
usb_osal_sem_delete(chan->waitsem); usb_osal_sem_delete(chan->waitsem);
return 0; return 0;
} }
@@ -659,14 +665,14 @@ int usbh_control_transfer(usbh_epinfo_t ep, struct usb_setup_packet *setup, uint
{ {
int ret; int ret;
uint32_t old_ep_index; 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) { if (ret < 0) {
return ret; return ret;
} }
ret = usb_musb_chan_waitsetup(chan); ret = musb_pipe_waitsetup(chan);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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; HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET) = USB_CSRL0_TXRDY | USB_CSRL0_SETUP;
USBC_SelectActiveEp(old_ep_index); 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) { if (ret < 0) {
goto errout_with_mutex; goto errout_with_mutex;
} }
usb_osal_mutex_give(g_usbhost.exclsem[0]); usb_osal_mutex_give(g_musb_hcd.exclsem[0]);
return ret; return ret;
errout_with_mutex: errout_with_mutex:
chan->waiter = false; chan->waiter = false;
usb_osal_mutex_give(g_usbhost.exclsem[0]); usb_osal_mutex_give(g_musb_hcd.exclsem[0]);
return ret; return ret;
} }
@@ -718,14 +724,14 @@ int usbh_ep_bulk_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t buflen, ui
{ {
int ret; int ret;
uint32_t old_ep_index; 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) { if (ret < 0) {
return ret; return ret;
} }
ret = usb_musb_chan_waitsetup(chan); ret = musb_pipe_waitsetup(chan);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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); USBC_SelectActiveEp(old_ep_index);
ret = usb_musb_chan_wait(chan, timeout); ret = musb_pipe_wait(chan, timeout);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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; return ret;
errout_with_mutex: errout_with_mutex:
chan->waiter = false; 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; return ret;
} }
@@ -791,14 +797,14 @@ int usbh_ep_intr_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t buflen, ui
{ {
int ret; int ret;
uint32_t old_ep_index; 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) { if (ret < 0) {
return ret; return ret;
} }
ret = usb_musb_chan_waitsetup(chan); ret = musb_pipe_waitsetup(chan);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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); USBC_SelectActiveEp(old_ep_index);
ret = usb_musb_chan_wait(chan, timeout); ret = musb_pipe_wait(chan, timeout);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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; return ret;
errout_with_mutex: errout_with_mutex:
chan->waiter = false; 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; return ret;
} }
@@ -864,18 +870,18 @@ int usbh_ep_bulk_async_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t bufl
{ {
int ret; int ret;
uint32_t old_ep_index; 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; 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) { if (ret < 0) {
return ret; return ret;
} }
ret = usb_musb_chan_asynchsetup(chan, callback, arg); ret = musb_pipe_asynchsetup(chan, callback, arg);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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); 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; return ret;
errout_with_mutex: errout_with_mutex:
g_usbhost.active_chan[chan->ep_idx] = NULL; g_musb_hcd.active_chan[chan->ep_idx] = NULL;
usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]);
return ret; return ret;
} }
@@ -936,18 +942,18 @@ int usbh_ep_intr_async_transfer(usbh_epinfo_t ep, uint8_t *buffer, uint32_t bufl
{ {
int ret; int ret;
uint32_t old_ep_index; 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; 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) { if (ret < 0) {
return ret; return ret;
} }
ret = usb_musb_chan_asynchsetup(chan, callback, arg); ret = musb_pipe_asynchsetup(chan, callback, arg);
if (ret < 0) { if (ret < 0) {
goto errout_with_mutex; 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); 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; return ret;
errout_with_mutex: errout_with_mutex:
g_usbhost.active_chan[chan->ep_idx] = NULL; g_musb_hcd.active_chan[chan->ep_idx] = NULL;
usb_osal_mutex_give(g_usbhost.exclsem[chan->ep_idx]); usb_osal_mutex_give(g_musb_hcd.exclsem[chan->ep_idx]);
return ret; return ret;
} }
int usb_ep_cancel(usbh_epinfo_t ep) int usb_ep_cancel(usbh_epinfo_t ep)
{ {
size_t flags; 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 #ifdef CONFIG_USBHOST_ASYNCH
usbh_asynch_callback_t callback; usbh_asynch_callback_t callback;
void *arg; void *arg;
@@ -1025,7 +1031,7 @@ int usb_ep_cancel(usbh_epinfo_t ep)
chan->xfrd = 0; chan->xfrd = 0;
#endif #endif
g_usbhost.active_chan[chan->ep_idx] = NULL; g_musb_hcd.active_chan[chan->ep_idx] = NULL;
usb_osal_leave_critical_section(flags); usb_osal_leave_critical_section(flags);
/* Is there a thread waiting for this transfer to complete? */ /* 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) void handle_ep0(void)
{ {
uint8_t ep0_status; uint8_t ep0_status;
struct usb_musb_chan *chan; struct musb_pipe *chan;
int result = 0; 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); USBC_SelectActiveEp(0);
ep0_status = HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET); ep0_status = HWREGB(USB_BASE + MUSB_IND_TXCSRL_OFFSET);
@@ -1155,7 +1161,7 @@ void handle_ep0(void)
chan_wait: chan_wait:
if (chan) { if (chan) {
chan->result = result; chan->result = result;
usb_musb_chan_wakeup(chan); musb_pipe_wakeup(chan);
} }
} }
@@ -1166,7 +1172,7 @@ void USBH_IRQHandler(void)
uint32_t rxis; uint32_t rxis;
uint8_t ep_csrl_status; uint8_t ep_csrl_status;
// uint8_t ep_csrh_status; // uint8_t ep_csrh_status;
struct usb_musb_chan *chan; struct musb_pipe *chan;
uint8_t ep_idx; uint8_t ep_idx;
uint8_t old_ep_idx; uint8_t old_ep_idx;
int result = 0; int result = 0;
@@ -1188,10 +1194,10 @@ void USBH_IRQHandler(void)
if (is & USB_IS_DISCON) { if (is & USB_IS_DISCON) {
if (usbh_get_port_connect_status(0) == false) { if (usbh_get_port_connect_status(0) == false) {
for (uint8_t ep_index = 0; ep_index < CONIFG_USB_MUSB_EP_NUM; ep_index++) { for (uint8_t ep_index = 0; ep_index < CONIFG_USB_MUSB_EP_NUM; ep_index++) {
if (g_usbhost.active_chan[ep_index]) { if (g_musb_hcd.active_chan[ep_index]) {
chan = (struct usb_musb_chan *)g_usbhost.active_chan[ep_index]; chan = (struct musb_pipe *)g_musb_hcd.active_chan[ep_index];
chan->result = -ENXIO; chan->result = -ENXIO;
usb_musb_chan_wakeup(chan); musb_pipe_wakeup(chan);
} }
} }
@@ -1230,7 +1236,7 @@ void USBH_IRQHandler(void)
txis &= ~(1 << ep_idx); txis &= ~(1 << ep_idx);
HWREGH(USB_BASE + MUSB_TXIS_OFFSET) = (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); USBC_SelectActiveEp(ep_idx);
@@ -1275,7 +1281,7 @@ void USBH_IRQHandler(void)
rxis &= ~(1 << ep_idx); rxis &= ~(1 << ep_idx);
HWREGH(USB_BASE + MUSB_RXIS_OFFSET) = (1 << ep_idx); // clear isr flag 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); USBC_SelectActiveEp(ep_idx);
@@ -1322,6 +1328,6 @@ chan_wait:
USBC_SelectActiveEp(old_ep_idx); USBC_SelectActiveEp(old_ep_idx);
if (chan) { if (chan) {
chan->result = result; chan->result = result;
usb_musb_chan_wakeup(chan); musb_pipe_wakeup(chan);
} }
} }

View File

@@ -20,11 +20,11 @@ struct usb_dc_ep_state {
}; };
/* Driver state */ /* Driver state */
struct usb_dc_config_priv { struct xxx_udc {
volatile uint8_t dev_addr; volatile uint8_t dev_addr;
struct usb_dc_ep_state in_ep[USB_NUM_BIDIR_ENDPOINTS]; /*!< IN endpoint parameters*/ 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 */ 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) __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) 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(); usb_dc_low_level_init();
return 0; 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); uint8_t ep_idx = USB_EP_GET_IDX(ep_cfg->ep_addr);
if (USB_EP_DIR_IS_OUT(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; g_xxx_udc.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_type = ep_cfg->ep_type;
} else { } else {
usb_dc_cfg.in_ep[ep_idx].ep_mps = ep_cfg->ep_mps; g_xxx_udc.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_type = ep_cfg->ep_type;
} }
return 0; 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; return 0;
} }
if (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 = usb_dc_cfg.in_ep[ep_idx].ep_mps; data_len = g_xxx_udc.in_ep[ep_idx].ep_mps;
} }
if (ret_bytes) { if (ret_bytes) {

View File

@@ -4,20 +4,25 @@
#define USBH_IRQHandler OTG_FS_IRQHandler #define USBH_IRQHandler OTG_FS_IRQHandler
#endif #endif
struct usb_xxx_priv { struct xxx_hcd {
volatile bool connected; /* Connected to device */ volatile bool connected; /* Connected to device */
volatile bool pscwait; /* True: Thread is waiting for a port event */ volatile bool pscwait; /* True: Thread is waiting for a port event */
usb_osal_sem_t exclsem; /* Support mutually exclusive access */ usb_osal_sem_t exclsem; /* Support mutually exclusive access */
} g_usbhost; } g_xxx_hcd;
__WEAK void usb_hc_low_level_init(void) __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(); usb_hc_low_level_init();
return 0; return 0;