diff options
| author | hathach <[email protected]> | 2013-02-04 21:52:50 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-02-04 21:52:50 +0700 |
| commit | aa040c4c984039ba9b5820aa15fd0264582bc207 (patch) | |
| tree | 7876b0f9ba01258800ebbb373ce80c3694cca157 /tinyusb/host/usbh.c | |
| parent | 93269b034396673062ec79e69673e95d47f29438 (diff) | |
rename device_info_pool to usbh_device_info_pool
update enum task to post set address
Diffstat (limited to 'tinyusb/host/usbh.c')
| -rw-r--r-- | tinyusb/host/usbh.c | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index f60299a06..ffdb2769f 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -56,8 +56,9 @@ //--------------------------------------------------------------------+ // 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) @@ -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) { 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 OSAL_QUEUE_DEF(enum_queue, ENUM_QUEUE_DEPTH, uin32_t); osal_queue_handle_t enum_queue_hdl; + 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; + + void usbh_enumeration_task(void) { tusb_error_t error; + static uint8_t new_addr; OSAL_TASK_LOOP_BEGIN @@ -95,9 +100,8 @@ void usbh_enumeration_task(void) error = hcd_addr0_open(&device_addr0); TASK_ASSERT_STATUS(error); - { - tusb_std_request_t request_device_desc = - { + { // Get first 8 bytes of device descriptor to get Control Endpoint Size + tusb_std_request_t request_device_desc = { .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, .bRequest = TUSB_REQUEST_GET_DESCRIPTOR, .wValue = (TUSB_DESC_DEVICE << 8), @@ -109,22 +113,14 @@ void usbh_enumeration_task(void) TASK_ASSERT_STATUS(error); } - { - uint8_t new_addr = 0; - 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); + new_addr = get_new_address(); + TASK_ASSERT(new_addr < TUSB_CFG_HOST_DEVICE_MAX); - tusb_std_request_t request_set_address = - { + { // Set new 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 }, .bRequest = TUSB_REQUEST_SET_ADDRESS, - .wValue = (new_addr+1), - .wLength = 8 + .wValue = (new_addr+1) }; 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); } + // 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 { @@ -153,7 +158,7 @@ tusb_error_t usbh_init(void) { 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++) { @@ -167,3 +172,18 @@ tusb_error_t usbh_init(void) return TUSB_ERROR_NONE; } #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; +} + |
