fix(usb/host): Correctly parse bInterval field in HighSpeed EP descriptors

For LS and FS interrupt endpoint: interval = bInterval
For isochronous and HS interrupt endpoint: interval = 2^(bInterval-1)
This commit is contained in:
Tomas Rezucha 2023-12-06 18:05:41 +01:00 committed by Darian Leung
parent 0ce4aa114e
commit 1e2c271bd0
No known key found for this signature in database
GPG Key ID: 8AC9127B487AA4EF
3 changed files with 21 additions and 34 deletions

View File

@ -142,7 +142,7 @@ typedef struct {
uint32_t val; uint32_t val;
}; };
struct { struct {
usb_hal_interval_t interval; /**< The interval of the endpoint */ unsigned int interval; /**< The interval of the endpoint in frames (FS) or microframes (HS) */
uint32_t phase_offset_frames; /**< Phase offset in number of frames */ uint32_t phase_offset_frames; /**< Phase offset in number of frames */
} periodic; /**< Characteristic for periodic (interrupt/isochronous) endpoints only */ } periodic; /**< Characteristic for periodic (interrupt/isochronous) endpoints only */
} usb_dwc_hal_ep_char_t; } usb_dwc_hal_ep_char_t;

View File

@ -51,19 +51,6 @@ typedef enum {
USB_HAL_FRAME_LIST_LEN_64 = 64, USB_HAL_FRAME_LIST_LEN_64 = 64,
} usb_hal_frame_list_len_t; } usb_hal_frame_list_len_t;
/**
* @brief Support intervals in number of USB frames (i.e., 1ms)
*/
typedef enum {
USB_HAL_INTERVAL_1 = 1,
USB_HAL_INTERVAL_2 = 2,
USB_HAL_INTERVAL_4 = 4,
USB_HAL_INTERVAL_8 = 8,
USB_HAL_INTERVAL_16 = 16,
USB_HAL_INTERVAL_32 = 32,
USB_HAL_INTERVAL_64 = 64,
} usb_hal_interval_t;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1578,31 +1578,31 @@ static void pipe_set_ep_char(const hcd_pipe_config_t *pipe_config, usb_transfer_
// Calculate the pipe's interval in terms of USB frames // Calculate the pipe's interval in terms of USB frames
// @see USB-OTG programming guide chapter 6.5 for more information // @see USB-OTG programming guide chapter 6.5 for more information
if (type == USB_TRANSFER_TYPE_INTR || type == USB_TRANSFER_TYPE_ISOCHRONOUS) { if (type == USB_TRANSFER_TYPE_INTR || type == USB_TRANSFER_TYPE_ISOCHRONOUS) {
unsigned int interval_frames; // Convert bInterval field to real value
unsigned int xfer_list_len; // @see USB 2.0 specs, Table 9-13
if (type == USB_TRANSFER_TYPE_INTR) { unsigned int interval_value;
interval_frames = pipe_config->ep_desc->bInterval; if (type == USB_TRANSFER_TYPE_INTR && pipe_config->dev_speed != USB_SPEED_HIGH) {
xfer_list_len = XFER_LIST_LEN_INTR; interval_value = pipe_config->ep_desc->bInterval;
} else { } else {
interval_frames = (1 << (pipe_config->ep_desc->bInterval - 1)); interval_value = (1 << (pipe_config->ep_desc->bInterval - 1));
xfer_list_len = XFER_LIST_LEN_ISOC;
} }
// Round down interval to nearest power of 2 // Round down interval to nearest power of 2
if (interval_frames >= 32) { if (interval_value >= 32) {
interval_frames = 32; interval_value = 32;
} else if (interval_frames >= 16) { } else if (interval_value >= 16) {
interval_frames = 16; interval_value = 16;
} else if (interval_frames >= 8) { } else if (interval_value >= 8) {
interval_frames = 8; interval_value = 8;
} else if (interval_frames >= 4) { } else if (interval_value >= 4) {
interval_frames = 4; interval_value = 4;
} else if (interval_frames >= 2) { } else if (interval_value >= 2) {
interval_frames = 2; interval_value = 2;
} else if (interval_frames >= 1) { } else if (interval_value >= 1) {
interval_frames = 1; interval_value = 1;
} }
ep_char->periodic.interval = interval_frames; ep_char->periodic.interval = interval_value;
// We are the Nth pipe to be allocated. Use N as a phase offset // We are the Nth pipe to be allocated. Use N as a phase offset
unsigned int xfer_list_len = (type == USB_TRANSFER_TYPE_INTR) ? XFER_LIST_LEN_INTR : XFER_LIST_LEN_ISOC;
ep_char->periodic.phase_offset_frames = pipe_idx & (xfer_list_len - 1); ep_char->periodic.phase_offset_frames = pipe_idx & (xfer_list_len - 1);
} else { } else {
ep_char->periodic.interval = 0; ep_char->periodic.interval = 0;