mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
refractor
- rename usbh_device_info_t.status to state - rename enum TUSB_DEVICE_STATUS_* to TUSB_DEVICE_STATE_*
This commit is contained in:
parent
0c6d406ddf
commit
d7ba86c85e
@ -78,7 +78,7 @@ void setUp(void)
|
||||
usbh_device_info_pool[i].hub_addr = hub_addr;
|
||||
usbh_device_info_pool[i].hub_port = hub_port;
|
||||
usbh_device_info_pool[i].speed = TUSB_SPEED_HIGH;
|
||||
usbh_device_info_pool[i].status = TUSB_DEVICE_STATUS_READY;
|
||||
usbh_device_info_pool[i].state = TUSB_DEVICE_STATE_READY;
|
||||
}
|
||||
|
||||
regs = get_operational_register(hostid);
|
||||
@ -184,10 +184,10 @@ void test_device_unplugged_status(void)
|
||||
{
|
||||
ehci_controller_device_unplug(hostid);
|
||||
hcd_isr(hostid);
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[dev_addr].status);
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_device_info_pool[dev_addr].state);
|
||||
|
||||
regs->usb_sts_bit.async_advance = 1;
|
||||
hcd_isr(hostid); // async advance
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_UNPLUG, usbh_device_info_pool[dev_addr].status);
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_device_info_pool[dev_addr].state);
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERRUPT PIPE
|
||||
// PIPE OPEN
|
||||
//--------------------------------------------------------------------+
|
||||
tusb_descriptor_endpoint_t const desc_ept_interrupt_out =
|
||||
{
|
||||
@ -176,3 +176,25 @@ void test_open_interrupt_qhd_non_hs(void)
|
||||
TEST_ASSERT_EQUAL(1, p_qhd->interrupt_smask);
|
||||
TEST_ASSERT_EQUAL(0x1c, p_qhd->non_hs_interrupt_cmask);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PIPE CLOSE
|
||||
//--------------------------------------------------------------------+
|
||||
void test_interrupt_close(void)
|
||||
{
|
||||
ehci_qhd_t *p_qhd;
|
||||
pipe_handle_t pipe_hdl;
|
||||
|
||||
pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID);
|
||||
p_qhd = qhd_get_from_pipe_handle(pipe_hdl);
|
||||
|
||||
//------------- Code Under TEST -------------//
|
||||
hcd_pipe_close(pipe_hdl);
|
||||
|
||||
TEST_IGNORE(); // check operation removing interrupt head
|
||||
|
||||
// TEST_ASSERT(p_qhd->is_removing);
|
||||
// TEST_ASSERT( align32(period_head) != (uint32_t) p_qhd );
|
||||
// TEST_ASSERT_EQUAL_HEX( (uint32_t) get_async_head(hostid), align32(p_qhd->next.address ) );
|
||||
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ void test_enum_failed_get_full_dev_desc(void)
|
||||
|
||||
usbh_enumeration_task();
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[1].status);
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_device_info_pool[1].state);
|
||||
TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[1].speed);
|
||||
TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[1].core_id);
|
||||
TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[1].hub_addr);
|
||||
|
@ -100,11 +100,11 @@ void test_keyboard_no_instances_invalid_para(void)
|
||||
|
||||
void test_keyboard_install_ok(void)
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_install(device_hdl, (uint8_t*) &kbd_descriptor));
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ pipe_status_t pipe_status_get_stub(pipe_handle_t pipe_hdl, int num_call)
|
||||
|
||||
void test_keyboard_get_invalid_para()
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, 0, NULL));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(0);
|
||||
@ -162,18 +162,18 @@ void test_keyboard_get_invalid_para()
|
||||
|
||||
void test_keyboard_get_class_not_supported()
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
keyboard_info_pool[device_hdl].instance[0].pipe_in = (pipe_handle_t) { 0 };
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
|
||||
void test_keyboard_get_report_not_available()
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_BUSY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_AVAILABLE);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
@ -182,16 +182,16 @@ void test_keyboard_get_ok()
|
||||
{
|
||||
usbh_pipe_status_get_StubWithCallback(pipe_status_get_stub);
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATUS_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
|
||||
}
|
||||
|
@ -63,16 +63,16 @@ void tearDown(void)
|
||||
//--------------------------------------------------------------------+
|
||||
void test_usbh_status_get_fail(void)
|
||||
{
|
||||
usbh_device_info_pool[dev_hdl].status = 0;
|
||||
usbh_device_info_pool[dev_hdl].state = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL( 0, tusbh_device_status_get(TUSB_CFG_HOST_DEVICE_MAX+1) );
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_UNPLUG, tusbh_device_status_get(dev_hdl) );
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_status_get(dev_hdl) );
|
||||
}
|
||||
|
||||
void test_usbh_status_get_succeed(void)
|
||||
{
|
||||
usbh_device_info_pool[dev_hdl].status = TUSB_DEVICE_STATUS_READY;
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(dev_hdl) );
|
||||
usbh_device_info_pool[dev_hdl].state = TUSB_DEVICE_STATE_READY;
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_READY, tusbh_device_status_get(dev_hdl) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -167,7 +167,7 @@ void test_usbh_device_unplugged_isr_device_not_previously_mounted(void)
|
||||
{
|
||||
uint8_t dev_addr = 1;
|
||||
|
||||
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_UNPLUG;
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
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;
|
||||
@ -179,7 +179,7 @@ void test_usbh_device_unplugged_isr(void)
|
||||
{
|
||||
uint8_t dev_addr = 1;
|
||||
|
||||
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_READY;
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_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;
|
||||
@ -190,5 +190,5 @@ void test_usbh_device_unplugged_isr(void)
|
||||
//------------- Code Under Test -------------//
|
||||
usbh_device_unplugged_isr(0);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_REMOVING, usbh_device_info_pool[dev_addr].status);
|
||||
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_device_info_pool[dev_addr].state);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8
|
||||
{
|
||||
keyboard_interface_t *p_kbd;
|
||||
|
||||
ASSERT_INT(TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(device_hdl), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
ASSERT_INT(TUSB_DEVICE_STATE_READY, tusbh_device_status_get(device_hdl), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT(instance_num < TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
@ -82,7 +82,7 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8
|
||||
|
||||
uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl)
|
||||
{
|
||||
ASSERT_INT(TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(device_hdl), 0);
|
||||
ASSERT_INT(TUSB_DEVICE_STATE_READY, tusbh_device_status_get(device_hdl), 0);
|
||||
|
||||
return keyboard_info_pool[device_hdl].instance_count;
|
||||
}
|
||||
|
@ -66,6 +66,11 @@ typedef struct {
|
||||
uint8_t index;
|
||||
} pipe_handle_t;
|
||||
|
||||
typedef enum {
|
||||
BUS_XFER_COMPLETE,
|
||||
BUS_XFER_ERROR
|
||||
}usb_bus_event_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBH-HCD API
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -101,7 +101,7 @@ static inline uint8_t get_configure_number_for_device(tusb_descriptor_device_t*
|
||||
tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl)
|
||||
{
|
||||
ASSERT(device_hdl <= TUSB_CFG_HOST_DEVICE_MAX, 0);
|
||||
return usbh_device_info_pool[device_hdl].status;
|
||||
return usbh_device_info_pool[device_hdl].state;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -135,6 +135,7 @@ tusb_error_t usbh_init(void)
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
//------------- USBH control transfer -------------//
|
||||
// function called within a task, requesting os blocking services, subtask input parameter must be static/global variables
|
||||
tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t const* p_request, uint8_t* data)
|
||||
{
|
||||
@ -207,7 +208,7 @@ void usbh_device_unplugged_isr(uint8_t hostid)
|
||||
!(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 &&
|
||||
usbh_device_info_pool[dev_addr].status != TUSB_DEVICE_STATUS_UNPLUG
|
||||
usbh_device_info_pool[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG
|
||||
)
|
||||
)
|
||||
{
|
||||
@ -226,13 +227,13 @@ void usbh_device_unplugged_isr(uint8_t hostid)
|
||||
usbh_pipe_control_close(dev_addr);
|
||||
|
||||
// set to REMOVING to end wait for HCD to clean up its cached data for this device
|
||||
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_REMOVING;
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
|
||||
}
|
||||
|
||||
// HCD cleaned up cached data for this device
|
||||
void usbh_device_hcd_data_cleaned_up_cb(uint8_t dev_addr)
|
||||
{
|
||||
usbh_device_info_pool[dev_addr].status = TUSB_DEVICE_STATUS_UNPLUG;
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -298,7 +299,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
|
||||
usbh_device_info_pool[new_addr].hub_addr = usbh_device_info_pool[0].hub_addr;
|
||||
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;
|
||||
usbh_device_info_pool[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED;
|
||||
usbh_pipe_control_close(0);
|
||||
|
||||
// hcd_port_reset( usbh_device_info_pool[new_addr].core_id ); TODO verified
|
||||
@ -408,7 +409,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
|
||||
)
|
||||
);
|
||||
|
||||
usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_READY;
|
||||
usbh_device_info_pool[new_addr].state = TUSB_DEVICE_STATE_READY;
|
||||
tusbh_device_mount_succeed_cb(new_addr);
|
||||
|
||||
// TODO invoke mounted callback
|
||||
@ -431,7 +432,7 @@ static inline uint8_t get_new_address(void)
|
||||
uint8_t addr;
|
||||
for (addr=1; addr <= TUSB_CFG_HOST_DEVICE_MAX; addr++)
|
||||
{
|
||||
if (usbh_device_info_pool[addr].status == TUSB_DEVICE_STATUS_UNPLUG)
|
||||
if (usbh_device_info_pool[addr].state == TUSB_DEVICE_STATE_UNPLUG)
|
||||
break;
|
||||
}
|
||||
return addr;
|
||||
|
@ -95,13 +95,13 @@
|
||||
|
||||
/// Device Status
|
||||
enum tusbh_device_status_{
|
||||
TUSB_DEVICE_STATUS_UNPLUG = 0,
|
||||
TUSB_DEVICE_STATUS_ADDRESSED,
|
||||
TUSB_DEVICE_STATE_UNPLUG = 0,
|
||||
TUSB_DEVICE_STATE_ADDRESSED,
|
||||
|
||||
TUSB_DEVICE_STATUS_READY, /* Configured */
|
||||
TUSB_DEVICE_STATE_READY, /* Configured */
|
||||
|
||||
TUSB_DEVICE_STATUS_REMOVING,
|
||||
TUSB_DEVICE_STATUS_SAFE_REMOVE,
|
||||
TUSB_DEVICE_STATE_REMOVING,
|
||||
TUSB_DEVICE_STATE_SAFE_REMOVE,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
|
@ -90,7 +90,7 @@ typedef struct { // TODO internal structure, re-order members
|
||||
//------------- configuration descriptor info -------------//
|
||||
uint8_t interface_count; // bNumInterfaces alias
|
||||
|
||||
uint8_t status; // value from enum tusbh_device_status_
|
||||
uint8_t state; // value from enum tusbh_device_status_
|
||||
|
||||
tusb_std_request_t control_request;
|
||||
OSAL_SEM_DEF(semaphore);
|
||||
|
Loading…
x
Reference in New Issue
Block a user