usbh rename vars

This commit is contained in:
hathach 2018-12-07 00:47:16 +07:00
parent 2fe9abe71f
commit c93fb23693
17 changed files with 171 additions and 159 deletions

View File

@ -287,7 +287,7 @@ tusb_error_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
if (dev_addr != 0)
{
//------------- insert to async list -------------//
list_insert( (ehci_link_t*) get_async_head(usbh_devices[dev_addr].core_id),
list_insert( (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].core_id),
(ehci_link_t*) p_qhd, EHCI_QUEUE_ELEMENT_QHD);
}
@ -344,7 +344,7 @@ tusb_error_t hcd_pipe_control_close(uint8_t dev_addr)
if (dev_addr != 0)
{
TU_ASSERT_ERR( list_remove_qhd( (ehci_link_t*) get_async_head( usbh_devices[dev_addr].core_id ),
TU_ASSERT_ERR( list_remove_qhd( (ehci_link_t*) get_async_head( _usbh_devices[dev_addr].core_id ),
(ehci_link_t*) p_qhd) );
}
@ -376,12 +376,12 @@ pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_desc_endpoint_t const * p_end
if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_BULK)
{
list_head = (ehci_link_t*) get_async_head(usbh_devices[dev_addr].core_id);
list_head = (ehci_link_t*) get_async_head(_usbh_devices[dev_addr].core_id);
}
#if EHCI_PERIODIC_LIST // TODO refractor/group this together
else if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_INTERRUPT)
{
list_head = get_period_head(usbh_devices[dev_addr].core_id, p_qhd->interval_ms);
list_head = get_period_head(_usbh_devices[dev_addr].core_id, p_qhd->interval_ms);
}
#endif
@ -443,14 +443,14 @@ tusb_error_t hcd_pipe_close(pipe_handle_t pipe_hdl)
if ( pipe_hdl.xfer_type == TUSB_XFER_BULK )
{
TU_ASSERT_ERR( list_remove_qhd(
(ehci_link_t*) get_async_head( usbh_devices[pipe_hdl.dev_addr].core_id ),
(ehci_link_t*) get_async_head( _usbh_devices[pipe_hdl.dev_addr].core_id ),
(ehci_link_t*) p_qhd) );
}
#if EHCI_PERIODIC_LIST // TODO refractor/group this together
else
{
TU_ASSERT_ERR( list_remove_qhd(
get_period_head( usbh_devices[pipe_hdl.dev_addr].core_id, p_qhd->interval_ms ),
get_period_head( _usbh_devices[pipe_hdl.dev_addr].core_id, p_qhd->interval_ms ),
(ehci_link_t*) p_qhd) );
}
#endif
@ -505,7 +505,7 @@ static void async_advance_isr(ehci_qhd_t * const async_head)
async_head->p_qtd_list_head = async_head->p_qtd_list_tail = NULL;
async_head->qtd_overlay.halted = 1;
usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG;
_usbh_devices[0].state = TUSB_DEVICE_STATE_UNPLUG;
}
for(uint8_t relative_dev_addr=0; relative_dev_addr < CFG_TUSB_HOST_DEVICE_MAX; relative_dev_addr++)
@ -518,7 +518,7 @@ static void async_advance_isr(ehci_qhd_t * const async_head)
p_control_qhd->used = 0;
// Host Controller has cleaned up its cached data for this device, set state to unplug
usbh_devices[relative_dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG;
_usbh_devices[relative_dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG;
for (uint8_t i=0; i<HCD_MAX_ENDPOINT; i++) // free all qhd
{
@ -833,7 +833,7 @@ static inline ehci_link_t* get_period_head(uint8_t hostid, uint8_t interval_ms)
static inline ehci_qhd_t* get_control_qhd(uint8_t dev_addr)
{
return (dev_addr == 0) ?
get_async_head( usbh_devices[dev_addr].core_id ) :
get_async_head( _usbh_devices[dev_addr].core_id ) :
&ehci_data.device[dev_addr-1].control.qhd;
}
static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr)
@ -942,7 +942,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si
p_qhd->device_address = dev_addr;
p_qhd->non_hs_period_inactive_next_xact = 0;
p_qhd->endpoint_number = endpoint_addr & 0x0F;
p_qhd->endpoint_speed = usbh_devices[dev_addr].speed;
p_qhd->endpoint_speed = _usbh_devices[dev_addr].speed;
p_qhd->data_toggle_control = (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0;
p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static asyn list head
p_qhd->max_package_size = max_packet_size;
@ -979,8 +979,8 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_si
p_qhd->interrupt_smask = p_qhd->non_hs_interrupt_cmask = 0;
}
p_qhd->hub_address = usbh_devices[dev_addr].hub_addr;
p_qhd->hub_port = usbh_devices[dev_addr].hub_port;
p_qhd->hub_address = _usbh_devices[dev_addr].hub_addr;
p_qhd->hub_port = _usbh_devices[dev_addr].hub_port;
p_qhd->mult = 1; // TODO not use high bandwidth/park mode yet
//------------- HCD Management Data -------------//

View File

@ -118,7 +118,7 @@ enum { USBH_CLASS_DRIVER_COUNT = sizeof(usbh_class_drivers) / sizeof(host_class_
//--------------------------------------------------------------------+
// INTERNAL OBJECT & FUNCTION DECLARATION
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
OSAL_TASK_DEF(_usbh_task_def, "usbh", usbh_task, CFG_TUH_TASK_PRIO, CFG_TUH_TASK_STACK_SZ);
@ -127,7 +127,7 @@ OSAL_TASK_DEF(_usbh_task_def, "usbh", usbh_task, CFG_TUH_TASK_PRIO, CFG_TUH_TASK
OSAL_QUEUE_DEF(OPT_MODE_HOST, _usbh_qdef, CFG_TUH_TASK_QUEUE_SZ, hcd_event_t);
static osal_queue_t _usbh_q;
CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) STATIC_VAR uint8_t enum_data_buffer[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
//------------- Reporter Task Data -------------//
@ -141,12 +141,12 @@ static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_de
tusb_device_state_t tuh_device_get_state (uint8_t const dev_addr)
{
TU_ASSERT( dev_addr <= CFG_TUSB_HOST_DEVICE_MAX, TUSB_DEVICE_STATE_INVALID_PARAMETER);
return (tusb_device_state_t) usbh_devices[dev_addr].state;
return (tusb_device_state_t) _usbh_devices[dev_addr].state;
}
uint32_t tuh_device_get_mounted_class_flag(uint8_t dev_addr)
{
return tuh_device_is_configured(dev_addr) ? usbh_devices[dev_addr].flag_supported_class : 0;
return tuh_device_is_configured(dev_addr) ? _usbh_devices[dev_addr].flag_supported_class : 0;
}
//--------------------------------------------------------------------+
@ -154,7 +154,7 @@ uint32_t tuh_device_get_mounted_class_flag(uint8_t dev_addr)
//--------------------------------------------------------------------+
bool usbh_init(void)
{
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
//------------- Enumeration & Reporter Task init -------------//
_usbh_q = osal_queue_create( &_usbh_qdef );
@ -165,7 +165,7 @@ bool usbh_init(void)
//------------- Semaphore, Mutex for Control Pipe -------------//
for(uint8_t i=0; i<CFG_TUSB_HOST_DEVICE_MAX+1; i++) // including address zero
{
usbh_device_info_t * const p_device = &usbh_devices[i];
usbh_device_t * const p_device = &_usbh_devices[i];
p_device->control.sem_hdl = osal_semaphore_create(&p_device->control.sem_def);
TU_ASSERT(p_device->control.sem_hdl != NULL);
@ -193,7 +193,7 @@ bool usbh_init(void)
bool usbh_control_xfer_subtask (uint8_t dev_addr, uint8_t bmRequestType, uint8_t bRequest,
uint16_t wValue, uint16_t wIndex, uint16_t wLength, uint8_t* data)
{
usbh_device_info_t* dev = &usbh_devices[dev_addr];
usbh_device_t* dev = &_usbh_devices[dev_addr];
TU_ASSERT(osal_mutex_lock(dev->control.mutex_hdl, OSAL_TIMEOUT_NORMAL));
@ -223,7 +223,7 @@ bool usbh_control_xfer_subtask (uint8_t dev_addr, uint8_t bmRequestType, uint8_t
tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
{
osal_semaphore_reset( usbh_devices[dev_addr].control.sem_hdl );
osal_semaphore_reset( _usbh_devices[dev_addr].control.sem_hdl );
//osal_mutex_reset( usbh_devices[dev_addr].control.mutex_hdl );
TU_ASSERT_ERR( hcd_pipe_control_open(dev_addr, max_packet_size) );
@ -263,9 +263,9 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, xfer_result_t eve
uint8_t class_index = std_class_code_to_index(class_code);
if (TUSB_XFER_CONTROL == pipe_hdl.xfer_type)
{
usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = event;
_usbh_devices[ pipe_hdl.dev_addr ].control.pipe_status = event;
// usbh_devices[ pipe_hdl.dev_addr ].control.xferred_bytes = xferred_bytes; not yet neccessary
osal_semaphore_post( usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl, true );
osal_semaphore_post( _usbh_devices[ pipe_hdl.dev_addr ].control.sem_hdl, true );
}else if (usbh_class_drivers[class_index].isr)
{
usbh_class_drivers[class_index].isr(pipe_hdl, event, xferred_bytes);
@ -279,7 +279,7 @@ void usbh_hub_port_plugged_isr(uint8_t hub_addr, uint8_t hub_port)
{
hcd_event_t event =
{
.rhport = usbh_devices[hub_addr].core_id,
.rhport = _usbh_devices[hub_addr].core_id,
.event_id = HCD_EVENT_DEVICE_PLUG
};
@ -321,15 +321,15 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_
//------------- find the all devices (star-network) under port that is unplugged -------------//
for (uint8_t dev_addr = 0; dev_addr <= CFG_TUSB_HOST_DEVICE_MAX; dev_addr ++)
{
if (usbh_devices[dev_addr].core_id == hostid &&
(hub_addr == 0 || usbh_devices[dev_addr].hub_addr == hub_addr) && // hub_addr == 0 & hub_port == 0 means roothub
(hub_port == 0 || usbh_devices[dev_addr].hub_port == hub_port) &&
usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG)
if (_usbh_devices[dev_addr].core_id == hostid &&
(hub_addr == 0 || _usbh_devices[dev_addr].hub_addr == hub_addr) && // hub_addr == 0 & hub_port == 0 means roothub
(hub_port == 0 || _usbh_devices[dev_addr].hub_port == hub_port) &&
_usbh_devices[dev_addr].state != TUSB_DEVICE_STATE_UNPLUG)
{
// TODO Hub multiple level
for (uint8_t class_index = 1; class_index < USBH_CLASS_DRIVER_COUNT; class_index++)
{
if ((usbh_devices[dev_addr].flag_supported_class & BIT_(class_index)) &&
if ((_usbh_devices[dev_addr].flag_supported_class & BIT_(class_index)) &&
usbh_class_drivers[class_index].close)
{
usbh_class_drivers[class_index].close(dev_addr);
@ -339,8 +339,8 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_
// TODO refractor
// set to REMOVING to allow HCD to clean up its cached data for this device
// HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
usbh_devices[dev_addr].flag_supported_class = 0;
_usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
_usbh_devices[dev_addr].flag_supported_class = 0;
usbh_pipe_control_close(dev_addr);
@ -349,7 +349,7 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_
}
}
if (is_found) hcd_port_unplug(usbh_devices[0].core_id); // TODO hack
if (is_found) hcd_port_unplug(_usbh_devices[0].core_id); // TODO hack
}
@ -370,7 +370,8 @@ void usbh_hcd_rhport_unplugged_isr(uint8_t hostid)
//--------------------------------------------------------------------+
// ENUMERATION TASK
//--------------------------------------------------------------------+
bool usbh_task_body(void)
bool enum_task(hcd_event_t* event)
{
enum {
POWER_STABLE_DELAY = 500,
@ -378,21 +379,14 @@ bool usbh_task_body(void)
};
// for OSAL_NONE local variable won't retain value after blocking service sem_wait/queue_recv
static uint8_t new_addr;
static uint8_t configure_selected = 1; // TODO move
static uint8_t *p_desc = NULL; // TODO move
hcd_event_t event;
if ( !osal_queue_receive(_usbh_q, &event) ) return false;
usbh_device_t* dev0 = &_usbh_devices[0];
// FIXME remove later
if ( !(event.event_id == HCD_EVENT_DEVICE_PLUG || event.event_id == HCD_EVENT_DEVICE_UNPLUG) ) return false;
usbh_device_info_t* dev0 = &usbh_devices[0];
dev0->core_id = event.rhport; // TODO refractor integrate to device_pool
dev0->hub_addr = event.plug.hub_addr;
dev0->hub_port = event.plug.hub_port;
dev0->core_id = event->rhport; // TODO refractor integrate to device_pool
dev0->hub_addr = event->plug.hub_addr;
dev0->hub_port = event->plug.hub_port;
dev0->state = TUSB_DEVICE_STATE_UNPLUG;
//------------- connected/disconnected directly with roothub -------------//
@ -425,14 +419,14 @@ bool usbh_task_body(void)
//------------- Get Port Status -------------//
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, dev0->hub_port,
4, enum_data_buffer )
4, _usbh_ctrl_buf )
, hub_status_pipe_queue( dev0->hub_addr) ); // TODO hub refractor
// Acknowledge 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;
p_port_status = ((hub_port_status_response_t *) enum_data_buffer);
p_port_status = ((hub_port_status_response_t *) _usbh_ctrl_buf);
if ( ! p_port_status->status_change.connect_status ) return true; // only handle connection change
@ -464,7 +458,7 @@ bool usbh_task_body(void)
//------------- 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),
TUSB_REQ_GET_DESCRIPTOR,
(TUSB_DESC_DEVICE << 8), 0, 8, enum_data_buffer);
(TUSB_DESC_DEVICE << 8), 0, 8, _usbh_ctrl_buf);
//------------- Reset device again before Set Address -------------//
if (dev0->hub_addr == 0)
@ -491,7 +485,7 @@ bool usbh_task_body(void)
#endif
//------------- Set new address -------------//
new_addr = get_new_address();
uint8_t const new_addr = get_new_address();
TU_ASSERT(new_addr <= CFG_TUSB_HOST_DEVICE_MAX); // TODO notify application we reach max devices
TU_ASSERT(usbh_control_xfer_subtask( 0, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
@ -499,32 +493,33 @@ bool usbh_task_body(void)
0, NULL ));
//------------- update port info & close control pipe of addr0 -------------//
usbh_devices[new_addr].core_id = dev0->core_id;
usbh_devices[new_addr].hub_addr = dev0->hub_addr;
usbh_devices[new_addr].hub_port = dev0->hub_port;
usbh_devices[new_addr].speed = dev0->speed;
usbh_devices[new_addr].state = TUSB_DEVICE_STATE_ADDRESSED;
usbh_device_t* new_dev = &_usbh_devices[new_addr];
new_dev->core_id = dev0->core_id;
new_dev->hub_addr = dev0->hub_addr;
new_dev->hub_port = dev0->hub_port;
new_dev->speed = dev0->speed;
new_dev->state = TUSB_DEVICE_STATE_ADDRESSED;
usbh_pipe_control_close(0);
dev0->state = TUSB_DEVICE_STATE_UNPLUG;
// 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*) _usbh_ctrl_buf)->bMaxPacketSize0 ) );
//------------- Get full device descriptor -------------//
TU_ASSERT(
usbh_control_xfer_subtask(new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_DEVICE << 8), 0,
18,
enum_data_buffer));
_usbh_ctrl_buf));
// update device info TODO alignment issue
usbh_devices[new_addr].vendor_id = ((tusb_desc_device_t*) enum_data_buffer)->idVendor;
usbh_devices[new_addr].product_id = ((tusb_desc_device_t*) enum_data_buffer)->idProduct;
usbh_devices[new_addr].configure_count = ((tusb_desc_device_t*) enum_data_buffer)->bNumConfigurations;
new_dev->vendor_id = ((tusb_desc_device_t*) _usbh_ctrl_buf)->idVendor;
new_dev->product_id = ((tusb_desc_device_t*) _usbh_ctrl_buf)->idProduct;
new_dev->configure_count = ((tusb_desc_device_t*) _usbh_ctrl_buf)->bNumConfigurations;
configure_selected = get_configure_number_for_device((tusb_desc_device_t*) enum_data_buffer);
TU_ASSERT(configure_selected <= usbh_devices[new_addr].configure_count); // TODO notify application when invalid configuration
configure_selected = get_configure_number_for_device((tusb_desc_device_t*) _usbh_ctrl_buf);
TU_ASSERT(configure_selected <= new_dev->configure_count); // TODO notify application when invalid configuration
//------------- Get 9 bytes of configuration descriptor -------------//
TU_ASSERT(
@ -532,33 +527,33 @@ bool usbh_task_body(void)
TUSB_REQ_GET_DESCRIPTOR,
(TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1), 0,
9,
enum_data_buffer));
_usbh_ctrl_buf));
TU_VERIFY_HDLR( CFG_TUSB_HOST_ENUM_BUFFER_SIZE >= ((tusb_desc_configuration_t*)enum_data_buffer)->wTotalLength,
TU_VERIFY_HDLR( CFG_TUSB_HOST_ENUM_BUFFER_SIZE >= ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength,
tuh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_CONFIG_DESC_TOO_LONG, NULL) );
//------------- Get full configuration descriptor -------------//
TU_ASSERT( usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_IN, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
TUSB_REQ_GET_DESCRIPTOR, (TUSB_DESC_CONFIGURATION << 8) | (configure_selected - 1), 0,
CFG_TUSB_HOST_ENUM_BUFFER_SIZE, enum_data_buffer ) );
CFG_TUSB_HOST_ENUM_BUFFER_SIZE, _usbh_ctrl_buf ) );
// update configuration info
usbh_devices[new_addr].interface_count = ((tusb_desc_configuration_t*) enum_data_buffer)->bNumInterfaces;
new_dev->interface_count = ((tusb_desc_configuration_t*) _usbh_ctrl_buf)->bNumInterfaces;
//------------- Set Configure -------------//
TU_ASSERT( usbh_control_xfer_subtask( new_addr, bm_request_type(TUSB_DIR_OUT, TUSB_REQ_TYPE_STANDARD, TUSB_REQ_RCPT_DEVICE),
TUSB_REQ_SET_CONFIGURATION, configure_selected, 0,
0, NULL ));
usbh_devices[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
new_dev->state = TUSB_DEVICE_STATE_CONFIGURED;
//------------- TODO Get String Descriptors -------------//
//------------- parse configuration & install drivers -------------//
p_desc = enum_data_buffer + sizeof(tusb_desc_configuration_t);
p_desc = _usbh_ctrl_buf + sizeof(tusb_desc_configuration_t);
// parse each interfaces
while( p_desc < enum_data_buffer + ((tusb_desc_configuration_t*)enum_data_buffer)->wTotalLength )
while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength )
{
// skip until we see interface descriptor
if ( TUSB_DESC_INTERFACE != p_desc[DESC_OFFSET_TYPE] )
@ -572,15 +567,16 @@ bool usbh_task_body(void)
TU_ASSERT( class_index != 0 ); // class_index == 0 means corrupted data, abort enumeration
if (usbh_class_drivers[class_index].open_subtask &&
!(class_index == TUSB_CLASS_HUB && usbh_devices[new_addr].hub_addr != 0))
{ // supported class, TODO Hub disable multiple level
!(class_index == TUSB_CLASS_HUB && new_dev->hub_addr != 0))
{
// supported class, TODO Hub disable multiple level
static uint16_t length;
length = 0;
if ( usbh_class_drivers[class_index].open_subtask(new_addr, (tusb_desc_interface_t*) p_desc, &length) )
{
TU_ASSERT( length >= sizeof(tusb_desc_interface_t) );
usbh_devices[new_addr].flag_supported_class |= BIT_(class_index);
new_dev->flag_supported_class |= BIT_(class_index);
p_desc += length;
}else // Interface open failed, for example a subclass is not supported
{
@ -598,6 +594,22 @@ bool usbh_task_body(void)
return true;
}
bool usbh_task_body(void)
{
while (1)
{
hcd_event_t event;
if ( !osal_queue_receive(_usbh_q, &event) ) return false;
switch (event.event_id)
{
case HCD_EVENT_DEVICE_PLUG:
case HCD_EVENT_DEVICE_UNPLUG:
enum_task(&event);
break;
}
}
}
/* USB Host task
* Thread that handles all device events. With an real RTOS, the task must be a forever loop and never return.
@ -626,7 +638,7 @@ static inline uint8_t get_new_address(void)
uint8_t addr;
for (addr=1; addr <= CFG_TUSB_HOST_DEVICE_MAX; addr++)
{
if (usbh_devices[addr].state == TUSB_DEVICE_STATE_UNPLUG)
if (_usbh_devices[addr].state == TUSB_DEVICE_STATE_UNPLUG)
break;
}
return addr;

View File

@ -86,9 +86,9 @@ typedef struct {
osal_mutex_def_t mutex_def;
osal_mutex_t mutex_hdl; // used to exclusively occupy control pipe
} control;
} usbh_device_info_t;
} usbh_device_t;
extern usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address
//--------------------------------------------------------------------+
// callback from HCD ISR

View File

@ -51,7 +51,7 @@
#include "mock_osal.h"
#include "mock_usbh_hcd.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t hostid;

View File

@ -50,7 +50,7 @@
#include "mock_osal.h"
#include "mock_usbh_hcd.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t hostid;
static ehci_registers_t * regs;

View File

@ -51,7 +51,7 @@
#include "mock_osal.h"
#include "mock_usbh_hcd.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
//--------------------------------------------------------------------+
// Setup/Teardown + helper declare

View File

@ -51,7 +51,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t const hub_addr = 2;
static uint8_t const hub_port = 2;
@ -70,7 +70,7 @@ void setUp(void)
dev_addr = 1;
hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX;
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH);
async_head = get_async_head( hostid );
@ -85,7 +85,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack
TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address);
TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact);
TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number);
TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
TEST_ASSERT_EQUAL(_usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size);
TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable

View File

@ -51,7 +51,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t hub_addr = 2;
static uint8_t hub_port = 2;
@ -91,7 +91,7 @@ void setUp(void)
{
ehci_controller_init();
tu_memclr(xfer_data, sizeof(xfer_data));
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
TEST_ASSERT_STATUS( hcd_init() );
@ -146,7 +146,7 @@ void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length)
void test_bulk_xfer_hs_ping_out(void)
{
usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH;
_usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH;
pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC);
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl);

View File

@ -51,7 +51,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t const control_max_packet_size = 64;
static uint8_t const hub_addr = 2;
@ -67,7 +67,7 @@ static ehci_qhd_t *p_control_qhd;
//--------------------------------------------------------------------+
void setUp(void)
{
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
TEST_ASSERT_STATUS( hcd_init() );
@ -90,7 +90,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack
TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address);
TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact);
TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number);
TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
TEST_ASSERT_EQUAL(_usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size);
TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable
@ -149,7 +149,7 @@ void test_control_open_qhd_data(void)
void test_control_open_highspeed(void)
{
usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH;
_usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH;
//------------- Code Under TEST -------------//
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );
@ -158,7 +158,7 @@ void test_control_open_highspeed(void)
void test_control_open_non_highspeed(void)
{
usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
_usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
//------------- Code Under TEST -------------//
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );

View File

@ -51,7 +51,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t const control_max_packet_size = 64;
static uint8_t const hub_addr = 2;
@ -74,7 +74,7 @@ void setUp(void)
{
ehci_controller_init();
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(xfer_data, sizeof(xfer_data));
TEST_ASSERT_STATUS( hcd_init() );

View File

@ -50,7 +50,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t const hub_addr = 2;
static uint8_t const hub_port = 2;
@ -67,7 +67,7 @@ static pipe_handle_t pipe_hdl;
//--------------------------------------------------------------------+
void setUp(void)
{
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
hcd_init();
@ -90,7 +90,7 @@ void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_pack
TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address);
TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact);
TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number);
TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
TEST_ASSERT_EQUAL(_usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size);
TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable
@ -272,7 +272,7 @@ void test_open_interrupt_hs_interval_8(void)
void test_open_interrupt_qhd_non_hs(void)
{
usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
_usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
//------------- Code Under TEST -------------//
pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_interrupt_out, TUSB_CLASS_HID);
@ -294,7 +294,7 @@ void test_open_interrupt_qhd_non_hs_9(void)
tusb_desc_endpoint_t int_edp_interval = desc_ept_interrupt_out;
int_edp_interval.bInterval = 32;
usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
_usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
//------------- Code Under TEST -------------//
pipe_hdl = hcd_pipe_open(dev_addr, &int_edp_interval, TUSB_CLASS_HID);

View File

@ -51,7 +51,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t const hub_addr = 2;
static uint8_t const hub_port = 2;
@ -91,7 +91,7 @@ void setUp(void)
{
ehci_controller_init();
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(xfer_data, sizeof(xfer_data));
TEST_ASSERT_STATUS( hcd_init() );

View File

@ -50,7 +50,7 @@
#include "ehci_controller_fake.h"
#include "host_helper.h"
usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
static uint8_t const hub_addr = 2;
static uint8_t const hub_port = 2;
@ -63,7 +63,7 @@ static ehci_qhd_t *period_head_arr;
//--------------------------------------------------------------------+
void setUp(void)
{
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
hcd_init();

View File

@ -69,11 +69,11 @@ static inline void helper_usbh_init_expect(void)
static inline void helper_usbh_device_emulate(uint8_t dev_addr, uint8_t hub_addr, uint8_t hub_port, uint8_t hostid, tusb_speed_t speed)
{
usbh_devices[dev_addr].core_id = hostid;
usbh_devices[dev_addr].hub_addr = hub_addr;
usbh_devices[dev_addr].hub_port = hub_port;
usbh_devices[dev_addr].speed = speed;
usbh_devices[dev_addr].state = dev_addr ? TUSB_DEVICE_STATE_CONFIGURED : TUSB_DEVICE_STATE_UNPLUG;
_usbh_devices[dev_addr].core_id = hostid;
_usbh_devices[dev_addr].hub_addr = hub_addr;
_usbh_devices[dev_addr].hub_port = hub_port;
_usbh_devices[dev_addr].speed = speed;
_usbh_devices[dev_addr].state = dev_addr ? TUSB_DEVICE_STATE_CONFIGURED : TUSB_DEVICE_STATE_UNPLUG;
}

View File

@ -51,7 +51,7 @@
#include "mock_cdc_host.h"
#include "mock_msc_host.h"
extern usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
extern uint8_t enum_data_buffer[CFG_TUSB_HOST_ENUM_BUFFER_SIZE];
usbh_enumerate_t const enum_connect = {
@ -73,7 +73,7 @@ enum {
void setUp(void)
{
tu_memclr(usbh_devices, sizeof(usbh_device_info_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
tu_memclr(_usbh_devices, sizeof(usbh_device_t)*(CFG_TUSB_HOST_DEVICE_MAX+1));
osal_queue_receive_StubWithCallback(queue_recv_stub);
osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub);
@ -89,8 +89,8 @@ void setUp(void)
osal_task_delay_Expect(RESET_DELAY);
hcd_port_speed_get_ExpectAndReturn(enum_connect.core_id, device_speed);
osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl );
osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl );
hcd_pipe_control_open_ExpectAndReturn(0, 8, TUSB_ERROR_NONE);
}
@ -222,53 +222,53 @@ void test_addr0_failed_dev_desc(void)
usbh_enumeration_task(NULL);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, _usbh_devices[0].state);
}
void test_addr0_failed_set_address(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(1));
hcd_port_reset_Expect( usbh_devices[0].core_id );
hcd_port_reset_Expect( _usbh_devices[0].core_id );
osal_task_delay_Expect(RESET_DELAY);
// tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
usbh_enumeration_task(NULL);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[0].state);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, _usbh_devices[0].state);
TEST_ASSERT_EQUAL_MEMORY(&desc_device, enum_data_buffer, 8);
}
void test_enum_failed_get_full_dev_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2));
hcd_port_reset_Expect( usbh_devices[0].core_id );
hcd_port_reset_Expect( _usbh_devices[0].core_id );
osal_task_delay_Expect(RESET_DELAY);
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl );
osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl );
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
// tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
usbh_enumeration_task(NULL);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, usbh_devices[0].state);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, usbh_devices[1].state);
TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, usbh_devices[1].speed);
TEST_ASSERT_EQUAL(enum_connect.core_id, usbh_devices[1].core_id);
TEST_ASSERT_EQUAL(enum_connect.hub_addr, usbh_devices[1].hub_addr);
TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_devices[1].hub_port);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_UNPLUG, _usbh_devices[0].state);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_ADDRESSED, _usbh_devices[1].state);
TEST_ASSERT_EQUAL(TUSB_SPEED_FULL, _usbh_devices[1].speed);
TEST_ASSERT_EQUAL(enum_connect.core_id, _usbh_devices[1].core_id);
TEST_ASSERT_EQUAL(enum_connect.hub_addr, _usbh_devices[1].hub_addr);
TEST_ASSERT_EQUAL(enum_connect.hub_port, _usbh_devices[1].hub_port);
}
void test_enum_failed_get_9byte_config_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3));
hcd_port_reset_Expect( usbh_devices[0].core_id );
hcd_port_reset_Expect( _usbh_devices[0].core_id );
osal_task_delay_Expect(RESET_DELAY);
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl );
osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl );
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
tusbh_device_attached_cb_ExpectAndReturn((tusb_desc_device_t*) enum_data_buffer, 1);
@ -276,19 +276,19 @@ void test_enum_failed_get_9byte_config_desc(void)
usbh_enumeration_task(NULL);
TEST_ASSERT_EQUAL(desc_device.idVendor, usbh_devices[1].vendor_id);
TEST_ASSERT_EQUAL(desc_device.idProduct, usbh_devices[1].product_id);
TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, usbh_devices[1].configure_count);
TEST_ASSERT_EQUAL(desc_device.idVendor, _usbh_devices[1].vendor_id);
TEST_ASSERT_EQUAL(desc_device.idProduct, _usbh_devices[1].product_id);
TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, _usbh_devices[1].configure_count);
}
void test_enum_failed_get_full_config_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4));
hcd_port_reset_Expect( usbh_devices[0].core_id );
hcd_port_reset_Expect( _usbh_devices[0].core_id );
osal_task_delay_Expect(RESET_DELAY);
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl );
osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl );
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
tusbh_device_attached_cb_ExpectAndReturn((tusb_desc_device_t*) enum_data_buffer, 1);
// tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
@ -299,11 +299,11 @@ void test_enum_failed_get_full_config_desc(void)
void test_enum_parse_config_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
hcd_port_reset_Expect( usbh_devices[0].core_id );
hcd_port_reset_Expect( _usbh_devices[0].core_id );
osal_task_delay_Expect(RESET_DELAY);
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl );
osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl );
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
tusbh_device_attached_cb_ExpectAndReturn((tusb_desc_device_t*) enum_data_buffer, 1);
@ -311,17 +311,17 @@ void test_enum_parse_config_desc(void)
usbh_enumeration_task(NULL);
TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count);
TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, _usbh_devices[1].interface_count);
}
void test_enum_set_configure(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6));
hcd_port_reset_Expect( usbh_devices[0].core_id );
hcd_port_reset_Expect( _usbh_devices[0].core_id );
osal_task_delay_Expect(RESET_DELAY);
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( usbh_devices[0].control.mutex_hdl );
osal_semaphore_reset_Expect( _usbh_devices[0].control.sem_hdl );
osal_mutex_reset_Expect( _usbh_devices[0].control.mutex_hdl );
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
tusbh_device_attached_cb_ExpectAndReturn((tusb_desc_device_t*) enum_data_buffer, 1);
@ -335,5 +335,5 @@ void test_enum_set_configure(void)
usbh_enumeration_task(NULL);
TEST_ASSERT_EQUAL( BIT_(TUSB_CLASS_HID) | BIT_(TUSB_CLASS_MSC) | BIT_(TUSB_CLASS_CDC),
usbh_devices[1].flag_supported_class); // TODO change later
_usbh_devices[1].flag_supported_class); // TODO change later
}

View File

@ -68,7 +68,7 @@ void tearDown(void)
//--------------------------------------------------------------------+
void test_usbh_status_get_fail(void)
{
usbh_devices[dev_addr].state = 0;
_usbh_devices[dev_addr].state = 0;
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_INVALID_PARAMETER, tusbh_device_get_state(CFG_TUSB_HOST_DEVICE_MAX+1) );
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_get_state(dev_addr) );
@ -76,7 +76,7 @@ void test_usbh_status_get_fail(void)
void test_usbh_status_get_succeed(void)
{
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
_usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_get_state(dev_addr) );
}
@ -136,7 +136,7 @@ void test_usbh_init_ok(void)
for (uint8_t i=0; i<CFG_TUSB_HOST_DEVICE_MAX+1; i++)
{
TEST_ASSERT_NOT_NULL(usbh_devices[i].control.sem_hdl);
TEST_ASSERT_NOT_NULL(_usbh_devices[i].control.sem_hdl);
}
}
@ -146,10 +146,10 @@ void test_usbh_hcd_rhport_unplugged_isr_device_not_previously_mounted(void)
{
uint8_t dev_addr = 1;
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
usbh_devices[dev_addr].core_id = 0;
usbh_devices[dev_addr].hub_addr = 0;
usbh_devices[dev_addr].hub_port = 0;
_usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
_usbh_devices[dev_addr].core_id = 0;
_usbh_devices[dev_addr].hub_addr = 0;
_usbh_devices[dev_addr].hub_port = 0;
usbh_hcd_rhport_unplugged_isr(0);
}
@ -158,11 +158,11 @@ void test_usbh_hcd_rhport_unplugged_isr(void)
{
uint8_t dev_addr = 1;
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
usbh_devices[dev_addr].core_id = 0;
usbh_devices[dev_addr].hub_addr = 0;
usbh_devices[dev_addr].hub_port = 0;
usbh_devices[dev_addr].flag_supported_class = BIT_(TUSB_CLASS_HID);
_usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
_usbh_devices[dev_addr].core_id = 0;
_usbh_devices[dev_addr].hub_addr = 0;
_usbh_devices[dev_addr].hub_port = 0;
_usbh_devices[dev_addr].flag_supported_class = BIT_(TUSB_CLASS_HID);
hidh_close_Expect(dev_addr);
hcd_pipe_control_close_ExpectAndReturn(dev_addr, TUSB_ERROR_NONE);
@ -170,18 +170,18 @@ void test_usbh_hcd_rhport_unplugged_isr(void)
//------------- Code Under Test -------------//
usbh_hcd_rhport_unplugged_isr(0);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, _usbh_devices[dev_addr].state);
}
void test_usbh_device_unplugged_multple_class(void)
{
uint8_t dev_addr = 1;
usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
usbh_devices[dev_addr].core_id = 0;
usbh_devices[dev_addr].hub_addr = 0;
usbh_devices[dev_addr].hub_port = 0;
usbh_devices[dev_addr].flag_supported_class = BIT_(TUSB_CLASS_HID) | BIT_(TUSB_CLASS_MSC) | BIT_(TUSB_CLASS_CDC);
_usbh_devices[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
_usbh_devices[dev_addr].core_id = 0;
_usbh_devices[dev_addr].hub_addr = 0;
_usbh_devices[dev_addr].hub_port = 0;
_usbh_devices[dev_addr].flag_supported_class = BIT_(TUSB_CLASS_HID) | BIT_(TUSB_CLASS_MSC) | BIT_(TUSB_CLASS_CDC);
cdch_close_Expect(dev_addr);
hidh_close_Expect(dev_addr);
@ -192,7 +192,7 @@ void test_usbh_device_unplugged_multple_class(void)
//------------- Code Under Test -------------//
usbh_hcd_rhport_unplugged_isr(0);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, usbh_devices[dev_addr].state);
TEST_ASSERT_EQUAL(TUSB_DEVICE_STATE_REMOVING, _usbh_devices[dev_addr].state);
}
#endif
@ -219,7 +219,7 @@ void test_usbh_control_xfer_mutex_failed(void)
};
osal_mutex_wait_StubWithCallback(mutex_wait_failed_stub);
osal_mutex_release_ExpectAndReturn(usbh_devices[dev_addr].control.mutex_hdl, TUSB_ERROR_NONE);
osal_mutex_release_ExpectAndReturn(_usbh_devices[dev_addr].control.mutex_hdl, TUSB_ERROR_NONE);
//------------- Code Under Test -------------//
usbh_control_xfer_subtask(dev_addr, 1, 2, 3, 4, 0, NULL);
@ -241,7 +241,7 @@ void test_usbh_control_xfer_ok(void)
hcd_pipe_control_xfer_ExpectAndReturn(dev_addr, &a_request, NULL, TUSB_ERROR_NONE);
osal_semaphore_wait_StubWithCallback(semaphore_wait_success_stub);
osal_mutex_release_ExpectAndReturn(usbh_devices[dev_addr].control.mutex_hdl, TUSB_ERROR_NONE);
osal_mutex_release_ExpectAndReturn(_usbh_devices[dev_addr].control.mutex_hdl, TUSB_ERROR_NONE);
//------------- Code Under Test -------------//
usbh_control_xfer_subtask(dev_addr, 1, 2, 3, 4, 0, NULL);

View File

@ -54,7 +54,7 @@
LPC_USB0_Type lpc_usb0;
LPC_USB1_Type lpc_usb1;
extern usbh_device_info_t usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
//--------------------------------------------------------------------+
// IMPLEMENTATION
@ -67,7 +67,7 @@ void ehci_controller_init(void)
void ehci_controller_control_xfer_proceed(uint8_t dev_addr, uint8_t p_data[])
{
ehci_registers_t* const regs = get_operational_register( usbh_devices[dev_addr].core_id );
ehci_registers_t* const regs = get_operational_register( _usbh_devices[dev_addr].core_id );
ehci_qhd_t * p_qhd = get_control_qhd(dev_addr);
ehci_qtd_t * p_qtd_setup = get_control_qtds(dev_addr);
ehci_qtd_t * p_qtd_data = p_qtd_setup + 1;
@ -86,7 +86,7 @@ void ehci_controller_control_xfer_proceed(uint8_t dev_addr, uint8_t p_data[])
regs->usb_sts = EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_NXP_PERIODIC;
hcd_isr( usbh_devices[dev_addr].core_id );
hcd_isr( _usbh_devices[dev_addr].core_id );
}
void complete_qtd_in_qhd(ehci_qhd_t *p_qhd)