minor clean up

This commit is contained in:
hathach 2018-12-06 22:50:19 +07:00
parent 07c3fd5e1e
commit ac829c0a87
3 changed files with 35 additions and 53 deletions

View File

@ -69,13 +69,7 @@ static inline cdc_pipeid_t get_app_pipeid(pipe_handle_t pipe_hdl)
static inline bool tusbh_cdc_is_mounted(uint8_t dev_addr) static inline bool tusbh_cdc_is_mounted(uint8_t dev_addr)
{ {
// FIXME cannot use mounted class flag as at the point _open_sublass is called, the flag is not set yet return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) && pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out);
#ifdef _TEST_
return (tusbh_device_get_mounted_class_flag(dev_addr) & BIT_(TUSB_CLASS_CDC)) != 0;
#else
return pipehandle_is_valid(cdch_data[dev_addr-1].pipe_in) &&
pipehandle_is_valid(cdch_data[dev_addr-1].pipe_out);
#endif
} }
bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid) bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
@ -100,7 +94,6 @@ bool tuh_cdc_is_busy(uint8_t dev_addr, cdc_pipeid_t pipeid)
} }
} }
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// APPLICATION API (parameter validation needed) // APPLICATION API (parameter validation needed)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@ -361,7 +361,6 @@ bool usbh_task_body(void)
RESET_DELAY = 200 // USB specs say only 50ms but many devices require much longer RESET_DELAY = 200 // USB specs say only 50ms but many devices require much longer
}; };
tusb_error_t error;
usbh_enumerate_t enum_entry; usbh_enumerate_t enum_entry;
// for OSAL_NONE local variable won't retain value after blocking service sem_wait/queue_recv // for OSAL_NONE local variable won't retain value after blocking service sem_wait/queue_recv
@ -371,31 +370,33 @@ bool usbh_task_body(void)
if ( !osal_queue_receive(_usbh_q, &enum_entry) ) return false; if ( !osal_queue_receive(_usbh_q, &enum_entry) ) return false;
usbh_devices[0].core_id = enum_entry.core_id; // TODO refractor integrate to device_pool usbh_device_info_t* dev0 = &usbh_devices[0];
usbh_devices[0].hub_addr = enum_entry.hub_addr;
usbh_devices[0].hub_port = enum_entry.hub_port; dev0->core_id = enum_entry.core_id; // TODO refractor integrate to device_pool
usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; dev0->hub_addr = enum_entry.hub_addr;
dev0->hub_port = enum_entry.hub_port;
dev0->state = TUSB_DEVICE_STATE_UNPLUG;
//------------- connected/disconnected directly with roothub -------------// //------------- connected/disconnected directly with roothub -------------//
if ( usbh_devices[0].hub_addr == 0) if ( dev0->hub_addr == 0)
{ {
if( hcd_port_connect_status(usbh_devices[0].core_id) ) if( hcd_port_connect_status(dev0->core_id) )
{ {
// connection event // connection event
osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get
// exit if device unplugged while delaying // exit if device unplugged while delaying
if ( !hcd_port_connect_status(usbh_devices[0].core_id) ) return true; if ( !hcd_port_connect_status(dev0->core_id) ) return true;
hcd_port_reset( usbh_devices[0].core_id ); // port must be reset to have correct speed operation hcd_port_reset( dev0->core_id ); // port must be reset to have correct speed operation
osal_task_delay(RESET_DELAY); osal_task_delay(RESET_DELAY);
usbh_devices[0].speed = hcd_port_speed_get( usbh_devices[0].core_id ); dev0->speed = hcd_port_speed_get( dev0->core_id );
} }
else else
{ {
// disconnection event // disconnection event
usbh_device_unplugged(usbh_devices[0].core_id, 0, 0); usbh_device_unplugged(dev0->core_id, 0, 0);
return true; // restart task return true; // restart task
} }
} }
@ -404,13 +405,13 @@ bool usbh_task_body(void)
else else
{ {
//------------- Get Port Status -------------// //------------- Get Port Status -------------//
TU_VERIFY_HDLR( usbh_control_xfer_subtask( usbh_devices[0].hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER), TU_VERIFY_HDLR( usbh_control_xfer_subtask( dev0->hub_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_CLASS, TUSB_REQ_RCPT_OTHER),
HUB_REQUEST_GET_STATUS, 0, usbh_devices[0].hub_port, HUB_REQUEST_GET_STATUS, 0, dev0->hub_port,
4, enum_data_buffer ) 4, enum_data_buffer )
, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor , hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor
// Acknowledge Port Connection Change // Acknowledge Port Connection Change
hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE); hub_port_clear_feature_subtask(dev0->hub_addr, dev0->hub_port, HUB_FEATURE_PORT_CONNECTION_CHANGE);
hub_port_status_response_t * p_port_status; hub_port_status_response_t * p_port_status;
p_port_status = ((hub_port_status_response_t *) enum_data_buffer); p_port_status = ((hub_port_status_response_t *) enum_data_buffer);
@ -420,27 +421,27 @@ bool usbh_task_body(void)
if ( ! p_port_status->status_current.connect_status ) if ( ! p_port_status->status_current.connect_status )
{ {
// Disconnection event // Disconnection event
usbh_device_unplugged(usbh_devices[0].core_id, usbh_devices[0].hub_addr, usbh_devices[0].hub_port); usbh_device_unplugged(dev0->core_id, dev0->hub_addr, dev0->hub_port);
(void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe (void) hub_status_pipe_queue( dev0->hub_addr ); // done with hub, waiting for next data on status pipe
return true; // restart task return true; // restart task
} }
else else
{ {
// Connection Event // Connection Event
TU_VERIFY_HDLR(hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port), TU_VERIFY_HDLR(hub_port_reset_subtask(dev0->hub_addr, dev0->hub_port),
hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor
usbh_devices[0].speed = hub_port_get_speed(); dev0->speed = hub_port_get_speed();
// Acknowledge Port Reset Change // Acknowledge Port Reset Change
hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE); hub_port_clear_feature_subtask(dev0->hub_addr, dev0->hub_port, HUB_FEATURE_PORT_RESET_CHANGE);
} }
} }
#endif #endif
TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) ); TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) );
usbh_devices[0].state = TUSB_DEVICE_STATE_ADDRESSED; dev0->state = TUSB_DEVICE_STATE_ADDRESSED;
//------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------// //------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------//
bool is_ok = usbh_control_xfer_subtask(0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE), bool is_ok = usbh_control_xfer_subtask(0, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
@ -448,26 +449,26 @@ bool usbh_task_body(void)
(TUSB_DESC_DEVICE << 8), 0, 8, enum_data_buffer); (TUSB_DESC_DEVICE << 8), 0, 8, enum_data_buffer);
//------------- Reset device again before Set Address -------------// //------------- Reset device again before Set Address -------------//
if (usbh_devices[0].hub_addr == 0) if (dev0->hub_addr == 0)
{ {
// connected directly to roothub // connected directly to roothub
TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times
hcd_port_reset( usbh_devices[0].core_id ); // reset port after 8 byte descriptor hcd_port_reset( dev0->core_id ); // reset port after 8 byte descriptor
osal_task_delay(RESET_DELAY); osal_task_delay(RESET_DELAY);
} }
#if CFG_TUH_HUB #if CFG_TUH_HUB
else else
{ {
// connected via a hub // connected via a hub
TU_VERIFY_HDLR(is_ok, hub_status_pipe_queue( usbh_devices[0].hub_addr) ); // TODO hub refractor TU_VERIFY_HDLR(is_ok, hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor
if ( hub_port_reset_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port) ) if ( hub_port_reset_subtask(dev0->hub_addr, dev0->hub_port) )
{ {
// Acknowledge Port Reset Change if Reset Successful // Acknowledge Port Reset Change if Reset Successful
hub_port_clear_feature_subtask(usbh_devices[0].hub_addr, usbh_devices[0].hub_port, HUB_FEATURE_PORT_RESET_CHANGE); hub_port_clear_feature_subtask(dev0->hub_addr, dev0->hub_port, HUB_FEATURE_PORT_RESET_CHANGE);
} }
(void) hub_status_pipe_queue( usbh_devices[0].hub_addr ); // done with hub, waiting for next data on status pipe (void) hub_status_pipe_queue( dev0->hub_addr ); // done with hub, waiting for next data on status pipe
} }
#endif #endif
@ -480,14 +481,14 @@ bool usbh_task_body(void)
0, NULL )); 0, NULL ));
//------------- update port info & close control pipe of addr0 -------------// //------------- update port info & close control pipe of addr0 -------------//
usbh_devices[new_addr].core_id = usbh_devices[0].core_id; usbh_devices[new_addr].core_id = dev0->core_id;
usbh_devices[new_addr].hub_addr = usbh_devices[0].hub_addr; usbh_devices[new_addr].hub_addr = dev0->hub_addr;
usbh_devices[new_addr].hub_port = usbh_devices[0].hub_port; usbh_devices[new_addr].hub_port = dev0->hub_port;
usbh_devices[new_addr].speed = usbh_devices[0].speed; usbh_devices[new_addr].speed = dev0->speed;
usbh_devices[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED; usbh_devices[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED;
usbh_pipe_control_close(0); usbh_pipe_control_close(0);
usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG; dev0->state = TUSB_DEVICE_STATE_UNPLUG;
// open control pipe for new address // open control pipe for new address
TU_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) ); TU_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
@ -599,14 +600,6 @@ void usbh_task(void* param)
#endif #endif
} }
//--------------------------------------------------------------------+
// REPORTER TASK & ITS DATA
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// INTERNAL HELPER // INTERNAL HELPER
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@ -52,10 +52,6 @@
#include "common/tusb_common.h" #include "common/tusb_common.h"
#include "osal/osal.h" #include "osal/osal.h"
#ifdef _TEST_
#include "hcd.h"
#endif
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// USBH-HCD common data structure // USBH-HCD common data structure
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+