[bsp/at32] update usb host driver (#8560)
This commit is contained in:
parent
1f69929b0b
commit
b14f299e7d
|
@ -6,6 +6,7 @@
|
|||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2023-02-28 leo first version
|
||||
* 2024-02-26 shelton update drv_pipe_xfer
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
@ -107,9 +108,8 @@ static rt_err_t drv_reset_port(rt_uint8_t port)
|
|||
static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbytes, int timeouts)
|
||||
{
|
||||
int timeout = timeouts;
|
||||
volatile int retry = 0;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(!connect_status)
|
||||
{
|
||||
return -1;
|
||||
|
@ -216,31 +216,22 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
|
|||
p_usbotg_instance->p_otg_core->host.hch[pipe->pipe_index].trans_count = 0;
|
||||
p_usbotg_instance->p_otg_core->host.hch[pipe->pipe_index].state = HCH_IDLE;
|
||||
|
||||
__resend:
|
||||
/* data in/out for host */
|
||||
usbh_in_out_request((&p_usbotg_instance->p_otg_core->host), pipe->pipe_index);
|
||||
|
||||
retry = 0xFFFFFFFF;
|
||||
while(retry --)
|
||||
{
|
||||
rt_completion_wait(&urb_completion, timeout);
|
||||
rt_thread_mdelay(1);
|
||||
|
||||
if(usbh_get_status((&p_usbotg_instance->p_otg_core->host), pipe->pipe_index) == HCH_NAK)
|
||||
if(usbh_get_urb_status((&p_usbotg_instance->p_otg_core->host), pipe->pipe_index) == URB_NOTREADY)
|
||||
{
|
||||
LOG_D("nak");
|
||||
if (pipe->ep.bmAttributes == USB_EP_ATTR_INT)
|
||||
if((pipe->ep.bEndpointAddress & 0x80) == 0)
|
||||
{
|
||||
rt_thread_delay((pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) > 0 ? (pipe->ep.bInterval * RT_TICK_PER_SECOND / 1000) : 1);
|
||||
goto __resend;
|
||||
}
|
||||
usb_hch_halt((&p_usbotg_instance->p_otg_core->host)->usb_reg, pipe->pipe_index);
|
||||
|
||||
usbh_hc_open(&p_usbotg_instance->p_otg_core->host,
|
||||
pipe->pipe_index,
|
||||
pipe->ep.bEndpointAddress,
|
||||
pipe->inst->address,
|
||||
pipe->ep.bmAttributes,
|
||||
pipe->ep.wMaxPacketSize,
|
||||
USB_PRTSPD_FULL_SPEED);
|
||||
continue;
|
||||
}
|
||||
else if (usbh_get_status(&p_usbotg_instance->p_otg_core->host, pipe->pipe_index) == HCH_STALL)
|
||||
else if (usbh_get_urb_status(&p_usbotg_instance->p_otg_core->host, pipe->pipe_index) == URB_STALL)
|
||||
{
|
||||
LOG_D("stall");
|
||||
pipe->status = UPIPE_STATUS_STALL;
|
||||
|
@ -250,7 +241,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
else if (usbh_get_status(&p_usbotg_instance->p_otg_core->host, pipe->pipe_index) == URB_ERROR)
|
||||
else if (usbh_get_urb_status(&p_usbotg_instance->p_otg_core->host, pipe->pipe_index) == URB_ERROR)
|
||||
{
|
||||
LOG_D("error");
|
||||
pipe->status = UPIPE_STATUS_ERROR;
|
||||
|
@ -260,7 +251,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
|
|||
}
|
||||
return -1;
|
||||
}
|
||||
else if(URB_DONE == usbh_get_urb_status(&p_usbotg_instance->p_otg_core->host, pipe->pipe_index))
|
||||
else if (usbh_get_urb_status(&p_usbotg_instance->p_otg_core->host, pipe->pipe_index) == URB_DONE)
|
||||
{
|
||||
LOG_D("ok");
|
||||
pipe->status = UPIPE_STATUS_OK;
|
||||
|
@ -268,7 +259,7 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
|
|||
{
|
||||
pipe->callback(pipe);
|
||||
}
|
||||
size_t size = (&p_usbotg_instance->p_otg_core->host)->hch[pipe->pipe_index].trans_count;
|
||||
rt_size_t size = (&p_usbotg_instance->p_otg_core->host)->hch[pipe->pipe_index].trans_count;
|
||||
if (pipe->ep.bEndpointAddress & 0x80)
|
||||
{
|
||||
return size;
|
||||
|
@ -279,8 +270,8 @@ static int drv_pipe_xfer(upipe_t pipe, rt_uint8_t token, void *buffer, int nbyte
|
|||
}
|
||||
return nbytes;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static rt_uint16_t pipe_index = 0;
|
||||
|
|
Loading…
Reference in New Issue