replace speed reconfig with mult

This commit is contained in:
sakimisu
2023-03-12 15:04:21 +08:00
parent cda6e48fc1
commit 4cd9031d31
8 changed files with 70 additions and 76 deletions

View File

@@ -85,15 +85,15 @@ uint16_t usbh_get_frame_number(void);
int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf); int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf);
/** /**
* @brief reconfig control endpoint pipe. * @brief reconfig endpoint pipe.
* *
* @param pipe A memory allocated for pipe. * @param pipe A memory allocated for pipe.
* @param dev_addr device address. * @param dev_addr device address.
* @param ep_mps control endpoint max packet size. * @param ep_mps endpoint max packet size.
* @param speed port speed * @param mult endpoint additional transcation
* @return On success will return 0, and others indicate fail. * @return On success will return 0, and others indicate fail.
*/ */
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed); int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult);
/** /**
* @brief Allocate pipe for endpoint * @brief Allocate pipe for endpoint

View File

@@ -438,7 +438,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
ep_mps = ((struct usb_device_descriptor *)ep0_request_buffer)->bMaxPacketSize0; ep_mps = ((struct usb_device_descriptor *)ep0_request_buffer)->bMaxPacketSize0;
/* Reconfigure EP0 with the correct maximum packet size */ /* Reconfigure EP0 with the correct maximum packet size */
usbh_ep0_pipe_reconfigure(hport->ep0, 0, ep_mps, hport->speed); usbh_ep_pipe_reconfigure(hport->ep0, 0, ep_mps, 0);
#ifdef CONFIG_USBHOST_XHCI #ifdef CONFIG_USBHOST_XHCI
extern int usbh_get_xhci_devaddr(usbh_pipe_t * pipe); extern int usbh_get_xhci_devaddr(usbh_pipe_t * pipe);
@@ -478,7 +478,7 @@ int usbh_enumerate(struct usbh_hubport *hport)
hport->dev_addr = dev_addr; hport->dev_addr = dev_addr;
/* And reconfigure EP0 with the correct address */ /* And reconfigure EP0 with the correct address */
usbh_ep0_pipe_reconfigure(hport->ep0, dev_addr, ep_mps, hport->speed); usbh_ep_pipe_reconfigure(hport->ep0, dev_addr, ep_mps, 0);
/* Read the full device descriptor */ /* Read the full device descriptor */
setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_DEVICE; setup->bmRequestType = USB_REQUEST_DIR_IN | USB_REQUEST_STANDARD | USB_REQUEST_RECIPIENT_DEVICE;

View File

