mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-15 21:40:18 +00:00
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
This commit is contained in:
parent
1b963f6a71
commit
9e3785e7e1
@ -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
|
||||
|
@ -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();
|
||||
.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;
|
||||
}
|
||||
|
||||
void test_enum_task_connect(void)
|
||||
{
|
||||
osal_queue_receive_StubWithCallback(queue_recv_stub);
|
||||
hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true);
|
||||
|
||||
usbh_enumerate_task();
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void test_keyboard_open_invalid_para()
|
||||
{
|
||||
tusb_handle_keyboard_t keyboard_handle;
|
||||
|
||||
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) );
|
||||
}
|
||||
|
||||
void test_keyboard_open_succeed()
|
||||
{
|
||||
tusb_handle_keyboard_t keyboard_handle = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_open(0, 1, &keyboard_handle));
|
||||
TEST_ASSERT_TRUE( 0 != keyboard_handle);
|
||||
}
|
||||
|
||||
void test_keyboard_callback__()
|
||||
void test_enum_task_disconnect(void)
|
||||
{
|
||||
TEST_IGNORE();
|
||||
}
|
||||
|
||||
void test_enum_task_connect_via_hub(void)
|
||||
{
|
||||
TEST_IGNORE();
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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)
|
||||
|
@ -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]);
|
||||
|
@ -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)\
|
||||
|
@ -41,7 +41,6 @@
|
||||
|
||||
tusb_error_t hcd_init(uint8_t coreid)
|
||||
{
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
//
|
||||
|
@ -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)
|
||||
//--------------------------------------------------------------------+
|
||||
@ -73,23 +67,45 @@ tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device
|
||||
return device_info_pool[device_hdl].status;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// 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
|
||||
|
@ -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;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -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
|
||||
|
||||
|
@ -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 ) \
|
||||
|
@ -62,48 +62,15 @@
|
||||
/// 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
|
||||
#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
|
||||
|
||||
#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
|
||||
#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
|
||||
|
||||
#endif
|
||||
|
||||
#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
|
||||
//#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.
|
||||
@ -111,12 +78,54 @@
|
||||
#error TUSB_CFG_ATTR_USBRAM is not defined, please help me know how to place data in accessible RAM for usb controller
|
||||
#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
|
||||
|
||||
#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 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
|
||||
|
||||
#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
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// DEVICE OPTIONS
|
||||
//--------------------------------------------------------------------+
|
||||
//#define TUSB_CFG_DEVICE
|
||||
|
||||
#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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user