diff options
| author | hathach <[email protected]> | 2013-06-27 16:19:22 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-06-27 16:19:22 +0700 |
| commit | 3bca56665cb802e6e599fb4a1a2be5dd6e64b70b (patch) | |
| tree | ee67c6bac3050face4e8747b38317dfa2aba4927 /tinyusb/osal | |
| parent | c81c4bb817925f385b45c46857b3f0630edb99ed (diff) | |
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)
Diffstat (limited to 'tinyusb/osal')
| -rw-r--r-- | tinyusb/osal/osal.h | 24 | ||||
| -rw-r--r-- | tinyusb/osal/osal_none.h | 49 |
2 files changed, 62 insertions, 11 deletions
diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h index c28bc4790..f40900919 100644 --- a/tinyusb/osal/osal.h +++ b/tinyusb/osal/osal.h @@ -133,12 +133,28 @@ typedef osal_semaphore_t * osal_semaphore_handle_t; #define OSAL_SEM_REF(name)\ &name -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); +osal_semaphore_handle_t osal_semaphore_create(osal_semaphore_t * p_sem); +void osal_semaphore_wait(osal_semaphore_handle_t sem_hdl, uint32_t msec, tusb_error_t *p_error); +tusb_error_t osal_semaphore_post(osal_semaphore_handle_t sem_hdl); +void osal_semaphore_reset(osal_semaphore_handle_t sem_hdl); //--------------------------------------------------------------------+ +// MUTEX API (priority inheritance) +//--------------------------------------------------------------------+ +#define OSAL_MUTEX_DEF(name)\ + osal_mutex_t name + +#define OSAL_MUTEX_REF(name)\ + &name + +typedef osal_semaphore_t osal_mutex_t; +typedef osal_semaphore_handle_t osal_mutex_handle_t; + +osal_mutex_handle_t osal_mutex_create(osal_mutex_t * p_mutex); +void osal_mutex_wait(osal_mutex_handle_t mutex_hdl, uint32_t msec, tusb_error_t *p_error); +tusb_error_t osal_mutex_release(osal_mutex_handle_t mutex_hdl); +void osal_mutex_reset(osal_mutex_handle_t mutex_hdl); +//--------------------------------------------------------------------+ // QUEUE API //--------------------------------------------------------------------+ typedef struct{ diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h index 936513d1b..5090d14f5 100644 --- a/tinyusb/osal/osal_none.h +++ b/tinyusb/osal/osal_none.h @@ -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; } @@ -203,6 +203,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 //--------------------------------------------------------------------+ typedef struct{ |
