clean up osal semaphore/queue/mutex
This commit is contained in:
@@ -77,29 +77,29 @@ static inline void osal_task_delay(uint32_t msec)
|
||||
//--------------------------------------------------------------------+
|
||||
// Semaphore API
|
||||
//--------------------------------------------------------------------+
|
||||
#define OSAL_SEM_DEF(name)
|
||||
#define OSAL_SEM_REF(name)
|
||||
typedef xSemaphoreHandle osal_semaphore_handle_t;
|
||||
typedef xSemaphoreHandle osal_semaphore_t;
|
||||
|
||||
// create FreeRTOS binary semaphore with zero as init value TODO: omit semaphore take from vSemaphoreCreateBinary API, should double checks this
|
||||
#define osal_semaphore_create(x) xSemaphoreCreateBinary()
|
||||
//#define osal_semaphore_create(x) xSemaphoreCreateBinary()
|
||||
|
||||
static inline osal_semaphore_t osal_semaphore_create(uint32_t max, uint32_t init)
|
||||
{
|
||||
return xSemaphoreCreateCounting(max, init);
|
||||
}
|
||||
|
||||
// TODO add timeout (with instant return from ISR option) for semaphore post & queue send
|
||||
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_t sem_hdl)
|
||||
{
|
||||
return (xSemaphoreGive(sem_hdl) == pdTRUE) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_SEMAPHORE_FAILED;
|
||||
}
|
||||
|
||||
static inline void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE;
|
||||
static inline void osal_semaphore_wait(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error)
|
||||
static inline void osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec, tusb_error_t *p_error)
|
||||
{
|
||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec);
|
||||
(*p_error) = ( xSemaphoreTake(sem_hdl, ticks) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
|
||||
}
|
||||
|
||||
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_t const sem_hdl)
|
||||
{
|
||||
(void) xSemaphoreTake(sem_hdl, 0);
|
||||
}
|
||||
@@ -107,27 +107,22 @@ static inline void osal_semaphore_reset(osal_semaphore_handle_t const sem_hdl)
|
||||
//--------------------------------------------------------------------+
|
||||
// MUTEX API (priority inheritance)
|
||||
//--------------------------------------------------------------------+
|
||||
#define OSAL_MUTEX_DEF OSAL_SEM_DEF
|
||||
#define OSAL_MUTEX_REF OSAL_SEM_REF
|
||||
typedef xSemaphoreHandle osal_mutex_handle_t;
|
||||
typedef xSemaphoreHandle osal_mutex_t;
|
||||
|
||||
#define osal_mutex_create(x) xSemaphoreCreateMutex()
|
||||
|
||||
static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE;
|
||||
static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t const mutex_hdl)
|
||||
static inline tusb_error_t osal_mutex_release(osal_mutex_t mutex_hdl)
|
||||
{
|
||||
return (xSemaphoreGive(mutex_hdl) == pdPASS) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_MUTEX_FAILED;
|
||||
return osal_semaphore_post(mutex_hdl);
|
||||
}
|
||||
|
||||
static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE;
|
||||
static inline void osal_mutex_wait(osal_mutex_handle_t const mutex_hdl, uint32_t msec, tusb_error_t *p_error)
|
||||
static inline void osal_mutex_wait(osal_mutex_t mutex_hdl, uint32_t msec, tusb_error_t *p_error)
|
||||
{
|
||||
uint32_t const ticks = (msec == OSAL_TIMEOUT_WAIT_FOREVER) ? portMAX_DELAY : osal_tick_from_msec(msec);
|
||||
(*p_error) = ( xSemaphoreTake(mutex_hdl, ticks) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
|
||||
osal_semaphore_wait(mutex_hdl, msec, p_error);
|
||||
}
|
||||
|
||||
static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl) ATTR_ALWAYS_INLINE;
|
||||
static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl)
|
||||
// TOOD remove
|
||||
static inline void osal_mutex_reset(osal_mutex_t mutex_hdl)
|
||||
{
|
||||
xSemaphoreGive(mutex_hdl);
|
||||
}
|
||||
@@ -137,7 +132,6 @@ static inline void osal_mutex_reset(osal_mutex_handle_t const mutex_hdl)
|
||||
//--------------------------------------------------------------------+
|
||||
typedef xQueueHandle osal_queue_t;
|
||||
|
||||
|
||||
static inline osal_queue_t osal_queue_create(uint32_t depth, uint32_t item_size)
|
||||
{
|
||||
return xQueueCreate(depth, item_size);
|
||||
|
||||
Reference in New Issue
Block a user