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
This commit is contained in:
hathach
2013-04-25 17:48:55 +07:00
parent 3763e22c9a
commit c0104b996e
7 changed files with 27 additions and 16 deletions

View File

@@ -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);

View File

@@ -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
}

View File

@@ -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

View File

@@ -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