summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-03-13 11:20:02 +0700
committerhathach <[email protected]>2013-03-13 11:20:02 +0700
commit97c436a16ee6de7852c5cb77fa4359a5f00f4c46 (patch)
treea4c4685fee6f233f5b084440cb6f0dd493b84538 /tinyusb
parent97c9001d401b217b383046b6af3b8fd957e835f4 (diff)
add usbh_pipe_control_close (in conjunction with usbh pipe control open)
close control pipe when unplugged
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/core/tusb_types.h7
-rw-r--r--tinyusb/host/ehci/ehci.c1
-rw-r--r--tinyusb/host/usbh.c17
3 files changed, 21 insertions, 4 deletions
diff --git a/tinyusb/core/tusb_types.h b/tinyusb/core/tusb_types.h
index 45c6fbeac..1d69b9326 100644
--- a/tinyusb/core/tusb_types.h
+++ b/tinyusb/core/tusb_types.h
@@ -146,12 +146,13 @@ typedef enum {
}tusb_std_class_code_t;
enum {
- TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7),
- TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
- TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5)
+ TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5),
+ TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
+ TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7)
};
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
+
#ifdef __cplusplus
}
#endif
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c
index 2696033f3..f79b478e6 100644
--- a/tinyusb/host/ehci/ehci.c
+++ b/tinyusb/host/ehci/ehci.c
@@ -67,6 +67,7 @@ STATIC_ASSERT( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4
#if CONTROLLER_HOST_NUMBER > 1
STATIC_ASSERT( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment");
#endif
+// TODO static assert for memory placement on some known MCU such as lpc43xx
//--------------------------------------------------------------------+
// IMPLEMENTATION
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index 5f679facf..0e78a315b 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -151,6 +151,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons
OSAL_SUBTASK_END
}
+tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) ATTR_ALWAYS_INLINE;
tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
{
osal_semaphore_reset( usbh_device_info_pool[dev_addr].sem_hdl );
@@ -160,6 +161,14 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
return TUSB_ERROR_NONE;
}
+static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t usbh_pipe_control_close(uint8_t dev_addr)
+{
+ ASSERT_STATUS( hcd_pipe_control_close(dev_addr) );
+
+ return TUSB_ERROR_NONE;
+}
+
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl)
{
return PIPE_STATUS_BUSY;
@@ -192,6 +201,7 @@ void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed)
void usbh_device_unplugged_isr(uint8_t hostid)
{
+ //------------- find the device address that is unplugged -------------//
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 &&
@@ -202,12 +212,17 @@ void usbh_device_unplugged_isr(uint8_t hostid)
ASSERT(dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, (void) 0 );
+ // if device unplugged is not a hub TODO handle hub unplugged
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_pipe_control_close(dev_addr);
+
+ // set to REMOVING to prevent allocate to other new device
+ // need to set to UNPLUGGED by HCD after freeing all resources
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_REMOVING;
}
@@ -276,7 +291,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
usbh_device_info_pool[new_addr].hub_port = usbh_device_info_pool[0].hub_port;
usbh_device_info_pool[new_addr].speed = usbh_device_info_pool[0].speed;
usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_ADDRESSED;
- hcd_pipe_control_close(0);
+ usbh_pipe_control_close(0);
// hcd_port_reset( usbh_device_info_pool[new_addr].core_id ); TODO verified