From dffe9b335ee38a7720adff9a819f17b2899e38d1 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 20:26:47 +0700 Subject: [PATCH] clean up host pipe api --- examples/host/cdc_msc_hid/src/tusb_config.h | 2 +- src/class/cdc/cdc_host.c | 4 +- src/class/msc/msc_host.c | 2 +- src/host/ehci/ehci.c | 43 +++++++-------------- src/host/hcd.h | 5 +-- src/host/hub.c | 2 +- src/host/ohci/ohci.c | 12 ------ 7 files changed, 19 insertions(+), 51 deletions(-) diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h index be584b181..07764fa90 100644 --- a/examples/host/cdc_msc_hid/src/tusb_config.h +++ b/examples/host/cdc_msc_hid/src/tusb_config.h @@ -80,7 +80,7 @@ // DEVICE CONFIGURATION //-------------------------------------------------------------------- -#define CFG_TUH_HUB 1 // not tested +#define CFG_TUH_HUB 1 #define CFG_TUH_CDC 1 #define CFG_TUH_HID_KEYBOARD 0 #define CFG_TUH_HID_MOUSE 0 diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c index 9e1ca0e7a..c6378e546 100644 --- a/src/class/cdc/cdc_host.c +++ b/src/class/cdc/cdc_host.c @@ -174,7 +174,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it { // notification endpoint if any tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc; - p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, ep_desc, TUSB_CLASS_CDC); + p_cdc->pipe_notification = hcd_pipe_open(rhport, dev_addr, ep_desc); p_cdc->ep_notif = ep_desc->bEndpointAddress; @@ -201,7 +201,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it pipe_handle_t * p_pipe_hdl = ( ep_desc->bEndpointAddress & TUSB_DIR_IN_MASK ) ? &p_cdc->pipe_in : &p_cdc->pipe_out; - (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, ep_desc, TUSB_CLASS_CDC); + (*p_pipe_hdl) = hcd_pipe_open(rhport, dev_addr, ep_desc); TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl) ); if ( edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN ) diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c index 57a409ffd..4f5f0c599 100644 --- a/src/class/msc/msc_host.c +++ b/src/class/msc/msc_host.c @@ -368,7 +368,7 @@ bool msch_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_interfac .bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_ENDPOINT, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT }, .bRequest = TUSB_REQ_CLEAR_FEATURE, .wValue = 0, - .wIndex = hcd_pipe_get_endpoint_addr(msch_data[dev_addr-1].bulk_in), + .wIndex = hcd_pipe_get_endpoint_addr(msch_data[dev_addr-1].bulk_in), // FIXME use ep addr .wLength = 0 }; diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c index e71b817aa..dd19a5224 100644 --- a/src/host/ehci/ehci.c +++ b/src/host/ehci/ehci.c @@ -325,7 +325,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const* { // FIXME control only for now (void) rhport; - hcd_pipe_open(rhport, dev_addr, ep_desc, 0); + hcd_pipe_open(rhport, dev_addr, ep_desc); return true; } @@ -344,23 +344,23 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * // FIXME control only for now if ( epnum == 0 ) { - ehci_qhd_t * const p_qhd = get_control_qhd(dev_addr); - ehci_qtd_t *p_data = get_control_qtds(dev_addr); + ehci_qhd_t* qhd = get_control_qhd(dev_addr); + ehci_qtd_t* qtd = get_control_qtds(dev_addr); - qtd_init(p_data, (uint32_t) buffer, buflen); + qtd_init(qtd, (uint32_t) buffer, buflen); // first first data toggle is always 1 (data & setup stage) - p_data->data_toggle = 1; - p_data->pid = dir ? EHCI_PID_IN : EHCI_PID_OUT; - p_data->int_on_complete = 1; - p_data->next.terminate = 1; + qtd->data_toggle = 1; + qtd->pid = dir ? EHCI_PID_IN : EHCI_PID_OUT; + qtd->int_on_complete = 1; + qtd->next.terminate = 1; // sw region - p_qhd->p_qtd_list_head = p_data; - p_qhd->p_qtd_list_tail = p_data; + qhd->p_qtd_list_head = qtd; + qhd->p_qtd_list_tail = qtd; // attach TD - p_qhd->qtd_overlay.next.address = (uint32_t) p_data; + qhd->qtd_overlay.next.address = (uint32_t) qtd; } return true; @@ -389,7 +389,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet //--------------------------------------------------------------------+ // BULK/INT/ISO PIPE API //--------------------------------------------------------------------+ -pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc, uint8_t class_code) +pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc) { pipe_handle_t const null_handle = { .index = 0 }; @@ -511,24 +511,12 @@ bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl) return !p_qhd->qtd_overlay.halted && (p_qhd->p_qtd_list_head != NULL); } -bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl) -{ - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); - return p_qhd->qtd_overlay.halted; -} - bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl) { ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); return p_qhd->qtd_overlay.halted && !qhd_has_xact_error(p_qhd); } -uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl) -{ - ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); - return p_qhd->endpoint_number + ( (p_qhd->pid_non_control == EHCI_PID_IN) ? TUSB_DIR_IN_MASK : 0); -} - tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl) { ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(dev_addr, pipe_hdl); @@ -596,11 +584,8 @@ static void port_connect_status_change_isr(uint8_t hostid) static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) { - uint8_t max_loop = 0; - // 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 - && max_loop < HCD_MAX_XFER) + 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); @@ -616,8 +601,6 @@ static void qhd_xfer_complete_isr(ehci_qhd_t * p_qhd) hcd_event_xfer_complete(p_qhd->device_address, edpt_addr(p_qhd->endpoint_number, p_qhd->pid_non_control == EHCI_PID_IN ? 1 : 0), XFER_RESULT_SUCCESS, p_qhd->total_xferred_bytes); p_qhd->total_xferred_bytes = 0; } - - max_loop++; } } diff --git a/src/host/hcd.h b/src/host/hcd.h index 0f83838e9..9ea86a5fe 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -144,18 +144,15 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * //--------------------------------------------------------------------+ // TODO control xfer should be used via usbh layer -pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * endpoint_desc, uint8_t class_code) ATTR_WARN_UNUSED_RESULT; +pipe_handle_t hcd_pipe_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc); tusb_error_t hcd_pipe_queue_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes) ATTR_WARN_UNUSED_RESULT; // only queue, not transferring yet tusb_error_t hcd_pipe_xfer(uint8_t dev_addr, pipe_handle_t pipe_hdl, uint8_t buffer[], uint16_t total_bytes, bool int_on_complete) ATTR_WARN_UNUSED_RESULT; bool hcd_pipe_close(uint8_t rhport, uint8_t dev_addr, pipe_handle_t pipe_hdl); bool hcd_pipe_is_busy(uint8_t dev_addr, pipe_handle_t pipe_hdl); -bool hcd_pipe_is_error(uint8_t dev_addr, pipe_handle_t pipe_hdl); bool hcd_pipe_is_stalled(uint8_t dev_addr, pipe_handle_t pipe_hdl); // stalled also counted as error tusb_error_t hcd_pipe_clear_stall(uint8_t dev_addr, pipe_handle_t pipe_hdl); -uint8_t hcd_pipe_get_endpoint_addr(uint8_t dev_addr, pipe_handle_t pipe_hdl); - #if 0 tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; #endif diff --git a/src/host/hub.c b/src/host/hub.c index 2a71c45fc..bc0592a97 100644 --- a/src/host/hub.c +++ b/src/host/hub.c @@ -167,7 +167,7 @@ bool hub_open_subtask(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t co TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType); TU_ASSERT(TUSB_XFER_INTERRUPT == p_endpoint->bmAttributes.xfer); - hub_data[dev_addr-1].pipe_status = hcd_pipe_open(rhport, dev_addr, p_endpoint, TUSB_CLASS_HUB); + hub_data[dev_addr-1].pipe_status = hcd_pipe_open(rhport, dev_addr, p_endpoint); TU_ASSERT( pipehandle_is_valid(hub_data[dev_addr-1].pipe_status) ); hub_data[dev_addr-1].interface_number = p_interface_desc->bInterfaceNumber; diff --git a/src/host/ohci/ohci.c b/src/host/ohci/ohci.c index 08d562e0d..5923be936 100644 --- a/src/host/ohci/ohci.c +++ b/src/host/ohci/ohci.c @@ -589,24 +589,12 @@ bool hcd_pipe_is_busy(pipe_handle_t pipe_hdl) return tu_align16(p_ed->td_head.address) != tu_align16(p_ed->td_tail.address); } -bool hcd_pipe_is_error(pipe_handle_t pipe_hdl) -{ - ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); - return p_ed->td_head.halted; -} - bool hcd_pipe_is_stalled(pipe_handle_t pipe_hdl) { ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); return p_ed->td_head.halted && p_ed->is_stalled; } -uint8_t hcd_pipe_get_endpoint_addr(pipe_handle_t pipe_hdl) -{ - ohci_ed_t const * const p_ed = ed_from_pipe_handle(pipe_hdl); - return p_ed->endpoint_number | (p_ed->direction == OHCI_PID_IN ? TUSB_DIR_IN_MASK : 0 ); -} - tusb_error_t hcd_pipe_clear_stall(pipe_handle_t pipe_hdl) { ohci_ed_t * const p_ed = ed_from_pipe_handle(pipe_hdl);