clean osal_freertos, update freertos examples to work with configSUPPORT_DYNAMIC_ALLOCATION only
note: for example to build with configSUPPORT_STATIC_ALLOCATION = 0, one of heap_n.c must be included in makefile/cmake
This commit is contained in:
@@ -37,6 +37,43 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF PROTYPES
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
typedef StaticSemaphore_t osal_semaphore_def_t;
|
||||
typedef StaticSemaphore_t osal_mutex_def_t;
|
||||
#else
|
||||
// not used therefore defined to smallest possible type to save space
|
||||
typedef uint8_t osal_semaphore_def_t;
|
||||
typedef uint8_t osal_mutex_def_t;
|
||||
#endif
|
||||
|
||||
typedef SemaphoreHandle_t osal_semaphore_t;
|
||||
typedef SemaphoreHandle_t osal_mutex_t;
|
||||
|
||||
// _int_set is not used with an RTOS
|
||||
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
|
||||
static _type _name##_##buf[_depth];\
|
||||
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t depth;
|
||||
uint16_t item_sz;
|
||||
void* buf;
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
StaticQueue_t sq;
|
||||
#endif
|
||||
}osal_queue_def_t;
|
||||
|
||||
typedef QueueHandle_t osal_queue_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TASK API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec)
|
||||
{
|
||||
if (msec == OSAL_TIMEOUT_WAIT_FOREVER) return portMAX_DELAY;
|
||||
@@ -51,9 +88,6 @@ TU_ATTR_ALWAYS_INLINE static inline uint32_t _osal_ms2tick(uint32_t msec)
|
||||
return ticks;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// TASK API
|
||||
//--------------------------------------------------------------------+
|
||||
TU_ATTR_ALWAYS_INLINE static inline void osal_task_delay(uint32_t msec)
|
||||
{
|
||||
vTaskDelay( pdMS_TO_TICKS(msec) );
|
||||
@@ -62,19 +96,13 @@ 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
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
return xSemaphoreCreateBinaryStatic(semdef);
|
||||
#else
|
||||
(void)(semdef);
|
||||
(void) semdef;
|
||||
return xSemaphoreCreateBinary();
|
||||
#endif
|
||||
}
|
||||
@@ -101,7 +129,7 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_post(osal_semaphore_t se
|
||||
}
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait (osal_semaphore_t sem_hdl, uint32_t msec)
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_semaphore_wait(osal_semaphore_t sem_hdl, uint32_t msec)
|
||||
{
|
||||
return xSemaphoreTake(sem_hdl, _osal_ms2tick(msec));
|
||||
}
|
||||
@@ -114,25 +142,18 @@ 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
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
return xSemaphoreCreateMutexStatic(mdef);
|
||||
#else
|
||||
(void)(mdef);
|
||||
(void) mdef;
|
||||
return xSemaphoreCreateMutex();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock (osal_mutex_t mutex_hdl, uint32_t msec)
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_lock(osal_mutex_t mutex_hdl, uint32_t msec)
|
||||
{
|
||||
return osal_semaphore_wait(mutex_hdl, msec);
|
||||
}
|
||||
@@ -146,26 +167,9 @@ TU_ATTR_ALWAYS_INLINE static inline bool osal_mutex_unlock(osal_mutex_t mutex_hd
|
||||
// QUEUE API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
// _int_set is not used with an RTOS
|
||||
#define OSAL_QUEUE_DEF(_int_set, _name, _depth, _type) \
|
||||
static _type _name##_##buf[_depth];\
|
||||
osal_queue_def_t _name = { .depth = _depth, .item_sz = sizeof(_type), .buf = _name##_##buf };
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t depth;
|
||||
uint16_t item_sz;
|
||||
void* buf;
|
||||
#if configSUPPORT_STATIC_ALLOCATION == 1
|
||||
StaticQueue_t sq;
|
||||
#endif
|
||||
}osal_queue_def_t;
|
||||
|
||||
typedef QueueHandle_t osal_queue_t;
|
||||
|
||||
TU_ATTR_ALWAYS_INLINE static inline osal_queue_t osal_queue_create(osal_queue_def_t* qdef)
|
||||
{
|
||||
#if configSUPPORT_STATIC_ALLOCATION == 1
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
return xQueueCreateStatic(qdef->depth, qdef->item_sz, (uint8_t*) qdef->buf, &qdef->sq);
|
||||
#else
|
||||
return xQueueCreate(qdef->depth, qdef->item_sz);
|
||||
|
||||
Reference in New Issue
Block a user