diff options
Diffstat (limited to 'tinyusb/host')
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 45 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 11 | ||||
| -rw-r--r-- | tinyusb/host/usbh.h | 2 | ||||
| -rw-r--r-- | tinyusb/host/usbh_hcd.h | 2 |
4 files changed, 31 insertions, 29 deletions
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 7a8ad8f30..7293c264a 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -135,11 +135,6 @@ void hcd_port_reset(uint8_t hostid) // NXP specific, port reset will automatically be 0 when reset sequence complete // there is chance device is unplugged while reset sequence is not complete while( regs->portsc_bit.port_reset) {} - - // TODO finalize delay after reset, hack delay 100 ms, otherwise speed is detected as LOW in most cases - volatile uint32_t delay_us = 100000; - delay_us *= (SystemCoreClock / 1000000) / 3; - while(delay_us--); #endif } @@ -457,6 +452,14 @@ void port_connect_status_change_isr(uint8_t hostid) if (regs->portsc_bit.current_connect_status) // device plugged { hcd_port_reset(hostid); + + #ifndef _TEST_ + // TODO finalize delay after reset, hack delay 100 ms, otherwise speed is detected as LOW in most cases + volatile uint32_t delay_us = 100000; + delay_us *= (SystemCoreClock / 1000000) / 3; + while(delay_us--); + #endif + usbh_device_plugged_isr(hostid, regs->portsc_bit.nxp_port_speed); // NXP specific port speed }else // device unplugged { @@ -485,7 +488,7 @@ void async_list_process_isr(ehci_qhd_t * const async_head) pipe_hdl.xfer_type = TUSB_XFER_BULK; pipe_hdl.index = qhd_get_index(p_qhd); } - usbh_isr( pipe_hdl, p_qhd->class_code, BUS_EVENT_XFER_COMPLETE); // call USBH callback + usbh_isr( pipe_hdl, p_qhd->class_code, TUSB_EVENT_XFER_COMPLETE); // call USBH callback } p_qhd->p_qtd_list_head->used = 0; // free QTD @@ -525,7 +528,7 @@ void period_list_process_isr(ehci_qhd_t const * const period_head) pipe_hdl.xfer_type = TUSB_XFER_INTERRUPT; pipe_hdl.index = qhd_get_index(p_qhd_int); } - usbh_isr( pipe_hdl, p_qhd_int->class_code, BUS_EVENT_XFER_COMPLETE); // call USBH callback + usbh_isr( pipe_hdl, p_qhd_int->class_code, TUSB_EVENT_XFER_COMPLETE); // call USBH callback } p_qhd_int->p_qtd_list_head->used = 0; // free QTD @@ -565,7 +568,8 @@ void xfer_error_isr(uint8_t hostid) pipe_hdl.xfer_type = TUSB_XFER_BULK; pipe_hdl.index = qhd_get_index(p_qhd); } - usbh_isr( pipe_hdl, p_qhd->class_code, BUS_EVENT_XFER_ERROR); // call USBH callback + hal_debugger_breakpoint(); + usbh_isr( pipe_hdl, p_qhd->class_code, TUSB_EVENT_XFER_ERROR); // call USBH callback } p_qhd = (ehci_qhd_t*) align32(p_qhd->next.address); @@ -585,10 +589,21 @@ void hcd_isr(uint8_t hostid) if (int_status == 0) return; + if (int_status & EHCI_INT_MASK_PORT_CHANGE) + { + uint32_t port_status = regs->portsc & EHCI_PORTSC_MASK_ALL; + + if (regs->portsc_bit.connect_status_change) + { + port_connect_status_change_isr(hostid); + } + + regs->portsc |= port_status; // Acknowledge change bits in portsc + } + if (int_status & EHCI_INT_MASK_ERROR) { // TODO handle Queue Head halted - hal_debugger_breakpoint(); xfer_error_isr(hostid); } @@ -603,18 +618,6 @@ void hcd_isr(uint8_t hostid) period_list_process_isr( get_period_head(hostid) ); } - if (int_status & EHCI_INT_MASK_PORT_CHANGE) - { - uint32_t port_status = regs->portsc & EHCI_PORTSC_MASK_ALL; - - if (regs->portsc_bit.connect_status_change) - { - port_connect_status_change_isr(hostid); - } - - regs->portsc |= port_status; // Acknowledge change bits in portsc - } - if (int_status & EHCI_INT_MASK_ASYNC_ADVANCE) // need to place after EHCI_INT_MASK_NXP_ASYNC { async_advance_isr( get_async_head(hostid) ); diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index eada2d6cb..8c3b20703 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -187,11 +187,11 @@ tusb_interface_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl) // USBH-HCD ISR/Callback API //--------------------------------------------------------------------+ // interrupt caused by a TD (with IOC=1) in pipe of class class_code -void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_bus_event_t event) +void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event) { if (class_code == 0) // Control transfer { - usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = (event == BUS_EVENT_XFER_COMPLETE) ? TUSB_INTERFACE_STATUS_COMPLETE : TUSB_INTERFACE_STATUS_ERROR; + usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = (event == TUSB_EVENT_XFER_COMPLETE) ? TUSB_INTERFACE_STATUS_COMPLETE : TUSB_INTERFACE_STATUS_ERROR; osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl ); }else if (usbh_class_drivers[class_code].isr) { @@ -217,9 +217,7 @@ void usbh_device_unplugged_isr(uint8_t hostid) !(usbh_devices[dev_addr].core_id == hostid && usbh_devices[dev_addr].hub_addr == 0 && usbh_devices[dev_addr].hub_port == 0 && - usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG - ) - ) + usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG ) ) { dev_addr++; } @@ -290,7 +288,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) ) ); - hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor +// hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor //------------- Set new address -------------// new_addr = get_new_address(); @@ -317,6 +315,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) usbh_devices[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED; usbh_pipe_control_close(0); + usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; // open control pipe for new address TASK_ASSERT_STATUS ( usbh_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) ); diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index 684505471..2eac1d886 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -74,7 +74,7 @@ typedef enum tusb_interface_status_{ typedef struct { void (* const init) (void); tusb_error_t (* const open_subtask)(uint8_t, tusb_descriptor_interface_t const *, uint16_t*); - void (* const isr) (pipe_handle_t, tusb_bus_event_t); + void (* const isr) (pipe_handle_t, tusb_event_t); void (* const close) (uint8_t); } host_class_driver_t; //--------------------------------------------------------------------+ diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index 815d35b32..f235c3170 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -106,7 +106,7 @@ typedef struct { // TODO internal structure, re-order members extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address //------------- callback from HCD ISR-------------// -void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_bus_event_t event); +void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event); void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed); void usbh_device_unplugged_isr(uint8_t hostid); |
