add mutex support for osal

add test for mutex in test_osal_none.c
implement usbh_control_xfer using mutex to get access to queue xfer on control pipe
(while semaphore is used to sync with hcd DMA)
failed to issue control xfer: set idle & get report descriptor in hidh_open_subtask (more to work on)
This commit is contained in:
hathach
2013-06-27 16:19:22 +07:00
parent c81c4bb817
commit 3bca56665c
11 changed files with 270 additions and 29 deletions

View File

@@ -166,23 +166,23 @@ typedef osal_semaphore_t * osal_semaphore_handle_t;
#define OSAL_SEM_REF(name)\
&name
static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const p_sem) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * const p_sem)
static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem)
{
(*p_sem) = 0;
(*p_sem) = 0; // TODO consider to have initial count parameter
return (osal_semaphore_handle_t) p_sem;
}
static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl) ATTR_ALWAYS_INLINE;
static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t const sem_hdl)
static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl) ATTR_ALWAYS_INLINE;
static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl)
{
(*sem_hdl)++;
return TUSB_ERROR_NONE;
}
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)
static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl) ATTR_ALWAYS_INLINE;
static inline void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl)
{
(*sem_hdl) = 0;
}
@@ -202,6 +202,41 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl)
}\
}while(0)
//--------------------------------------------------------------------+
// MUTEX API (priority inheritance)
//--------------------------------------------------------------------+
typedef osal_semaphore_t osal_mutex_t;
typedef osal_semaphore_handle_t osal_mutex_handle_t;
#define OSAL_MUTEX_DEF(name)\
osal_mutex_t name
#define OSAL_MUTEX_REF(name)\
&name
static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex) ATTR_WARN_UNUSED_RESULT ATTR_ALWAYS_INLINE;
static inline osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex)
{
(*p_mutex) = 1;
return (osal_mutex_handle_t) p_mutex;
}
static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl) ATTR_ALWAYS_INLINE;
static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl)
{
(*mutex_hdl) = 1; // mutex is a binary semaphore
return TUSB_ERROR_NONE;
}
static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl) ATTR_ALWAYS_INLINE;
static inline void osal_mutex_reset(osal_mutex_handle_t mutex_hdl)
{
(*mutex_hdl) = 1;
}
#define osal_mutex_wait osal_semaphore_wait
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+