2013-05-06 12:50:19 +07:00
|
|
|
/**************************************************************************/
|
|
|
|
/*!
|
|
|
|
@file test_ehci_pipe_bulk_xfer.c
|
|
|
|
@author hathach (tinyusb.org)
|
2013-03-07 19:54:00 +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-07 19:54:00 +07:00
|
|
|
|
|
|
|
#include "unity.h"
|
|
|
|
#include "tusb_option.h"
|
|
|
|
#include "errors.h"
|
|
|
|
#include "binary.h"
|
|
|
|
|
|
|
|
#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-07 19:54:00 +07:00
|
|
|
#include "ehci.h"
|
2013-03-10 19:28:38 +07:00
|
|
|
#include "ehci_controller.h"
|
2013-03-07 19:54:00 +07:00
|
|
|
|
2013-03-24 16:44:59 +07:00
|
|
|
usbh_device_info_t usbh_devices[TUSB_CFG_HOST_DEVICE_MAX+1];
|
2013-03-07 19:54:00 +07:00
|
|
|
|
|
|
|
uint8_t const hub_addr = 2;
|
|
|
|
uint8_t const hub_port = 2;
|
|
|
|
uint8_t dev_addr;
|
|
|
|
uint8_t hostid;
|
|
|
|
uint8_t xfer_data [18000]; // 18K to test buffer pointer list
|
2013-03-09 13:11:02 +07:00
|
|
|
uint8_t data2[100];
|
2013-03-07 19:54:00 +07:00
|
|
|
|
|
|
|
ehci_qhd_t *async_head;
|
|
|
|
ehci_qhd_t *p_qhd_bulk;
|
|
|
|
pipe_handle_t pipe_hdl_bulk;
|
|
|
|
|
|
|
|
tusb_descriptor_endpoint_t const desc_ept_bulk_in =
|
|
|
|
{
|
|
|
|
.bLength = sizeof(tusb_descriptor_endpoint_t),
|
|
|
|
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
|
|
|
.bEndpointAddress = 0x81,
|
|
|
|
.bmAttributes = { .xfer = TUSB_XFER_BULK },
|
|
|
|
.wMaxPacketSize = 512,
|
|
|
|
.bInterval = 0
|
|
|
|
};
|
|
|
|
|
2013-03-23 14:18:17 +07:00
|
|
|
tusb_descriptor_endpoint_t const desc_ept_bulk_out =
|
|
|
|
{
|
|
|
|
.bLength = sizeof(tusb_descriptor_endpoint_t),
|
|
|
|
.bDescriptorType = TUSB_DESC_ENDPOINT,
|
|
|
|
.bEndpointAddress = 0x01,
|
|
|
|
.bmAttributes = { .xfer = TUSB_XFER_BULK },
|
|
|
|
.wMaxPacketSize = 512,
|
|
|
|
.bInterval = 0
|
|
|
|
};
|
|
|
|
|
2013-03-07 19:54:00 +07:00
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// Setup/Teardown + helper declare
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
void setUp(void)
|
|
|
|
{
|
2013-04-05 14:26:28 +07:00
|
|
|
ehci_controller_init();
|
2013-03-07 19:54:00 +07:00
|
|
|
|
2013-03-24 16:44:59 +07:00
|
|
|
memclr_(usbh_devices, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1));
|
2013-03-07 19:54:00 +07:00
|
|
|
memclr_(xfer_data, sizeof(xfer_data));
|
|
|
|
|
|
|
|
hcd_init();
|
|
|
|
|
|
|
|
dev_addr = 1;
|
|
|
|
|
|
|
|
hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX;
|
2013-03-23 17:31:51 +07:00
|
|
|
for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX+1; i++)
|
2013-03-07 19:54:00 +07:00
|
|
|
{
|
2013-03-24 16:44:59 +07:00
|
|
|
usbh_devices[i].core_id = hostid;
|
|
|
|
usbh_devices[i].hub_addr = hub_addr;
|
|
|
|
usbh_devices[i].hub_port = hub_port;
|
|
|
|
usbh_devices[i].speed = TUSB_SPEED_HIGH;
|
2013-03-07 19:54:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
async_head = get_async_head( hostid );
|
2013-03-09 21:37:49 +07:00
|
|
|
pipe_hdl_bulk = hcd_pipe_open(dev_addr, &desc_ept_bulk_in, TUSB_CLASS_MSC);
|
2013-03-07 19:54:00 +07:00
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL(dev_addr, pipe_hdl_bulk.dev_addr);
|
|
|
|
TEST_ASSERT_EQUAL(TUSB_XFER_BULK, pipe_hdl_bulk.xfer_type);
|
|
|
|
|
2013-03-22 21:21:00 +07:00
|
|
|
p_qhd_bulk = &ehci_data.device[ dev_addr -1].qhd[ pipe_hdl_bulk.index ];
|
2013-03-07 19:54:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
void tearDown(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
// BULK TRANSFER
|
|
|
|
//--------------------------------------------------------------------+
|
|
|
|
void verify_qtd(ehci_qtd_t *p_qtd, uint8_t p_data[], uint16_t length)
|
|
|
|
{
|
|
|
|
TEST_ASSERT_TRUE(p_qtd->alternate.terminate); // not used, always invalid
|
|
|
|
|
|
|
|
//------------- status -------------//
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->pingstate_err);
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->non_hs_split_state);
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->non_hs_period_missed_uframe);
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->xact_err);
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->babble_err);
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->buffer_err);
|
|
|
|
TEST_ASSERT_FALSE(p_qtd->halted);
|
|
|
|
TEST_ASSERT_TRUE(p_qtd->active);
|
|
|
|
|
2013-03-09 13:11:02 +07:00
|
|
|
TEST_ASSERT_FALSE(p_qtd->data_toggle);
|
2013-03-07 19:54:00 +07:00
|
|
|
TEST_ASSERT_EQUAL(3, p_qtd->cerr);
|
|
|
|
TEST_ASSERT_EQUAL(0, p_qtd->current_page);
|
|
|
|
TEST_ASSERT_EQUAL(length, p_qtd->total_bytes);
|
2013-03-09 13:11:02 +07:00
|
|
|
TEST_ASSERT_TRUE(p_qtd->used);
|
2013-03-07 19:54:00 +07:00
|
|
|
|
|
|
|
TEST_ASSERT_EQUAL_HEX( p_data, p_qtd->buffer[0] );
|
|
|
|
for(uint8_t i=1; i<5; i++)
|
|
|
|
{
|
|
|
|
TEST_ASSERT_EQUAL_HEX( align4k((uint32_t) (p_data+4096*i)), align4k(p_qtd->buffer[i]) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-22 21:50:07 +07:00
|
|
|
void test_bulk_xfer_hs_ping_out(void)
|
2013-03-07 19:54:00 +07:00
|
|
|
{
|
2013-03-24 16:44:59 +07:00
|
|
|
usbh_devices[dev_addr].speed = TUSB_SPEED_HIGH;
|
2013-03-22 21:50:07 +07:00
|
|
|
|
|
|
|
pipe_handle_t pipe_hdl = hcd_pipe_open(dev_addr, &desc_ept_bulk_out, TUSB_CLASS_MSC);
|
2013-03-23 10:23:37 +07:00
|
|
|
ehci_qhd_t *p_qhd = qhd_get_from_pipe_handle(pipe_hdl);
|
2013-03-22 21:50:07 +07:00
|
|
|
|
|
|
|
//------------- Code Under Test -------------//
|
|
|
|
hcd_pipe_xfer(pipe_hdl, xfer_data, sizeof(xfer_data), true);
|
2013-03-07 19:54:00 +07:00
|
|
|
|
2013-03-22 21:50:07 +07:00
|
|
|
ehci_qtd_t* p_qtd = p_qhd->p_qtd_list_head;
|
|
|
|
TEST_ASSERT(p_qtd->pingstate_err);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_bulk_xfer(void)
|
|
|
|
{
|
2013-03-07 19:54:00 +07:00
|
|
|
//------------- Code Under Test -------------//
|
2013-03-09 14:19:40 +07:00
|
|
|
hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), true);
|
2013-03-07 19:54:00 +07:00
|
|
|
|
|
|
|
ehci_qtd_t* p_qtd = p_qhd_bulk->p_qtd_list_head;
|
|
|
|
TEST_ASSERT_NOT_NULL(p_qtd);
|
|
|
|
|
|
|
|
verify_qtd( p_qtd, xfer_data, sizeof(xfer_data));
|
2013-03-09 13:11:02 +07:00
|
|
|
TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_qtd);
|
2013-03-07 19:54:00 +07:00
|
|
|
TEST_ASSERT_TRUE(p_qtd->next.terminate);
|
|
|
|
TEST_ASSERT_EQUAL(EHCI_PID_IN, p_qtd->pid);
|
|
|
|
TEST_ASSERT_TRUE(p_qtd->int_on_complete);
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_bulk_xfer_double(void)
|
|
|
|
{
|
|
|
|
//------------- Code Under Test -------------//
|
2013-03-09 14:19:40 +07:00
|
|
|
hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false);
|
|
|
|
hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true);
|
2013-03-07 19:54:00 +07:00
|
|
|
|
2013-03-09 13:11:02 +07:00
|
|
|
ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head;
|
2013-03-10 19:28:38 +07:00
|
|
|
ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail;
|
2013-03-07 19:54:00 +07:00
|
|
|
|
2013-03-09 13:11:02 +07:00
|
|
|
//------------- list head -------------//
|
|
|
|
TEST_ASSERT_NOT_NULL(p_head);
|
|
|
|
verify_qtd(p_head, xfer_data, sizeof(xfer_data));
|
|
|
|
TEST_ASSERT_EQUAL_HEX(p_qhd_bulk->qtd_overlay.next.address, p_head);
|
|
|
|
TEST_ASSERT_EQUAL(EHCI_PID_IN, p_head->pid);
|
|
|
|
TEST_ASSERT_FALSE(p_head->next.terminate);
|
|
|
|
TEST_ASSERT_FALSE(p_head->int_on_complete);
|
2013-03-07 19:54:00 +07:00
|
|
|
|
2013-03-09 13:11:02 +07:00
|
|
|
//------------- list tail -------------//
|
2013-03-10 19:28:38 +07:00
|
|
|
TEST_ASSERT_NOT_NULL(p_tail);
|
|
|
|
verify_qtd(p_tail, data2, sizeof(data2));
|
|
|
|
TEST_ASSERT_EQUAL_HEX( align32(p_head->next.address), p_tail);
|
|
|
|
TEST_ASSERT_EQUAL(EHCI_PID_IN, p_tail->pid);
|
|
|
|
TEST_ASSERT_TRUE(p_tail->next.terminate);
|
|
|
|
TEST_ASSERT_TRUE(p_tail->int_on_complete);
|
2013-03-07 19:54:00 +07:00
|
|
|
}
|
2013-03-10 17:51:53 +07:00
|
|
|
|
2013-03-23 15:00:56 +07:00
|
|
|
void test_bulk_xfer_complete_isr(void)
|
2013-03-10 19:28:38 +07:00
|
|
|
{
|
|
|
|
hcd_pipe_xfer(pipe_hdl_bulk, xfer_data, sizeof(xfer_data), false);
|
|
|
|
hcd_pipe_xfer(pipe_hdl_bulk, data2, sizeof(data2), true);
|
|
|
|
|
|
|
|
ehci_qtd_t* p_head = p_qhd_bulk->p_qtd_list_head;
|
|
|
|
ehci_qtd_t* p_tail = p_qhd_bulk->p_qtd_list_tail;
|
|
|
|
|
2013-04-07 05:09:18 +07:00
|
|
|
usbh_isr_Expect(pipe_hdl_bulk, TUSB_CLASS_MSC, TUSB_EVENT_XFER_COMPLETE);
|
2013-03-10 19:28:38 +07:00
|
|
|
|
|
|
|
//------------- Code Under Test -------------//
|
2013-03-23 17:31:51 +07:00
|
|
|
ehci_controller_run(hostid);
|
2013-03-10 19:28:38 +07:00
|
|
|
|
|
|
|
TEST_ASSERT_TRUE(p_qhd_bulk->qtd_overlay.next.terminate);
|
|
|
|
TEST_ASSERT_FALSE(p_head->used);
|
|
|
|
TEST_ASSERT_FALSE(p_tail->used);
|
|
|
|
TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_head);
|
|
|
|
TEST_ASSERT_NULL(p_qhd_bulk->p_qtd_list_tail);
|
|
|
|
}
|