diff options
| author | hathach <[email protected]> | 2013-04-25 17:48:55 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-04-25 17:48:55 +0700 |
| commit | c0104b996e9ea0c5c25861ccf24e0255431a8f9c (patch) | |
| tree | e6bc02cedad783d2c4d771ac4a9633be23b982d5 /tinyusb | |
| parent | 3763e22c9a91e9bb21f9fa3dc5dafc9eea6254b7 (diff) | |
implement hcd_port_speed_get
move port reset & speed detection from isr context to usbh enumeration task
- decrease time in isr significantly from 50 ms to 580us
fix bug with osal_task_delay for freeRTOS buil
Diffstat (limited to 'tinyusb')
| -rw-r--r-- | tinyusb/host/ehci/ehci.c | 10 | ||||
| -rw-r--r-- | tinyusb/host/hcd.h | 5 | ||||
| -rw-r--r-- | tinyusb/host/usbh.c | 11 | ||||
| -rw-r--r-- | tinyusb/host/usbh_hcd.h | 4 | ||||
| -rw-r--r-- | tinyusb/osal/osal_freeRTOS.h | 2 |
5 files changed, 20 insertions, 12 deletions
diff --git a/tinyusb/host/ehci/ehci.c b/tinyusb/host/ehci/ehci.c index a91f62ef8..cef713133 100644 --- a/tinyusb/host/ehci/ehci.c +++ b/tinyusb/host/ehci/ehci.c @@ -137,7 +137,7 @@ void hcd_port_reset(uint8_t hostid) #ifndef _TEST_ // NXP specific, port reset will automatically be 0 when reset sequence complete // there is chance device is unplugged while reset sequence is not complete - while( regs->portsc_bit.port_reset) {} + while( regs->portsc_bit.port_reset) {} // TODO use task delay to remove blocking #endif } @@ -146,6 +146,11 @@ bool hcd_port_connect_status(uint8_t hostid) return get_operational_register(hostid)->portsc_bit.current_connect_status; } +tusb_speed_t hcd_port_speed_get(uint8_t hostid) +{ + return get_operational_register(hostid)->portsc_bit.nxp_port_speed; // NXP specific port speed +} + //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ @@ -479,8 +484,7 @@ void port_connect_status_change_isr(uint8_t hostid) if (regs->portsc_bit.current_connect_status) // device plugged { - hcd_port_reset(hostid); - usbh_device_plugged_isr(hostid, regs->portsc_bit.nxp_port_speed); // NXP specific port speed + usbh_device_plugged_isr(hostid); }else // device unplugged { usbh_device_unplugged_isr(hostid); diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index 999fbf734..fed45bf8a 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -105,8 +105,9 @@ tusb_error_t hcd_pipe_cancel()ATTR_WARN_UNUSED_RESULT; // PORT API //--------------------------------------------------------------------+ /// return the current connect status of roothub port -bool hcd_port_connect_status(uint8_t core_id) ATTR_CONST ATTR_WARN_UNUSED_RESULT; -void hcd_port_reset(uint8_t core_id); +bool hcd_port_connect_status(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible +void hcd_port_reset(uint8_t hostid); +tusb_speed_t hcd_port_speed_get(uint8_t hostid) ATTR_PURE ATTR_WARN_UNUSED_RESULT; // TODO make inline if possible #ifdef __cplusplus } diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index c62b75c48..333d2d9a2 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -202,10 +202,10 @@ void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event) } } -void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed) +void usbh_device_plugged_isr(uint8_t hostid) { osal_queue_send(enum_queue_hdl, - &(usbh_enumerate_t){ .core_id = hostid, .speed = speed} ); + &(usbh_enumerate_t){ .core_id = hostid} ); } void usbh_device_unplugged_isr(uint8_t hostid) @@ -277,16 +277,19 @@ tusb_error_t enumeration_body_subtask(void) osal_queue_receive(enum_queue_hdl, &enum_entry, OSAL_TIMEOUT_WAIT_FOREVER, &error); SUBTASK_ASSERT( hcd_port_connect_status(enum_entry.core_id) ); // ensure device is still plugged + 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; + + hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation + usbh_devices[0].speed = hcd_port_speed_get( usbh_devices[0].core_id ); SUBTASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) ); usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; #ifndef _TEST_ - // TODO finalize delay after reset, hack delay 100 ms, otherwise speed is detected as LOW in most cases + // TODO hack delay 100 ms for slow device (use retry on the 1st xfer instead later) osal_task_delay(100); #endif diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h index f235c3170..cda536939 100644 --- a/tinyusb/host/usbh_hcd.h +++ b/tinyusb/host/usbh_hcd.h @@ -72,7 +72,7 @@ typedef struct ATTR_ALIGNED(4){ uint8_t core_id; uint8_t hub_addr; uint8_t hub_port; - uint8_t speed; + uint8_t reserve; } usbh_enumerate_t; typedef struct { // TODO internal structure, re-order members @@ -107,7 +107,7 @@ extern usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1]; // including //------------- callback from HCD ISR-------------// void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code, tusb_event_t event); -void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed); +void usbh_device_plugged_isr(uint8_t hostid); void usbh_device_unplugged_isr(uint8_t hostid); #ifdef __cplusplus diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h index 44681e736..6d091ed29 100644 --- a/tinyusb/osal/osal_freeRTOS.h +++ b/tinyusb/osal/osal_freeRTOS.h @@ -99,7 +99,7 @@ static inline tusb_error_t osal_task_create(osal_task_t *task) static inline void osal_task_delay(uint32_t msec) ATTR_ALWAYS_INLINE; static inline void osal_task_delay(uint32_t msec) { - vTaskDelay(TUSB_CFG_OS_TICKS_PER_SECOND * msec); + vTaskDelay( (TUSB_CFG_OS_TICKS_PER_SECOND * msec) / 1000 ); } #define OSAL_TASK_LOOP_BEGIN \ |
