updating usbh init with class init

This commit is contained in:
hathach 2013-02-08 12:52:46 +07:00
parent 489b98cb93
commit 5bacdc6c0f
7 changed files with 48 additions and 6 deletions

View File

@ -144,6 +144,9 @@ tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * cons
TEST_ASSERT_EQUAL(desc_configuration.configuration.wTotalLength, p_request->wLength); TEST_ASSERT_EQUAL(desc_configuration.configuration.wTotalLength, p_request->wLength);
memcpy(data, &desc_configuration, p_request->wLength); memcpy(data, &desc_configuration, p_request->wLength);
break; break;
default:
return TUSB_ERROR_OSAL_TIMEOUT;
} }
return TUSB_ERROR_NONE; return TUSB_ERROR_NONE;
@ -210,3 +213,14 @@ void test_enum_failed_get_full_config_desc(void)
usbh_enumeration_task(); usbh_enumeration_task();
} }
void test_enum_parse_config_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1);
// hid_install
usbh_enumeration_task();
}

View File

@ -41,6 +41,7 @@
#include "mock_osal.h" #include "mock_osal.h"
#include "mock_hcd.h" #include "mock_hcd.h"
#include "mock_usbh_hcd.h" #include "mock_usbh_hcd.h"
#include "mock_tusb_callback.h"
extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1];
tusb_handle_device_t dev_hdl; tusb_handle_device_t dev_hdl;
@ -111,18 +112,28 @@ void test_usbh_init_reporter_queue_create_failed(void)
TEST_IGNORE(); TEST_IGNORE();
} }
void class_init_expect(void)
{
hidh_init_Expect();
//TODO update more classes
}
void test_usbh_init_ok(void) void test_usbh_init_ok(void)
{ {
uint32_t dummy; osal_queue_handle_t dummy;
usbh_device_info_t device_info_zero[TUSB_CFG_HOST_DEVICE_MAX+1]; usbh_device_info_t device_info_zero[TUSB_CFG_HOST_DEVICE_MAX+1];
memclr_(device_info_zero, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); memclr_(device_info_zero, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1));
hcd_init_expect(); hcd_init_expect();
osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE); osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE);
osal_queue_create_IgnoreAndReturn((osal_queue_handle_t)(&dummy)); osal_queue_create_IgnoreAndReturn(dummy);
class_init_expect();
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init()); TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init());
TEST_ASSERT_EQUAL_MEMORY(device_info_zero, usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1)); TEST_ASSERT_EQUAL_MEMORY(device_info_zero, usbh_device_info_pool, sizeof(usbh_device_info_t)*(TUSB_CFG_HOST_DEVICE_MAX+1));
} }

View File

@ -61,6 +61,7 @@
uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT;
void tusbh_device_mounted_cb (tusb_handle_device_t device_hdl) ATTR_WEAK; void tusbh_device_mounted_cb (tusb_handle_device_t device_hdl) ATTR_WEAK;
void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK; void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK;
void hidh_init(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -81,8 +81,16 @@ typedef struct {
keyboard_interface_t instance[TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE]; keyboard_interface_t instance[TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE];
} class_hid_keyboard_info_t; } class_hid_keyboard_info_t;
void class_hid_keyboard_init(void); void hidh_keyboard_init(void);
tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor) ATTR_WARN_UNUSED_RESULT; tusb_error_t hidh_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor) ATTR_WARN_UNUSED_RESULT;
static inline void hidh_init(void) ATTR_ALWAYS_INLINE;
static inline void hidh_init(void)
{
#if TUSB_CFG_HOST_HID_KEYBOARD
hidh_keyboard_init();
#endif
}
#endif #endif

View File

@ -79,8 +79,10 @@
// TODO try to manipulate gcc cmd option instead // TODO try to manipulate gcc cmd option instead
#ifndef _TEST_ #ifndef _TEST_
#define STATIC_ static #define STATIC_ static
#define INLINE_ inline
#else #else
#define STATIC_ #define STATIC_
#define INLINE_
#endif #endif
#define STRING_(x) #x // stringify without expand #define STRING_(x) #x // stringify without expand

View File

@ -93,10 +93,16 @@ tusb_error_t usbh_init(void)
ASSERT_STATUS( hcd_init(TUSB_CFG_HOST_CONTROLLER_START_INDEX+i) ); ASSERT_STATUS( hcd_init(TUSB_CFG_HOST_CONTROLLER_START_INDEX+i) );
} }
//------------- Enumeration & Reporter Task init -------------//
ASSERT_STATUS( osal_task_create(&enum_task) ); ASSERT_STATUS( osal_task_create(&enum_task) );
enum_queue_hdl = osal_queue_create(&enum_queue); enum_queue_hdl = osal_queue_create(&enum_queue);
ASSERT_PTR(enum_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED); ASSERT_PTR(enum_queue_hdl, TUSB_ERROR_OSAL_QUEUE_FAILED);
//------------- class init -------------//
#if HOST_CLASS_HID
hidh_init();
#endif
return TUSB_ERROR_NONE; return TUSB_ERROR_NONE;
} }
@ -109,7 +115,7 @@ void usbh_enumeration_task(void)
usbh_enumerate_t enum_entry; usbh_enumerate_t enum_entry;
tusb_std_request_t request_packet; tusb_std_request_t request_packet;
// for OSAL_NONE local variable wont retain value after blocking service sem_wait/queue_recv // for OSAL_NONE local variable won't retain value after blocking service sem_wait/queue_recv
static uint8_t new_addr; static uint8_t new_addr;
static uint8_t configure_selected = 1; static uint8_t configure_selected = 1;

View File

@ -123,7 +123,7 @@
#warning TUSB_CFG_HOST_ENUM_BUFFER_SIZE is not defined, default value is 256 #warning TUSB_CFG_HOST_ENUM_BUFFER_SIZE is not defined, default value is 256
#endif #endif
#define HOST_CLASS_HID ( (defined TUSB_CFG_HOST_HID_KEYBOARD) ) #define HOST_CLASS_HID ( TUSB_CFG_HOST_HID_KEYBOARD )
#define HOST_EHCI #define HOST_EHCI
#endif // end TUSB_CFG_HOST #endif // end TUSB_CFG_HOST