add usbh_pipe_control_close (in conjunction with usbh pipe control open)

close control pipe when unplugged
This commit is contained in:
hathach 2013-03-13 11:20:02 +07:00
parent 97c9001d40
commit 97c436a16e
4 changed files with 30 additions and 9 deletions

View File

@ -164,14 +164,18 @@ void class_close_expect(void)
void test_usbh_device_unplugged_isr(void)
{
usbh_device_info_pool[1].status = TUSB_DEVICE_STATUS_READY;
usbh_device_info_pool[1].core_id = 0;
usbh_device_info_pool[1].hub_addr = 0;
usbh_device_info_pool[1].hub_port = 0;
uint8_t dev_addr = 1;
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_READY;
usbh_device_info_pool[dev_addr].core_id = 0;
usbh_device_info_pool[dev_addr].hub_addr = 0;
usbh_device_info_pool[dev_addr].hub_port = 0;
class_close_expect();
hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE);
//------------- Code Under Test -------------//
usbh_device_unplugged_isr(0);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[1].status);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[dev_addr].status);
}

View File

@ -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

View File

@ -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

View File

@ -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