diff options
| author | hathach <[email protected]> | 2013-03-24 16:44:59 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-03-24 16:44:59 +0700 |
| commit | 92c137243dd119b8b460d8dc8498777d58f582e3 (patch) | |
| tree | 5fdcf33b0f9e2fccfafcbd21539684b9f773b6e8 | |
| parent | ea04815bbc3e17bdf9d6ca94dca4f8b44d250c50 (diff) | |
refractor
- rename usbh_device_info_pool to usbh_devices
- create a struct for control pipe in usbh_device_info_t
| -rw-r--r-- | tests/test/host/ehci/test_ehci_init.c | 2 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_ehci_isr.c | 2 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_ehci_structure.c | 2 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_ehci_usbh_hcd_integration.c | 18 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_pipe_bulk_open.c | 14 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_pipe_bulk_xfer.c | 14 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_pipe_control_open.c | 18 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_pipe_control_xfer.c | 12 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_pipe_interrupt_open.c | 16 | ||||
| -rw-r--r-- | tests/test/host/ehci/test_pipe_isochronous_open.c | 12 | ||||
| -rw-r--r-- | tests/test/host/test_enum_task.c | 40 | ||||
| -rw-r--r-- | tests/test/host/test_usbh.c | 30 | ||||
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 24 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 72 | ||||
| -rw-r--r-- | tinyusb/host/usbh_hcd.h | 13 |
15 files changed, 145 insertions, 144 deletions
diff --git a/tests/test/host/ehci/test_ehci_init.c b/tests/test/host/ehci/test_ehci_init.c index 487df4678..99ade4e95 100644 --- a/tests/test/host/ehci/test_ehci_init.c +++ b/tests/test/host/ehci/test_ehci_init.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; //--------------------------------------------------------------------+ // Setup/Teardown + helper declare diff --git a/tests/test/host/ehci/test_ehci_isr.c b/tests/test/host/ehci/test_ehci_isr.c index af3fc0589..c25a2a8f3 100644 --- a/tests/test/host/ehci/test_ehci_isr.c +++ b/tests/test/host/ehci/test_ehci_isr.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t hostid; ehci_registers_t * regs; diff --git a/tests/test/host/ehci/test_ehci_structure.c b/tests/test/host/ehci/test_ehci_structure.c index 61634777e..744c8d53f 100644 --- a/tests/test/host/ehci/test_ehci_structure.c +++ b/tests/test/host/ehci/test_ehci_structure.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; //--------------------------------------------------------------------+ // Setup/Teardown + helper declare diff --git a/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c b/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c index 3769844b6..da451d2d1 100644 --- a/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c +++ b/tests/test/host/ehci/test_ehci_usbh_hcd_integration.c @@ -49,7 +49,7 @@ #include "ehci_controller.h" #define _TINY_USB_SOURCE_FILE_ -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const control_max_packet_size = 64; uint8_t hub_addr; uint8_t hub_port; @@ -63,7 +63,7 @@ void setUp(void) { memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); hub_addr = hub_port = 0; dev_addr = 1; @@ -74,11 +74,11 @@ void setUp(void) for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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].state = i ? TUSB_DEVICE_STATE_CONFIGURED : TUSB_DEVICE_STATE_UNPLUG; + usbh_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; + usbh_devices[i].state = i ? TUSB_DEVICE_STATE_CONFIGURED : TUSB_DEVICE_STATE_UNPLUG; } 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_STATE_REMOVING, usbh_device_info_pool[dev_addr].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state); regs->usb_sts_bit.async_advance = 1; hcd_isr(hostid); // async advance - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_device_info_pool[dev_addr].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[dev_addr].state); } diff --git a/tests/test/host/ehci/test_pipe_bulk_open.c b/tests/test/host/ehci/test_pipe_bulk_open.c index fe2ba3bef..5fc08e30a 100644 --- a/tests/test/host/ehci/test_pipe_bulk_open.c +++ b/tests/test/host/ehci/test_pipe_bulk_open.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const hub_addr = 2; uint8_t const hub_port = 2; @@ -61,7 +61,7 @@ ehci_qhd_t *async_head; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); hcd_init(); @@ -70,10 +70,10 @@ void setUp(void) hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; } async_head = get_async_head( hostid ); @@ -88,7 +88,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); - TEST_ASSERT_EQUAL(usbh_device_info_pool[dev_addr].speed, p_qhd->endpoint_speed); + TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable diff --git a/tests/test/host/ehci/test_pipe_bulk_xfer.c b/tests/test/host/ehci/test_pipe_bulk_xfer.c index 98539c4a7..14d2b27a7 100644 --- a/tests/test/host/ehci/test_pipe_bulk_xfer.c +++ b/tests/test/host/ehci/test_pipe_bulk_xfer.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const control_max_packet_size = 64; uint8_t const hub_addr = 2; @@ -89,7 +89,7 @@ void setUp(void) memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); memclr_(xfer_data, sizeof(xfer_data)); hcd_init(); @@ -99,10 +99,10 @@ void setUp(void) hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; } async_head = get_async_head( hostid ); @@ -149,7 +149,7 @@ void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length) void test_bulk_xfer_hs_ping_out(void) { - usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_HIGH; + usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC); ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl); diff --git a/tests/test/host/ehci/test_pipe_control_open.c b/tests/test/host/ehci/test_pipe_control_open.c index 76575915f..d67e1f352 100644 --- a/tests/test/host/ehci/test_pipe_control_open.c +++ b/tests/test/host/ehci/test_pipe_control_open.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const control_max_packet_size = 64; uint8_t const hub_addr = 2; @@ -63,7 +63,7 @@ ehci_qhd_t *p_control_qhd; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); hcd_init(); @@ -72,10 +72,10 @@ void setUp(void) hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; } async_head = get_async_head( hostid ); @@ -91,7 +91,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); - TEST_ASSERT_EQUAL(usbh_device_info_pool[dev_addr].speed, p_qhd->endpoint_speed); + TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable @@ -150,7 +150,7 @@ void test_control_open_qhd_data(void) void test_control_open_highspeed(void) { - usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_HIGH; + usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH; //------------- Code Under TEST -------------// hcd_pipe_control_open(dev_addr, control_max_packet_size); @@ -159,7 +159,7 @@ void test_control_open_highspeed(void) void test_control_open_non_highspeed(void) { - usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_FULL; + usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; //------------- Code Under TEST -------------// hcd_pipe_control_open(dev_addr, control_max_packet_size); diff --git a/tests/test/host/ehci/test_pipe_control_xfer.c b/tests/test/host/ehci/test_pipe_control_xfer.c index fd6f79ecc..700762ca2 100644 --- a/tests/test/host/ehci/test_pipe_control_xfer.c +++ b/tests/test/host/ehci/test_pipe_control_xfer.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const control_max_packet_size = 64; uint8_t const hub_addr = 2; @@ -71,7 +71,7 @@ void setUp(void) memclr_(&lpc_usb0, sizeof(LPC_USB0_Type)); memclr_(&lpc_usb1, sizeof(LPC_USB1_Type)); - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); memclr_(xfer_data, sizeof(xfer_data)); hcd_init(); @@ -81,10 +81,10 @@ void setUp(void) hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; } async_head = get_async_head( hostid ); diff --git a/tests/test/host/ehci/test_pipe_interrupt_open.c b/tests/test/host/ehci/test_pipe_interrupt_open.c index ecd63d20d..f9bffd908 100644 --- a/tests/test/host/ehci/test_pipe_interrupt_open.c +++ b/tests/test/host/ehci/test_pipe_interrupt_open.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const hub_addr = 2; uint8_t const hub_port = 2; @@ -61,7 +61,7 @@ ehci_qhd_t *period_head; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); hcd_init(); @@ -70,10 +70,10 @@ void setUp(void) hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; } period_head = get_period_head( hostid ); @@ -88,7 +88,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address); TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact); TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number); - TEST_ASSERT_EQUAL(usbh_device_info_pool[dev_addr].speed, p_qhd->endpoint_speed); + TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed); TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size); TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable @@ -161,7 +161,7 @@ void test_open_interrupt_qhd_non_hs(void) ehci_qhd_t *p_qhd; pipe_handle_t pipe_hdl; - usbh_device_info_pool[dev_addr].speed = TUSB_SPEED_FULL; + usbh_devices[dev_addr].speed = TUSB_SPEED_FULL; //------------- Code Under TEST -------------// pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID); diff --git a/tests/test/host/ehci/test_pipe_isochronous_open.c b/tests/test/host/ehci/test_pipe_isochronous_open.c index 60403750d..cb09e0ea8 100644 --- a/tests/test/host/ehci/test_pipe_isochronous_open.c +++ b/tests/test/host/ehci/test_pipe_isochronous_open.c @@ -47,7 +47,7 @@ #include "ehci.h" #include "ehci_controller.h" -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t const hub_addr = 2; uint8_t const hub_port = 2; @@ -60,7 +60,7 @@ ehci_qhd_t *period_head; //--------------------------------------------------------------------+ void setUp(void) { - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); hcd_init(); @@ -69,10 +69,10 @@ void setUp(void) hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX; for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) { - usbh_device_info_pool[i].core_id = hostid; - 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_devices[i].core_id = hostid; + usbh_devices[i].hub_addr = hub_addr; + usbh_devices[i].hub_port = hub_port; + usbh_devices[i].speed = TUSB_SPEED_HIGH; } period_head = get_period_head( hostid ); diff --git a/tests/test/host/test_enum_task.c b/tests/test/host/test_enum_task.c index 9540ca44f..5f46c1536 100644 --- a/tests/test/host/test_enum_task.c +++ b/tests/test/host/test_enum_task.c @@ -47,7 +47,7 @@ #include "mock_tusb_callback.h" #include "mock_hid_host.h" -extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; extern uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE]; uint8_t dev_addr; @@ -64,14 +64,14 @@ tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * cons void setUp(void) { - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); osal_queue_receive_StubWithCallback(queue_recv_stub); osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub); hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub); hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); - osal_semaphore_reset_Expect( usbh_device_info_pool[0].control_sem_hdl ); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); hcd_pipe_control_open_ExpectAndReturn(0, 8, TUSB_ERROR_NONE); } @@ -172,7 +172,7 @@ void test_addr0_failed_dev_desc(void) usbh_enumeration_task(); - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_device_info_pool[0].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state); } @@ -183,7 +183,7 @@ void test_addr0_failed_set_address(void) usbh_enumeration_task(); - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_device_info_pool[0].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state); TEST_ASSERT_EQUAL_MEMORY(&desc_device, enum_data_buffer, 8); } @@ -193,19 +193,19 @@ void test_enum_failed_get_full_dev_desc(void) hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_device_info_pool[0].control_sem_hdl ); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); usbh_enumeration_task(); - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_device_info_pool[0].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[0].state); - 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); - TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[1].hub_port); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[1].state); + TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_devices[1].speed); + TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_devices[1].core_id); + TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_devices[1].hub_addr); + TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_devices[1].hub_port); } void test_enum_failed_get_9byte_config_desc(void) @@ -213,23 +213,23 @@ void test_enum_failed_get_9byte_config_desc(void) osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3)); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_device_info_pool[0].control_sem_hdl ); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); usbh_enumeration_task(); - TEST_ASSERT_EQUAL(desc_device.idVendor, usbh_device_info_pool[1].vendor_id); - TEST_ASSERT_EQUAL(desc_device.idProduct, usbh_device_info_pool[1].product_id); - TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, usbh_device_info_pool[1].configure_count); + TEST_ASSERT_EQUAL(desc_device.idVendor, usbh_devices[1].vendor_id); + TEST_ASSERT_EQUAL(desc_device.idProduct, usbh_devices[1].product_id); + TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, usbh_devices[1].configure_count); } void test_enum_failed_get_full_config_desc(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4)); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_device_info_pool[0].control_sem_hdl ); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); @@ -246,7 +246,7 @@ void test_enum_parse_config_desc(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5)); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_device_info_pool[0].control_sem_hdl ); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); @@ -255,14 +255,14 @@ void test_enum_parse_config_desc(void) usbh_enumeration_task(); - TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_device_info_pool[1].interface_count); + TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count); } void test_enum_set_configure(void) { osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6)); hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE); - osal_semaphore_reset_Expect( usbh_device_info_pool[0].control_sem_hdl ); + osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl ); hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE); tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1); class_install_expect(); diff --git a/tests/test/host/test_usbh.c b/tests/test/host/test_usbh.c index 84d7185b1..35870ca8c 100644 --- a/tests/test/host/test_usbh.c +++ b/tests/test/host/test_usbh.c @@ -46,12 +46,12 @@ #include "mock_tusb_callback.h" #include "mock_hid_host.h" -extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; +extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; uint8_t dev_addr; void setUp(void) { dev_addr = 0; - memset(usbh_device_info_pool, 0, (TUSB_CFG_HOST_DEVICE_MAX+1)*sizeof(usbh_device_info_t)); + memset(usbh_devices, 0, (TUSB_CFG_HOST_DEVICE_MAX+1)*sizeof(usbh_device_info_t)); } void tearDown(void) @@ -63,7 +63,7 @@ void tearDown(void) //--------------------------------------------------------------------+ void test_usbh_status_get_fail(void) { - usbh_device_info_pool[dev_addr].state = 0; + usbh_devices[dev_addr].state = 0; TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_INVALID_PARAMETER, tusbh_device_get_state(TUSB_CFG_HOST_DEVICE_MAX+1) ); TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_get_state(dev_addr) ); @@ -71,7 +71,7 @@ void test_usbh_status_get_fail(void) void test_usbh_status_get_succeed(void) { - usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; + usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_get_state(dev_addr) ); } @@ -143,7 +143,7 @@ void test_usbh_init_ok(void) { osal_semaphore_handle_t sem_hdl_dummy = 0x2233; osal_semaphore_create_IgnoreAndReturn(sem_hdl_dummy); - device_info_zero[i].control_sem_hdl = sem_hdl_dummy; + device_info_zero[i].control.sem_hdl = sem_hdl_dummy; } osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); @@ -153,7 +153,7 @@ void test_usbh_init_ok(void) TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init()); - TEST_ASSERT_EQUAL_MEMORY(device_info_zero, usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + TEST_ASSERT_EQUAL_MEMORY(device_info_zero, usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); } @@ -167,10 +167,10 @@ void test_usbh_device_unplugged_isr_device_not_previously_mounted(void) { uint8_t dev_addr = 1; - 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; + usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG; + usbh_devices[dev_addr].core_id = 0; + usbh_devices[dev_addr].hub_addr = 0; + usbh_devices[dev_addr].hub_port = 0; usbh_device_unplugged_isr(0); } @@ -179,10 +179,10 @@ void test_usbh_device_unplugged_isr(void) { uint8_t dev_addr = 1; - usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; - 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; + usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; + usbh_devices[dev_addr].core_id = 0; + usbh_devices[dev_addr].hub_addr = 0; + usbh_devices[dev_addr].hub_port = 0; class_close_expect(); hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE); @@ -190,5 +190,5 @@ void test_usbh_device_unplugged_isr(void) //------------- Code Under Test -------------// usbh_device_unplugged_isr(0); - TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_device_info_pool[dev_addr].state); + TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state); } diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index 119f514f7..78db3bc40 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -168,7 +168,7 @@ void async_advance_isr(ehci_qhd_t * const async_head) p_control_qhd->p_qtd_list_head = p_control_qhd->p_qtd_list_tail = NULL; // Host Controller has cleaned up its cached data for this device, set state to unplug - usbh_device_info_pool[relative_dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG; + usbh_devices[relative_dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG; } // check if any other endpoints in pool is removing @@ -424,7 +424,7 @@ tusb_error_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size) { //------------- insert to async list -------------// // TODO might need to to disable async list first - list_insert( (ehci_link_t*) get_async_head(usbh_device_info_pool[dev_addr].core_id), + list_insert( (ehci_link_t*) get_async_head(usbh_devices[dev_addr].core_id), (ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD); } @@ -481,7 +481,7 @@ tusb_error_t hcd_pipe_control_close(uint8_t dev_addr) if (dev_addr != 0) { - ASSERT_STATUS( list_remove_qhd_from_async(get_async_head( usbh_device_info_pool[dev_addr].core_id ), p_qhd) ); + ASSERT_STATUS( list_remove_qhd_from_async(get_async_head( usbh_devices[dev_addr].core_id ), p_qhd) ); } return TUSB_ERROR_NONE; @@ -510,11 +510,11 @@ pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_BULK) { // TODO might need to to disable async list first - list_head = get_async_head(usbh_device_info_pool[dev_addr].core_id); + list_head = get_async_head(usbh_devices[dev_addr].core_id); }else if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_INTERRUPT) { // TODO might need to to disable period list first - list_head = get_period_head(usbh_device_info_pool[dev_addr].core_id); + list_head = get_period_head(usbh_devices[dev_addr].core_id); } //------------- insert to async/period list -------------// @@ -562,7 +562,7 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl) if ( pipe_hdl.xfer_type == TUSB_XFER_BULK ) { ASSERT_STATUS( list_remove_qhd_from_async( - get_async_head( usbh_device_info_pool[pipe_hdl.dev_addr].core_id ), + get_async_head( usbh_devices[pipe_hdl.dev_addr].core_id ), p_qhd) ); }else { @@ -613,7 +613,7 @@ STATIC_ INLINE_ ehci_qhd_t* get_period_head(uint8_t hostid) STATIC_ INLINE_ ehci_qhd_t* get_control_qhd(uint8_t dev_addr) { return (dev_addr == 0) ? - get_async_head( usbh_device_info_pool[dev_addr].core_id ) : + get_async_head( usbh_devices[dev_addr].core_id ) : &ehci_data.device[dev_addr-1].control.qhd; } STATIC_ INLINE_ ehci_qtd_t* get_control_qtds(uint8_t dev_addr) @@ -693,18 +693,18 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si p_qhd->device_address = dev_addr; p_qhd->non_hs_period_inactive_next_xact = 0; p_qhd->endpoint_number = endpoint_addr & 0x0F; - p_qhd->endpoint_speed = usbh_device_info_pool[dev_addr].speed; + p_qhd->endpoint_speed = usbh_devices[dev_addr].speed; p_qhd->data_toggle_control = (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0; p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head p_qhd->max_package_size = max_packet_size; - p_qhd->non_hs_control_endpoint = ((TUSB_XFER_CONTROL == xfer_type) && (usbh_device_info_pool[dev_addr].speed != TUSB_SPEED_HIGH) ) ? 1 : 0; + p_qhd->non_hs_control_endpoint = ((TUSB_XFER_CONTROL == xfer_type) && (usbh_devices[dev_addr].speed != TUSB_SPEED_HIGH) ) ? 1 : 0; p_qhd->nak_count_reload = 0; // Bulk/Control -> smask = cmask = 0 if (TUSB_XFER_INTERRUPT == xfer_type) { // Highspeed: schedule every uframe (1 us interval); Full/Low: schedule only 1st frame - p_qhd->interrupt_smask = (TUSB_SPEED_HIGH == usbh_device_info_pool[dev_addr].speed) ? 0xFF : 0x01; + p_qhd->interrupt_smask = (TUSB_SPEED_HIGH == usbh_devices[dev_addr].speed) ? 0xFF : 0x01; // Highspeed: ignored by Host Controller, Full/Low: 4.12.2.1 (EHCI) case 1 schedule complete split at 2,3,4 uframe p_qhd->non_hs_interrupt_cmask = BIN8(11100); }else @@ -712,8 +712,8 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si p_qhd->interrupt_smask = p_qhd->non_hs_interrupt_cmask = 0; } - p_qhd->hub_address = usbh_device_info_pool[dev_addr].hub_addr; - p_qhd->hub_port = usbh_device_info_pool[dev_addr].hub_port; + p_qhd->hub_address = usbh_devices[dev_addr].hub_addr; + p_qhd->hub_port = usbh_devices[dev_addr].hub_port; p_qhd->mult = 1; // TODO not use high bandwidth/park mode yet //------------- active, but no TD list -------------// diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 0dd2e6eec..e78789264 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -81,7 +81,7 @@ static host_class_driver_t const usbh_class_drivers[TUSB_CLASS_MAX_CONSEC_NUMBER //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ -usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1] TUSB_CFG_ATTR_USBRAM; // including zero-address +usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1] TUSB_CFG_ATTR_USBRAM; // including zero-address //------------- Enumeration Task Data -------------// OSAL_TASK_DEF(enum_task, usbh_enumeration_task, 128, OSAL_PRIO_HIGH); @@ -101,7 +101,7 @@ static inline uint8_t get_configure_number_for_device(tusb_descriptor_device_t* tusb_device_state_t tusbh_device_get_state (uint8_t const dev_addr) { ASSERT(dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, TUSB_DEVICE_STATE_INVALID_PARAMETER); - return usbh_device_info_pool[dev_addr].state; + return usbh_devices[dev_addr].state; } //--------------------------------------------------------------------+ @@ -109,15 +109,15 @@ tusb_device_state_t tusbh_device_get_state (uint8_t const dev_addr) //--------------------------------------------------------------------+ tusb_error_t usbh_init(void) { - memclr_(usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); + memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); ASSERT_STATUS( hcd_init() ); //------------- Semaphore for Control Pipe -------------// for(uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++) // including address zero { - usbh_device_info_pool[i].control_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbh_device_info_pool[i].semaphore) ); - ASSERT_PTR(usbh_device_info_pool[i].control_sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); + usbh_devices[i].control.sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbh_devices[i].control.semaphore) ); + ASSERT_PTR(usbh_devices[i].control.sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED); } //------------- Enumeration & Reporter Task init -------------// @@ -143,13 +143,13 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons OSAL_SUBTASK_BEGIN - usbh_device_info_pool[dev_addr].control_pipe_status = PIPE_STATUS_BUSY; - usbh_device_info_pool[dev_addr].control_request = *p_request; - (void) hcd_pipe_control_xfer(dev_addr, &usbh_device_info_pool[dev_addr].control_request, data); + usbh_devices[dev_addr].control.pipe_status = PIPE_STATUS_BUSY; + usbh_devices[dev_addr].control.request = *p_request; + (void) hcd_pipe_control_xfer(dev_addr, &usbh_devices[dev_addr].control.request, data); - osal_semaphore_wait(usbh_device_info_pool[dev_addr].control_sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static + osal_semaphore_wait(usbh_devices[dev_addr].control.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static // TODO make handler for this function general purpose - SUBTASK_ASSERT_STATUS_WITH_HANDLER(error || usbh_device_info_pool[dev_addr].control_pipe_status == PIPE_STATUS_ERROR, + SUBTASK_ASSERT_STATUS_WITH_HANDLER(error || usbh_devices[dev_addr].control.pipe_status == PIPE_STATUS_ERROR, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) ); OSAL_SUBTASK_END @@ -158,7 +158,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons 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].control_sem_hdl ); + osal_semaphore_reset( usbh_devices[dev_addr].control.sem_hdl ); ASSERT_STATUS( hcd_pipe_control_open(dev_addr, max_packet_size) ); @@ -186,8 +186,8 @@ void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_bus_event_t event { if (class_code == 0) // Control transfer { - usbh_device_info_pool[ pipe_hdl.dev_addr ].control_pipe_status = (event == BUS_EVENT_XFER_COMPLETE) ? PIPE_STATUS_COMPLETE : PIPE_STATUS_ERROR; - osal_semaphore_post( usbh_device_info_pool[ pipe_hdl.dev_addr ].control_sem_hdl ); + usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = (event == BUS_EVENT_XFER_COMPLETE) ? PIPE_STATUS_COMPLETE : PIPE_STATUS_ERROR; + osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl ); }else if (usbh_class_drivers[class_code].isr) { usbh_class_drivers[class_code].isr(pipe_hdl, event); @@ -209,10 +209,10 @@ void usbh_device_unplugged_isr(uint8_t hostid) //------------- find the device address that is unplugged -------------// uint8_t dev_addr = 0; 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 && - usbh_device_info_pool[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG + !(usbh_devices[dev_addr].core_id == hostid && + usbh_devices[dev_addr].hub_addr == 0 && + usbh_devices[dev_addr].hub_port == 0 && + usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG ) ) { @@ -236,7 +236,7 @@ void usbh_device_unplugged_isr(uint8_t hostid) // set to REMOVING to allow HCD to clean up its cached data for this device // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done - usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_REMOVING; + usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING; } //--------------------------------------------------------------------+ @@ -258,13 +258,13 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) osal_queue_receive(enum_queue_hdl, (uint32_t*)(&enum_entry), OSAL_TIMEOUT_WAIT_FOREVER, &error); TASK_ASSERT( hcd_port_connect_status(enum_entry.core_id) ); // device may be unplugged - usbh_device_info_pool[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool - usbh_device_info_pool[0].hub_addr = enum_entry.hub_addr; - usbh_device_info_pool[0].hub_port = enum_entry.hub_port; - usbh_device_info_pool[0].speed = enum_entry.speed; + usbh_devices[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool + usbh_devices[0].hub_addr = enum_entry.hub_addr; + usbh_devices[0].hub_port = enum_entry.hub_port; + usbh_devices[0].speed = enum_entry.speed; TASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) ); - usbh_device_info_pool[0].state = TUSB_DEVICE_STATE_ADDRESSED; + usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; //------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------// OSAL_SUBTASK_INVOKED_AND_WAIT( @@ -299,14 +299,14 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) ); //------------- update port info & close control pipe of addr0 -------------// - usbh_device_info_pool[new_addr].core_id = usbh_device_info_pool[0].core_id; - 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].state = TUSB_DEVICE_STATE_ADDRESSED; + usbh_devices[new_addr].core_id = usbh_devices[0].core_id; + usbh_devices[new_addr].hub_addr = usbh_devices[0].hub_addr; + usbh_devices[new_addr].hub_port = usbh_devices[0].hub_port; + usbh_devices[new_addr].speed = usbh_devices[0].speed; + usbh_devices[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED; usbh_pipe_control_close(0); - usbh_device_info_pool[0].state = TUSB_DEVICE_STATE_UNPLUG; + usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; // hcd_port_reset( usbh_device_info_pool[new_addr].core_id ); TODO verified @@ -329,12 +329,12 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) ); // update device info - usbh_device_info_pool[new_addr].vendor_id = ((tusb_descriptor_device_t*) enum_data_buffer)->idVendor; - usbh_device_info_pool[new_addr].product_id = ((tusb_descriptor_device_t*) enum_data_buffer)->idProduct; - usbh_device_info_pool[new_addr].configure_count = ((tusb_descriptor_device_t*) enum_data_buffer)->bNumConfigurations; + usbh_devices[new_addr].vendor_id = ((tusb_descriptor_device_t*) enum_data_buffer)->idVendor; + usbh_devices[new_addr].product_id = ((tusb_descriptor_device_t*) enum_data_buffer)->idProduct; + usbh_devices[new_addr].configure_count = ((tusb_descriptor_device_t*) enum_data_buffer)->bNumConfigurations; configure_selected = get_configure_number_for_device((tusb_descriptor_device_t*) enum_data_buffer); - TASK_ASSERT(configure_selected <= usbh_device_info_pool[new_addr].configure_count); + TASK_ASSERT(configure_selected <= usbh_devices[new_addr].configure_count); //------------- Get 9 bytes of configuration descriptor -------------// OSAL_SUBTASK_INVOKED_AND_WAIT( @@ -369,7 +369,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) ); // update configuration info - usbh_device_info_pool[new_addr].interface_count = ((tusb_descriptor_configuration_t*) enum_data_buffer)->bNumInterfaces; + usbh_devices[new_addr].interface_count = ((tusb_descriptor_configuration_t*) enum_data_buffer)->bNumInterfaces; //------------- parse configuration & install drivers -------------// p_desc = enum_data_buffer + sizeof(tusb_descriptor_configuration_t); @@ -415,7 +415,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) ) ); - usbh_device_info_pool[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED; + usbh_devices[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED; tusbh_device_mount_succeed_cb(new_addr); OSAL_TASK_LOOP_END @@ -437,7 +437,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].state == TUSB_DEVICE_STATE_UNPLUG) + if (usbh_devices[addr].state == TUSB_DEVICE_STATE_UNPLUG) break; } return addr; diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index 9d5f75eb3..9349c64e4 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -93,14 +93,15 @@ typedef struct { // TODO internal structure, re-order members volatile uint8_t state; // device state, value from enum tusbh_device_state_t //------------- control pipe -------------// - volatile uint8_t control_pipe_status; - tusb_std_request_t control_request; - OSAL_SEM_DEF(semaphore); // TODO move to semaphore pool - osal_semaphore_handle_t control_sem_hdl; - + struct { + volatile uint8_t pipe_status; + tusb_std_request_t request; + OSAL_SEM_DEF(semaphore); // TODO move to semaphore pool + osal_semaphore_handle_t sem_hdl; + } control; } usbh_device_info_t; -extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address +extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_bus_event_t event); void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed); |
