mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-19 15:40:41 +00:00
add usbh_pipe_control_close (in conjunction with usbh pipe control open)
close control pipe when unplugged
This commit is contained in:
parent
97c9001d40
commit
97c436a16e
@ -164,14 +164,18 @@ void class_close_expect(void)
|
|||||||
|
|
||||||
void test_usbh_device_unplugged_isr(void)
|
void test_usbh_device_unplugged_isr(void)
|
||||||
{
|
{
|
||||||
usbh_device_info_pool[1].status = TUSB_DEVICE_STATUS_READY;
|
uint8_t dev_addr = 1;
|
||||||
usbh_device_info_pool[1].core_id = 0;
|
|
||||||
usbh_device_info_pool[1].hub_addr = 0;
|
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_READY;
|
||||||
usbh_device_info_pool[1].hub_port = 0;
|
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();
|
class_close_expect();
|
||||||
|
hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE);
|
||||||
|
|
||||||
|
//------------- Code Under Test -------------//
|
||||||
usbh_device_unplugged_isr(0);
|
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);
|
||||||
}
|
}
|
||||||
|
@ -146,12 +146,13 @@ typedef enum {
|
|||||||
}tusb_std_class_code_t;
|
}tusb_std_class_code_t;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7),
|
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5),
|
||||||
TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
|
TUSB_DESC_CONFIG_ATT_SELF_POWER = BIT_(6),
|
||||||
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP = BIT_(5)
|
TUSB_DESC_CONFIG_ATT_BUS_POWER = BIT_(7)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
|
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,6 +67,7 @@ STATIC_ASSERT( ALIGN_OF(period_frame_list0) == 4096, "Period Framelist must be 4
|
|||||||
#if CONTROLLER_HOST_NUMBER > 1
|
#if CONTROLLER_HOST_NUMBER > 1
|
||||||
STATIC_ASSERT( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment");
|
STATIC_ASSERT( ALIGN_OF(period_frame_list1) == 4096, "Period Framelist must be 4k alginment");
|
||||||
#endif
|
#endif
|
||||||
|
// TODO static assert for memory placement on some known MCU such as lpc43xx
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// IMPLEMENTATION
|
// IMPLEMENTATION
|
||||||
|
@ -151,6 +151,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons
|
|||||||
OSAL_SUBTASK_END
|
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)
|
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 );
|
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;
|
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)
|
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl)
|
||||||
{
|
{
|
||||||
return PIPE_STATUS_BUSY;
|
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)
|
void usbh_device_unplugged_isr(uint8_t hostid)
|
||||||
{
|
{
|
||||||
|
//------------- find the device address that is unplugged -------------//
|
||||||
uint8_t dev_addr=1;
|
uint8_t dev_addr=1;
|
||||||
while ( dev_addr <= TUSB_CFG_HOST_DEVICE_MAX && ! (usbh_device_info_pool[dev_addr].core_id == hostid &&
|
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_addr == 0 &&
|
||||||
@ -202,12 +212,17 @@ void usbh_device_unplugged_isr(uint8_t hostid)
|
|||||||
|
|
||||||
ASSERT(dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, (void) 0 );
|
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++)
|
for (uint8_t class_code = 1; class_code < TUSB_CLASS_MAX_CONSEC_NUMBER; class_code++)
|
||||||
{
|
{
|
||||||
if (usbh_class_drivers[class_code].close)
|
if (usbh_class_drivers[class_code].close)
|
||||||
usbh_class_drivers[class_code].close(dev_addr);
|
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;
|
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].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].speed = usbh_device_info_pool[0].speed;
|
||||||
usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_ADDRESSED;
|
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
|
// hcd_port_reset( usbh_device_info_pool[new_addr].core_id ); TODO verified
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user