2013-05-06 12:50:19 +07:00
|
|
|
/**************************************************************************/
|
|
|
|
/*!
|
|
|
|
@file test_ehci_pipe.c
|
|
|
|
@author hathach (tinyusb.org)
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-05-06 12:50:19 +07:00
|
|
|
@section LICENSE
|
|
|
|
|
|
|
|
Software License Agreement (BSD License)
|
|
|
|
|
|
|
|
Copyright (c) 2013, hathach (tinyusb.org)
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
|
|
|
3. Neither the name of the copyright holders nor the
|
|
|
|
names of its contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
This file is part of the tinyusb stack.
|
|
|
|
*/
|
|
|
|
/**************************************************************************/
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-05-12 20:16:17 +07:00
|
|
|
#include <stdlib.h>
|
2013-03-05 14:26:36 +07:00
|
|
|
#include "unity.h"
|
|
|
|
#include "tusb_option.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "binary.h"
|
2013-05-13 23:18:56 +07:00
|
|
|
#include "type_helper.h"
|
2013-03-05 14:26:36 +07:00
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
#include "mock_osal.h"
|
|
|
|
#include "hcd.h"
|
2013-03-10 17:51:53 +07:00
|
|
|
#include "mock_usbh_hcd.h"
|
2013-03-05 14:26:36 +07:00
|
|
|
#include "ehci.h"
|
2013-05-09 13:05:48 +07:00
|
|
|
#include "ehci_controller_fake.h"
|
2013-05-13 22:57:54 +07:00
|
|
|
#include "host_helper.h"
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-24 16:44:59 +07:00
|
|
|
usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1];
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-05-11 00:40:21 +07:00
|
|
|
static uint8_t const control_max_packet_size = 64;
|
|
|
|
static uint8_t const hub_addr = 2;
|
|
|
|
static uint8_t const hub_port = 2;
|
|
|
|
static uint8_t dev_addr;
|
|
|
|
static uint8_t hostid;
|
2013-03-05 15:23:12 +07:00
|
|
|
|
2013-05-11 00:40:21 +07:00
|
|
|
static ehci_qhd_t *async_head;
|
|
|
|
static ehci_qhd_t *p_control_qhd;
|
2013-03-05 23:08:00 +07:00
|
|
|
|
2013-03-05 14:26:36 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Setup/Teardown + helper declare
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
void setUp(void)
|
|
|
|
{
|
2013-03-24 16:44:59 +07:00
|
|
|
memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1));
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_init() );
|
2013-03-05 15:23:12 +07:00
|
|
|
|
|
|
|
dev_addr = 1;
|
|
|
|
hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX;
|
2013-05-12 20:16:17 +07:00
|
|
|
|
2013-05-13 22:57:54 +07:00
|
|
|
helper_usbh_device_emulate(0, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH);
|
|
|
|
helper_usbh_device_emulate(dev_addr, hub_addr, hub_port, hostid, TUSB_SPEED_HIGH);
|
2013-03-05 15:23:12 +07:00
|
|
|
|
|
|
|
async_head = get_async_head( hostid );
|
2013-03-22 17:34:59 +07:00
|
|
|
p_control_qhd = &ehci_data.device[dev_addr-1].control.qhd;
|
2013-03-05 14:26:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-06 14:55:02 +07:00
|
|
|
void verify_open_qhd(ehci_qhd_t *p_qhd, uint8_t endpoint_addr, uint16_t max_packet_size)
|
2013-03-05 14:26:36 +07:00
|
|
|
{
|
|
|
|
TEST_ASSERT_EQUAL(dev_addr, p_qhd->device_address);
|
2013-03-13 12:29:44 +07:00
|
|
|
TEST_ASSERT_FALSE(p_qhd->non_hs_period_inactive_next_xact);
|
2013-03-06 14:55:02 +07:00
|
|
|
TEST_ASSERT_EQUAL(endpoint_addr & 0x0F, p_qhd->endpoint_number);
|
2013-03-24 16:44:59 +07:00
|
|
|
TEST_ASSERT_EQUAL(usbh_devices[dev_addr].speed, p_qhd->endpoint_speed);
|
2013-03-06 14:55:02 +07:00
|
|
|
TEST_ASSERT_EQUAL(max_packet_size, p_qhd->max_package_size);
|
|
|
|
TEST_ASSERT_EQUAL(0, p_qhd->nak_count_reload); // TDD NAK Reload disable
|
|
|
|
|
2013-03-05 14:26:36 +07:00
|
|
|
TEST_ASSERT_EQUAL(hub_addr, p_qhd->hub_address);
|
|
|
|
TEST_ASSERT_EQUAL(hub_port, p_qhd->hub_port);
|
2013-03-06 22:21:42 +07:00
|
|
|
TEST_ASSERT_EQUAL(1, p_qhd->mult); // TDD operation model for mult
|
2013-03-06 11:24:20 +07:00
|
|
|
|
|
|
|
TEST_ASSERT_FALSE(p_qhd->qtd_overlay.halted);
|
2013-03-05 14:26:36 +07:00
|
|
|
TEST_ASSERT(p_qhd->qtd_overlay.next.terminate);
|
|
|
|
TEST_ASSERT(p_qhd->qtd_overlay.alternate.terminate);
|
|
|
|
|
|
|
|
//------------- HCD -------------//
|
|
|
|
TEST_ASSERT(p_qhd->used);
|
2013-03-13 21:42:19 +07:00
|
|
|
TEST_ASSERT_FALSE(p_qhd->is_removing);
|
2013-03-07 19:54:00 +07:00
|
|
|
TEST_ASSERT_NULL(p_qhd->p_qtd_list_head);
|
2013-03-09 13:11:02 +07:00
|
|
|
TEST_ASSERT_NULL(p_qhd->p_qtd_list_tail);
|
2013-03-05 14:26:36 +07:00
|
|
|
}
|
|
|
|
|
2013-03-05 23:08:00 +07:00
|
|
|
void verify_control_open_qhd(ehci_qhd_t *p_qhd)
|
|
|
|
{
|
2013-03-06 14:55:02 +07:00
|
|
|
verify_open_qhd(p_qhd, 0, control_max_packet_size);
|
2013-03-05 23:08:00 +07:00
|
|
|
|
2013-03-09 21:37:49 +07:00
|
|
|
TEST_ASSERT_EQUAL(0, p_qhd->class_code);
|
2013-03-05 23:08:00 +07:00
|
|
|
TEST_ASSERT_EQUAL(1, p_qhd->data_toggle_control);
|
2013-03-06 14:55:02 +07:00
|
|
|
TEST_ASSERT_EQUAL(0, p_qhd->interrupt_smask);
|
2013-03-06 22:21:42 +07:00
|
|
|
TEST_ASSERT_EQUAL(0, p_qhd->non_hs_interrupt_cmask);
|
2013-03-05 23:08:00 +07:00
|
|
|
}
|
|
|
|
|
2013-03-23 14:18:17 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// PIPE OPEN
|
|
|
|
//--------------------------------------------------------------------+
|
2013-03-05 14:26:36 +07:00
|
|
|
void test_control_open_addr0_qhd_data(void)
|
|
|
|
{
|
|
|
|
dev_addr = 0;
|
|
|
|
|
2013-03-06 14:55:02 +07:00
|
|
|
//------------- Code Under Test -------------//
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
verify_control_open_qhd(async_head);
|
|
|
|
TEST_ASSERT(async_head->head_list_flag);
|
2013-03-05 14:26:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_control_open_qhd_data(void)
|
|
|
|
{
|
2013-03-06 14:55:02 +07:00
|
|
|
//------------- Code Under TEST -------------//
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size));
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
verify_control_open_qhd(p_control_qhd);
|
|
|
|
TEST_ASSERT_FALSE(p_control_qhd->head_list_flag);
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-05 15:23:12 +07:00
|
|
|
//------------- async list check -------------//
|
2013-03-22 17:34:59 +07:00
|
|
|
TEST_ASSERT_EQUAL_HEX((uint32_t) p_control_qhd, align32(async_head->next.address));
|
2013-03-05 15:23:12 +07:00
|
|
|
TEST_ASSERT_FALSE(async_head->next.terminate);
|
|
|
|
TEST_ASSERT_EQUAL(EHCI_QUEUE_ELEMENT_QHD, async_head->next.type);
|
2013-03-05 14:26:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_control_open_highspeed(void)
|
|
|
|
{
|
2013-03-24 16:44:59 +07:00
|
|
|
usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH;
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-06 14:55:02 +07:00
|
|
|
//------------- Code Under TEST -------------//
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );
|
2013-03-22 17:34:59 +07:00
|
|
|
TEST_ASSERT_FALSE(p_control_qhd->non_hs_control_endpoint);
|
2013-03-05 14:26:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_control_open_non_highspeed(void)
|
|
|
|
{
|
2013-03-24 16:44:59 +07:00
|
|
|
usbh_devices[dev_addr].speed = TUSB_SPEED_FULL;
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-06 14:55:02 +07:00
|
|
|
//------------- Code Under TEST -------------//
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );
|
2013-03-05 14:26:36 +07:00
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
TEST_ASSERT_TRUE(p_control_qhd->non_hs_control_endpoint);
|
2013-03-05 14:26:36 +07:00
|
|
|
}
|
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// PIPE CLOSE
|
|
|
|
//--------------------------------------------------------------------+
|
2013-03-13 21:42:19 +07:00
|
|
|
void test_control_addr0_close(void)
|
|
|
|
{
|
|
|
|
dev_addr = 0;
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );
|
2013-03-13 21:42:19 +07:00
|
|
|
|
|
|
|
//------------- Code Under Test -------------//
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) );
|
2013-03-13 21:42:19 +07:00
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
TEST_ASSERT(async_head->head_list_flag);
|
|
|
|
TEST_ASSERT(async_head->is_removing);
|
2013-03-13 21:42:19 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void test_control_close(void)
|
|
|
|
{
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_open(dev_addr, control_max_packet_size) );
|
2013-03-13 21:42:19 +07:00
|
|
|
|
|
|
|
//------------- Code Under TEST -------------//
|
2013-05-13 23:18:56 +07:00
|
|
|
TEST_ASSERT_STATUS( hcd_pipe_control_close(dev_addr) );
|
2013-05-12 20:16:17 +07:00
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
TEST_ASSERT(p_control_qhd->is_removing);
|
|
|
|
TEST_ASSERT(p_control_qhd->used);
|
2013-03-13 21:42:19 +07:00
|
|
|
|
2013-03-22 17:34:59 +07:00
|
|
|
TEST_ASSERT( align32(get_async_head(hostid)->next.address) != (uint32_t) p_control_qhd );
|
|
|
|
TEST_ASSERT_EQUAL( get_async_head(hostid), align32(p_control_qhd->next.address));
|
2013-03-07 16:06:28 +07:00
|
|
|
}
|