27#ifndef TUSB_OSAL_FREERTOS_H_
28#define TUSB_OSAL_FREERTOS_H_
31#include TU_INCLUDE_PATH(CFG_TUSB_OS_INC_PATH,FreeRTOS.h)
32#include TU_INCLUDE_PATH(CFG_TUSB_OS_INC_PATH,semphr.h)
33#include TU_INCLUDE_PATH(CFG_TUSB_OS_INC_PATH,queue.h)
34#include TU_INCLUDE_PATH(CFG_TUSB_OS_INC_PATH,task.h)
44#if configSUPPORT_STATIC_ALLOCATION
63#if defined(configQUEUE_REGISTRY_SIZE) && (configQUEUE_REGISTRY_SIZE>0)
67#if configSUPPORT_STATIC_ALLOCATION
72#if defined(configQUEUE_REGISTRY_SIZE) && (configQUEUE_REGISTRY_SIZE>0)
73 #define _OSAL_Q_NAME(_name) .name = #_name
75 #define _OSAL_Q_NAME(_name)
79#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
80 static _type _name##_##buf[_depth];\
81 osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf, _OSAL_Q_NAME(_name) }
87TU_ATTR_ALWAYS_INLINE
static inline uint32_t
_osal_ms2tick(uint32_t msec) {
88 if ( msec == OSAL_TIMEOUT_WAIT_FOREVER )
return portMAX_DELAY;
89 if ( msec == 0 )
return 0;
91 uint32_t ticks = pdMS_TO_TICKS(msec);
95 if ( ticks == 0 ) ticks = 1;
101 vTaskDelay(pdMS_TO_TICKS(msec));
109#if configSUPPORT_STATIC_ALLOCATION
110 return xSemaphoreCreateBinaryStatic(semdef);
113 return xSemaphoreCreateBinary();
118 vSemaphoreDelete(semd_hdl);
124 return xSemaphoreGive(sem_hdl) != 0;
126 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
127 BaseType_t res = xSemaphoreGiveFromISR(sem_hdl, &xHigherPriorityTaskWoken);
129#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
131 if ( xHigherPriorityTaskWoken ) portYIELD_FROM_ISR();
133 portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
145 xQueueReset(sem_hdl);
153#if configSUPPORT_STATIC_ALLOCATION
154 return xSemaphoreCreateMutexStatic(mdef);
157 return xSemaphoreCreateMutex();
162 vSemaphoreDelete(mutex_hdl);
171 return xSemaphoreGive(mutex_hdl);
181#if configSUPPORT_STATIC_ALLOCATION
182 q = xQueueCreateStatic(qdef->
depth, qdef->
item_sz, (uint8_t*) qdef->
buf, &qdef->
sq);
187#if defined(configQUEUE_REGISTRY_SIZE) && (configQUEUE_REGISTRY_SIZE>0)
188 vQueueAddToRegistry(q, qdef->
name);
205 return xQueueSendToBack(qhdl,
data, OSAL_TIMEOUT_WAIT_FOREVER) != 0;
207 BaseType_t xHigherPriorityTaskWoken = pdFALSE;
208 BaseType_t res = xQueueSendToBackFromISR(qhdl,
data, &xHigherPriorityTaskWoken);
210#if CFG_TUSB_MCU == OPT_MCU_ESP32S2 || CFG_TUSB_MCU == OPT_MCU_ESP32S3
212 if ( xHigherPriorityTaskWoken ) portYIELD_FROM_ISR();
214 portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
222 return uxQueueMessagesWaiting(qhdl) == 0;
StaticSemaphore_t osal_semaphore_def_t
static TU_ATTR_ALWAYS_INLINE bool osal_queue_empty(osal_queue_t qhdl)
static TU_ATTR_ALWAYS_INLINE bool osal_semaphore_delete(osal_semaphore_t semd_hdl)
static TU_ATTR_ALWAYS_INLINE bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
static TU_ATTR_ALWAYS_INLINE osal_queue_t osal_queue_create(osal_queue_def_t *qdef)
StaticSemaphore_t osal_mutex_def_t
QueueHandle_t osal_queue_t
static TU_ATTR_ALWAYS_INLINE bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
static TU_ATTR_ALWAYS_INLINE void osal_task_delay(uint32_t msec)
static TU_ATTR_ALWAYS_INLINE bool osal_queue_send(osal_queue_t qhdl, void const *data, bool in_isr)
SemaphoreHandle_t osal_semaphore_t
static TU_ATTR_ALWAYS_INLINE bool osal_mutex_unlock(osal_mutex_t mutex_hdl)
static TU_ATTR_ALWAYS_INLINE bool osal_mutex_delete(osal_mutex_t mutex_hdl)
static TU_ATTR_ALWAYS_INLINE bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
static TU_ATTR_ALWAYS_INLINE bool osal_queue_receive(osal_queue_t qhdl, void *data, uint32_t msec)
static TU_ATTR_ALWAYS_INLINE bool osal_queue_delete(osal_queue_t qhdl)
static TU_ATTR_ALWAYS_INLINE void osal_semaphore_reset(osal_semaphore_t const sem_hdl)
SemaphoreHandle_t osal_mutex_t
static TU_ATTR_ALWAYS_INLINE osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t *semdef)
static TU_ATTR_ALWAYS_INLINE uint32_t _osal_ms2tick(uint32_t msec)
static TU_ATTR_ALWAYS_INLINE osal_mutex_t osal_mutex_create(osal_mutex_def_t *mdef)