rename device_info_pool to usbh_device_info_pool
update enum task to post set address
This commit is contained in:
parent
93269b0343
commit
aa040c4c98
|
@ -42,12 +42,12 @@
|
||||||
#include "mock_hcd.h"
|
#include "mock_hcd.h"
|
||||||
#include "mock_usbh_hcd.h"
|
#include "mock_usbh_hcd.h"
|
||||||
|
|
||||||
extern usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||||
tusb_handle_device_t dev_hdl;
|
tusb_handle_device_t dev_hdl;
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
{
|
{
|
||||||
dev_hdl = 0;
|
dev_hdl = 0;
|
||||||
memset(device_info_pool, 0, TUSB_CFG_HOST_DEVICE_MAX*sizeof(usbh_device_info_t));
|
memset(usbh_device_info_pool, 0, TUSB_CFG_HOST_DEVICE_MAX*sizeof(usbh_device_info_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void tearDown(void)
|
void tearDown(void)
|
||||||
|
@ -98,12 +98,12 @@ void test_usbh_init_ok(void)
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init());
|
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init());
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL_MEMORY(device_info_zero, device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
TEST_ASSERT_EQUAL_MEMORY(device_info_zero, usbh_device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_usbh_status_get_fail(void)
|
void test_usbh_status_get_fail(void)
|
||||||
{
|
{
|
||||||
device_info_pool[dev_hdl].status = 0;
|
usbh_device_info_pool[dev_hdl].status = 0;
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL( 0, tusbh_device_status_get(TUSB_CFG_HOST_DEVICE_MAX) );
|
TEST_ASSERT_EQUAL( 0, tusbh_device_status_get(TUSB_CFG_HOST_DEVICE_MAX) );
|
||||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_UNPLUG, tusbh_device_status_get(dev_hdl) );
|
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_UNPLUG, tusbh_device_status_get(dev_hdl) );
|
||||||
|
@ -111,7 +111,7 @@ void test_usbh_status_get_fail(void)
|
||||||
|
|
||||||
void test_usbh_status_get_succeed(void)
|
void test_usbh_status_get_succeed(void)
|
||||||
{
|
{
|
||||||
device_info_pool[dev_hdl].status = TUSB_DEVICE_STATUS_READY;
|
usbh_device_info_pool[dev_hdl].status = TUSB_DEVICE_STATUS_READY;
|
||||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(dev_hdl) );
|
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(dev_hdl) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,15 +194,29 @@ void test_enum_task_connect(void)
|
||||||
osal_queue_receive_StubWithCallback(queue_recv_stub);
|
osal_queue_receive_StubWithCallback(queue_recv_stub);
|
||||||
hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true);
|
hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true);
|
||||||
hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL);
|
hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL);
|
||||||
hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE);
|
|
||||||
|
|
||||||
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
|
{
|
||||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
|
hcd_addr0_open_IgnoreAndReturn(TUSB_ERROR_NONE);
|
||||||
|
|
||||||
|
// get 8-byte of device descriptor
|
||||||
|
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
|
||||||
|
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
|
||||||
|
// set device address
|
||||||
|
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
|
||||||
|
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
|
||||||
|
|
||||||
|
hcd_addr0_close_IgnoreAndReturn(TUSB_ERROR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub);
|
|
||||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_stub);
|
|
||||||
|
|
||||||
usbh_enumeration_task();
|
usbh_enumeration_task();
|
||||||
|
|
||||||
|
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATUS_ADDRESSED, usbh_device_info_pool[0].status);
|
||||||
|
TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_device_info_pool[0].speed);
|
||||||
|
TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_device_info_pool[0].core_id);
|
||||||
|
TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_device_info_pool[0].hub_addr);
|
||||||
|
TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[0].hub_port);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_enum_task_disconnect(void)
|
void test_enum_task_disconnect(void)
|
||||||
|
|
|
@ -56,8 +56,9 @@
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE;
|
||||||
|
|
||||||
STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
STATIC_ usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// PUBLIC API (Parameter Verification is required)
|
// PUBLIC API (Parameter Verification is required)
|
||||||
|
@ -65,7 +66,7 @@ STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||||
tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl)
|
tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl)
|
||||||
{
|
{
|
||||||
ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, 0);
|
ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, 0);
|
||||||
return device_info_pool[device_hdl].status;
|
return usbh_device_info_pool[device_hdl].status;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -76,11 +77,15 @@ OSAL_TASK_DEF(enum_task, usbh_enumeration_task, 128, OSAL_PRIO_HIGH);
|
||||||
#define ENUM_QUEUE_DEPTH 5
|
#define ENUM_QUEUE_DEPTH 5
|
||||||
OSAL_QUEUE_DEF(enum_queue, ENUM_QUEUE_DEPTH, uin32_t);
|
OSAL_QUEUE_DEF(enum_queue, ENUM_QUEUE_DEPTH, uin32_t);
|
||||||
osal_queue_handle_t enum_queue_hdl;
|
osal_queue_handle_t enum_queue_hdl;
|
||||||
|
|
||||||
usbh_device_addr0_t device_addr0 TUSB_CFG_ATTR_USBRAM;
|
usbh_device_addr0_t device_addr0 TUSB_CFG_ATTR_USBRAM;
|
||||||
uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM;
|
uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_USBRAM;
|
||||||
|
|
||||||
|
|
||||||
void usbh_enumeration_task(void)
|
void usbh_enumeration_task(void)
|
||||||
{
|
{
|
||||||
tusb_error_t error;
|
tusb_error_t error;
|
||||||
|
static uint8_t new_addr;
|
||||||
|
|
||||||
OSAL_TASK_LOOP_BEGIN
|
OSAL_TASK_LOOP_BEGIN
|
||||||
|
|
||||||
|
@ -95,9 +100,8 @@ void usbh_enumeration_task(void)
|
||||||
error = hcd_addr0_open(&device_addr0);
|
error = hcd_addr0_open(&device_addr0);
|
||||||
TASK_ASSERT_STATUS(error);
|
TASK_ASSERT_STATUS(error);
|
||||||
|
|
||||||
{
|
{ // Get first 8 bytes of device descriptor to get Control Endpoint Size
|
||||||
tusb_std_request_t request_device_desc =
|
tusb_std_request_t request_device_desc = {
|
||||||
{
|
|
||||||
.bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
|
.bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
|
||||||
.bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
|
.bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
|
||||||
.wValue = (TUSB_DESC_DEVICE << 8),
|
.wValue = (TUSB_DESC_DEVICE << 8),
|
||||||
|
@ -109,22 +113,14 @@ void usbh_enumeration_task(void)
|
||||||
TASK_ASSERT_STATUS(error);
|
TASK_ASSERT_STATUS(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
new_addr = get_new_address();
|
||||||
uint8_t new_addr = 0;
|
TASK_ASSERT(new_addr < TUSB_CFG_HOST_DEVICE_MAX);
|
||||||
for (new_addr=0; new_addr<TUSB_CFG_HOST_DEVICE_MAX; new_addr++)
|
|
||||||
{
|
|
||||||
if (device_info_pool[new_addr].status == TUSB_DEVICE_STATUS_UNPLUG)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
TASK_ASSERT(new_addr < TUSB_CFG_HOST_DEVICE_MAX);
|
{ // Set new address
|
||||||
|
tusb_std_request_t request_set_address = {
|
||||||
tusb_std_request_t request_set_address =
|
|
||||||
{
|
|
||||||
.bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
|
.bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
|
||||||
.bRequest = TUSB_REQUEST_SET_ADDRESS,
|
.bRequest = TUSB_REQUEST_SET_ADDRESS,
|
||||||
.wValue = (new_addr+1),
|
.wValue = (new_addr+1)
|
||||||
.wLength = 8
|
|
||||||
};
|
};
|
||||||
|
|
||||||
hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_set_address, NULL);
|
hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_set_address, NULL);
|
||||||
|
@ -132,6 +128,15 @@ void usbh_enumeration_task(void)
|
||||||
TASK_ASSERT_STATUS(error);
|
TASK_ASSERT_STATUS(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update data for the new device
|
||||||
|
usbh_device_info_pool[new_addr].core_id = device_addr0.enum_entry.core_id;
|
||||||
|
usbh_device_info_pool[new_addr].hub_addr = device_addr0.enum_entry.hub_addr;
|
||||||
|
usbh_device_info_pool[new_addr].hub_port = device_addr0.enum_entry.hub_port;
|
||||||
|
usbh_device_info_pool[new_addr].speed = device_addr0.speed;
|
||||||
|
usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_ADDRESSED;
|
||||||
|
|
||||||
|
hcd_addr0_close(&device_addr0);
|
||||||
|
|
||||||
|
|
||||||
}else // device connect via a hub
|
}else // device connect via a hub
|
||||||
{
|
{
|
||||||
|
@ -153,7 +158,7 @@ tusb_error_t usbh_init(void)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
memset(device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
memset(usbh_device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||||
|
|
||||||
for(i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++)
|
for(i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++)
|
||||||
{
|
{
|
||||||
|
@ -167,3 +172,18 @@ tusb_error_t usbh_init(void)
|
||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// INTERNAL HELPER
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
static inline uint8_t get_new_address(void)
|
||||||
|
{
|
||||||
|
uint8_t new_addr;
|
||||||
|
for (new_addr=0; new_addr<TUSB_CFG_HOST_DEVICE_MAX; new_addr++)
|
||||||
|
{
|
||||||
|
if (usbh_device_info_pool[new_addr].status == TUSB_DEVICE_STATUS_UNPLUG)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return new_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -102,10 +102,12 @@ enum {
|
||||||
/// Device Status
|
/// Device Status
|
||||||
enum {
|
enum {
|
||||||
TUSB_DEVICE_STATUS_UNPLUG = 0,
|
TUSB_DEVICE_STATUS_UNPLUG = 0,
|
||||||
TUSB_DEVICE_STATUS_READY = BIT_(0),
|
TUSB_DEVICE_STATUS_ADDRESSED,
|
||||||
|
|
||||||
TUSB_DEVICE_STATUS_REMOVING = BIT_(2),
|
TUSB_DEVICE_STATUS_READY, /* Configured */
|
||||||
TUSB_DEVICE_STATUS_SAFE_REMOVE = BIT_(3),
|
|
||||||
|
TUSB_DEVICE_STATUS_REMOVING,
|
||||||
|
TUSB_DEVICE_STATUS_SAFE_REMOVE,
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -110,6 +110,7 @@ typedef struct { // TODO internal structure, re-order members
|
||||||
// ADDRESS 0 API
|
// ADDRESS 0 API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
tusb_error_t hcd_addr0_open(usbh_device_addr0_t *dev_addr0) ATTR_WARN_UNUSED_RESULT;
|
tusb_error_t hcd_addr0_open(usbh_device_addr0_t *dev_addr0) ATTR_WARN_UNUSED_RESULT;
|
||||||
|
tusb_error_t hcd_addr0_close(usbh_device_addr0_t *dev_addr0) ATTR_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue