diff options
| author | hathach <[email protected]> | 2013-03-13 10:57:30 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-03-13 10:57:30 +0700 |
| commit | 97c9001d401b217b383046b6af3b8fd957e835f4 (patch) | |
| tree | 565b4ff5ad55cebd0dea9425bc533848b17a825e /tinyusb | |
| parent | 63765b37c7ebab2a7586122924cfb8b134db17f8 (diff) | |
add hard fault handler to bsp.c
rename class_install_subtask to class_open_subtask
add class_close for unmount
adding code for usbh_device_unplugged_isr & invoke it in hcd_isr
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/class/hid_host.h | 3 | ||||
| -rw-r--r-- | tinyusb/class/msc_host.h | 4 | ||||
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 3 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 33 | ||||
| -rw-r--r-- | tinyusb/host/usbh.h | 3 |
5 files changed, 35 insertions, 11 deletions
diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index 8d9b268c9..f85beef67 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -88,8 +88,9 @@ tusb_error_t hidh_keyboard_install(uint8_t dev_addr, uint8_t const *descriptor) // CLASS DRIVER FUNCTION (all declared with WEAK) //--------------------------------------------------------------------+ void hidh_init(void) ATTR_WEAK; -tusb_error_t hidh_install_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; +tusb_error_t hidh_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; void hidh_isr(pipe_handle_t pipe_hdl) ATTR_WEAK; +void hidh_close(uint8_t dev_addr) ATTR_WEAK; #endif diff --git a/tinyusb/class/msc_host.h b/tinyusb/class/msc_host.h index 7fc1ce48c..021d30412 100644 --- a/tinyusb/class/msc_host.h +++ b/tinyusb/class/msc_host.h @@ -69,9 +69,9 @@ #ifdef _TINY_USB_SOURCE_FILE_ void msch_init(void) ATTR_WEAK; -tusb_error_t msch_install_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; +tusb_error_t msch_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; void msch_isr(pipe_handle_t pipe_hdl) ATTR_WEAK; - +void msch_close(uint8_t dev_addr) ATTR_WEAK; #endif #ifdef __cplusplus diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 8577195f5..2696033f3 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -175,7 +175,7 @@ void port_connect_status_isr(uint8_t hostid) usbh_device_plugged_isr(hostid, regs->portsc_bit.nxp_port_speed); // NXP specific port speed }else // device unplugged { -// usbh_device_ + usbh_device_unplugged_isr(hostid); } } @@ -578,6 +578,7 @@ static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) static void init_qhd(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type) { + // address 0 uses async head, which always on the list --> cannot be cleared (ehci halted otherwise) if (dev_addr != 0) { memclr_(p_qhd, sizeof(ehci_qhd_t)); diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index dc37b9e3c..5f679facf 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -65,14 +65,16 @@ class_driver_t const usbh_class_drivers[TUSB_CLASS_MAX_CONSEC_NUMBER] = { [TUSB_CLASS_HID] = { .init = hidh_init, - .install_subtask = hidh_install_subtask, - .isr = hidh_isr + .open_subtask = hidh_open_subtask, + .isr = hidh_isr, + .close = hidh_close }, [TUSB_CLASS_MSC] = { .init = msch_init, - .install_subtask = msch_install_subtask, - .isr = msch_isr + .open_subtask = msch_open_subtask, + .isr = msch_isr, + .close = msch_close } }; @@ -190,7 +192,23 @@ void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed) void usbh_device_unplugged_isr(uint8_t hostid) { + uint8_t dev_addr=1; + while ( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX && ! (usbh_device_info_pool[dev_addr].core_id == hostid && + usbh_device_info_pool[dev_addr].hub_addr == 0 && + usbh_device_info_pool[dev_addr].hub_port ==0)) + { + dev_addr++; + } + + ASSERT(dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, (void) 0 ); + + for (uint8_t class_code = 1; class_code < TUSB_CLASS_MAX_CONSEC_NUMBER; class_code++) + { + if (usbh_class_drivers[class_code].close) + usbh_class_drivers[class_code].close(dev_addr); + } + usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_REMOVING; } @@ -260,6 +278,8 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_ADDRESSED; hcd_pipe_control_close(0); +// hcd_port_reset( usbh_device_info_pool[new_addr].core_id ); TODO verified + // open control pipe for new address TASK_ASSERT_STATUS ( usbh_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) ); @@ -335,11 +355,11 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) TASK_ASSERT( false ); // corrupted data, abort enumeration } else if ( class_code < TUSB_CLASS_MAX_CONSEC_NUMBER) { - if ( usbh_class_drivers[class_code].install_subtask ) + if ( usbh_class_drivers[class_code].open_subtask ) { uint16_t length; OSAL_SUBTASK_INVOKED_AND_WAIT ( // parameters in task/sub_task must be static storage (static or global) - usbh_class_drivers[ ((tusb_descriptor_interface_t*) p_desc)->bInterfaceClass ].install_subtask(new_addr, p_desc, &length) ); + usbh_class_drivers[ ((tusb_descriptor_interface_t*) p_desc)->bInterfaceClass ].open_subtask(new_addr, p_desc, &length) ); p_desc += length; } } else // unsupported class (not enable or yet implemented) @@ -366,6 +386,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) ) ); + usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_READY; tusbh_device_mount_succeed_cb(new_addr); // TODO invoke mounted callback diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index b89cc3bb9..2d74cd359 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -151,8 +151,9 @@ typedef uint8_t tusbh_device_status_t; typedef struct { void (* const init) (void); - tusb_error_t (* const install_subtask)(uint8_t, uint8_t const *, uint16_t*); + tusb_error_t (* const open_subtask)(uint8_t, uint8_t const *, uint16_t*); void (* const isr) (pipe_handle_t); + void (* const close) (uint8_t) } class_driver_t; //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION |
