add semaphore reset & queue flush API for osal

add semaphore reset when opening control pipe
This commit is contained in:
hathach 2013-03-12 00:10:52 +07:00
parent 8eaad2326b
commit 38ff7123b4
4 changed files with 21 additions and 4 deletions

View File

@ -71,6 +71,7 @@ void setUp(void)
hcd_pipe_control_xfer_StubWithCallback(control_xfer_stub);
hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true);
osal_semaphore_reset_Expect( usbh_device_info_pool[0].sem_hdl );
hcd_pipe_control_open_ExpectAndReturn(0, 8, TUSB_ERROR_NONE);
}
@ -187,6 +188,7 @@ void test_enum_failed_get_full_dev_desc(void)
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2));
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_device_info_pool[0].sem_hdl );
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
@ -204,6 +206,7 @@ void test_enum_failed_get_9byte_config_desc(void)
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3));
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_device_info_pool[0].sem_hdl );
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);
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
@ -219,6 +222,7 @@ void test_enum_failed_get_full_config_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4));
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_device_info_pool[0].sem_hdl );
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);
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
@ -235,6 +239,7 @@ void test_enum_parse_config_desc(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_device_info_pool[0].sem_hdl );
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);
@ -250,6 +255,7 @@ void test_enum_set_configure(void)
{
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6));
hcd_pipe_control_close_ExpectAndReturn(0, TUSB_ERROR_NONE);
osal_semaphore_reset_Expect( usbh_device_info_pool[0].sem_hdl );
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);
class_install_expect();

View File

@ -156,6 +156,15 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons
OSAL_SUBTASK_END
}
tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
{
osal_semaphore_reset( usbh_device_info_pool[dev_addr].sem_hdl );
ASSERT_STATUS( hcd_pipe_control_open(dev_addr, max_packet_size) );
return TUSB_ERROR_NONE;
}
//--------------------------------------------------------------------+
// ENUMERATION TASK
//--------------------------------------------------------------------+
@ -180,7 +189,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
usbh_device_info_pool[0].hub_port = enum_entry.hub_port;
usbh_device_info_pool[0].speed = enum_entry.speed;
TASK_ASSERT_STATUS( hcd_pipe_control_open(0, 8) );
TASK_ASSERT_STATUS( usbh_pipe_control_open(0, 8) );
//------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT(
@ -223,7 +232,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
hcd_pipe_control_close(0);
// open control pipe for new address
TASK_ASSERT_STATUS ( hcd_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
TASK_ASSERT_STATUS ( usbh_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
//------------- Get full device descriptor -------------//
OSAL_SUBTASK_INVOKED_AND_WAIT(

View File

@ -153,6 +153,7 @@ typedef void* osal_semaphore_handle_t;
osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem);
void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error);
tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl);
void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl);
//--------------------------------------------------------------------+
// QUEUE API
@ -166,6 +167,7 @@ typedef void* osal_queue_handle_t;
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, uint32_t msec, tusb_error_t *p_error);
tusb_error_t osal_queue_send (osal_queue_handle_t const queue_hdl, uint32_t data);
void osal_queue_flush(osal_queue_handle_t const queue_hdl);
//--------------------------------------------------------------------+
// TICK API

View File

@ -178,8 +178,8 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se
return TUSB_ERROR_NONE;
}
static inline void osal_sempahore_reset(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE;
static inline void osal_sempahore_reset(osal_semaphore_handle_t const sem_hdl)
static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE;
static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl)
{
(*sem_hdl) = 0;
}