44 #ifndef _TUSB_OSAL_FREERTOS_H_
45 #define _TUSB_OSAL_FREERTOS_H_
62 #define osal_tick_get xTaskGetTickCount
67 #define OSAL_TASK_FUNCTION portTASK_FUNCTION
72 unsigned portSHORT stack_depth;
73 unsigned portBASE_TYPE prio;
76 #define OSAL_TASK_DEF(task_code, task_stack_depth, task_prio) \
77 osal_task_t osal_task_def_##task_code = {\
78 .name = #task_code , \
80 .stack_depth = task_stack_depth , \
84 #define OSAL_TASK_REF(name) (&osal_task_def_##name)
89 return pdPASS == xTaskCreate(task->code, (
signed portCHAR
const *) task->name, task->stack_depth, NULL, task->prio, NULL) ?
90 TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TASK_CREATE_FAILED;
94 static inline void osal_task_delay(uint32_t msec)
102 #define OSAL_SEM_DEF(name)
103 typedef xSemaphoreHandle osal_semaphore_handle_t;
106 #define osal_semaphore_create(x) \
107 xQueueGenericCreate( ( unsigned portBASE_TYPE ) 1, semSEMAPHORE_QUEUE_ITEM_LENGTH, queueQUEUE_TYPE_BINARY_SEMAPHORE )
111 static inline tusb_error_t osal_semaphore_post(osal_semaphore_handle_t
const sem_hdl)
113 portBASE_TYPE task_waken;
114 return (xSemaphoreGiveFromISR(sem_hdl, &task_waken) == pdTRUE) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_SEMAPHORE_FAILED;
118 static inline void osal_semaphore_wait(osal_semaphore_handle_t
const sem_hdl, uint32_t msec,
tusb_error_t *p_error)
120 (*p_error) = ( xSemaphoreTake(sem_hdl, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
123 static inline void osal_semaphore_reset(osal_semaphore_handle_t
const sem_hdl)
ATTR_ALWAYS_INLINE;
124 static inline void osal_semaphore_reset(osal_semaphore_handle_t
const sem_hdl)
126 portBASE_TYPE task_waken;
127 xSemaphoreTakeFromISR(sem_hdl, &task_waken);
133 #define OSAL_MUTEX_DEF OSAL_SEM_DEF
134 typedef xSemaphoreHandle osal_mutex_handle_t;
136 #define osal_mutex_create(x) \
137 xSemaphoreCreateMutex()
140 static inline tusb_error_t osal_mutex_release(osal_mutex_handle_t
const mutex_hdl)
142 return (xSemaphoreGive(mutex_hdl) == pdPASS) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_MUTEX_FAILED;
146 static inline void osal_mutex_wait(osal_mutex_handle_t
const mutex_hdl, uint32_t msec,
tusb_error_t *p_error)
148 (*p_error) = ( xSemaphoreTake(mutex_hdl, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
151 static inline void osal_mutex_reset(osal_mutex_handle_t
const mutex_hdl)
ATTR_ALWAYS_INLINE;
152 static inline void osal_mutex_reset(osal_mutex_handle_t
const mutex_hdl)
154 xSemaphoreGive(mutex_hdl);
167 #define OSAL_QUEUE_DEF(name, queue_depth, type)\
168 osal_queue_t name = {\
169 .depth = queue_depth,\
170 .item_size = sizeof(type)\
173 #define OSAL_QUEUE_REF(name) (&name)
175 #define osal_queue_create(p_queue) \
176 xQueueCreate((p_queue)->depth, (p_queue)->item_size)
178 static inline void osal_queue_receive (osal_queue_handle_t
const queue_hdl,
void *p_data, uint32_t msec,
tusb_error_t *p_error)
ATTR_ALWAYS_INLINE;
179 static inline void osal_queue_receive (osal_queue_handle_t
const queue_hdl,
void *p_data, uint32_t msec,
tusb_error_t *p_error)
181 (*p_error) = ( xQueueReceive(queue_hdl, p_data, osal_tick_from_msec(msec)) == pdPASS ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_TIMEOUT;
185 static inline tusb_error_t osal_queue_send(osal_queue_handle_t
const queue_hdl,
void const * data)
187 portBASE_TYPE taskWaken;
188 return ( xQueueSendFromISR(queue_hdl, data, &taskWaken) == pdTRUE ) ? TUSB_ERROR_NONE : TUSB_ERROR_OSAL_QUEUE_FAILED;
191 static inline void osal_queue_flush(osal_queue_handle_t
const queue_hdl)
ATTR_ALWAYS_INLINE;
192 static inline void osal_queue_flush(osal_queue_handle_t
const queue_hdl)
194 xQueueReset(queue_hdl);
#define ATTR_WARN_UNUSED_RESULT
The warn_unused_result attribute causes a warning to be emitted if a caller of the function with this...
Definition: compiler_gcc.h:118
uint8_t const item_size
size of each item
Definition: osal_freeRTOS.h:162
Definition: osal_freeRTOS.h:160
tusb_error_t
Error Code returned.
Definition: tusb_errors.h:100
#define TUSB_CFG_TICKS_HZ
The rate ticks in hert. This is used in conjunction with tusb_tick_get to calculate timing...
Definition: configuration.txt:24
uint8_t const depth
buffer size
Definition: osal_freeRTOS.h:161
#define ATTR_ALWAYS_INLINE
Generally, functions are not inlined unless optimization is specified. For functions declared inline...
Definition: compiler_gcc.h:89
Definition: osal_freeRTOS.h:69