add test for hcd/host init

- TT control
- usb cmd
complete hcd/host initialization code
This commit is contained in:
hathach 2013-03-04 00:46:40 +07:00
parent 74e6b545e1
commit d644eaeb5c
4 changed files with 70 additions and 8 deletions

View File

@ -315,7 +315,7 @@ void test_ehci_data(void)
}
//--------------------------------------------------------------------+
// Initalization
// Initialization
//--------------------------------------------------------------------+
void test_hcd_init_data(void)
{
@ -375,7 +375,6 @@ void test_hcd_init_async_list(void)
TEST_ASSERT(async_head->qtd_overlay.alternate.terminate);
TEST_ASSERT(async_head->qtd_overlay.halted);
}
}
void test_hcd_init_period_list(void)
@ -406,6 +405,43 @@ void test_hcd_init_period_list(void)
}
#endif
}
void test_hcd_init_tt_control(void)
{
hcd_init();
for(uint32_t i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++)
{
uint8_t const hostid = i+TUSB_CFG_HOST_CONTROLLER_START_INDEX;
ehci_registers_t* const regs = get_operational_register(hostid);
TEST_ASSERT_EQUAL(0, regs->tt_control);
}
}
void test_hcd_init_usbcmd(void)
{
hcd_init();
for(uint32_t i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++)
{
uint8_t const hostid = i+TUSB_CFG_HOST_CONTROLLER_START_INDEX;
ehci_registers_t* const regs = get_operational_register(hostid);
TEST_ASSERT(regs->usb_cmd_bit.async_enable);
#if EHCI_PERIODIC_LIST
TEST_ASSERT(regs->usb_cmd_bit.periodic_enable);
#else
TEST_ASSERT_FALSE(regs->usb_cmd_bit.periodic_enable);
#endif
//------------- Framelist size (NXP specific) -------------//
TEST_ASSERT_BITS(BIN8(11), EHCI_CFG_FRAMELIST_SIZE_BITS, regs->usb_cmd_bit.framelist_size);
TEST_ASSERT_EQUAL(EHCI_CFG_FRAMELIST_SIZE_BITS >> 2, regs->usb_cmd_bit.nxp_framelist_size_msb);
}
}
//--------------------------------------------------------------------+
// Helper
//--------------------------------------------------------------------+

View File

@ -61,12 +61,14 @@ extern "C"
//--------------------------------------------------------------------+
// Compile-time Assert
//--------------------------------------------------------------------+
#ifdef __COUNTER__
#define STATIC_ASSSERT(const_expr) enum { XSTRING_CONCAT(static_assert_, __COUNTER__) = 1/(!!(const_expr)) }
#if defined __COUNTER__ && __COUNTER__ != __COUNTER__
#define _ASSERT_COUNTER __COUNTER__
#else
#define STATIC_ASSSERT(const_expr) enum { XSTRING_CONCAT(static_assert_, __LINE__) = 1/(!!(const_expr)) }
#define _ASSERT_COUNTER __LINE__
#endif
#define STATIC_ASSSERT(const_expr) enum { XSTRING_CONCAT(static_assert_, _ASSERT_COUNTER) = 1/(!!(const_expr)) }
//#if ( defined CFG_PRINTF_UART || defined CFG_PRINTF_USBCDC || defined CFG_PRINTF_DEBUG )
#if TUSB_CFG_DEBUG == 3
#define _PRINTF(...) printf(__VA_ARGS__)

View File

@ -123,7 +123,7 @@ tusb_error_t hcd_controller_init(uint8_t hostid)
regs->usb_sts = EHCI_INT_MASK_ALL; // 2. clear all status
regs->usb_int_enable =
/*EHCI_INT_MASK_USB |*/ EHCI_INT_MASK_ERROR | EHCI_INT_MASK_PORT_CHANGE | EHCI_INT_MASK_ASYNC_ADVANCE
#if 1
#if 1 // TODO enable usbint olny
| EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_NXP_PERIODIC
#endif
;
@ -164,8 +164,19 @@ tusb_error_t hcd_controller_init(uint8_t hostid)
#else
regs->periodic_list_base = 0;
#endif
//------------- TT Control (NXP only) -------------//
regs->tt_control = 0;
//------------- USB CMD Register -------------//
regs->usb_cmd = BIT_(EHCI_USBCMD_POS_ASYNC_ENABLE)
#if EHCI_PERIODIC_LIST
| BIT_(EHCI_USBCMD_POS_PERIOD_ENABLE)
#endif
| ((EHCI_CFG_FRAMELIST_SIZE_BITS & BIN8(011)) << EHCI_USBCMD_POS_FRAMELIST_SZIE)
| ((EHCI_CFG_FRAMELIST_SIZE_BITS >> 2) << EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB);
//------------- ConfigFlag Register (skip) -------------//
return TUSB_ERROR_NONE;

View File

@ -83,9 +83,14 @@
#define EHCI_MAX_ITD 4
#define EHCI_MAX_SITD 16
#define EHCI_CFG_FRAMELIST_SIZE_BITS 5 /// (0:1024) - (1:512) - (2:256) - (3:128) - (4:64) - (5:32) - (6:16) - (7:8)
#define EHCI_CFG_FRAMELIST_SIZE_BITS 7 /// Framelist Size (NXP specific) (0:1024) - (1:512) - (2:256) - (3:128) - (4:64) - (5:32) - (6:16) - (7:8)
#define EHCI_FRAMELIST_SIZE (1024 >> EHCI_CFG_FRAMELIST_SIZE_BITS)
//------------- Validation -------------//
#if EHCI_CFG_FRAMELIST_SIZE_BITS > 7
#error EHCI_CFG_FRAMELIST_SIZE_BITS must be from 0-7
#endif
//--------------------------------------------------------------------+
// EHCI Data Structure
//--------------------------------------------------------------------+
@ -308,6 +313,14 @@ enum ehci_interrupt_mask_{
EHCI_INT_MASK_NXP_ASYNC | EHCI_INT_MASK_NXP_PERIODIC
};
enum ehci_usbcmd_pos_ {
EHCI_USBCMD_POS_FRAMELIST_SZIE = 2,
EHCI_USBCMD_POS_PERIOD_ENABLE = 4,
EHCI_USBCMD_POS_ASYNC_ENABLE = 5,
EHCI_USBCMD_POS_NXP_FRAMELIST_SIZE_MSB = 15,
EHCI_USBCMD_POS_INTERRUPT_THRESHOLD = 16
};
typedef volatile struct {
union {
uint32_t usb_cmd ; ///< The Command Register indicates the command to be executed by the serial bus host controller. Writing to the register causes a command to be executed