diff options
| author | hathach <[email protected]> | 2013-02-01 10:33:43 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-02-01 10:33:43 +0700 |
| commit | 9e3785e7e1bd5bac3c8e24477edbde12cc09dd4b (patch) | |
| tree | c2233323659aeda002dbbcb6e910b669f1147aac | |
| parent | 1b963f6a7117d754c47e860159ac0aa90d1db6dc (diff) | |
add std=gnu99 for test build
add hcd_init to usbh_init and update test code
add TUSB_CFG_OS_TICK_PER_SECOND define for TUSB_OS_NONE
change osal_semaphore_wait and osal_queue_receive API to have timeout effectively
| -rw-r--r-- | tests/project.yml | 4 | ||||
| -rw-r--r-- | tests/test/host/test_usbd_host.c | 66 | ||||
| -rw-r--r-- | tests/test/support/tusb_config.h | 1 | ||||
| -rw-r--r-- | tests/test/test_osal_none.c | 11 | ||||
| -rw-r--r-- | tinyusb/common/errors.h | 1 | ||||
| -rw-r--r-- | tinyusb/host/hcd.c | 1 | ||||
| -rw-r--r-- | tinyusb/host/hcd.h | 5 | ||||
| -rw-r--r-- | tinyusb/host/usbd_host.c | 40 | ||||
| -rw-r--r-- | tinyusb/host/usbd_host.h | 1 | ||||
| -rw-r--r-- | tinyusb/osal/osal.h | 9 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 2 | ||||
| -rw-r--r-- | tinyusb/tusb_option.h | 73 |
12 files changed, 136 insertions, 78 deletions
diff --git a/tests/project.yml b/tests/project.yml index 039d04579..feedb7b65 100644 --- a/tests/project.yml +++ b/tests/project.yml @@ -44,14 +44,14 @@ :commmon: &common_defines [] :test: - *common_defines - - _TEST_ + - _TEST_ -std=gnu99 - MCU=MCU_LPC43XX - CORE_M4 - __CODE_RED - _TINY_USB_SOURCE_FILE_ :test_preprocess: - *common_defines - - _TEST_ + - _TEST_ -std=gnu99 - MCU=MCU_LPC43XX - CORE_M4 - __CODE_RED diff --git a/tests/test/host/test_usbd_host.c b/tests/test/host/test_usbd_host.c index 255ef3dad..7dceff7db 100644 --- a/tests/test/host/test_usbd_host.c +++ b/tests/test/host/test_usbd_host.c @@ -39,6 +39,7 @@ #include "errors.h" #include "usbd_host.h" #include "mock_osal.h" +#include "mock_hcd.h" extern usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; tusb_handle_device_t dev_hdl; @@ -55,26 +56,42 @@ void tearDown(void) //--------------------------------------------------------------------+ // init, get_status //--------------------------------------------------------------------+ +void test_usbh_init_hcd_failed(void) +{ + hcd_init_IgnoreAndReturn(TUSB_ERROR_HCD_FAILED); + TEST_ASSERT_EQUAL(TUSB_ERROR_HCD_FAILED, usbh_init()); +} + void test_usbh_init_task_create_failed(void) { + for(uint32_t i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++) + hcd_init_ExpectAndReturn(i, TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_OSAL_TASK_FAILED); TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TASK_FAILED, usbh_init()); } void test_usbh_init_queue_create_failed(void) { + for(uint32_t i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++) + hcd_init_ExpectAndReturn(i, TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); osal_queue_create_IgnoreAndReturn(NULL); TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init()); } -void test_usbh_init_checkmem(void) + +void test_usbh_init_ok(void) { uint32_t dummy; usbh_device_info_t device_info_zero[TUSB_CFG_HOST_DEVICE_MAX]; memset(device_info_zero, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + for(uint32_t i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++) + hcd_init_ExpectAndReturn(i, TUSB_ERROR_NONE); + osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); osal_queue_create_IgnoreAndReturn((osal_queue_handle_t)(&dummy)); @@ -100,40 +117,41 @@ void test_usbh_status_get_succeed(void) //--------------------------------------------------------------------+ // enum task //--------------------------------------------------------------------+ -void test_enum_task(void) +extern osal_queue_handle_t enumeration_queue_hdl; +usbh_enumerate_t enum_connect = { -// osal_queue_ - TEST_IGNORE(); - usbh_enumerate_task(); -} + .core_id = 0, + .hub_address = 0, + .hub_port = 0, + .connect_status = 1 +}; +void queue_recv_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, osal_timeout_t msec, tusb_error_t *p_error, int num_call) +{ + TEST_ASSERT_EQUAL_PTR(enumeration_queue_hdl, queue_hdl); + memcpy(p_data, &enum_connect, 4); + (*p_error) = TUSB_ERROR_NONE; +} -#if 0 -void test_keyboard_open_invalid_para() +void test_enum_task_connect(void) { - tusb_handle_keyboard_t keyboard_handle; + osal_queue_receive_StubWithCallback(queue_recv_stub); + hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(TUSB_CFG_HOST_DEVICE_MAX, 1, &keyboard_handle) ); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 0, &keyboard_handle) ); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, TUSB_CFG_CONFIGURATION_MAX+1, &keyboard_handle) ); - TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 1, NULL) ); + usbh_enumerate_task(); } -void test_keyboard_open_succeed() +void test_enum_task_disconnect(void) { - tusb_handle_keyboard_t keyboard_handle = 0; + TEST_IGNORE(); +} - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_open(0, 1, &keyboard_handle)); - TEST_ASSERT_TRUE( 0 != keyboard_handle); +void test_enum_task_connect_via_hub(void) +{ + TEST_IGNORE(); } -void test_keyboard_callback__() +void test_enum_task_disconnect_via_hub(void) { TEST_IGNORE(); - tusb_handle_device_t device_handle = __LINE__; - tusb_handle_configure_t configure_handle = __LINE__; - tusb_handle_interface_t interface_handle = __LINE__; - uint32_t configure_flags = BIT_(TUSB_CLASS_HID); - tusbh_usbd_device_mounted_cb_ExpectWithArray(TUSB_ERROR_NONE, device_handle, &configure_flags, 1, 1); } -#endif diff --git a/tests/test/support/tusb_config.h b/tests/test/support/tusb_config.h index c02f12d66..87b09a9dd 100644 --- a/tests/test/support/tusb_config.h +++ b/tests/test/support/tusb_config.h @@ -88,6 +88,7 @@ #define TUSB_CFG_DEBUG 3 #define TUSB_CFG_OS TUSB_OS_NONE +#define TUSB_CFG_OS_TICK_PER_SECOND 1000 // 1 ms tick #ifdef __CODE_RED // make use of code red's support for ram region macros #if (MCU == MCU_LPC11UXX) || (MCU == MCU_LPC13UXX) diff --git a/tests/test/test_osal_none.c b/tests/test/test_osal_none.c index 8ae0bfd51..122dc48e2 100644 --- a/tests/test/test_osal_none.c +++ b/tests/test/test_osal_none.c @@ -107,19 +107,20 @@ void test_queue_send(void) //--------------------------------------------------------------------+ void sample_task_semaphore(void) { + tusb_error_t error = TUSB_ERROR_NONE; OSAL_TASK_LOOP { OSAL_TASK_LOOP_BEGIN statements[0]++; - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER); + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); statements[1]++; - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER); + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); statements[2]++; - osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER); + osal_semaphore_wait(sem_hdl, OSAL_TIMEOUT_WAIT_FOREVER, &error); statements[3]++; OSAL_TASK_LOOP_END @@ -139,12 +140,16 @@ void test_task_with_semaphore(void) sample_task_semaphore(); TEST_ASSERT_EQUAL(1, statements[1]); + // post 2 consecutive times osal_semaphore_post(sem_hdl); osal_semaphore_post(sem_hdl); sample_task_semaphore(); TEST_ASSERT_EQUAL(1, statements[2]); TEST_ASSERT_EQUAL(1, statements[3]); + // timeout + + // reach end of task loop, back to beginning sample_task_semaphore(); TEST_ASSERT_EQUAL(2, statements[0]); diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h index 7af82920e..f885362e7 100644 --- a/tinyusb/common/errors.h +++ b/tinyusb/common/errors.h @@ -65,6 +65,7 @@ ENTRY(TUSB_ERROR_DEVICE_NOT_READY)\ ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\ ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\ + ENTRY(TUSB_ERROR_HCD_FAILED)\ ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\ ENTRY(TUSB_ERROR_OSAL_TASK_FAILED)\ ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED)\ diff --git a/tinyusb/host/hcd.c b/tinyusb/host/hcd.c index 2c085566e..6960d2cfa 100644 --- a/tinyusb/host/hcd.c +++ b/tinyusb/host/hcd.c @@ -41,7 +41,6 @@ tusb_error_t hcd_init(uint8_t coreid) { - return TUSB_ERROR_NONE; } diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index 9ea26bdda..ed68171b7 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -60,7 +60,6 @@ typedef uint32_t pipe_handle_t; -#if 0 /** \brief Initialize HCD * * \param[in] para1 @@ -71,6 +70,10 @@ typedef uint32_t pipe_handle_t; tusb_error_t hcd_init(uint8_t hostid) ATTR_WARN_UNUSED_RESULT; +/// return the current connect status of roothub port +bool hcd_port_connect_status(uint8_t hostid) ATTR_WARN_UNUSED_RESULT; + +#if 0 //tusb_error_t hcd_pipe_open( // uint8_t hostid, uint8_t device_address, // diff --git a/tinyusb/host/usbd_host.c b/tinyusb/host/usbd_host.c index c3489525d..3c8c9ce83 100644 --- a/tinyusb/host/usbd_host.c +++ b/tinyusb/host/usbd_host.c @@ -58,12 +58,6 @@ //--------------------------------------------------------------------+ STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; -OSAL_TASK_DEF(enumeration_task, usbh_enumerate_task, 128, OSAL_PRIO_HIGH); - -#define ENUM_QUEUE_DEPTH 5 -OSAL_DEF_QUEUE(enumeration_queue, ENUM_QUEUE_DEPTH, uin32_t); -osal_queue_handle_t enumeration_queue_hdl; - //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) //--------------------------------------------------------------------+ @@ -74,22 +68,44 @@ tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device } //--------------------------------------------------------------------+ +// ENUMERATION TASK & ITS DATA +//--------------------------------------------------------------------+ +OSAL_TASK_DEF(enumeration_task, usbh_enumerate_task, 128, OSAL_PRIO_HIGH); + +#define ENUM_QUEUE_DEPTH 5 +OSAL_DEF_QUEUE(enumeration_queue, ENUM_QUEUE_DEPTH, uin32_t); +osal_queue_handle_t enumeration_queue_hdl; + +void usbh_enumerate_task(void) +{ + OSAL_TASK_LOOP + { + OSAL_TASK_LOOP_BEGIN + + + + OSAL_TASK_LOOP_END + } +} + +//--------------------------------------------------------------------+ // CLASS-USBD API (don't require to verify parameters) //--------------------------------------------------------------------+ tusb_error_t usbh_init(void) { + uint32_t i; + memset(device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX); + for(i=0; i<TUSB_CFG_HOST_CONTROLLER_NUM; i++) + { + ASSERT_STATUS( hcd_init(i) ); + } + ASSERT_STATUS( osal_task_create(&enumeration_task) ); enumeration_queue_hdl = osal_queue_create(&enumeration_queue); ASSERT_PTR(enumeration_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED); return TUSB_ERROR_NONE; } - -void usbh_enumerate_task(void) -{ - -} - #endif diff --git a/tinyusb/host/usbd_host.h b/tinyusb/host/usbd_host.h index d218fbd15..54d58ab81 100644 --- a/tinyusb/host/usbd_host.h +++ b/tinyusb/host/usbd_host.h @@ -140,6 +140,7 @@ typedef struct { uint8_t core_id; uint8_t hub_address; uint8_t hub_port; + uint8_t connect_status; } usbh_enumerate_t; //--------------------------------------------------------------------+ diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index 0dfb73686..0c99e497f 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -76,6 +76,9 @@ typedef uint32_t osal_timeout_t; +//------------- Tick -------------// +uint32_t osal_tick_get(void); + //------------- Task -------------// typedef uint32_t osal_task_t; #define OSAL_TASK_DEF(name, code, stack_depth, prio) \ @@ -91,7 +94,7 @@ tusb_error_t osal_task_create(osal_task_t *task); typedef uint32_t osal_semaphore_t; typedef void* osal_semaphore_handle_t; osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem); -tusb_error_t osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, osal_timeout_t msec); +void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, osal_timeout_t msec, tusb_error_t *p_error); tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl); //------------- Queue -------------// @@ -101,7 +104,9 @@ typedef void* osal_queue_handle_t; #define OSAL_DEF_QUEUE(name, queue_depth, type) \ osal_queue_t name -osal_queue_handle_t osal_queue_create(osal_queue_t *queue); +osal_queue_handle_t osal_queue_create (osal_queue_t *p_queue); +void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, osal_timeout_t msec, tusb_error_t *p_error); +tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, uint32_t data); #endif diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 6833ada24..84373b6de 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -106,7 +106,7 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se return TUSB_ERROR_NONE; } -#define osal_semaphore_wait(sem_hdl, msec) \ +#define osal_semaphore_wait(sem_hdl, msec, p_error) \ do {\ state = __LINE__; case __LINE__:\ if( (*sem_hdl) == 0 ) \ diff --git a/tinyusb/tusb_option.h b/tinyusb/tusb_option.h index 04316ac9c..79c957051 100644 --- a/tinyusb/tusb_option.h +++ b/tinyusb/tusb_option.h @@ -62,61 +62,70 @@ /// define this symbol will make tinyusb look for external configure file #include "tusb_config.h" +//--------------------------------------------------------------------+ +// COMMON OPTIONS +//--------------------------------------------------------------------+ /// 0: no debug information 3: most debug information provided #ifndef TUSB_CFG_DEBUG #define TUSB_CFG_DEBUG 3 #warning TUSB_CFG_DEBUG is not defined, default value is 3 #endif -/// Enable Host Support -#ifdef TUSB_CFG_HOST - -#ifndef TUSB_CFG_HOST_CONTROLLER_NUM - #define TUSB_CFG_HOST_CONTROLLER_NUM 1 - #warning TUSB_CFG_HOST_CONTROLLER_NUM is not defined, default value is 1 +/// USB RAM Section Placement, MCU's usb controller often has limited access to specific RAM region. This will be used to declare internal variables as follow: +/// uint8_t tinyusb_data[10] TUSB_CFG_ATTR_USBRAM; +/// if your mcu's usb controller has no such limit, define TUSB_CFG_ATTR_USBRAM as empty macro. +#ifndef TUSB_CFG_ATTR_USBRAM + #error TUSB_CFG_ATTR_USBRAM is not defined, please help me know how to place data in accessible RAM for usb controller #endif -#ifndef TUSB_CFG_HOST_DEVICE_MAX - #define TUSB_CFG_HOST_DEVICE_MAX 1 - #warning TUSB_CFG_HOST_DEVICE_MAX is not defined, default value is 1 -#endif +//--------------------------------------------------------------------+ +// HOST OPTIONS +//--------------------------------------------------------------------+ +#ifdef TUSB_CFG_HOST + #ifndef TUSB_CFG_HOST_CONTROLLER_NUM + #define TUSB_CFG_HOST_CONTROLLER_NUM 1 + #warning TUSB_CFG_HOST_CONTROLLER_NUM is not defined, default value is 1 + #endif -#if TUSB_CFG_HOST_HID_KEYBOARD - #if !defined(TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE) - #define TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE 64 - #warning TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE is not defined, default value is 64 - #elif TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE < 8 - #error no endpoint size is allowed to be less than 8 + #ifndef TUSB_CFG_HOST_DEVICE_MAX + #define TUSB_CFG_HOST_DEVICE_MAX 1 + #warning TUSB_CFG_HOST_DEVICE_MAX is not defined, default value is 1 #endif - #if !defined(TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE) - #define TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE 1 + #if TUSB_CFG_HOST_HID_KEYBOARD + #if !defined(TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE) + #define TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE 64 + #warning TUSB_CFG_HOST_HID_KEYBOARD_ENDPOINT_SIZE is not defined, default value is 64 + #endif + + #if !defined(TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE) + #define TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE 1 + #endif + #endif // end TUSB_CFG_HOST_HID_KEYBOARD + + #if TUSB_CFG_OS == TUSB_OS_NONE + #ifndef TUSB_CFG_OS_TICK_PER_SECOND + #error TUSB_CFG_OS_TICK_PER_SECOND is required to use with OS_NONE + #endif #endif -#endif -#endif + #define HOST_CLASS_HID ( (defined TUSB_CFG_HOST_HID_KEYBOARD) ) + #define HOST_EHCI +#endif // end TUSB_CFG_HOST #ifndef TUSB_CFG_CONFIGURATION_MAX #define TUSB_CFG_CONFIGURATION_MAX 1 #warning TUSB_CFG_CONFIGURATION_MAX is not defined, default value is 1 #endif -/// Enable Device Support +//--------------------------------------------------------------------+ +// DEVICE OPTIONS +//--------------------------------------------------------------------+ //#define TUSB_CFG_DEVICE -/// USB RAM Section Placement, MCU's usb controller often has limited access to specific RAM region. This will be used to declare internal variables as follow: -/// uint8_t tinyusb_data[10] TUSB_CFG_ATTR_USBRAM; -/// if your mcu's usb controller has no such limit, define TUSB_CFG_ATTR_USBRAM as empty macro. -#ifndef TUSB_CFG_ATTR_USBRAM - #error TUSB_CFG_ATTR_USBRAM is not defined, please help me know how to place data in accessible RAM for usb controller -#endif - #define DEVICE_CLASS_HID ( (defined TUSB_CFG_DEVICE_HID_KEYBOARD) || (defined TUSB_CFG_DEVICE_HID_MOUSE) ) -#define HOST_CLASS_HID ( (defined TUSB_CFG_HOST_HID_KEYBOARD) ) - -#define HOST_EHCI -// TODO APP +// TODO Device APP #define USB_MAX_IF_NUM 8 #define USB_MAX_EP_NUM 5 |
