mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-21 03:40:52 +00:00
add semphore reset & queue flush API
modify test to check control pipe semaphore created with usbh_init
This commit is contained in:
parent
c1ceec067f
commit
8eaad2326b
@ -87,6 +87,12 @@ void test_usbh_init_hcd_failed(void)
|
|||||||
void test_usbh_init_enum_task_create_failed(void)
|
void test_usbh_init_enum_task_create_failed(void)
|
||||||
{
|
{
|
||||||
hcd_init_ExpectAndReturn(TUSB_ERROR_NONE);
|
hcd_init_ExpectAndReturn(TUSB_ERROR_NONE);
|
||||||
|
for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX; i++)
|
||||||
|
{
|
||||||
|
osal_semaphore_handle_t sem_hdl_dummy = 0x2233;
|
||||||
|
osal_semaphore_create_IgnoreAndReturn(sem_hdl_dummy);
|
||||||
|
}
|
||||||
|
|
||||||
osal_task_create_IgnoreAndReturn(TUSB_ERROR_OSAL_TASK_FAILED);
|
osal_task_create_IgnoreAndReturn(TUSB_ERROR_OSAL_TASK_FAILED);
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TASK_FAILED, usbh_init());
|
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TASK_FAILED, usbh_init());
|
||||||
}
|
}
|
||||||
@ -94,6 +100,13 @@ void test_usbh_init_enum_task_create_failed(void)
|
|||||||
void test_usbh_init_enum_queue_create_failed(void)
|
void test_usbh_init_enum_queue_create_failed(void)
|
||||||
{
|
{
|
||||||
hcd_init_ExpectAndReturn(TUSB_ERROR_NONE);
|
hcd_init_ExpectAndReturn(TUSB_ERROR_NONE);
|
||||||
|
for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX; i++)
|
||||||
|
{
|
||||||
|
osal_semaphore_handle_t sem_hdl_dummy = 0x2233;
|
||||||
|
osal_semaphore_create_IgnoreAndReturn(sem_hdl_dummy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE);
|
osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE);
|
||||||
osal_queue_create_IgnoreAndReturn(NULL);
|
osal_queue_create_IgnoreAndReturn(NULL);
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init());
|
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init());
|
||||||
@ -118,12 +131,21 @@ void class_init_expect(void)
|
|||||||
|
|
||||||
void test_usbh_init_ok(void)
|
void test_usbh_init_ok(void)
|
||||||
{
|
{
|
||||||
osal_queue_handle_t dummy;
|
osal_queue_handle_t dummy = 0x1122;
|
||||||
|
|
||||||
|
|
||||||
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_ExpectAndReturn(TUSB_ERROR_NONE);
|
hcd_init_ExpectAndReturn(TUSB_ERROR_NONE);
|
||||||
|
|
||||||
|
for (uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX; i++)
|
||||||
|
{
|
||||||
|
osal_semaphore_handle_t sem_hdl_dummy = 0x2233;
|
||||||
|
osal_semaphore_create_IgnoreAndReturn(sem_hdl_dummy);
|
||||||
|
device_info_zero[i].sem_hdl = sem_hdl_dummy;
|
||||||
|
}
|
||||||
|
|
||||||
osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE);
|
osal_task_create_IgnoreAndReturn(TUSB_ERROR_NONE);
|
||||||
osal_queue_create_IgnoreAndReturn(dummy);
|
osal_queue_create_IgnoreAndReturn(dummy);
|
||||||
|
|
||||||
|
@ -340,7 +340,6 @@ static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr) ATTR_ALWAYS_INLINE
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// CONTROL PIPE API
|
// CONTROL PIPE API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// TODO subject to pure function
|
|
||||||
static void init_qtd(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes)
|
static void init_qtd(ehci_qtd_t* p_qtd, uint32_t data_ptr, uint16_t total_bytes)
|
||||||
{
|
{
|
||||||
memclr_(p_qtd, sizeof(ehci_qtd_t));
|
memclr_(p_qtd, sizeof(ehci_qtd_t));
|
||||||
@ -537,7 +536,6 @@ static inline ehci_qtd_t* get_control_qtds(uint8_t dev_addr)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO subject to pure function
|
|
||||||
static void init_qhd(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type)
|
static void init_qhd(ehci_qhd_t *p_qhd, uint8_t dev_addr, uint16_t max_packet_size, uint8_t endpoint_addr, uint8_t xfer_type)
|
||||||
{
|
{
|
||||||
memclr_(p_qhd, sizeof(ehci_qhd_t));
|
memclr_(p_qhd, sizeof(ehci_qhd_t));
|
||||||
|
@ -103,6 +103,13 @@ tusb_error_t usbh_init(void)
|
|||||||
|
|
||||||
ASSERT_STATUS( hcd_init() );
|
ASSERT_STATUS( hcd_init() );
|
||||||
|
|
||||||
|
//------------- Semaphore for Control Pipe -------------//
|
||||||
|
for(uint8_t i=0; i<TUSB_CFG_HOST_DEVICE_MAX; i++)
|
||||||
|
{
|
||||||
|
usbh_device_info_pool[i].sem_hdl = osal_semaphore_create( OSAL_SEM_REF(usbh_device_info_pool[i].semaphore) );
|
||||||
|
ASSERT_PTR(usbh_device_info_pool[i].sem_hdl, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
|
||||||
|
}
|
||||||
|
|
||||||
//------------- Enumeration & Reporter Task init -------------//
|
//------------- 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);
|
||||||
@ -118,9 +125,19 @@ tusb_error_t usbh_init(void)
|
|||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// interrupt caused by a TD (with IOC=1) in pipe of class class_code
|
||||||
void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code)
|
void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code)
|
||||||
{
|
{
|
||||||
|
if (class_code == 0) // Control transfer
|
||||||
|
{
|
||||||
|
// TODO some semaphore posting
|
||||||
|
}else if (usbh_class_drivers[class_code].isr)
|
||||||
|
{
|
||||||
|
usbh_class_drivers[class_code].isr(pipe_hdl);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
ASSERT(false, (void) 0); // something wrong, no one claims the isr's source
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// function called within a task, requesting os blocking services, subtask input parameter must be static/global variables
|
// function called within a task, requesting os blocking services, subtask input parameter must be static/global variables
|
||||||
|
@ -90,20 +90,12 @@ typedef struct { // TODO internal structure, re-order members
|
|||||||
//------------- configuration descriptor info -------------//
|
//------------- configuration descriptor info -------------//
|
||||||
uint8_t interface_count; // bNumInterfaces alias
|
uint8_t interface_count; // bNumInterfaces alias
|
||||||
|
|
||||||
uint8_t status; // value from enum tusbh_device_status_
|
uint8_t status; // value from enum tusbh_device_status_
|
||||||
|
|
||||||
// pipe_handle_t pipe_control; NOTE: use device address/handle instead
|
|
||||||
tusb_std_request_t control_request;
|
tusb_std_request_t control_request;
|
||||||
OSAL_SEM_DEF(semaphore);
|
OSAL_SEM_DEF(semaphore);
|
||||||
osal_semaphore_handle_t sem_hdl;
|
osal_semaphore_handle_t sem_hdl;
|
||||||
|
|
||||||
#if 0 // TODO allow configure for vendor/product
|
|
||||||
struct {
|
|
||||||
uint8_t interface_count;
|
|
||||||
uint8_t attributes;
|
|
||||||
} configuration;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} usbh_device_info_t;
|
} usbh_device_info_t;
|
||||||
|
|
||||||
extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address
|
extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; // including zero-address
|
||||||
|
@ -147,6 +147,9 @@ typedef void* osal_semaphore_handle_t;
|
|||||||
#define OSAL_SEM_DEF(name)\
|
#define OSAL_SEM_DEF(name)\
|
||||||
osal_semaphore_t name
|
osal_semaphore_t name
|
||||||
|
|
||||||
|
#define OSAL_SEM_REF(name)\
|
||||||
|
&name
|
||||||
|
|
||||||
osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const sem);
|
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);
|
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);
|
tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl);
|
||||||
|
@ -150,6 +150,7 @@ static inline uint32_t osal_tick_get(void)
|
|||||||
#define SUBTASK_ASSERT_STATUS_WITH_HANDLER(...) TASK_ASSERT_STATUS_WITH_HANDLER(__VA_ARGS__)
|
#define SUBTASK_ASSERT_STATUS_WITH_HANDLER(...) TASK_ASSERT_STATUS_WITH_HANDLER(__VA_ARGS__)
|
||||||
#define SUBTASK_ASSERT(...) TASK_ASSERT(__VA_ARGS__)
|
#define SUBTASK_ASSERT(...) TASK_ASSERT(__VA_ARGS__)
|
||||||
#define SUBTASK_ASSERT_WITH_HANDLER(...) TASK_ASSERT_WITH_HANDLER(__VA_ARGS__)
|
#define SUBTASK_ASSERT_WITH_HANDLER(...) TASK_ASSERT_WITH_HANDLER(__VA_ARGS__)
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Semaphore API
|
// Semaphore API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -177,6 +178,12 @@ static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const se
|
|||||||
return TUSB_ERROR_NONE;
|
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)
|
||||||
|
{
|
||||||
|
(*sem_hdl) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define osal_semaphore_wait(sem_hdl, msec, p_error) \
|
#define osal_semaphore_wait(sem_hdl, msec, p_error) \
|
||||||
do {\
|
do {\
|
||||||
timeout = osal_tick_get();\
|
timeout = osal_tick_get();\
|
||||||
@ -242,6 +249,12 @@ static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl,
|
|||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl) ATTR_ALWAYS_INLINE;
|
||||||
|
static inline void osal_queue_flush(osal_queue_handle_t const queue_hdl)
|
||||||
|
{
|
||||||
|
queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0;
|
||||||
|
}
|
||||||
|
|
||||||
#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
|
#define osal_queue_receive(queue_hdl, p_data, msec, p_error) \
|
||||||
do {\
|
do {\
|
||||||
timeout = osal_tick_get();\
|
timeout = osal_tick_get();\
|
||||||
|
Loading…
x
Reference in New Issue
Block a user