re-add sof event

This commit is contained in:
hathach 2024-05-21 18:34:25 +07:00
parent 953e3bd634
commit 4a5b190a22
No known key found for this signature in database
GPG Key ID: 26FAB84F615C3C52
2 changed files with 38 additions and 27 deletions

View File

@ -63,8 +63,13 @@
// USB DEV AD
#define USBHS_DEV_AD_OFFSET 0x03
// USB FRAME_NO
#define USBHS_FRAME_NO_OFFSET 0x04
#define USBHS_FRAME_NO_NUM_MASK (0x7FF)
#define USBHS_FRAME_NO_MICROFRAME_SHIFT (11)
#define USBHS_FRAME_NO_MICROFRAME_MASK (0x7 << USBHS_FRAME_NO_MICROFRAME_SHIFT)
// USB SUSPEND
#define USBHS_SUSPEND_OFFSET 0x06
#define USBHS_DEV_REMOTE_WAKEUP (1 << 2)

View File

@ -336,13 +336,18 @@ void dcd_int_handler(uint8_t rhport) {
uint8_t int_status = USBHSD->INT_ST;
if (int_flag & (USBHS_ISO_ACT_FLAG | USBHS_TRANSFER_FLAG)) {
uint8_t const rx_token = int_status & MASK_UIS_TOKEN;
uint8_t const token = int_status & MASK_UIS_TOKEN;
if (token == USBHS_TOKEN_PID_SOF) {
uint32_t frame_count = USBHSD->FRAME_NO & USBHS_FRAME_NO_NUM_MASK;
dcd_event_sof(rhport, frame_count, true);
}else {
uint8_t const ep_num = int_status & MASK_UIS_ENDP;
tusb_dir_t const ep_dir = (rx_token == USBHS_TOKEN_PID_IN) ? TUSB_DIR_IN : TUSB_DIR_OUT;
tusb_dir_t const ep_dir = (token == USBHS_TOKEN_PID_IN) ? TUSB_DIR_IN : TUSB_DIR_OUT;
uint8_t const ep_addr = tu_edpt_addr(ep_num, ep_dir);
xfer_ctl_t* xfer = XFER_CTL_BASE(ep_num, ep_dir);
if (rx_token == USBHS_TOKEN_PID_OUT) {
if (token == USBHS_TOKEN_PID_OUT) {
uint16_t rx_len = USBHSD->RX_LEN;
if (ep_num == 0) {
@ -353,11 +358,11 @@ void dcd_int_handler(uint8_t rhport) {
if (rx_len < xfer->max_size) {
xfer->is_last_packet = true;
}
} else if (rx_token == USBHS_TOKEN_PID_IN) {
} else if (token == USBHS_TOKEN_PID_IN) {
if (xfer->is_iso && xfer->is_last_packet) {
/* Disable EP to avoid ISO_ACT interrupt generation */
USBHSD->ENDP_CONFIG &= ~(USBHS_EP0_T_EN << ep_num);
}else {
} else {
// Do nothing, no need to update xfer->is_last_packet, it is already updated in xfer_data_packet
}
}
@ -369,6 +374,7 @@ void dcd_int_handler(uint8_t rhport) {
/* prepare next part of packet to xref */
xfer_data_packet(ep_num, ep_dir, xfer);
}
}
USBHSD->INT_FG = (int_flag & (USBHS_ISO_ACT_FLAG | USBHS_TRANSFER_FLAG)); /* Clear flag */
} else if (int_flag & USBHS_SETUP_FLAG) {