@@ -607,23 +607,12 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
return 0; return 0;
} }
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult)
{ {
struct chusb_pipe *ppipe = (struct chusb_pipe *)pipe; struct chusb_pipe *ppipe = (struct chusb_pipe *)pipe;
ppipe->dev_addr = dev_addr; ppipe->dev_addr = dev_addr;
ppipe->ep_mps = ep_mps; ppipe->ep_mps = ep_mps;
ppipe->speed = speed;
if (speed == USB_SPEED_HIGH) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_HIGH \r\n");
} else if (speed == USB_SPEED_FULL) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_FULL \r\n");
chusbh_set_self_speed(USB_SPEED_FULL);
} else if (speed == USB_SPEED_LOW) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_LOW \r\n");
chusbh_set_self_speed(USB_SPEED_LOW);
}
USBFS_HOST->DEV_ADDR = (USBFS_DEV_ADDR_OFFSET & USBFS_UDA_GP_BIT) | (dev_addr & USBFS_USB_ADDR_MASK); USBFS_HOST->DEV_ADDR = (USBFS_DEV_ADDR_OFFSET & USBFS_UDA_GP_BIT) | (dev_addr & USBFS_USB_ADDR_MASK);
return 0; return 0;
@@ -661,6 +650,15 @@ int usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_cfg)
ppipe->hport = ep_cfg->hport; ppipe->hport = ep_cfg->hport;
if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) { if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) {
if (ppipe->speed == USB_SPEED_HIGH) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_HIGH \r\n");
} else if (ppipe->speed == USB_SPEED_FULL) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_FULL \r\n");
chusbh_set_self_speed(USB_SPEED_FULL);
} else if (ppipe->speed == USB_SPEED_LOW) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_LOW \r\n");
chusbh_set_self_speed(USB_SPEED_LOW);
}
} else { } else {
if (ppipe->speed == USB_SPEED_HIGH) { if (ppipe->speed == USB_SPEED_HIGH) {
} else if (ppipe->speed == USB_SPEED_FULL) { } else if (ppipe->speed == USB_SPEED_FULL) {
@@ -842,7 +840,7 @@ static int8_t chusb_outpipe_irq_handler(uint8_t res_state)
} else { } else {
if (g_chusb_hcd.prv_set_zero == true) { if (g_chusb_hcd.prv_set_zero == true) {
/** /**
* It is unlikely to run here, * It is unlikely to run here,
* because the device can probably receive 0 length byte packets * because the device can probably receive 0 length byte packets
*/ */
urb->errorcode = 0; urb->errorcode = 0;
@@ -1121,7 +1119,7 @@ static int8_t chusb_inpipe_irq_handler(uint8_t res_state)
/*!< Ctrol endpoint */ /*!< Ctrol endpoint */
/** /**
* Status stage * Status stage
* *
* Setup ---> out data ---> in status stage * Setup ---> out data ---> in status stage
*/ */
if ((g_chusb_hcd.ep0_state == USB_EP0_STATE_IN_STATUS) && (rx_len == 0)) { if ((g_chusb_hcd.ep0_state == USB_EP0_STATE_IN_STATUS) && (rx_len == 0)) {
@@ -1252,37 +1250,37 @@ void USBH_IRQHandler(void)
} }
} else if (intflag & USBFS_UIF_DETECT) { } else if (intflag & USBFS_UIF_DETECT) {
if (USBFS_HOST->MIS_ST & USBFS_UMS_DEV_ATTACH) { if (USBFS_HOST->MIS_ST & USBFS_UMS_DEV_ATTACH) {
USB_LOG_INFO("Dev connect \r\n"); USB_LOG_INFO("Dev connect \r\n");
g_chusb_hcd.port_csc = 1; g_chusb_hcd.port_csc = 1;
g_chusb_hcd.port_pec = 1; g_chusb_hcd.port_pec = 1;
g_chusb_hcd.port_pe = 1; g_chusb_hcd.port_pe = 1;
usbh_roothub_thread_wakeup(1); usbh_roothub_thread_wakeup(1);
} else { } else {
USB_LOG_INFO("Dev remove \r\n"); USB_LOG_INFO("Dev remove \r\n");
/** /**
* Device remove * Device remove
* Disable port and stop send sof * Disable port and stop send sof
*/ */
USBFS_HOST->HOST_SETUP &= ~USBFS_UH_SOF_EN; USBFS_HOST->HOST_SETUP &= ~USBFS_UH_SOF_EN;
USBFS_HOST->HOST_CTRL &= ~USBFS_UH_PORT_EN; USBFS_HOST->HOST_CTRL &= ~USBFS_UH_PORT_EN;
if (g_chusb_hcd.main_pipe_using) { if (g_chusb_hcd.main_pipe_using) {
g_chusb_hcd.main_pipe_using = false; g_chusb_hcd.main_pipe_using = false;
} }
g_chusb_hcd.port_csc = 1; g_chusb_hcd.port_csc = 1;
g_chusb_hcd.port_pec = 1; g_chusb_hcd.port_pec = 1;
g_chusb_hcd.port_pe = 0; g_chusb_hcd.port_pe = 0;
for (uint8_t index = 0; index < CONFIG_USBHOST_PIPE_NUM; index++) { for (uint8_t index = 0; index < CONFIG_USBHOST_PIPE_NUM; index++) {
for (uint8_t j = 0; j < 2; j++) { for (uint8_t j = 0; j < 2; j++) {
struct chusb_pipe *pipe = &g_chusb_hcd.pipe_pool[index][j]; struct chusb_pipe *pipe = &g_chusb_hcd.pipe_pool[index][j];
struct usbh_urb *urb = pipe->urb; struct usbh_urb *urb = pipe->urb;
if (pipe->waiter) { if (pipe->waiter) {
pipe->waiter = false; pipe->waiter = false;
urb->errorcode = -ESHUTDOWN; urb->errorcode = -ESHUTDOWN;
usb_osal_sem_give(pipe->waitsem); usb_osal_sem_give(pipe->waitsem);
}
} }
} }
usbh_roothub_thread_wakeup(1); }
usbh_roothub_thread_wakeup(1);
} }
USBFS_HOST->INT_FG = USBFS_UIF_DETECT; USBFS_HOST->INT_FG = USBFS_UIF_DETECT;
} else { } else {
@@ -1293,8 +1291,8 @@ void USBH_IRQHandler(void)
return; return;
pipe_wait: pipe_wait:
/** /**
* enerally, only errors can arrive here. * enerally, only errors can arrive here.
* After testing, most cases arrive here because of the problem of the DATA PID, * After testing, most cases arrive here because of the problem of the DATA PID,
* but the transmission will be completed correctly next time. * but the transmission will be completed correctly next time.
*/ */
chusb_pipe_waitup(g_chusb_hcd.current_pipe, true); chusb_pipe_waitup(g_chusb_hcd.current_pipe, true);

View File

@@ -669,24 +669,13 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
return 0; return 0;
} }
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed)
{ {
struct chusb_pipe *ppipe = (struct chusb_pipe *)pipe; struct chusb_pipe *ppipe = (struct chusb_pipe *)pipe;
ppipe->dev_addr = dev_addr; ppipe->dev_addr = dev_addr;
ppipe->ep_mps = ep_mps; ppipe->ep_mps = ep_mps;
ppipe->speed = speed;
if (speed == USB_SPEED_HIGH) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_HIGH \r\n");
chusbh_set_self_speed(USB_SPEED_HIGH);
} else if (speed == USB_SPEED_FULL) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_FULL \r\n");
chusbh_set_self_speed(USB_SPEED_FULL);
} else if (speed == USB_SPEED_LOW) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_LOW \r\n");
chusbh_set_self_speed(USB_SPEED_LOW);
}
USBHS_HOST->DEV_AD = dev_addr & 0x7f; USBHS_HOST->DEV_AD = dev_addr & 0x7f;
return 0; return 0;
} }
@@ -723,6 +712,16 @@ int usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_cfg)
ppipe->hport = ep_cfg->hport; ppipe->hport = ep_cfg->hport;
if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) { if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) {
if (ppipe->speed == USB_SPEED_HIGH) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_HIGH \r\n");
chusbh_set_self_speed(USB_SPEED_HIGH);
} else if (ppipe->speed == USB_SPEED_FULL) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_FULL \r\n");
chusbh_set_self_speed(USB_SPEED_FULL);
} else if (ppipe->speed == USB_SPEED_LOW) {
USB_LOG_INFO("ep0 reconfigure USB_SPEED_LOW \r\n");
chusbh_set_self_speed(USB_SPEED_LOW);
}
} else { } else {
if (ppipe->speed == USB_SPEED_HIGH) { if (ppipe->speed == USB_SPEED_HIGH) {
if ((ep_cfg->ep_type == USB_ENDPOINT_TYPE_ISOCHRONOUS) || if ((ep_cfg->ep_type == USB_ENDPOINT_TYPE_ISOCHRONOUS) ||
@@ -914,7 +913,7 @@ static int8_t chusb_outpipe_irq_handler(uint8_t res_state)
urb->errorcode = 0; urb->errorcode = 0;
if (g_chusb_hcd.prv_set_zero == true) { if (g_chusb_hcd.prv_set_zero == true) {
/** /**
* It is unlikely to run here, * It is unlikely to run here,
* because the device can probably receive 0 length byte packets * because the device can probably receive 0 length byte packets
*/ */
g_chusb_hcd.prv_set_zero = false; g_chusb_hcd.prv_set_zero = false;
@@ -1172,7 +1171,7 @@ static int8_t chusb_inpipe_irq_handler(uint8_t res_state)
/*!< Ctrol endpoint */ /*!< Ctrol endpoint */
/** /**
* Status stage * Status stage
* *
* Setup ---> out data ---> in status stage * Setup ---> out data ---> in status stage
*/ */
if ((g_chusb_hcd.ep0_state == USB_EP0_STATE_IN_STATUS) && (rx_len == 0)) { if ((g_chusb_hcd.ep0_state == USB_EP0_STATE_IN_STATUS) && (rx_len == 0)) {

View File

@@ -676,7 +676,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
return 0; return 0;
} }
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult)
{ {
struct dwc2_pipe *chan; struct dwc2_pipe *chan;
@@ -684,7 +684,6 @@ int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps
chan->dev_addr = dev_addr; chan->dev_addr = dev_addr;
chan->ep_mps = ep_mps; chan->ep_mps = ep_mps;
chan->speed = speed;
return 0; return 0;
} }

View File

@@ -959,13 +959,13 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
return 0; return 0;
} }
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult)
{ {
struct ehci_pipe *ppipe = (struct ehci_pipe *)pipe; struct ehci_pipe *ppipe = (struct ehci_pipe *)pipe;
ppipe->dev_addr = dev_addr; ppipe->dev_addr = dev_addr;
ppipe->ep_mps = ep_mps; ppipe->ep_mps = ep_mps;
ppipe->speed = speed; ppipe->mult = mult;
return 0; return 0;
} }

View File

@@ -551,21 +551,13 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
return 0; return 0;
} }
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult)
{ {
struct musb_pipe *ppipe = (struct musb_pipe *)pipe; struct musb_pipe *ppipe = (struct musb_pipe *)pipe;
ppipe->dev_addr = dev_addr; ppipe->dev_addr = dev_addr;
ppipe->ep_mps = ep_mps; ppipe->ep_mps = ep_mps;
if (speed == USB_SPEED_HIGH) {
ppipe->speed = USB_TYPE0_SPEED_HIGH;
} else if (speed == USB_SPEED_FULL) {
ppipe->speed = USB_TYPE0_SPEED_FULL;
} else if (speed == USB_SPEED_LOW) {
ppipe->speed = USB_TYPE0_SPEED_LOW;
}
return 0; return 0;
} }
@@ -605,6 +597,13 @@ int usbh_pipe_alloc(usbh_pipe_t *pipe, const struct usbh_endpoint_cfg *ep_cfg)
ppipe->hport = ep_cfg->hport; ppipe->hport = ep_cfg->hport;
if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) { if (ep_cfg->ep_type == USB_ENDPOINT_TYPE_CONTROL) {
if (ppipe->speed == USB_SPEED_HIGH) {
ppipe->speed = USB_TYPE0_SPEED_HIGH;
} else if (ppipe->speed == USB_SPEED_FULL) {
ppipe->speed = USB_TYPE0_SPEED_FULL;
} else if (ppipe->speed == USB_SPEED_LOW) {
ppipe->speed = USB_TYPE0_SPEED_LOW;
}
} else { } else {
if (ppipe->speed == USB_SPEED_HIGH) { if (ppipe->speed == USB_SPEED_HIGH) {
ppipe->speed = USB_TXTYPE1_SPEED_HIGH; ppipe->speed = USB_TXTYPE1_SPEED_HIGH;

View File

@@ -185,7 +185,7 @@ int usbh_roothub_control(struct usb_setup_packet *setup, uint8_t *buf)
return 0; return 0;
} }
int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t speed) int usbh_ep_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps, uint8_t mult)
{ {
struct dwc2_pipe *chan; struct dwc2_pipe *chan;
@@ -193,7 +193,6 @@ int usbh_ep0_pipe_reconfigure(usbh_pipe_t pipe, uint8_t dev_addr, uint8_t ep_mps
chan->dev_addr = dev_addr; chan->dev_addr = dev_addr;
chan->ep_mps = ep_mps; chan->ep_mps = ep_mps;
chan->speed = speed;
return 0; return 0;
} }