mirror of
https://github.com/hathach/tinyusb.git
synced 2025-05-09 15:21:21 +08:00
minor clean up
This commit is contained in:
parent
0d2078d295
commit
0cce42fcc6
@ -246,32 +246,37 @@ static void __tusb_irq_path_func(dcd_rp2040_irq)(void)
|
|||||||
{
|
{
|
||||||
uint32_t const status = usb_hw->ints;
|
uint32_t const status = usb_hw->ints;
|
||||||
uint32_t handled = 0;
|
uint32_t handled = 0;
|
||||||
bool keep_sof_alive = false;
|
|
||||||
|
|
||||||
if (status & USB_INTF_DEV_SOF_BITS)
|
if (status & USB_INTF_DEV_SOF_BITS)
|
||||||
{
|
{
|
||||||
|
bool keep_sof_alive = false;
|
||||||
|
|
||||||
handled |= USB_INTF_DEV_SOF_BITS;
|
handled |= USB_INTF_DEV_SOF_BITS;
|
||||||
|
|
||||||
#if TUD_OPT_RP2040_USB_DEVICE_UFRAME_FIX
|
#if TUD_OPT_RP2040_USB_DEVICE_UFRAME_FIX
|
||||||
last_sof = time_us_32();
|
last_sof = time_us_32();
|
||||||
|
|
||||||
for (uint8_t i = 0; i < USB_MAX_ENDPOINTS; i++) {
|
for (uint8_t i = 0; i < USB_MAX_ENDPOINTS; i++)
|
||||||
|
{
|
||||||
struct hw_endpoint *ep = hw_endpoint_get_by_num(i, TUSB_DIR_IN);
|
struct hw_endpoint *ep = hw_endpoint_get_by_num(i, TUSB_DIR_IN);
|
||||||
hw_endpoint_lock_update(ep, 1);
|
hw_endpoint_lock_update(ep, 1);
|
||||||
|
|
||||||
// Bulk IN endpoint in a transfer?
|
// Bulk IN endpoint in a transfer?
|
||||||
if (rp2040_ep_needs_sof(ep) && ep->active)
|
if (rp2040_ep_needs_sof(ep) && ep->active) keep_sof_alive = true;
|
||||||
keep_sof_alive = true;
|
|
||||||
// Deferred enable?
|
// Deferred enable?
|
||||||
if (ep->pending) {
|
if (ep->pending)
|
||||||
|
{
|
||||||
hw_endpoint_start_next_buffer(ep);
|
hw_endpoint_start_next_buffer(ep);
|
||||||
ep->pending = 0;
|
ep->pending = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
hw_endpoint_lock_update(ep, -1);
|
hw_endpoint_lock_update(ep, -1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// disable SOF interrupt if it is used for RESUME in remote wakeup
|
// disable SOF interrupt if it is used for RESUME in remote wakeup
|
||||||
if (!keep_sof_alive && !_sof_enable)
|
if (!keep_sof_alive && !_sof_enable) usb_hw_clear->inte = USB_INTS_DEV_SOF_BITS;
|
||||||
usb_hw_clear->inte = USB_INTS_DEV_SOF_BITS;
|
|
||||||
|
|
||||||
dcd_event_sof(0, usb_hw->sof_rd & USB_SOF_RD_BITS, true);
|
dcd_event_sof(0, usb_hw->sof_rd & USB_SOF_RD_BITS, true);
|
||||||
}
|
}
|
||||||
|
@ -57,13 +57,14 @@ bool rp2040_critical_frame_period(struct hw_endpoint *ep)
|
|||||||
{
|
{
|
||||||
uint32_t delta;
|
uint32_t delta;
|
||||||
|
|
||||||
if (usb_hw->main_ctrl & USB_MAIN_CTRL_HOST_NDEVICE_BITS)
|
if (usb_hw->main_ctrl & USB_MAIN_CTRL_HOST_NDEVICE_BITS) return false;
|
||||||
return false;
|
|
||||||
|
|
||||||
if (tu_edpt_dir(ep->ep_addr) == TUSB_DIR_OUT ||
|
if (tu_edpt_dir(ep->ep_addr) == TUSB_DIR_OUT ||
|
||||||
ep->transfer_type == TUSB_XFER_INTERRUPT ||
|
ep->transfer_type == TUSB_XFER_INTERRUPT ||
|
||||||
ep->transfer_type == TUSB_XFER_ISOCHRONOUS)
|
ep->transfer_type == TUSB_XFER_ISOCHRONOUS)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/* Avoid the last 200us (uframe 6.5-7) of a frame, up to the EOF2 point.
|
/* Avoid the last 200us (uframe 6.5-7) of a frame, up to the EOF2 point.
|
||||||
* The device state machine cannot recover from receiving an incorrect PID
|
* The device state machine cannot recover from receiving an incorrect PID
|
||||||
@ -78,10 +79,8 @@ bool rp2040_critical_frame_period(struct hw_endpoint *ep)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool rp2040_ep_needs_sof(struct hw_endpoint *ep) {
|
bool rp2040_ep_needs_sof(struct hw_endpoint *ep) {
|
||||||
if (tu_edpt_dir(ep->ep_addr) == TUSB_DIR_IN &&
|
return (tu_edpt_dir(ep->ep_addr) == TUSB_DIR_IN &&
|
||||||
ep->transfer_type == TUSB_XFER_BULK)
|
ep->transfer_type == TUSB_XFER_BULK);
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -115,12 +114,15 @@ void __tusb_irq_path_func(hw_endpoint_reset_transfer)(struct hw_endpoint *ep)
|
|||||||
ep->user_buf = 0;
|
ep->user_buf = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void __tusb_irq_path_func(_hw_endpoint_buffer_control_update32)(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask) {
|
void __tusb_irq_path_func(_hw_endpoint_buffer_control_update32)(struct hw_endpoint *ep, uint32_t and_mask, uint32_t or_mask)
|
||||||
|
{
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
|
|
||||||
if ( and_mask )
|
if ( and_mask )
|
||||||
{
|
{
|
||||||
value = *ep->buffer_control & and_mask;
|
value = *ep->buffer_control & and_mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( or_mask )
|
if ( or_mask )
|
||||||
{
|
{
|
||||||
value |= or_mask;
|
value |= or_mask;
|
||||||
@ -146,6 +148,7 @@ void __tusb_irq_path_func(_hw_endpoint_buffer_control_update32)(struct hw_endpoi
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*ep->buffer_control = value;
|
*ep->buffer_control = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,13 +250,18 @@ void hw_endpoint_xfer_start(struct hw_endpoint *ep, uint8_t *buffer, uint16_t to
|
|||||||
ep->user_buf = buffer;
|
ep->user_buf = buffer;
|
||||||
|
|
||||||
if (rp2040_ep_needs_sof(ep))
|
if (rp2040_ep_needs_sof(ep))
|
||||||
|
{
|
||||||
usb_hw_set->inte = USB_INTS_DEV_SOF_BITS;
|
usb_hw_set->inte = USB_INTS_DEV_SOF_BITS;
|
||||||
|
}
|
||||||
|
|
||||||
if(!rp2040_critical_frame_period(ep)) {
|
if(!rp2040_critical_frame_period(ep))
|
||||||
|
{
|
||||||
hw_endpoint_start_next_buffer(ep);
|
hw_endpoint_start_next_buffer(ep);
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
ep->pending = 1;
|
ep->pending = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hw_endpoint_lock_update(ep, -1);
|
hw_endpoint_lock_update(ep, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ typedef struct hw_endpoint
|
|||||||
|
|
||||||
// Transfer scheduled but not active
|
// Transfer scheduled but not active
|
||||||
uint8_t pending;
|
uint8_t pending;
|
||||||
|
|
||||||
#if CFG_TUH_ENABLED
|
#if CFG_TUH_ENABLED
|
||||||
// Only needed for host
|
// Only needed for host
|
||||||
uint8_t dev_addr;
|
uint8_t dev_addr;
|
||||||
@ -89,6 +90,7 @@ typedef struct hw_endpoint
|
|||||||
// If interrupt endpoint
|
// If interrupt endpoint
|
||||||
uint8_t interrupt_num;
|
uint8_t interrupt_num;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} hw_endpoint_t;
|
} hw_endpoint_t;
|
||||||
|
|
||||||
#if !TUD_OPT_RP2040_USB_DEVICE_UFRAME_FIX
|
#if !TUD_OPT_RP2040_USB_DEVICE_UFRAME_FIX
|
||||||
|
Loading…
x
Reference in New Issue
Block a user