summaryrefslogtreecommitdiff
path: root/tinyusb/osal
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-02-04 18:05:22 +0700
committerhathach <[email protected]>2013-02-04 18:05:22 +0700
commit5e8d70a184f01121ed9849452dc81ebe9600b86f (patch)
tree3e01f6d45e58b854d712d59b13b0688b1f2ad892 /tinyusb/osal
parentdd9da7846a0ef74d240af22f508fe7a32a99085c (diff)
complete define osal_freeRTOS for semaphore and queue
Diffstat (limited to 'tinyusb/osal')
-rw-r--r--tinyusb/osal/osal_freeRTOS.h28
1 files changed, 27 insertions, 1 deletions
diff --git a/tinyusb/osal/osal_freeRTOS.h b/tinyusb/osal/osal_freeRTOS.h
index 4d89a1acc..b1f16adf0 100644
--- a/tinyusb/osal/osal_freeRTOS.h
+++ b/tinyusb/osal/osal_freeRTOS.h
@@ -85,10 +85,23 @@
#define OSAL_SEM_DEF(name)
typedef xSemaphoreHandle osal_semaphore_handle_t;
-// create FreeRTOS binary semaphore with zero as init value
+// 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) \
xQueueGenericCreate( ( unsigned portBASE_TYPE ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )
+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)
+{
+ portBASE_TYPE taskWaken;
+ return (xSemaphoreGiveFromISR(sem_hdl, &taskWaken) == 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)
+{
+ (*p_error) = ( xSemaphoreTake(sem_hdl, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
+}
+
//--------------------------------------------------------------------+
// QUEUE API
//--------------------------------------------------------------------+
@@ -106,6 +119,19 @@ typedef xQueueHandle osal_queue_handle_t;
#define osal_queue_create(p_queue) \
xQueueCreate((p_queue)->depth, sizeof(uint32_t))
+static inline void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error) ATTR_ALWAYS_INLINE;
+static inline void osal_queue_receive (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error)
+{
+ (*p_error) = ( xQueueReceive(queue_hdl, p_data, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
+}
+
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t osal_queue_send(osal_queue_handle_t const queue_hdl, uint32_t data)
+{
+ portBASE_TYPE taskWaken;
+ return ( xQueueSendFromISR(queue_hdl, &data, &taskWaken) == pdTRUE ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_QUEUE_FAILED;
+}
+
#ifdef __cplusplus
}
#endif