Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of non-static allocation for FreeRTOS mutexes & queues #1767

Merged
merged 8 commits into from
Dec 5, 2022
6 changes: 3 additions & 3 deletions src/host/usbh.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE];

// Control transfer: since most controller does not support multiple control transfer
// on multiple devices concurrently. And control transfer is not used much except enumeration
// We will only execute control transfer one at a time.
struct
// We will only execute control transfer one at a time.CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4096)
CFG_TUSB_MEM_SECTION struct
hathach marked this conversation as resolved.
Show resolved Hide resolved
{
tusb_control_request_t request TU_ATTR_ALIGNED(4);
uint8_t* buffer;
Expand Down Expand Up @@ -509,7 +509,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr)
default: break;
}

#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO
#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO && CFG_TUSB_OS != OPT_OS_FREERTOS
hathach marked this conversation as resolved.
Show resolved Hide resolved
// return if there is no more events, for application to run other background
if (osal_queue_empty(_usbh_q)) return;
#endif
Expand Down
23 changes: 22 additions & 1 deletion src/osal/osal_freertos.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
//--------------------------------------------------------------------+
// Semaphore API
//--------------------------------------------------------------------+
#if configSUPPORT_STATIC_ALLOCATION == 1
typedef StaticSemaphore_t osal_semaphore_def_t;
#else
typedef SemaphoreHandle_t osal_semaphore_def_t;
#endif
typedef SemaphoreHandle_t osal_semaphore_t;

TU_ATTR_ALWAYS_INLINE static inline osal_semaphore_t osal_semaphore_create(osal_semaphore_def_t* semdef)
{
#if configSUPPORT_STATIC_ALLOCATION == 1
return xSemaphoreCreateBinaryStatic(semdef);
#else
return xSemaphoreCreateBinary();
hathach marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t sem_hdl, bool in_isr)
Expand Down Expand Up @@ -105,12 +113,21 @@ TU_ATTR_ALWAYS_INLINE static inline void osal_semaphore_reset(osal_semaphore_t c
//--------------------------------------------------------------------+
// MUTEX API (priority inheritance)
//--------------------------------------------------------------------+
#if configSUPPORT_STATIC_ALLOCATION == 1
typedef StaticSemaphore_t osal_mutex_def_t;
#else
typedef SemaphoreHandle_t osal_mutex_def_t;
#endif
typedef SemaphoreHandle_t osal_mutex_t;

TU_ATTR_ALWAYS_INLINE static inline osal_mutex_t osal_mutex_create(osal_mutex_def_t* mdef)
{
#if configSUPPORT_STATIC_ALLOCATION == 1
return xSemaphoreCreateMutexStatic(mdef);
#else
return xSemaphoreCreateMutex();
#endif

}

TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
Expand Down Expand Up @@ -145,7 +162,11 @@ typedef QueueHandle_t osal_queue_t;

TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
{
return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
#if configSUPPORT_STATIC_ALLOCATION == 1
return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
hathach marked this conversation as resolved.
Show resolved Hide resolved
#else
return xQueueCreate(qdef->depth, qdef->item_sz);
#endif
}

TU_ATTR_ALWAYS_INLINE static inline bool osal_queue_receive(osal_queue_t qhdl, void* data, uint32_t msec)
Expand Down