From 13613eafb70acd028572305b3e0b9064f905b835 Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 11 May 2021 18:11:46 +0700 Subject: [PATCH] correct ehci control endpoint address report on xfer complete improve host log --- src/host/usbh.c | 9 ++++++--- src/host/usbh_control.c | 1 + src/portable/ehci/ehci.c | 15 ++++++++------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/host/usbh.c b/src/host/usbh.c index 5132d7e9..88e5c02a 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -626,10 +626,11 @@ static bool enum_hub_get_status0_complete(uint8_t dev_addr, tusb_control_request static bool enum_request_set_addr(void) { // Set Address - TU_LOG2("Set Address \r\n"); uint8_t const new_addr = get_new_address(); TU_ASSERT(new_addr <= CFG_TUSB_HOST_DEVICE_MAX); // TODO notify application we reach max devices + TU_LOG2("Set Address = %d\r\n", new_addr); + usbh_device_t* dev0 = &_usbh_devices[0]; usbh_device_t* new_dev = &_usbh_devices[new_addr]; @@ -783,6 +784,7 @@ static bool enum_set_address_complete(uint8_t dev_addr, tusb_control_request_t c TU_ASSERT ( usbh_pipe_control_open(new_addr, new_dev->ep0_packet_size) ); // Get full device descriptor + TU_LOG2("Get Device Descriptor\r\n"); tusb_control_request_t const new_request = { .bmRequestType_bit = @@ -849,7 +851,8 @@ static bool enum_get_9byte_config_desc_complete(uint8_t dev_addr, tusb_control_r TU_ASSERT(total_len <= CFG_TUSB_HOST_ENUM_BUFFER_SIZE); - //Get full configuration descriptor + // Get full configuration descriptor + TU_LOG2("Get Configuration Descriptor\r\n"); tusb_control_request_t const new_request = { .bmRequestType_bit = @@ -879,7 +882,7 @@ static bool enum_get_config_desc_complete(uint8_t dev_addr, tusb_control_request // Driver open aren't allowed to make any usb transfer yet parse_configuration_descriptor(dev_addr, (tusb_desc_configuration_t*) _usbh_ctrl_buf); - TU_LOG2("Set Configuration Descriptor\r\n"); + TU_LOG2("Set Configuration = %d\r\n", CONFIG_NUM); tusb_control_request_t const new_request = { .bmRequestType_bit = diff --git a/src/host/usbh_control.c b/src/host/usbh_control.c index de55bd5e..2b9f4779 100644 --- a/src/host/usbh_control.c +++ b/src/host/usbh_control.c @@ -80,6 +80,7 @@ bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, static void _xfer_complete(uint8_t dev_addr, xfer_result_t result) { + TU_LOG2("\r\n"); if (_ctrl_xfer.complete_cb) _ctrl_xfer.complete_cb(dev_addr, &_ctrl_xfer.request, result); } diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c index 484e4960..eab1f892 100644 --- a/src/portable/ehci/ehci.c +++ b/src/portable/ehci/ehci.c @@ -513,18 +513,19 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) // free all TDs from the head td to the first active TD while(p_qhd->p_qtd_list_head != NULL && !p_qhd->p_qtd_list_head->active) { - // TD need to be freed and removed from qhd, before invoking callback - bool is_ioc = (p_qhd->p_qtd_list_head->int_on_complete != 0); - p_qhd->total_xferred_bytes += p_qhd->p_qtd_list_head->expected_bytes - p_qhd->p_qtd_list_head->total_bytes; + ehci_qtd_t * volatile qtd = (ehci_qtd_t * volatile) p_qhd->p_qtd_list_head; + bool const is_ioc = (qtd->int_on_complete != 0); + uint8_t const ep_addr = tu_edpt_addr(p_qhd->ep_number, qtd->pid == EHCI_PID_IN ? 1 : 0); - p_qhd->p_qtd_list_head->used = 0; // free QTD + p_qhd->total_xferred_bytes += qtd->expected_bytes - qtd->total_bytes; + + // TD need to be freed and removed from qhd, before invoking callback + qtd->used = 0; // free QTD qtd_remove_1st_from_qhd(p_qhd); if (is_ioc) { - // end of request - // call USBH callback - hcd_event_xfer_complete(p_qhd->dev_addr, tu_edpt_addr(p_qhd->ep_number, p_qhd->pid == EHCI_PID_IN ? 1 : 0), p_qhd->total_xferred_bytes, XFER_RESULT_SUCCESS, true); + hcd_event_xfer_complete(p_qhd->dev_addr, ep_addr, p_qhd->total_xferred_bytes, XFER_RESULT_SUCCESS, true); p_qhd->total_xferred_bytes = 0; } }