SuperTinyKernel™ RTOS 1.06.x
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
Loading...
Searching...
No Matches
STK FreeRTOS API

FreeRTOS interface for C++ API of SuperTinyKernel RTOS. More...

Classes

struct  TaskParameters_t
 Parameters passed to xTaskCreate(). More...
struct  TaskStatus_t
struct  StaticTask_t
struct  StaticQueue_t
struct  StaticSemaphore_t
struct  StaticTimer_t
struct  StaticEventGroup_t
struct  StaticStreamBuffer_t
struct  StaticMessageBuffer_t
struct  MemoryRegion_t
struct  TaskParameters_restricted_t
struct  HeapStats_t

Macros

#define configMAX_PRIORITIES   32U
#define configMINIMAL_STACK_SIZE   128U
#define configTICK_RATE_HZ   1000U
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS   4U
#define configTASK_NOTIFICATION_ARRAY_ENTRIES   1U
#define configUSE_QUEUE_SETS   1U
#define configUSE_MUTEXES   1U
#define configUSE_TIMERS   1U
#define configUSE_EVENT_GROUPS   1U
#define configUSE_STREAM_BUFFERS   1U
#define configUSE_COUNTING_SEMAPHORES   1U
#define configUSE_TASK_NOTIFICATIONS   1U
#define configTOTAL_HEAP_SIZE   10240U
#define FREERTOS_STK_MAX_TASKS   16U
 Maximum number of concurrent tasks managed by the kernel. Increase if your application creates more tasks simultaneously.
#define FREERTOS_STK_DEFAULT_STACK_WORDS   256U
 Default stack depth in Words when the caller passes usStackDepth = 0.
#define FREERTOS_STK_PEND_CALL_QUEUE_SIZE   8U
 Capacity of the static deferred-call queue used by xTimerPendFunctionCall() and xTimerPendFunctionCallFromISR().
#define portMAX_DELAY   ((TickType_t)0xFFFFFFFFUL)
#define pdTRUE   ((BaseType_t)1)
#define pdFALSE   ((BaseType_t)0)
#define pdPASS   (pdTRUE)
#define pdFAIL   (pdFALSE)
#define errQUEUE_EMPTY   ((BaseType_t)0)
#define errQUEUE_FULL   ((BaseType_t)0)
#define configSTACK_DEPTH_TYPE   StackType_t
#define taskENTER_CRITICAL()
#define taskEXIT_CRITICAL()
#define taskDISABLE_INTERRUPTS()
#define taskENABLE_INTERRUPTS()
#define taskYIELD()
#define portYIELD()
#define taskSCHEDULER_NOT_STARTED   ((BaseType_t)0)
#define taskSCHEDULER_RUNNING   ((BaseType_t)1)
#define taskSCHEDULER_SUSPENDED   ((BaseType_t)2)
#define STATIC_TASK_TCB_SIZE_WORDS
#define STATIC_QUEUE_TCB_SIZE_WORDS   24U
#define STATIC_SEMAPHORE_TCB_SIZE_WORDS   8U
#define STATIC_TIMER_TCB_SIZE_WORDS   16U
#define STATIC_EVENT_GROUP_TCB_SIZE_WORDS   10U
#define STATIC_STREAM_BUFFER_TCB_SIZE_WORDS   26U
#define STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS   38U
#define portNUM_CONFIGURABLE_REGIONS   3U
#define pdMS_TO_TICKS(xTimeInMs)
#define tskIDLE_PRIORITY   ((UBaseType_t)0U)
#define xTaskHandle   TaskHandle_t

Typedefs

typedef uint32_t TickType_t
typedef long BaseType_t
typedef unsigned long UBaseType_t
typedef long portBASE_TYPE
typedef uintptr_t StackType_t
typedef void * TaskHandle_t
typedef void * QueueHandle_t
typedef void * SemaphoreHandle_t
typedef void * TimerHandle_t
typedef void * EventGroupHandle_t
typedef void * StreamBufferHandle_t
typedef void * MessageBufferHandle_t
typedef void * QueueSetHandle_t
typedef void * QueueSetMemberHandle_t
typedef void(* TaskFunction_t) (void *pvParameters)
typedef void(* TimerCallbackFunction_t) (TimerHandle_t xTimer)
typedef void(* PendedFunction_t) (void *pvParameter1, uint32_t ulParameter2)
typedef void(* StreamBufferCallbackFunction_t) (StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken)
typedef uint32_t EventBits_t

Enumerations

enum  eTaskState {
  eRunning = 0 ,
  eReady ,
  eBlocked ,
  eSuspended ,
  eDeleted ,
  eInvalid
}
 Task execution state, returned by eTaskGetState(). More...
enum  eNotifyAction {
  eNoAction = 0 ,
  eSetBits ,
  eIncrement ,
  eSetValueWithOverwrite ,
  eSetValueWithoutOverwrite
}
 Action applied to a task's notification value by xTaskNotify(). More...

Functions

void vPortEnterCritical (void)
void vPortExitCritical (void)
void taskYIELD_impl (void)
void vTaskStartScheduler (void)
void vTaskEndScheduler (void)
 End scheduling (KERNEL_DYNAMIC only). Included for API completeness.
void vTaskSuspendAll (void)
 Suspend the scheduler (disables preemption; interrupts remain enabled).
BaseType_t xTaskResumeAll (void)
TickType_t xTaskGetTickCount (void)
 Return the tick count since the scheduler started.
TickType_t xTaskGetTickCountFromISR (void)
 Return the tick count from ISR context (ISR-safe).
UBaseType_t uxTaskGetNumberOfTasks (void)
 Return the number of tasks currently under kernel management.
BaseType_t xTaskGetSchedulerState (void)
BaseType_t xTaskCreate (TaskFunction_t pvTaskCode, const char *pcName, uint32_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask)
void vTaskDelete (TaskHandle_t xTaskToDelete)
 Delete a task. Pass NULL to delete the calling task.
TaskHandle_t xTaskCreateStatic (TaskFunction_t pvTaskCode, const char *pcName, uint32_t ulStackDepth, void *pvParameters, UBaseType_t uxPriority, StackType_t *puxStackBuffer, StaticTask_t *pxTaskBuffer)
BaseType_t xTaskCreateRestrictedStatic (const TaskParameters_restricted_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask)
BaseType_t xTaskCreateRestricted (const TaskParameters_restricted_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask)
void vTaskList (char *pcWriteBuffer)
void vTaskGetRunTimeStats (char *pcWriteBuffer)
void vTaskSuspend (TaskHandle_t xTaskToSuspend)
 Suspend a task indefinitely. Pass NULL to suspend the calling task.
void vTaskResume (TaskHandle_t xTaskToResume)
 Resume a previously suspended task.
BaseType_t xTaskResumeFromISR (TaskHandle_t xTaskToResume)
BaseType_t xTaskAbortDelay (TaskHandle_t xTask)
void vTaskDelay (TickType_t xTicksToDelay)
 Block the calling task for a number of ticks.
void vTaskDelayUntil (TickType_t *pxPreviousWakeTime, TickType_t xTimeIncrement)
BaseType_t xTaskDelayUntil (TickType_t *pxPreviousWakeTime, TickType_t xTimeIncrement)
void vTaskPrioritySet (TaskHandle_t xTask, UBaseType_t uxNewPriority)
 Change the priority of a task. Pass NULL xTask for the calling task.
UBaseType_t uxTaskPriorityGet (TaskHandle_t xTask)
 Query the priority of a task. Pass NULL xTask for the calling task.
UBaseType_t uxTaskPriorityGetFromISR (TaskHandle_t xTask)
 Query the priority of a task from ISR context (ISR-safe).
eTaskState eTaskGetState (TaskHandle_t xTask)
 Return the current execution state of a task.
TaskHandle_t xTaskGetCurrentTaskHandle (void)
 Return the handle of the currently executing task.
TaskHandle_t xTaskGetHandle (const char *pcNameToQuery)
const char * pcTaskGetName (TaskHandle_t xTaskToQuery)
 Return the name string of a task.
UBaseType_t uxTaskGetStackHighWaterMark (TaskHandle_t xTask)
StackType_t uxTaskGetStackHighWaterMark2 (TaskHandle_t xTask)
UBaseType_t uxTaskGetSystemState (TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime)
QueueHandle_t xQueueCreate (UBaseType_t uxQueueLength, UBaseType_t uxItemSize)
QueueHandle_t xQueueCreateStatic (UBaseType_t uxQueueLength, UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue)
void vQueueDelete (QueueHandle_t xQueue)
 Delete a queue and free all associated memory.
BaseType_t xQueueSend (QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
BaseType_t xQueueSendToBack (QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
 Post an item to the back of a queue (alias of xQueueSend).
BaseType_t xQueueSendToFront (QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
BaseType_t xQueueReceive (QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
BaseType_t xQueuePeek (QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
BaseType_t xQueuePeekFromISR (QueueHandle_t xQueue, void *pvBuffer)
UBaseType_t uxQueueMessagesWaiting (QueueHandle_t xQueue)
 Return the number of items currently in the queue.
UBaseType_t uxQueueMessagesWaitingFromISR (QueueHandle_t xQueue)
UBaseType_t uxQueueSpacesAvailable (QueueHandle_t xQueue)
 Return the number of free slots in the queue.
BaseType_t xQueueReset (QueueHandle_t xQueue)
BaseType_t xQueueOverwrite (QueueHandle_t xQueue, const void *pvItemToQueue)
BaseType_t xQueueOverwriteFromISR (QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueSendFromISR (QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueReceiveFromISR (QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueSendToBackFromISR (QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueSendToFrontFromISR (QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueIsQueueEmptyFromISR (const QueueHandle_t xQueue)
BaseType_t xQueueIsQueueFullFromISR (const QueueHandle_t xQueue)
TaskHandle_t xQueueGetMutexHolder (QueueHandle_t xQueue)
TaskHandle_t xQueueGetMutexHolderFromISR (QueueHandle_t xQueue)
QueueSetHandle_t xQueueCreateSet (UBaseType_t uxEventQueueLength)
BaseType_t xQueueAddToSet (QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet)
BaseType_t xQueueRemoveFromSet (QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet)
QueueSetMemberHandle_t xQueueSelectFromSet (QueueSetHandle_t xQueueSet, TickType_t xTicksToWait)
QueueSetMemberHandle_t xQueueSelectFromSetFromISR (QueueSetHandle_t xQueueSet)
SemaphoreHandle_t xSemaphoreCreateBinary (void)
SemaphoreHandle_t xSemaphoreCreateBinaryStatic (StaticSemaphore_t *pxSemaphoreBuffer)
SemaphoreHandle_t xSemaphoreCreateCounting (UBaseType_t uxMaxCount, UBaseType_t uxInitialCount)
SemaphoreHandle_t xSemaphoreCreateCountingStatic (UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer)
SemaphoreHandle_t xSemaphoreCreateMutex (void)
SemaphoreHandle_t xSemaphoreCreateMutexStatic (StaticSemaphore_t *pxMutexBuffer)
SemaphoreHandle_t xSemaphoreCreateRecursiveMutex (void)
 Create a recursive mutex (same implementation as xSemaphoreCreateMutex).
SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic (StaticSemaphore_t *pxMutexBuffer)
void vSemaphoreDelete (SemaphoreHandle_t xSemaphore)
 Delete a semaphore or mutex and free its memory.
BaseType_t xSemaphoreTake (SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait)
BaseType_t xSemaphoreTakeFromISR (SemaphoreHandle_t xSemaphore, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xSemaphoreTakeRecursive (SemaphoreHandle_t xMutex, TickType_t xTicksToWait)
 Take a recursive mutex (blocking).
BaseType_t xSemaphoreGive (SemaphoreHandle_t xSemaphore)
BaseType_t xSemaphoreGiveRecursive (SemaphoreHandle_t xMutex)
 Give a recursive mutex.
BaseType_t xSemaphoreGiveFromISR (SemaphoreHandle_t xSemaphore, BaseType_t *pxHigherPriorityTaskWoken)
UBaseType_t uxSemaphoreGetCount (SemaphoreHandle_t xSemaphore)
TaskHandle_t xSemaphoreGetMutexHolder (SemaphoreHandle_t xMutex)
TaskHandle_t xSemaphoreGetMutexHolderFromISR (SemaphoreHandle_t xMutex)
TimerHandle_t xTimerCreate (const char *pcTimerName, TickType_t xTimerPeriodInTicks, UBaseType_t uxAutoReload, void *pvTimerID, TimerCallbackFunction_t pxCallbackFunction)
TimerHandle_t xTimerCreateStatic (const char *pcTimerName, TickType_t xTimerPeriodInTicks, UBaseType_t uxAutoReload, void *pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer)
BaseType_t xTimerDelete (TimerHandle_t xTimer, TickType_t xTicksToWait)
BaseType_t xTimerStart (TimerHandle_t xTimer, TickType_t xTicksToWait)
BaseType_t xTimerStop (TimerHandle_t xTimer, TickType_t xTicksToWait)
BaseType_t xTimerReset (TimerHandle_t xTimer, TickType_t xTicksToWait)
BaseType_t xTimerChangePeriod (TimerHandle_t xTimer, TickType_t xNewPeriod, TickType_t xTicksToWait)
BaseType_t xTimerIsTimerActive (TimerHandle_t xTimer)
void * pvTimerGetTimerID (TimerHandle_t xTimer)
 Return the application-defined ID stored in a timer.
void vTimerSetTimerID (TimerHandle_t xTimer, void *pvNewID)
 Set the application-defined ID stored in a timer.
const char * pcTimerGetName (TimerHandle_t xTimer)
 Return the name string of a timer.
TickType_t xTimerGetPeriod (TimerHandle_t xTimer)
 Return the period of a timer in ticks.
TickType_t xTimerGetExpiryTime (TimerHandle_t xTimer)
BaseType_t xTimerStartFromISR (TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTimerStopFromISR (TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTimerResetFromISR (TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTimerChangePeriodFromISR (TimerHandle_t xTimer, TickType_t xNewPeriod, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTimerPendFunctionCall (PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait)
BaseType_t xTimerPendFunctionCallFromISR (PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken)
EventGroupHandle_t xEventGroupCreate (void)
EventGroupHandle_t xEventGroupCreateStatic (StaticEventGroup_t *pxEventGroupBuffer)
void vEventGroupDelete (EventGroupHandle_t xEventGroup)
 Delete an event group and free its memory.
EventBits_t xEventGroupSetBits (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet)
EventBits_t xEventGroupClearBits (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToClear)
EventBits_t xEventGroupGetBits (EventGroupHandle_t xEventGroup)
 Return the current event group bits without blocking or modifying them.
EventBits_t xEventGroupWaitBits (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToWaitFor, BaseType_t xClearOnExit, BaseType_t xWaitForAllBits, TickType_t xTicksToWait)
BaseType_t xEventGroupSetBitsFromISR (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken)
EventBits_t xEventGroupClearBitsFromISR (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToClear)
EventBits_t xEventGroupSync (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet, EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait)
BaseType_t xTaskNotifyGive (TaskHandle_t xTaskToNotify)
uint32_t ulTaskNotifyTake (BaseType_t ulClearCountOnExit, TickType_t xTicksToWait)
BaseType_t xTaskNotify (TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction)
BaseType_t xTaskNotifyWait (uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait)
BaseType_t xTaskNotifyFromISR (TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskNotifyGiveIndexed (TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify)
uint32_t ulTaskNotifyTakeIndexed (UBaseType_t uxIndexToWait, BaseType_t ulClearCountOnExit, TickType_t xTicksToWait)
BaseType_t xTaskNotifyIndexed (TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction)
BaseType_t xTaskNotifyWaitIndexed (UBaseType_t uxIndexToWait, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait)
BaseType_t xTaskNotifyFromISRIndexed (TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskNotifyAndQuery (TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue)
BaseType_t xTaskNotifyAndQueryIndexed (TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue)
BaseType_t xTaskNotifyAndQueryFromISR (TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskNotifyAndQueryFromISRIndexed (TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskNotifyStateClear (TaskHandle_t xTask)
BaseType_t xTaskNotifyStateClearIndexed (TaskHandle_t xTask, UBaseType_t uxIndexToClear)
uint32_t ulTaskNotifyValueClear (TaskHandle_t xTask, uint32_t ulBitsToClear)
uint32_t ulTaskNotifyValueClearIndexed (TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear)
void vTaskSetThreadLocalStoragePointer (TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue)
void * pvTaskGetThreadLocalStoragePointer (TaskHandle_t xTaskToQuery, BaseType_t xIndex)
StreamBufferHandle_t xStreamBufferCreate (size_t xBufferSizeBytes, size_t xTriggerLevelBytes)
StreamBufferHandle_t xStreamBufferCreateStatic (size_t xBufferSizeBytes, size_t xTriggerLevelBytes, uint8_t *pucStreamBufferStorageArea, StaticStreamBuffer_t *pxStaticStreamBuffer)
void vStreamBufferDelete (StreamBufferHandle_t xStreamBuffer)
 Delete a stream buffer and free heap resources (if dynamically allocated).
size_t xStreamBufferSend (StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait)
size_t xStreamBufferSendFromISR (StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
size_t xStreamBufferReceive (StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait)
size_t xStreamBufferReceiveFromISR (StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
size_t xStreamBufferBytesAvailable (StreamBufferHandle_t xStreamBuffer)
 Return the number of bytes currently available to read.
size_t xStreamBufferSpacesAvailable (StreamBufferHandle_t xStreamBuffer)
 Return the number of free bytes available for writing.
BaseType_t xStreamBufferIsEmpty (StreamBufferHandle_t xStreamBuffer)
 Return pdTRUE if the stream buffer contains no data.
BaseType_t xStreamBufferIsFull (StreamBufferHandle_t xStreamBuffer)
 Return pdTRUE if the stream buffer is full (no write space remaining).
BaseType_t xStreamBufferReset (StreamBufferHandle_t xStreamBuffer)
BaseType_t xStreamBufferResetFromISR (StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xStreamBufferSetTriggerLevel (StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevelBytes)
size_t xStreamBufferGetTriggerLevel (StreamBufferHandle_t xStreamBuffer)
size_t xStreamBufferNextMessageLengthBytes (StreamBufferHandle_t xStreamBuffer)
StreamBufferHandle_t xStreamBufferCreateWithCallback (size_t xBufferSizeBytes, size_t xTriggerLevelBytes, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
StreamBufferHandle_t xStreamBufferCreateStaticWithCallback (size_t xBufferSizeBytes, size_t xTriggerLevelBytes, uint8_t *pucStreamBufferStorageArea, StaticStreamBuffer_t *pxStaticStreamBuffer, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
MessageBufferHandle_t xMessageBufferCreate (size_t xBufferSizeBytes, size_t xMaxMessageSize)
MessageBufferHandle_t xMessageBufferCreateStatic (size_t xMaxMessageSize, size_t xMessageCount, uint8_t *pucMessageBufferStorageArea, StaticMessageBuffer_t *pxStaticMessageBuffer)
MessageBufferHandle_t xMessageBufferCreateWithCallback (size_t xBufferSizeBytes, size_t xMaxMessageSize, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
MessageBufferHandle_t xMessageBufferCreateStaticWithCallback (size_t xMaxMessageSize, size_t xMessageCount, uint8_t *pucMessageBufferStorageArea, StaticMessageBuffer_t *pxStaticMessageBuffer, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
void vMessageBufferDelete (MessageBufferHandle_t xMessageBuffer)
 Delete a message buffer and free heap resources (if dynamically allocated).
size_t xMessageBufferSend (MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait)
size_t xMessageBufferSendFromISR (MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
size_t xMessageBufferReceive (MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait)
size_t xMessageBufferReceiveFromISR (MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xMessageBufferIsEmpty (MessageBufferHandle_t xMessageBuffer)
BaseType_t xMessageBufferIsFull (MessageBufferHandle_t xMessageBuffer)
size_t xMessageBufferSpacesAvailable (MessageBufferHandle_t xMessageBuffer)
size_t xMessageBufferNextLengthBytes (MessageBufferHandle_t xMessageBuffer)
BaseType_t xMessageBufferReset (MessageBufferHandle_t xMessageBuffer)
BaseType_t xMessageBufferResetFromISR (MessageBufferHandle_t xMessageBuffer, BaseType_t *pxHigherPriorityTaskWoken)
void * pvPortMalloc (size_t xWantedSize)
void vPortFree (void *pv)
size_t xPortGetFreeHeapSize (void)
size_t xPortGetMinimumEverFreeHeapSize (void)
void vPortGetHeapStats (HeapStats_t *pxHeapStats)

Detailed Description

FreeRTOS interface for C++ API of SuperTinyKernel RTOS.

Maps standard FreeRTOS C API onto the STK C++ API, allowing existing FreeRTOS-based projects to run on STK with minimal or no application changes.

Supported API groups:

  • Kernel control (vTaskStartScheduler, taskENTER/EXIT_CRITICAL, xTaskGetTickCount, vTaskDelay, vTaskDelayUntil, xTaskDelayUntil, xTaskGetSchedulerState)
  • Task management (xTaskCreate, vTaskDelete, vTaskSuspend, vTaskResume, xTaskAbortDelay, vTaskPrioritySet, uxTaskPriorityGet, xTaskGetHandle, xTaskGetCurrentTaskHandle, pcTaskGetName, uxTaskGetStackHighWaterMark, eTaskGetState, uxTaskGetSystemState, xTaskCreateRestricted, xTaskCreateRestrictedStatic, vTaskList, vTaskGetRunTimeStats)
  • Queue (xQueueCreate, xQueueCreateStatic, vQueueDelete, xQueueSend, xQueueSendToBack, xQueueSendToFront, xQueueReceive, xQueuePeek, xQueuePeekFromISR, xQueueOverwrite, xQueueOverwriteFromISR, uxQueueMessagesWaiting, uxQueueMessagesWaitingFromISR, uxQueueSpacesAvailable, xQueueReset, xQueueSendFromISR, xQueueReceiveFromISR, xQueueSendToBackFromISR, xQueueSendToFrontFromISR, xQueueIsQueueEmptyFromISR, xQueueIsQueueFullFromISR, xQueueGetMutexHolder, xQueueGetMutexHolderFromISR, xQueueCreateSet, xQueueAddToSet, xQueueRemoveFromSet, xQueueSelectFromSet, xQueueSelectFromSetFromISR)
  • Semaphore / Mutex (xSemaphoreCreateBinary, xSemaphoreCreateBinaryStatic, xSemaphoreCreateCounting, xSemaphoreCreateCountingStatic, xSemaphoreCreateMutex, xSemaphoreCreateMutexStatic, xSemaphoreCreateRecursiveMutex, xSemaphoreCreateRecursiveMutexStatic, vSemaphoreDelete, xSemaphoreTake, xSemaphoreTakeFromISR, xSemaphoreTakeRecursive, xSemaphoreGive, xSemaphoreGiveRecursive, xSemaphoreGiveFromISR, uxSemaphoreGetCount, xSemaphoreGetMutexHolder, xSemaphoreGetMutexHolderFromISR)
  • Software timers (xTimerCreate, xTimerCreateStatic, xTimerDelete, xTimerStart, xTimerStop, xTimerReset, xTimerChangePeriod, xTimerIsTimerActive, pvTimerGetTimerID, pcTimerGetName, xTimerStartFromISR, xTimerStopFromISR, xTimerResetFromISR, xTimerChangePeriodFromISR, xTimerPendFunctionCall, xTimerPendFunctionCallFromISR)
  • Event groups (xEventGroupCreate, xEventGroupCreateStatic, vEventGroupDelete, xEventGroupSetBits, xEventGroupClearBits, xEventGroupGetBits, xEventGroupWaitBits, xEventGroupSetBitsFromISR, xEventGroupClearBitsFromISR, xEventGroupSync)
  • Task notifications (xTaskNotifyGive, ulTaskNotifyTake, xTaskNotify, xTaskNotifyWait, xTaskNotifyFromISR, xTaskNotifyGiveIndexed, ulTaskNotifyTakeIndexed, xTaskNotifyIndexed, xTaskNotifyWaitIndexed, xTaskNotifyFromISRIndexed, xTaskNotifyAndQuery, xTaskNotifyAndQueryIndexed, xTaskNotifyAndQueryFromISR, xTaskNotifyAndQueryFromISRIndexed, xTaskNotifyStateClear, xTaskNotifyStateClearIndexed, ulTaskNotifyValueClear, ulTaskNotifyValueClearIndexed)
  • Stream buffers (xStreamBufferCreate, xStreamBufferCreateStatic, xStreamBufferCreateWithCallback, xStreamBufferCreateStaticWithCallback, xStreamBufferSend, xStreamBufferReceive, xStreamBufferSendFromISR, xStreamBufferReceiveFromISR, vStreamBufferDelete, xStreamBufferBytesAvailable, xStreamBufferSpacesAvailable, xStreamBufferIsEmpty, xStreamBufferIsFull, xStreamBufferReset, xStreamBufferResetFromISR, xStreamBufferSetTriggerLevel, xStreamBufferGetTriggerLevel, xStreamBufferNextMessageLengthBytes)
  • Message buffers (xMessageBufferCreate, xMessageBufferCreateStatic, xMessageBufferCreateWithCallback, xMessageBufferCreateStaticWithCallback, xMessageBufferSend, xMessageBufferSendFromISR, xMessageBufferReceive, xMessageBufferReceiveFromISR, vMessageBufferDelete, xMessageBufferIsEmpty, xMessageBufferIsFull, xMessageBufferSpacesAvailable, xMessageBufferReset, xMessageBufferResetFromISR, xMessageBufferNextLengthBytes)

Design notes:

  • All objects are heap-allocated with operator new/delete. For static deployments replace with a static pool allocator.
  • One global STK Kernel instance (g_StkKernel) is configured with KERNEL_DYNAMIC | KERNEL_SYNC and SwitchStrategyFP32 (32 fixed-priority levels, same strategy used by the CMSIS wrapper). FreeRTOS priorities (0=lowest .. configMAX_PRIORITIES-1=highest) map directly to STK priority levels 0..configMAX_PRIORITIES-1. configMAX_PRIORITIES must be <= 32 (compile-time assertion in the .cpp). The highest-priority ready task always preempts lower ones, exactly matching FreeRTOS fixed-priority preemptive scheduling semantics.
  • portMAX_DELAY (0xFFFFFFFF) is translated to stk::WAIT_INFINITE.
  • Timeout values are in ticks; STK also takes ticks, so no conversion needed when tick resolution is 1 ms (the default PERIODICITY_DEFAULT).
  • Recursive mutexes are backed by stk::sync::Mutex (always recursive in STK).
  • Binary semaphores are backed by stk::sync::Semaphore with max_count=1.
  • Counting semaphores are backed by stk::sync::Semaphore.
  • Event groups are backed by stk::sync::EventFlags (32-bit, bits 0..23 usable per FreeRTOS convention; bits 24..30 are free, bit 31 is reserved by STK).
  • Software timers are backed by stk::time::TimerHost.
  • Task notifications are backed by per-task stk::sync::Semaphore.
  • Queue sets are backed by a per-set stk::sync::MessageQueue of void* tokens (sizeof(void*) per slot). Member queues and semaphores carry a non-owning back-pointer to their registered set; QueueSetNotify() posts the member handle into the set's token FIFO after every successful send or signal. Type discrimination between FrtosQueue and FrtosSemaphore uses the fact that SemKind (offset 0 in FrtosSemaphore, values 0 or 1) is always < the first byte of a MessageQueue vtable pointer (>= 4).

Limitations / deviations:

  • Priority inheritance is not supported (STK mutex is always recursive, not priority-inheriting).
  • configUSE_PREEMPTION is assumed to be 1; cooperative scheduling is not modelled.
  • Task notifications: indexed API supports slots 0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1.
  • uxTaskGetNumberOfTasks() requires the kernel to be running.

Macro Definition Documentation

◆ configMAX_PRIORITIES

#define configMAX_PRIORITIES   32U

Definition at line 152 of file FreeRTOS.h.

Referenced by FrtosPrioToStkWeight(), and StkWeightToFrtosPrio().

◆ configMINIMAL_STACK_SIZE

#define configMINIMAL_STACK_SIZE   128U

Minimum stack depth in Words.

Definition at line 156 of file FreeRTOS.h.

◆ configNUM_THREAD_LOCAL_STORAGE_POINTERS

#define configNUM_THREAD_LOCAL_STORAGE_POINTERS   4U

Per-task TLS pointer slots.

Definition at line 164 of file FreeRTOS.h.

Referenced by FrtosTask::FrtosTask(), pvTaskGetThreadLocalStoragePointer(), and vTaskSetThreadLocalStoragePointer().

◆ configSTACK_DEPTH_TYPE

#define configSTACK_DEPTH_TYPE   StackType_t

Stack depth word type.

Definition at line 271 of file FreeRTOS.h.

Referenced by uxTaskGetStackHighWaterMark2(), and uxTaskGetSystemState().

◆ configTASK_NOTIFICATION_ARRAY_ENTRIES

#define configTASK_NOTIFICATION_ARRAY_ENTRIES   1U

Number of per-task notification slots (indexed API).

Definition at line 168 of file FreeRTOS.h.

Referenced by ResolveNotifyTarget().

◆ configTICK_RATE_HZ

#define configTICK_RATE_HZ   1000U

Definition at line 160 of file FreeRTOS.h.

◆ configTOTAL_HEAP_SIZE

#define configTOTAL_HEAP_SIZE   10240U

Dynamic heap size in bytes.

Definition at line 200 of file FreeRTOS.h.

◆ configUSE_COUNTING_SEMAPHORES

#define configUSE_COUNTING_SEMAPHORES   1U

Include counting semaphore API.

Definition at line 192 of file FreeRTOS.h.

◆ configUSE_EVENT_GROUPS

#define configUSE_EVENT_GROUPS   1U

Include event group API.

Definition at line 184 of file FreeRTOS.h.

◆ configUSE_MUTEXES

#define configUSE_MUTEXES   1U

Include mutex and recursive-mutex API.

Definition at line 176 of file FreeRTOS.h.

Referenced by FrtosSemaphore::FrtosSemaphore().

◆ configUSE_QUEUE_SETS

#define configUSE_QUEUE_SETS   1U

Include queue sets API.

Definition at line 172 of file FreeRTOS.h.

Referenced by FrtosQueue::FrtosQueue(), FrtosQueue::FrtosQueue(), and FrtosSemaphore::FrtosSemaphore().

◆ configUSE_STREAM_BUFFERS

#define configUSE_STREAM_BUFFERS   1U

Include stream buffer and message buffer API.

Definition at line 188 of file FreeRTOS.h.

◆ configUSE_TASK_NOTIFICATIONS

#define configUSE_TASK_NOTIFICATIONS   1U

Include task notification API (xTaskNotify etc.).

Definition at line 196 of file FreeRTOS.h.

◆ configUSE_TIMERS

#define configUSE_TIMERS   1U

Include software timer API.

Definition at line 180 of file FreeRTOS.h.

◆ errQUEUE_EMPTY

#define errQUEUE_EMPTY   ((BaseType_t)0)

Definition at line 267 of file FreeRTOS.h.

◆ errQUEUE_FULL

#define errQUEUE_FULL   ((BaseType_t)0)

Definition at line 268 of file FreeRTOS.h.

◆ FREERTOS_STK_DEFAULT_STACK_WORDS

#define FREERTOS_STK_DEFAULT_STACK_WORDS   256U

Default stack depth in Words when the caller passes usStackDepth = 0.

Definition at line 215 of file FreeRTOS.h.

Referenced by xTaskCreate().

◆ FREERTOS_STK_MAX_TASKS

#define FREERTOS_STK_MAX_TASKS   16U

Maximum number of concurrent tasks managed by the kernel. Increase if your application creates more tasks simultaneously.

Definition at line 208 of file FreeRTOS.h.

Referenced by uxTaskGetSystemState(), vTaskEndScheduler(), vTaskGetRunTimeStats(), vTaskList(), and xTaskGetHandle().

◆ FREERTOS_STK_PEND_CALL_QUEUE_SIZE

#define FREERTOS_STK_PEND_CALL_QUEUE_SIZE   8U

Capacity of the static deferred-call queue used by xTimerPendFunctionCall() and xTimerPendFunctionCallFromISR().

Each slot holds one PendCall record: one function pointer, one void* parameter, and one uint32_t parameter — typically 12–16 bytes on 32-bit targets. The queue lives in static storage (zero heap), so this value determines RAM consumption at link time rather than runtime.

Choose the maximum number of deferred calls that can be simultaneously in-flight before the TimerHost handler task drains them. A value of 8 is sufficient for most applications; increase it if your ISR rate is high relative to the RTOS tick rate or if several ISRs may pend calls concurrently.

Note
xTimerPendFunctionCall() returns pdFAIL when the queue is full.
xTimerPendFunctionCallFromISR() also returns pdFAIL when full (non-blocking).
Must be >= 1.

Definition at line 238 of file FreeRTOS.h.

◆ pdFAIL

◆ pdFALSE

◆ pdMS_TO_TICKS

#define pdMS_TO_TICKS ( xTimeInMs)
Value:
((TickType_t)(xTimeInMs))
uint32_t TickType_t
Definition FreeRTOS.h:256

1 ms tick resolution.

Definition at line 2028 of file FreeRTOS.h.

◆ pdPASS

◆ pdTRUE

◆ portMAX_DELAY

#define portMAX_DELAY   ((TickType_t)0xFFFFFFFFUL)

Block indefinitely.

Definition at line 262 of file FreeRTOS.h.

Referenced by FrtosTimeoutToStk().

◆ portNUM_CONFIGURABLE_REGIONS

#define portNUM_CONFIGURABLE_REGIONS   3U

MPU memory region descriptor used by xTaskCreateRestrictedStatic().

Note
STK does not implement MPU support. This struct is provided for source compatibility only; region fields are accepted but ignored.

Definition at line 558 of file FreeRTOS.h.

◆ portYIELD

#define portYIELD ( )
Value:
void taskYIELD_impl(void)

Definition at line 397 of file FreeRTOS.h.

◆ STATIC_EVENT_GROUP_TCB_SIZE_WORDS

#define STATIC_EVENT_GROUP_TCB_SIZE_WORDS   10U

Opaque buffer type that the caller must supply for xEventGroupCreateStatic(). Must be at least sizeof(FrtosEventGroup) bytes. Declared as a fixed-size array of uintptr_t to enforce natural alignment without exposing FrtosEventGroup internals.

Definition at line 506 of file FreeRTOS.h.

◆ STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS

#define STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS   38U

Opaque buffer type for xMessageBufferCreateStatic() and xMessageBufferCreateStaticWithCallback(). Covers FrtosMessageBuffer (BlockMemoryPool header + envelope MessageQueue header

  • ownership flags + two StreamBufferCallbackFunction_t pointers) on all supported STK targets. Size is conservative (+2 words vs the pre-callback layout).

Definition at line 528 of file FreeRTOS.h.

◆ STATIC_QUEUE_TCB_SIZE_WORDS

#define STATIC_QUEUE_TCB_SIZE_WORDS   24U

Opaque buffer type that the caller must supply for xQueueCreateStatic(). Must be at least sizeof(StaticQueue_t) bytes. Declared as a fixed-size array of uintptr_t to enforce natural alignment without exposing FrtosQueue internals. Size is conservative: covers FrtosQueue on all supported targets.

Definition at line 474 of file FreeRTOS.h.

◆ STATIC_SEMAPHORE_TCB_SIZE_WORDS

#define STATIC_SEMAPHORE_TCB_SIZE_WORDS   8U

Opaque buffer type that the caller must supply for xSemaphoreCreateBinaryStatic() and related static semaphore/mutex creation functions. Must be at least sizeof(FrtosSemaphore) bytes. Declared as a fixed-size array of uintptr_t to enforce natural alignment without exposing FrtosSemaphore internals. Size is conservative: covers FrtosSemaphore on all supported targets.

Definition at line 485 of file FreeRTOS.h.

◆ STATIC_STREAM_BUFFER_TCB_SIZE_WORDS

#define STATIC_STREAM_BUFFER_TCB_SIZE_WORDS   26U

Opaque buffer type for xStreamBufferCreateStatic() and xStreamBufferCreateStaticWithCallback(). Covers FrtosStreamBuffer (Pipe + trigger level + ownership flags + two StreamBufferCallbackFunction_t pointers) on all supported STK targets. Size is conservative (+2 words vs the pre-callback layout).

Definition at line 517 of file FreeRTOS.h.

◆ STATIC_TASK_TCB_SIZE_WORDS

#define STATIC_TASK_TCB_SIZE_WORDS
Value:
#define configTASK_NOTIFICATION_ARRAY_ENTRIES
Definition FreeRTOS.h:168
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS
Definition FreeRTOS.h:164

Opaque buffer type that the caller must supply for xTaskCreateStatic(). Must be at least sizeof(StaticTask_t) bytes; declared as a fixed-size array of uintptr_t so the compiler enforces natural alignment without requiring knowledge of FrtosTask internals. Size is conservative: covers FrtosTask on all supported STK targets.

Definition at line 463 of file FreeRTOS.h.

463#define STATIC_TASK_TCB_SIZE_WORDS (19U + configNUM_THREAD_LOCAL_STORAGE_POINTERS \
464 + (3U * (configTASK_NOTIFICATION_ARRAY_ENTRIES - 1U)))

◆ STATIC_TIMER_TCB_SIZE_WORDS

#define STATIC_TIMER_TCB_SIZE_WORDS   16U

Opaque buffer type that the caller must supply for xTimerCreateStatic(). Must be at least sizeof(FrtosTimer) bytes. Declared as a fixed-size array of uintptr_t to enforce natural alignment without exposing FrtosTimer internals. Size is conservative: covers FrtosTimer (vtable ptr + base + 5 members) on all supported targets.

Definition at line 496 of file FreeRTOS.h.

◆ taskDISABLE_INTERRUPTS

#define taskDISABLE_INTERRUPTS ( )
Value:
void vPortEnterCritical(void)

Definition at line 394 of file FreeRTOS.h.

◆ taskENABLE_INTERRUPTS

#define taskENABLE_INTERRUPTS ( )
Value:
void vPortExitCritical(void)

Definition at line 395 of file FreeRTOS.h.

◆ taskENTER_CRITICAL

#define taskENTER_CRITICAL ( )
Value:

Definition at line 392 of file FreeRTOS.h.

◆ taskEXIT_CRITICAL

#define taskEXIT_CRITICAL ( )
Value:

Definition at line 393 of file FreeRTOS.h.

◆ taskSCHEDULER_NOT_STARTED

#define taskSCHEDULER_NOT_STARTED   ((BaseType_t)0)

Scheduler has not yet been started (STATE_INACTIVE / STATE_READY).

Definition at line 427 of file FreeRTOS.h.

Referenced by xTaskGetSchedulerState().

◆ taskSCHEDULER_RUNNING

#define taskSCHEDULER_RUNNING   ((BaseType_t)1)

Scheduler is running normally (STATE_RUNNING).

Definition at line 428 of file FreeRTOS.h.

Referenced by xTaskGetSchedulerState().

◆ taskSCHEDULER_SUSPENDED

#define taskSCHEDULER_SUSPENDED   ((BaseType_t)2)

Scheduler is suspended via vTaskSuspendAll() (STATE_SUSPENDED).

Definition at line 429 of file FreeRTOS.h.

Referenced by xTaskGetSchedulerState().

◆ taskYIELD

#define taskYIELD ( )
Value:

Definition at line 396 of file FreeRTOS.h.

◆ tskIDLE_PRIORITY

#define tskIDLE_PRIORITY   ((UBaseType_t)0U)

Idle task priority.

Definition at line 2029 of file FreeRTOS.h.

Referenced by FrtosTask::FrtosTask().

◆ xTaskHandle

#define xTaskHandle   TaskHandle_t

Legacy handle alias.

Definition at line 2030 of file FreeRTOS.h.

Typedef Documentation

◆ BaseType_t

typedef long BaseType_t

Definition at line 257 of file FreeRTOS.h.

◆ EventBits_t

typedef uint32_t EventBits_t

Bitmask for event group operations (bits 0..23 per FreeRTOS convention).

Definition at line 380 of file FreeRTOS.h.

◆ EventGroupHandle_t

typedef void* EventGroupHandle_t

Handle for an event group.

Definition at line 314 of file FreeRTOS.h.

◆ MessageBufferHandle_t

typedef void* MessageBufferHandle_t

Handle for a message buffer.

Definition at line 316 of file FreeRTOS.h.

◆ PendedFunction_t

typedef void(* PendedFunction_t) (void *pvParameter1, uint32_t ulParameter2)

Callback for xTimerPendFunctionCall().

Definition at line 328 of file FreeRTOS.h.

◆ portBASE_TYPE

typedef long portBASE_TYPE

Definition at line 259 of file FreeRTOS.h.

◆ QueueHandle_t

typedef void* QueueHandle_t

Handle for a queue.

Definition at line 311 of file FreeRTOS.h.

◆ QueueSetHandle_t

typedef void* QueueSetHandle_t

Definition at line 319 of file FreeRTOS.h.

◆ QueueSetMemberHandle_t

typedef void* QueueSetMemberHandle_t

Definition at line 320 of file FreeRTOS.h.

◆ SemaphoreHandle_t

typedef void* SemaphoreHandle_t

Handle for a semaphore/mutex.

Definition at line 312 of file FreeRTOS.h.

◆ StackType_t

typedef uintptr_t StackType_t

Native-word stack element type, matches stk::Word.

Definition at line 260 of file FreeRTOS.h.

◆ StreamBufferCallbackFunction_t

typedef void(* StreamBufferCallbackFunction_t) (StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken)

Stream / message buffer send-complete and receive-complete callback. Invoked after bytes are successfully written (send) or read (receive) from the buffer. \a xHigherPriorityTaskWoken is always set to pdFALSE by the STK backend; it is included only for FreeRTOS API compatibility. May be NULL (no callback).

Definition at line 336 of file FreeRTOS.h.

◆ StreamBufferHandle_t

typedef void* StreamBufferHandle_t

Handle for a stream buffer.

Definition at line 315 of file FreeRTOS.h.

◆ TaskFunction_t

typedef void(* TaskFunction_t) (void *pvParameters)

Task entry function.

Definition at line 326 of file FreeRTOS.h.

◆ TaskHandle_t

typedef void* TaskHandle_t

Handle for a task.

Definition at line 310 of file FreeRTOS.h.

◆ TickType_t

typedef uint32_t TickType_t

Definition at line 256 of file FreeRTOS.h.

◆ TimerCallbackFunction_t

typedef void(* TimerCallbackFunction_t) (TimerHandle_t xTimer)

Timer expiry callback.

Definition at line 327 of file FreeRTOS.h.

◆ TimerHandle_t

typedef void* TimerHandle_t

Handle for a software timer.

Definition at line 313 of file FreeRTOS.h.

◆ UBaseType_t

typedef unsigned long UBaseType_t

Definition at line 258 of file FreeRTOS.h.

Enumeration Type Documentation

◆ eNotifyAction

Action applied to a task's notification value by xTaskNotify().

Enumerator
eNoAction 

No action; notification sent without modifying the value.

eSetBits 

OR ulValue into the notification value.

eIncrement 

Increment the notification value by 1 (ulValue ignored).

eSetValueWithOverwrite 

Set notification value to ulValue unconditionally.

eSetValueWithoutOverwrite 

Set only if the previous notification was consumed.

Definition at line 294 of file FreeRTOS.h.

295{
296 eNoAction = 0,
297 eSetBits,
298 eIncrement,
eNotifyAction
Action applied to a task's notification value by xTaskNotify().
Definition FreeRTOS.h:295
@ eIncrement
Definition FreeRTOS.h:298
@ eSetValueWithOverwrite
Definition FreeRTOS.h:299
@ eSetBits
Definition FreeRTOS.h:297
@ eNoAction
Definition FreeRTOS.h:296
@ eSetValueWithoutOverwrite
Definition FreeRTOS.h:300

◆ eTaskState

enum eTaskState

Task execution state, returned by eTaskGetState().

Enumerator
eRunning 

Task is actively executing on the CPU.

eReady 

Task is in the ready list, eligible to run.

eBlocked 

Task is waiting for an event or timeout.

eSuspended 

Task is explicitly suspended via vTaskSuspend().

eDeleted 

Task has been deleted but not yet cleaned up.

eInvalid 

Invalid / unknown state.

Definition at line 279 of file FreeRTOS.h.

280{
281 eRunning = 0,
282 eReady,
283 eBlocked,
284 eSuspended,
285 eDeleted,
286 eInvalid
287} eTaskState;
eTaskState
Task execution state, returned by eTaskGetState().
Definition FreeRTOS.h:280
@ eRunning
Definition FreeRTOS.h:281
@ eReady
Definition FreeRTOS.h:282
@ eInvalid
Definition FreeRTOS.h:286
@ eDeleted
Definition FreeRTOS.h:285
@ eBlocked
Definition FreeRTOS.h:283
@ eSuspended
Definition FreeRTOS.h:284

Function Documentation

◆ eTaskGetState()

eTaskState eTaskGetState ( TaskHandle_t xTask)

Return the current execution state of a task.

Definition at line 1326 of file freertos_stk.cpp.

1327{
1328 if (xTask == nullptr)
1329 return eInvalid;
1330
1331 FrtosTask *t = static_cast<FrtosTask *>(xTask);
1332
1334 return eDeleted;
1335
1337 return eSuspended;
1338
1339 // Check whether this is the currently running task.
1340 if (static_cast<uintptr_t>(stk::GetTid()) == reinterpret_cast<uintptr_t>(t))
1341 return eRunning;
1342
1343 return eReady;
1344}
TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:243
volatile State m_state

References FrtosTask::Deleted, eDeleted, eInvalid, eReady, eRunning, eSuspended, stk::GetTid(), FrtosTask::m_state, and FrtosTask::Suspended.

Here is the call graph for this function:

◆ pcTaskGetName()

const char * pcTaskGetName ( TaskHandle_t xTaskToQuery)

Return the name string of a task.

Definition at line 1376 of file freertos_stk.cpp.

1377{
1378 if (xTaskToQuery == nullptr)
1379 return nullptr;
1380
1381 return static_cast<FrtosTask *>(xTaskToQuery)->m_name;
1382}

◆ pcTimerGetName()

const char * pcTimerGetName ( TimerHandle_t xTimer)

Return the name string of a timer.

Definition at line 2899 of file freertos_stk.cpp.

2900{
2901 if (xTimer == nullptr)
2902 return nullptr;
2903
2904 return static_cast<FrtosTimer *>(xTimer)->m_name;
2905}

◆ pvPortMalloc()

void * pvPortMalloc ( size_t xWantedSize)

Allocate xWantedSize bytes from the system heap.

Returns
Pointer to the allocated block, or NULL on failure.
Note
Thread-safe if the underlying MemoryAllocator::Allocate is. The default implementation delegates to malloc.

Definition at line 184 of file freertos_stk.cpp.

185{
186 return stk::memory::MemoryAllocator::Allocate(xWantedSize);
187}
static void * Allocate(size_t size) __stk_weak
Allocate the memory chunk.

References __stk_weak, and stk::memory::MemoryAllocator::Allocate().

Referenced by ObjAlloc(), and ObjAllocArray().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pvTaskGetThreadLocalStoragePointer()

void * pvTaskGetThreadLocalStoragePointer ( TaskHandle_t xTaskToQuery,
BaseType_t xIndex )

Read a TLS pointer slot for a task.

Parameters
xTaskToQueryTask handle, or NULL for the calling task.
xIndexSlot index (0 .. configNUM_THREAD_LOCAL_STORAGE_POINTERS-1).
Returns
Stored pointer, or NULL if the index is out of range.

< Per-task TLS pointer slots.

Definition at line 3663 of file freertos_stk.cpp.

3665{
3666 if (xIndex < 0 || static_cast<size_t>(xIndex) >= configNUM_THREAD_LOCAL_STORAGE_POINTERS)
3667 return nullptr;
3668
3669 // Resolve NULL -> calling task.
3670 if (xTaskToQuery == nullptr)
3671 xTaskToQuery = xTaskGetCurrentTaskHandle();
3672
3673 if (xTaskToQuery == nullptr)
3674 return nullptr;
3675
3676 const FrtosTask *t = static_cast<const FrtosTask *>(xTaskToQuery);
3677
3679 return t->m_tls[static_cast<size_t>(xIndex)];
3680}
TaskHandle_t xTaskGetCurrentTaskHandle(void)
Return the handle of the currently executing task.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
Definition stk_sync_cs.h:54
void * m_tls[4U]

References configNUM_THREAD_LOCAL_STORAGE_POINTERS, FrtosTask::m_tls, and xTaskGetCurrentTaskHandle().

Here is the call graph for this function:

◆ pvTimerGetTimerID()

void * pvTimerGetTimerID ( TimerHandle_t xTimer)

Return the application-defined ID stored in a timer.

Definition at line 2883 of file freertos_stk.cpp.

2884{
2885 if (xTimer == nullptr)
2886 return nullptr;
2887
2888 return static_cast<FrtosTimer *>(xTimer)->m_timer_id;
2889}

◆ taskYIELD_impl()

void taskYIELD_impl ( void )

Definition at line 361 of file freertos_stk.cpp.

362{
363 stk::Yield();
364}
void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:386

References stk::Yield().

Here is the call graph for this function:

◆ ulTaskNotifyTake()

uint32_t ulTaskNotifyTake ( BaseType_t ulClearCountOnExit,
TickType_t xTicksToWait )

Receive a notification (slot 0), optionally clearing or decrementing the value.

Parameters
ulClearCountOnExitpdTRUE = clear to 0 on exit, pdFALSE = decrement by 1.
xTicksToWaitTicks to wait for a notification.
Returns
Notification value before the clear/decrement, or 0 on timeout.

Definition at line 3381 of file freertos_stk.cpp.

3382{
3383 return ulTaskNotifyTakeIndexed(0U, ulClearCountOnExit, xTicksToWait);
3384}
uint32_t ulTaskNotifyTakeIndexed(UBaseType_t uxIndexToWait, BaseType_t ulClearCountOnExit, TickType_t xTicksToWait)

References ulTaskNotifyTakeIndexed().

Here is the call graph for this function:

◆ ulTaskNotifyTakeIndexed()

uint32_t ulTaskNotifyTakeIndexed ( UBaseType_t uxIndexToWait,
BaseType_t ulClearCountOnExit,
TickType_t xTicksToWait )

Receive a notification from a specific slot of the calling task.

Parameters
uxIndexToWaitNotification slot index.
ulClearCountOnExitpdTRUE = clear slot value to 0, pdFALSE = decrement by 1.
xTicksToWaitTicks to wait.
Returns
Slot value before the clear/decrement, or 0 on timeout or bad index.

Definition at line 3264 of file freertos_stk.cpp.

3267{
3268 if (IsIrqContext())
3269 return 0U;
3270
3271 FrtosTask *t = ResolveNotifyTarget(nullptr, uxIndexToWait);
3272 if (t == nullptr)
3273 return 0U;
3274
3275 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToWait];
3276
3277 if (!slot.sem.Wait(FrtosTimeoutToStk(xTicksToWait)))
3278 return 0U;
3279
3280 uint32_t val = 0U;
3281
3282 {
3284 val = slot.value;
3285
3286 if (ulClearCountOnExit == pdTRUE)
3287 slot.value = 0U;
3288 else
3289 if (slot.value > 0U)
3290 slot.value--;
3291 }
3292
3293 return val + 1U; // +1: the semaphore signal itself counts
3294}
static stk::Timeout FrtosTimeoutToStk(TickType_t t)
static bool IsIrqContext()
static FrtosTask * ResolveNotifyTarget(TaskHandle_t xTask, UBaseType_t uxIndex)
#define pdTRUE
Definition FreeRTOS.h:263
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter).
NotifySlot m_notify[1U]
stk::sync::Semaphore sem
binary semaphore: blocks the waiter, signaled by notifier
volatile uint32_t value
notification value word

References FrtosTimeoutToStk(), IsIrqContext(), FrtosTask::m_notify, pdTRUE, ResolveNotifyTarget(), FrtosTask::NotifySlot::sem, FrtosTask::NotifySlot::value, and stk::sync::Semaphore::Wait().

Referenced by ulTaskNotifyTake().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ulTaskNotifyValueClear()

uint32_t ulTaskNotifyValueClear ( TaskHandle_t xTask,
uint32_t ulBitsToClear )

Atomically clear the specified bits in the notification value of slot 0 of a task, and return the value of the notification word before the bits were cleared.

Parameters
xTaskHandle of the task. NULL selects the calling task.
ulBitsToClearBitmask of bits to clear (ANDed with complement). Pass 0xFFFFFFFF to clear all bits.
Returns
Notification value before the clear operation, or 0 on bad handle.
Note
ISR-safe.

Definition at line 3616 of file freertos_stk.cpp.

3618{
3619 return ulTaskNotifyValueClearIndexed(xTask, 0U, ulBitsToClear);
3620}
uint32_t ulTaskNotifyValueClearIndexed(TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear)

References ulTaskNotifyValueClearIndexed().

Here is the call graph for this function:

◆ ulTaskNotifyValueClearIndexed()

uint32_t ulTaskNotifyValueClearIndexed ( TaskHandle_t xTask,
UBaseType_t uxIndexToClear,
uint32_t ulBitsToClear )

Indexed variant of ulTaskNotifyValueClear.

Parameters
xTaskHandle of the task. NULL selects the calling task.
uxIndexToClearNotification slot index.
ulBitsToClearBitmask of bits to clear.
Returns
Notification value before the clear, or 0 on bad handle / index.
Note
ISR-safe.

Definition at line 3594 of file freertos_stk.cpp.

3597{
3598 FrtosTask *t = ResolveNotifyTarget(xTask, uxIndexToClear);
3599 if (t == nullptr)
3600 return 0U;
3601
3602 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToClear];
3603
3605
3606 const uint32_t prev = slot.value;
3607 slot.value &= ~ulBitsToClear;
3608
3609 return prev;
3610}

References FrtosTask::m_notify, ResolveNotifyTarget(), and FrtosTask::NotifySlot::value.

Referenced by ulTaskNotifyValueClear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uxQueueMessagesWaiting()

UBaseType_t uxQueueMessagesWaiting ( QueueHandle_t xQueue)

Return the number of items currently in the queue.

Definition at line 1796 of file freertos_stk.cpp.

1797{
1798 if (xQueue == nullptr)
1799 return 0U;
1800
1801 return static_cast<UBaseType_t>(
1802 static_cast<FrtosQueue *>(xQueue)->m_mq.GetCount());
1803}
unsigned long UBaseType_t
Definition FreeRTOS.h:258
size_t GetCount() const
Get the current number of messages in the queue.
stk::sync::MessageQueue m_mq

References stk::sync::MessageQueue::GetCount(), and FrtosQueue::m_mq.

Here is the call graph for this function:

◆ uxQueueMessagesWaitingFromISR()

UBaseType_t uxQueueMessagesWaitingFromISR ( QueueHandle_t xQueue)

Return the number of items currently in the queue from ISR context.

Note
ISR-safe on targets where a size_t-aligned read is atomic.
Returns
Point-in-time snapshot of the message count.

Definition at line 1805 of file freertos_stk.cpp.

1806{
1807 // GetCount() is ISR-safe on targets where a size_t-aligned read is atomic
1808 // (per the STK MessageQueue documentation).
1809 if (xQueue == nullptr)
1810 return 0U;
1811
1812 return static_cast<UBaseType_t>(static_cast<FrtosQueue *>(xQueue)->m_mq.GetCount());
1813}

References stk::sync::MessageQueue::GetCount(), and FrtosQueue::m_mq.

Here is the call graph for this function:

◆ uxQueueSpacesAvailable()

UBaseType_t uxQueueSpacesAvailable ( QueueHandle_t xQueue)

Return the number of free slots in the queue.

Definition at line 1815 of file freertos_stk.cpp.

1816{
1817 if (xQueue == nullptr)
1818 return 0U;
1819
1820 return static_cast<UBaseType_t>(
1821 static_cast<FrtosQueue *>(xQueue)->m_mq.GetSpace());
1822}
size_t GetSpace() const
Get the number of free slots currently available.

References stk::sync::MessageQueue::GetSpace(), and FrtosQueue::m_mq.

Here is the call graph for this function:

◆ uxSemaphoreGetCount()

UBaseType_t uxSemaphoreGetCount ( SemaphoreHandle_t xSemaphore)

Return the current count of a counting semaphore, or 1/0 for a mutex (1 = unlocked, 0 = locked).

Definition at line 2500 of file freertos_stk.cpp.

2501{
2502 if (xSemaphore == nullptr)
2503 return 0U;
2504
2505 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2506
2507 if (s->m_kind == SemKind::Counting)
2508 return static_cast<UBaseType_t>(s->m_sem->GetCount());
2509
2510#if configUSE_MUTEXES
2511 // For a mutex, count = 0 means locked, 1 means unlocked.
2512 return (s->m_mtx->GetOwner() == stk::TID_NONE) ? 1U : 0U;
2513#else
2514 return 0U;
2515#endif
2516}
@ Counting
Binary or counting semaphore (backed by stk::sync::Semaphore).
static constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Definition stk_common.h:177
TId GetOwner() const
Get owner of the mutex.
uint16_t GetCount() const
Get current counter value.
stk::sync::Mutex * m_mtx
stk::sync::Semaphore * m_sem

References Counting, stk::sync::Semaphore::GetCount(), stk::sync::Mutex::GetOwner(), FrtosSemaphore::m_kind, FrtosSemaphore::m_mtx, FrtosSemaphore::m_sem, and stk::TID_NONE.

Here is the call graph for this function:

◆ uxTaskGetNumberOfTasks()

UBaseType_t uxTaskGetNumberOfTasks ( void )

Return the number of tasks currently under kernel management.

Definition at line 1082 of file freertos_stk.cpp.

1083{
1085 return static_cast<UBaseType_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
1086}
static StkKernel g_StkKernel

References g_StkKernel.

◆ uxTaskGetStackHighWaterMark()

UBaseType_t uxTaskGetStackHighWaterMark ( TaskHandle_t xTask)

Return the unused stack depth high-water mark in Words. Pass NULL for the calling task.

Definition at line 1384 of file freertos_stk.cpp.

1385{
1386 const FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<const FrtosTask *>(
1387 static_cast<uintptr_t>(stk::GetTid())) : static_cast<const FrtosTask *>(xTask);
1388
1389 if (t == nullptr)
1390 return 0U;
1391
1392 return static_cast<UBaseType_t>(t->GetStackHighWaterMark());
1393}
size_t GetStackHighWaterMark() const

References FrtosTask::GetStackHighWaterMark(), and stk::GetTid().

Here is the call graph for this function:

◆ uxTaskGetStackHighWaterMark2()

StackType_t uxTaskGetStackHighWaterMark2 ( TaskHandle_t xTask)

Return the unused stack depth high-water mark in Words. Pass NULL for the calling task.

< Stack depth word type.

< Stack depth word type.

Definition at line 1395 of file freertos_stk.cpp.

1396{
1397 const FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<const FrtosTask *>(
1398 static_cast<uintptr_t>(stk::GetTid())) : static_cast<const FrtosTask *>(xTask);
1399
1400 if (t == nullptr)
1401 return 0U;
1402
1403 return static_cast<configSTACK_DEPTH_TYPE>(t->GetStackHighWaterMark());
1404}
#define configSTACK_DEPTH_TYPE
Definition FreeRTOS.h:271

References configSTACK_DEPTH_TYPE, FrtosTask::GetStackHighWaterMark(), and stk::GetTid().

Here is the call graph for this function:

◆ uxTaskGetSystemState()

UBaseType_t uxTaskGetSystemState ( TaskStatus_t * pxTaskStatusArray,
UBaseType_t uxArraySize,
uint32_t * pulTotalRunTime )

Populate an array of TaskStatus_t with a snapshot of every task's state.

Parameters
pxTaskStatusArrayCaller-supplied array of at least uxArraySize elements.
uxArraySizeCapacity of pxTaskStatusArray (should be >= uxTaskGetNumberOfTasks()).
pulTotalRunTimeReceives 0 (STK has no global run-time counter). May be NULL.
Returns
Number of TaskStatus_t entries written. May be less than uxTaskGetNumberOfTasks() if pxTaskStatusArray was too small.

< Stack depth word type.

Definition at line 1406 of file freertos_stk.cpp.

1409{
1410 // STK has no global CPU run-time accumulator; report 0 per the FreeRTOS
1411 // convention for targets that do not implement run-time statistics.
1412 if (pulTotalRunTime != nullptr)
1413 *pulTotalRunTime = 0U;
1414
1415 if ((pxTaskStatusArray == nullptr) || (uxArraySize == 0U))
1416 return 0U;
1417
1418 UBaseType_t filled = 0U;
1419
1420 // Identify the currently running task once, outside the enumeration
1421 // loop, so the eRunning check is consistent across all entries.
1422 const uintptr_t running_tid = static_cast<uintptr_t>(stk::GetTid());
1423
1424 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *itask) -> bool
1425 {
1426 if (filled >= uxArraySize)
1427 return false; // array full — stop enumeration
1428
1429 const FrtosTask *t = static_cast<const FrtosTask *>(itask);
1430 TaskStatus_t &s = pxTaskStatusArray[filled];
1431
1432 // xHandle — the FrtosTask pointer cast to an opaque handle.
1433 s.xHandle = static_cast<TaskHandle_t>(const_cast<FrtosTask *>(t));
1434
1435 // pcTaskName — direct pointer into the task's name buffer (not a copy).
1436 s.pcTaskName = (t->m_name != nullptr) ? t->m_name : "";
1437
1438 // eCurrentState — mirrors eTaskGetState() logic.
1441 else
1444 else
1445 if (reinterpret_cast<uintptr_t>(t) == running_tid)
1447 else
1449
1450 // uxCurrentPriority / uxBasePriority — same value: STK has no
1451 // priority inheritance so the current and base priority are identical.
1454
1455 // ulRunTimeCounter — always 0 (STK has no per-task CPU accounting).
1456 s.ulRunTimeCounter = 0U;
1457
1458 // pxStackBase — bottom of the stack array (index 0).
1459 s.pxStackBase = reinterpret_cast<StackType_t *>(t->m_stack);
1460
1461 // usStackHighWaterMark — minimum observed free Words (watermark scan).
1464
1465 // xTaskNumber — monotonic serial assigned at construction.
1467
1468 ++filled;
1469 return true; // continue enumeration
1470 });
1471
1472 return filled;
1473}
static UBaseType_t StkWeightToFrtosPrio(int32_t w)
#define FREERTOS_STK_MAX_TASKS
Maximum number of concurrent tasks managed by the kernel. Increase if your application creates more t...
Definition FreeRTOS.h:208
uintptr_t StackType_t
Definition FreeRTOS.h:260
void * TaskHandle_t
Definition FreeRTOS.h:310
Interface for a user task.
Definition stk_common.h:589
StackType_t * pxStackBase
Definition FreeRTOS.h:371
uint32_t xTaskNumber
Definition FreeRTOS.h:373
eTaskState eCurrentState
Definition FreeRTOS.h:367
TaskHandle_t xHandle
Definition FreeRTOS.h:365
StackType_t usStackHighWaterMark
Definition FreeRTOS.h:372
UBaseType_t uxBasePriority
Definition FreeRTOS.h:369
UBaseType_t uxCurrentPriority
Definition FreeRTOS.h:368
uint32_t ulRunTimeCounter
Definition FreeRTOS.h:370
const char * pcTaskName
Definition FreeRTOS.h:366
const char * m_name
uint32_t m_task_number
volatile int32_t m_weight
stk::Word * m_stack

References configSTACK_DEPTH_TYPE, FrtosTask::Deleted, TaskStatus_t::eCurrentState, eDeleted, eReady, eRunning, eSuspended, FREERTOS_STK_MAX_TASKS, g_StkKernel, FrtosTask::GetStackHighWaterMark(), stk::GetTid(), FrtosTask::m_name, FrtosTask::m_stack, FrtosTask::m_state, FrtosTask::m_task_number, FrtosTask::m_weight, TaskStatus_t::pcTaskName, TaskStatus_t::pxStackBase, StkWeightToFrtosPrio(), FrtosTask::Suspended, TaskStatus_t::ulRunTimeCounter, TaskStatus_t::usStackHighWaterMark, TaskStatus_t::uxBasePriority, TaskStatus_t::uxCurrentPriority, TaskStatus_t::xHandle, and TaskStatus_t::xTaskNumber.

Here is the call graph for this function:

◆ uxTaskPriorityGet()

UBaseType_t uxTaskPriorityGet ( TaskHandle_t xTask)

Query the priority of a task. Pass NULL xTask for the calling task.

Definition at line 1310 of file freertos_stk.cpp.

1311{
1312 const FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<const FrtosTask *>(
1313 static_cast<uintptr_t>(stk::GetTid())) : static_cast<const FrtosTask *>(xTask);
1314
1315 if (t == nullptr)
1316 return 0U;
1317
1318 return StkWeightToFrtosPrio(t->m_weight);
1319}

References stk::GetTid(), FrtosTask::m_weight, and StkWeightToFrtosPrio().

Referenced by uxTaskPriorityGetFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ uxTaskPriorityGetFromISR()

UBaseType_t uxTaskPriorityGetFromISR ( TaskHandle_t xTask)

Query the priority of a task from ISR context (ISR-safe).

Definition at line 1321 of file freertos_stk.cpp.

1322{
1323 return uxTaskPriorityGet(xTask); // same implementation; GetTid() is ISR-safe
1324}
UBaseType_t uxTaskPriorityGet(TaskHandle_t xTask)
Query the priority of a task. Pass NULL xTask for the calling task.

References uxTaskPriorityGet().

Here is the call graph for this function:

◆ vEventGroupDelete()

void vEventGroupDelete ( EventGroupHandle_t xEventGroup)

Delete an event group and free its memory.

Definition at line 2992 of file freertos_stk.cpp.

2993{
2994 if (xEventGroup == nullptr)
2995 return;
2996
2997 ObjFree(static_cast<FrtosEventGroup *>(xEventGroup));
2998}
static void ObjFree(T *obj)

References ObjFree().

Here is the call graph for this function:

◆ vMessageBufferDelete()

void vMessageBufferDelete ( MessageBufferHandle_t xMessageBuffer)

Delete a message buffer and free heap resources (if dynamically allocated).

Definition at line 4206 of file freertos_stk.cpp.

4207{
4208 if (xMessageBuffer == nullptr)
4209 return;
4210
4211 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4212
4213 ObjFree(mb);
4214}

References ObjFree().

Here is the call graph for this function:

◆ vPortEnterCritical()

void vPortEnterCritical ( void )

Definition at line 351 of file freertos_stk.cpp.

352{
354}
static void Enter()
Enter a critical section.

References stk::hw::CriticalSection::Enter().

Here is the call graph for this function:

◆ vPortExitCritical()

void vPortExitCritical ( void )

Definition at line 356 of file freertos_stk.cpp.

357{
359}
static void Exit()
Exit a critical section.

References stk::hw::CriticalSection::Exit().

Here is the call graph for this function:

◆ vPortFree()

void vPortFree ( void * pv)

Free a block previously returned by pvPortMalloc().

Parameters
pvPointer to the block to free. NULL is a no-op.
Note
Thread-safe if the underlying MemoryAllocator::Free is.

Definition at line 189 of file freertos_stk.cpp.

190{
192}
static void Free(void *ptr) __stk_weak
Free the memory chunk.

References __stk_weak, and stk::memory::MemoryAllocator::Free().

Referenced by ObjFree(), ObjFreeArray(), and ObjFreeRaw().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ vPortGetHeapStats()

void vPortGetHeapStats ( HeapStats_t * pxHeapStats)

Fill pxHeapStats with a snapshot of the heap statistics.

Fields that require traversal of the internal free-block list are reported conservatively (see HeapStats_t documentation); all other fields are exact.

Parameters
pxHeapStatsPointer to the HeapStats_t structure to fill. NULL is silently ignored.

Definition at line 233 of file freertos_stk.cpp.

234{
235 if (pxHeapStats == nullptr)
236 return;
237
239 const size_t free_now = snap.GetAvailable();
240
241 (*pxHeapStats) = {};
242
243 // Fields derived directly from s_MemStats accounting.
244 pxHeapStats->xAvailableHeapSpaceInBytes = free_now;
247 pxHeapStats->xNumberOfSuccessfulFrees = snap.free_count;
248
249 // Fields that require free-block-list traversal are unavailable without a
250 // block-list allocator (we delegate to malloc). Report conservative values:
251 // - largest free block : current free bytes (treat heap as one region)
252 // - smallest free block : 0 (unknown subdivision)
253 // - number of free blocks: 1 (at least one region exists while free > 0)
254 pxHeapStats->xSizeOfLargestFreeBlockInBytes = free_now;
255 pxHeapStats->xSizeOfSmallestFreeBlockInBytes = (free_now > 0U) ? 1U : 0U;
256 pxHeapStats->xNumberOfFreeBlocks = (free_now > 0U) ? 1U : 0U;
257}
static stk::memory::MemoryAllocator::Stats s_MemStats(10240U)
Snapshot of the memory allocator's statistics.
volatile size_t allocate_count
Number of succesful allocations with Allocate().
size_t GetAvailable() const
Get number of bytes currently available for allocation.
volatile size_t free_count
Number of succesful frees with Free().
volatile size_t min_ever_free
Minimum free bytes recorded since system start (watermark).
size_t xSizeOfSmallestFreeBlockInBytes
Definition FreeRTOS.h:1979
size_t xMinimumEverFreeBytesRemaining
Definition FreeRTOS.h:1981
size_t xNumberOfSuccessfulAllocations
Definition FreeRTOS.h:1982
size_t xSizeOfLargestFreeBlockInBytes
Definition FreeRTOS.h:1978
size_t xNumberOfFreeBlocks
Definition FreeRTOS.h:1980
size_t xNumberOfSuccessfulFrees
Definition FreeRTOS.h:1983
size_t xAvailableHeapSpaceInBytes
Definition FreeRTOS.h:1977

References stk::memory::MemoryAllocator::Stats::allocate_count, stk::memory::MemoryAllocator::Stats::free_count, stk::memory::MemoryAllocator::Stats::GetAvailable(), stk::memory::MemoryAllocator::Stats::min_ever_free, s_MemStats, HeapStats_t::xAvailableHeapSpaceInBytes, HeapStats_t::xMinimumEverFreeBytesRemaining, HeapStats_t::xNumberOfFreeBlocks, HeapStats_t::xNumberOfSuccessfulAllocations, HeapStats_t::xNumberOfSuccessfulFrees, HeapStats_t::xSizeOfLargestFreeBlockInBytes, and HeapStats_t::xSizeOfSmallestFreeBlockInBytes.

Here is the call graph for this function:

◆ vQueueDelete()

void vQueueDelete ( QueueHandle_t xQueue)

Delete a queue and free all associated memory.

Definition at line 1700 of file freertos_stk.cpp.

1701{
1702 if (xQueue == nullptr)
1703 return;
1704
1705 ObjFree(static_cast<FrtosQueue *>(xQueue));
1706}

References ObjFree().

Here is the call graph for this function:

◆ vSemaphoreDelete()

void vSemaphoreDelete ( SemaphoreHandle_t xSemaphore)

Delete a semaphore or mutex and free its memory.

Definition at line 2380 of file freertos_stk.cpp.

2381{
2382 if (xSemaphore == nullptr)
2383 return;
2384
2385 ObjFree(static_cast<FrtosSemaphore *>(xSemaphore));
2386}

References ObjFree().

Here is the call graph for this function:

◆ vStreamBufferDelete()

void vStreamBufferDelete ( StreamBufferHandle_t xStreamBuffer)

Delete a stream buffer and free heap resources (if dynamically allocated).

Definition at line 3754 of file freertos_stk.cpp.

3755{
3756 if (xStreamBuffer == nullptr)
3757 return;
3758
3759 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3760
3761 ObjFree(sb);
3762}

References ObjFree().

Here is the call graph for this function:

◆ vTaskDelay()

void vTaskDelay ( TickType_t xTicksToDelay)

Block the calling task for a number of ticks.

Definition at line 1273 of file freertos_stk.cpp.

1274{
1275 if (IsIrqContext())
1276 return;
1277
1278 stk::Sleep(FrtosTimeoutToStk(xTicksToDelay));
1279}
void Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:341

References FrtosTimeoutToStk(), IsIrqContext(), and stk::Sleep().

Here is the call graph for this function:

◆ vTaskDelayUntil()

void vTaskDelayUntil ( TickType_t * pxPreviousWakeTime,
TickType_t xTimeIncrement )

Block until an absolute tick deadline for drift-free periodic loops. Updates *pxPreviousWakeTime on each call.

Definition at line 1281 of file freertos_stk.cpp.

1282{
1283 static_cast<void>(xTaskDelayUntil(pxPreviousWakeTime, xTimeIncrement));
1284}
BaseType_t xTaskDelayUntil(TickType_t *pxPreviousWakeTime, TickType_t xTimeIncrement)

References xTaskDelayUntil().

Here is the call graph for this function:

◆ vTaskDelete()

void vTaskDelete ( TaskHandle_t xTaskToDelete)

Delete a task. Pass NULL to delete the calling task.

Definition at line 1191 of file freertos_stk.cpp.

1192{
1193 FrtosTask *t = (xTaskToDelete == nullptr) ? static_cast<FrtosTask *>(
1194 reinterpret_cast<FrtosTask *>(static_cast<uintptr_t>(stk::GetTid()))) :
1195 static_cast<FrtosTask *>(xTaskToDelete);
1196
1197 if (t == nullptr)
1198 return;
1199
1201
1202 g_StkKernel.ScheduleTaskRemoval(t);
1203
1204 // Detached tasks are freed when the slot is released.
1205 // For this wrapper, all tasks are considered detached (no join semantics).
1206 ObjFree(t);
1207}

References g_StkKernel, stk::GetTid(), and ObjFree().

Here is the call graph for this function:

◆ vTaskEndScheduler()

void vTaskEndScheduler ( void )

End scheduling (KERNEL_DYNAMIC only). Included for API completeness.

Definition at line 1050 of file freertos_stk.cpp.

1051{
1052 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *task) -> bool
1053 {
1054 g_StkKernel.ScheduleTaskRemoval(task);
1055 return true;
1056 });
1057
1058 stk::Yield();
1059}

References FREERTOS_STK_MAX_TASKS, g_StkKernel, and stk::Yield().

Here is the call graph for this function:

◆ vTaskGetRunTimeStats()

void vTaskGetRunTimeStats ( char * pcWriteBuffer)

Write a human-readable CPU run-time statistics table into pcWriteBuffer.

Each row contains: task name, absolute run-time counter, and percentage of total run time. Column layout matches the standard FreeRTOS vTaskGetRunTimeStats() output so existing log parsers work unchanged.

Note
STK has no per-task CPU run-time accumulator. This wrapper always emits 0 for both the absolute counter and the percentage, matching the FreeRTOS convention for targets where configGENERATE_RUN_TIME_STATS is not enabled. The function is provided for link compatibility; applications that need real CPU accounting must instrument the target with a free-running hardware counter and replace the two MemoryAllocator definitions in freertos_stk.cpp with the appropriate port-layer calls.
Parameters
pcWriteBufferCaller-allocated destination buffer. A safe minimum is uxTaskGetNumberOfTasks() * 40 bytes.

Definition at line 1601 of file freertos_stk.cpp.

1602{
1603 if (pcWriteBuffer == nullptr)
1604 return;
1605
1606 // Column header matching FreeRTOS vTaskGetRunTimeStats() output format so
1607 // that existing log parsers (SystemView, Tracealyzer, custom scripts) find
1608 // the layout they expect.
1609 int off = snprintf(pcWriteBuffer, 64U,
1610 "%-12s %12s %8s\r\n",
1611 "Task", "Abs Time", "% Time");
1612
1613 if (off < 0) off = 0;
1614 char *p = pcWriteBuffer + off;
1615
1616 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *itask) -> bool
1617 {
1618 const FrtosTask *t = static_cast<const FrtosTask *>(itask);
1619 const char *name = (t->m_name != nullptr) ? t->m_name : "(unnamed)";
1620
1621 // ulRunTimeCounter is always 0: STK has no per-task CPU accounting.
1622 // Percentage is therefore also 0. Emit "<1%" only when a non-zero
1623 // total is available; here total is always 0 so we emit "0%".
1624 int n = snprintf(p, 48U, "%-12s %12lu %7lu%%\r\n",
1625 name,
1626 0UL, // ulRunTimeCounter
1627 0UL); // percentage
1628 if (n > 0) p += n;
1629
1630 return true; // continue enumeration
1631 });
1632
1633 *p = '\0'; // null-terminate
1634}

References FREERTOS_STK_MAX_TASKS, g_StkKernel, and FrtosTask::m_name.

◆ vTaskList()

void vTaskList ( char * pcWriteBuffer)

Write a human-readable task-status table into pcWriteBuffer.

Each row contains: name, state letter (X/R/B/S/D), priority, stack high-water mark (Words), and a 1-based task number. Column widths match the standard FreeRTOS vTaskList() output so that existing tools and log parsers work without modification.

Parameters
pcWriteBufferCaller-allocated destination buffer. Must be large enough for all active tasks. A safe minimum is uxTaskGetNumberOfTasks() * 40 bytes.
Note
The output is a snapshot; it is not thread-safe with respect to concurrent task creation or deletion.

Definition at line 1530 of file freertos_stk.cpp.

1531{
1532 if (pcWriteBuffer == nullptr)
1533 return;
1534
1535 // Write the column header that FreeRTOS vTaskList() produces, so that
1536 // existing log parsers find what they expect.
1537 int off = snprintf(pcWriteBuffer, 64U,
1538 "%-12s %c %4s %6s %4s\r\n",
1539 "Name", 'S', "Prio", "Stack", "Num");
1540
1541 if (off < 0) off = 0;
1542 char *p = pcWriteBuffer + off;
1543
1544 // Enumerate all tasks and fill one row per task.
1545 UBaseType_t task_num = 0U;
1546
1547 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *itask) -> bool
1548 {
1549 ++task_num;
1550 FrtosTask *t = static_cast<FrtosTask *>(itask);
1551
1552 // Determine state letter, matching FreeRTOS convention:
1553 // X = Running, R = Ready, B = Blocked, S = Suspended, D = Deleted
1554 char state_letter;
1556 state_letter = 'D';
1557 else
1559 state_letter = 'S';
1560 else
1561 if (static_cast<uintptr_t>(stk::GetTid()) == reinterpret_cast<uintptr_t>(t))
1562 state_letter = 'X';
1563 else
1564 state_letter = 'R';
1565
1566 const char *name = (t->m_name != nullptr) ? t->m_name : "(unnamed)";
1568 size_t hwm = t->GetStackHighWaterMark();
1569
1570 int n = snprintf(p, 48U, "%-12s %c %4u %6u %4u\r\n",
1571 name, state_letter,
1572 static_cast<unsigned>(prio),
1573 static_cast<unsigned>(hwm),
1574 static_cast<unsigned>(task_num));
1575 if (n > 0) p += n;
1576
1577 return true; // continue enumeration
1578 });
1579
1580 *p = '\0'; // null-terminate
1581}

References FrtosTask::Deleted, FREERTOS_STK_MAX_TASKS, g_StkKernel, FrtosTask::GetStackHighWaterMark(), stk::GetTid(), FrtosTask::m_name, FrtosTask::m_state, FrtosTask::m_weight, StkWeightToFrtosPrio(), and FrtosTask::Suspended.

Here is the call graph for this function:

◆ vTaskPrioritySet()

void vTaskPrioritySet ( TaskHandle_t xTask,
UBaseType_t uxNewPriority )

Change the priority of a task. Pass NULL xTask for the calling task.

Definition at line 1299 of file freertos_stk.cpp.

1300{
1301 FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<FrtosTask *>(
1302 static_cast<uintptr_t>(stk::GetTid())) : static_cast<FrtosTask *>(xTask);
1303
1304 if (t == nullptr)
1305 return;
1306
1307 t->m_weight = FrtosPrioToStkWeight(uxNewPriority);
1308}
static int32_t FrtosPrioToStkWeight(UBaseType_t p)

References FrtosPrioToStkWeight(), stk::GetTid(), and FrtosTask::m_weight.

Here is the call graph for this function:

◆ vTaskResume()

void vTaskResume ( TaskHandle_t xTaskToResume)

Resume a previously suspended task.

Definition at line 1223 of file freertos_stk.cpp.

1224{
1225 if (xTaskToResume == nullptr)
1226 return;
1227
1228 FrtosTask *t = static_cast<FrtosTask *>(xTaskToResume);
1229
1231
1233 return;
1234
1235 g_StkKernel.ResumeTask(t);
1237}

References g_StkKernel, FrtosTask::m_state, FrtosTask::Ready, and FrtosTask::Suspended.

◆ vTaskSetThreadLocalStoragePointer()

void vTaskSetThreadLocalStoragePointer ( TaskHandle_t xTaskToSet,
BaseType_t xIndex,
void * pvValue )

Write a TLS pointer slot for a task.

Parameters
xTaskToSetTask handle, or NULL for the calling task.
xIndexSlot index (0 .. configNUM_THREAD_LOCAL_STORAGE_POINTERS-1).
pvValueValue to store.

< Per-task TLS pointer slots.

Definition at line 3640 of file freertos_stk.cpp.

3643{
3644 if (xIndex < 0 || static_cast<size_t>(xIndex) >= configNUM_THREAD_LOCAL_STORAGE_POINTERS)
3645 return;
3646
3647 // Resolve NULL -> calling task.
3648 if (xTaskToSet == nullptr)
3649 xTaskToSet = xTaskGetCurrentTaskHandle();
3650
3651 if (xTaskToSet == nullptr)
3652 return;
3653
3654 FrtosTask *t = static_cast<FrtosTask *>(xTaskToSet);
3655
3656 // A critical section is not strictly required for a pointer-sized store on
3657 // aligned memory on single-issue cores, but we guard anyway for strict
3658 // correctness on SMP targets (RP2040, dual-core Cortex-M33).
3660 t->m_tls[static_cast<size_t>(xIndex)] = pvValue;
3661}

References configNUM_THREAD_LOCAL_STORAGE_POINTERS, FrtosTask::m_tls, and xTaskGetCurrentTaskHandle().

Here is the call graph for this function:

◆ vTaskStartScheduler()

void vTaskStartScheduler ( void )

Initialise STK and start the scheduler. Does not return for KERNEL_DYNAMIC until all tasks have exited.

Definition at line 1043 of file freertos_stk.cpp.

1044{
1046
1047 g_StkKernel.Start(); // does not return for KERNEL_DYNAMIC until all tasks exit
1048}
static void EnsureKernelInitialized()

References EnsureKernelInitialized(), and g_StkKernel.

Here is the call graph for this function:

◆ vTaskSuspend()

void vTaskSuspend ( TaskHandle_t xTaskToSuspend)

Suspend a task indefinitely. Pass NULL to suspend the calling task.

Definition at line 1209 of file freertos_stk.cpp.

1210{
1211 FrtosTask *t = (xTaskToSuspend == nullptr) ? static_cast<FrtosTask *>(
1212 reinterpret_cast<FrtosTask *>(static_cast<uintptr_t>(stk::GetTid()))) :
1213 static_cast<FrtosTask *>(xTaskToSuspend);
1214
1215 if (t == nullptr)
1216 return;
1217
1218 bool already = false;
1219 g_StkKernel.SuspendTask(t, already);
1221}

References g_StkKernel, stk::GetTid(), FrtosTask::m_state, and FrtosTask::Suspended.

Here is the call graph for this function:

◆ vTaskSuspendAll()

void vTaskSuspendAll ( void )

Suspend the scheduler (disables preemption; interrupts remain enabled).

Definition at line 1061 of file freertos_stk.cpp.

1062{
1064}

References stk::hw::CriticalSection::Enter().

Here is the call graph for this function:

◆ vTimerSetTimerID()

void vTimerSetTimerID ( TimerHandle_t xTimer,
void * pvNewID )

Set the application-defined ID stored in a timer.

Definition at line 2891 of file freertos_stk.cpp.

2892{
2893 if (xTimer == nullptr)
2894 return;
2895
2896 static_cast<FrtosTimer *>(xTimer)->m_timer_id = pvNewID;
2897}

◆ xEventGroupClearBits()

EventBits_t xEventGroupClearBits ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToClear )

Clear one or more bits in an event group (ISR-safe).

Returns
Value of the bits BEFORE clearing.

Definition at line 3010 of file freertos_stk.cpp.

3012{
3013 if (xEventGroup == nullptr)
3014 return 0U;
3015
3016 // STK Clear() returns the value BEFORE clearing - matches FreeRTOS contract.
3017 uint32_t prev = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Clear(uxBitsToClear);
3018 return StkFlagsToFrtos(prev);
3019}
static EventBits_t StkFlagsToFrtos(uint32_t result, EventBits_t snapshot=0U)

References StkFlagsToFrtos().

Here is the call graph for this function:

◆ xEventGroupClearBitsFromISR()

EventBits_t xEventGroupClearBitsFromISR ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToClear )

Clear event group bits from ISR context.

Returns
Value of the bits BEFORE clearing.

Definition at line 3068 of file freertos_stk.cpp.

3070{
3071 if (xEventGroup == nullptr)
3072 return 0U;
3073
3074 uint32_t prev = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Clear(
3075 static_cast<uint32_t>(uxBitsToClear));
3076 return StkFlagsToFrtos(prev);
3077}

References StkFlagsToFrtos().

Here is the call graph for this function:

◆ xEventGroupCreate()

EventGroupHandle_t xEventGroupCreate ( void )

Create an event group (all bits initialised to 0).

Returns
Event group handle, or NULL on failure.

Definition at line 2965 of file freertos_stk.cpp.

2966{
2967 if (IsIrqContext())
2968 return nullptr;
2969
2971 return static_cast<EventGroupHandle_t>(eg);
2972}
static T * ObjAlloc(Args &&...args)
void * EventGroupHandle_t
Definition FreeRTOS.h:314

References IsIrqContext(), and ObjAlloc().

Here is the call graph for this function:

◆ xEventGroupCreateStatic()

EventGroupHandle_t xEventGroupCreateStatic ( StaticEventGroup_t * pxEventGroupBuffer)

Create an event group using caller-supplied storage — no heap allocation.

Parameters
pxEventGroupBufferCaller-allocated control block (StaticEventGroup_t). Must remain valid for the lifetime of the event group.
Returns
Event group handle. Never NULL if pxEventGroupBuffer is non-NULL.

Definition at line 2974 of file freertos_stk.cpp.

2975{
2976 if (pxEventGroupBuffer == nullptr)
2977 return nullptr;
2978
2979 if (IsIrqContext())
2980 return nullptr;
2981
2982 static_assert(sizeof(StaticEventGroup_t) >= sizeof(FrtosEventGroup),
2983 "StaticEventGroup_t is too small to hold FrtosEventGroup. "
2984 "Increase STATIC_EVENT_GROUP_TCB_SIZE_WORDS in freertos_stk.h.");
2985
2986 FrtosEventGroup *eg = new (pxEventGroupBuffer) FrtosEventGroup();
2987 eg->m_cb_owned = false; // caller owns the memory; vEventGroupDelete must not delete it
2988
2989 return static_cast<EventGroupHandle_t>(eg);
2990}

References IsIrqContext(), and FrtosEventGroup::m_cb_owned.

Here is the call graph for this function:

◆ xEventGroupGetBits()

EventBits_t xEventGroupGetBits ( EventGroupHandle_t xEventGroup)

Return the current event group bits without blocking or modifying them.

Definition at line 3021 of file freertos_stk.cpp.

3022{
3023 if (xEventGroup == nullptr)
3024 return 0U;
3025
3026 return static_cast<EventBits_t>(static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Get());
3027}
uint32_t EventBits_t
Definition FreeRTOS.h:380
uint32_t Get() const
Read the current flags word without modifying it.
stk::sync::EventFlags m_ef

References stk::sync::EventFlags::Get(), and FrtosEventGroup::m_ef.

Here is the call graph for this function:

◆ xEventGroupSetBits()

EventBits_t xEventGroupSetBits ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToSet )

Set one or more bits in an event group (ISR-safe).

Returns
Value of the event group bits after the set operation.

Definition at line 3000 of file freertos_stk.cpp.

3002{
3003 if (xEventGroup == nullptr)
3004 return 0U;
3005
3006 uint32_t result = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Set(uxBitsToSet);
3007 return StkFlagsToFrtos(result);
3008}

References StkFlagsToFrtos().

Here is the call graph for this function:

◆ xEventGroupSetBitsFromISR()

BaseType_t xEventGroupSetBitsFromISR ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToSet,
BaseType_t * pxHigherPriorityTaskWoken )

Set event group bits from ISR context.

Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdPASS on success, pdFAIL on invalid bits argument.

Definition at line 3052 of file freertos_stk.cpp.

3055{
3056 if (xEventGroup == nullptr)
3057 return pdFAIL;
3058
3059 uint32_t result = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Set(
3060 static_cast<uint32_t>(uxBitsToSet));
3061
3062 if (pxHigherPriorityTaskWoken != nullptr)
3063 *pxHigherPriorityTaskWoken = pdFALSE;
3064
3065 return stk::sync::EventFlags::IsError(result) ? pdFAIL : pdPASS;
3066}
#define pdPASS
Definition FreeRTOS.h:265
#define pdFAIL
Definition FreeRTOS.h:266
#define pdFALSE
Definition FreeRTOS.h:264
static bool IsError(uint32_t result)
Checks if a return value from Set(), Clear(), or Wait() is an error.

References stk::sync::EventFlags::IsError(), pdFAIL, pdFALSE, and pdPASS.

Here is the call graph for this function:

◆ xEventGroupSync()

EventBits_t xEventGroupSync ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToSet,
EventBits_t uxBitsToWaitFor,
TickType_t xTicksToWait )

Task rendezvous / barrier synchronization using an event group.

Atomically sets uxBitsToSet in the event group, then blocks until uxBitsToWaitFor are all set (AND semantics). On success, all bits in uxBitsToWaitFor are atomically cleared before returning.

Note
This is the standard FreeRTOS "event group sync" / barrier primitive. All N participating tasks call xEventGroupSync() with the same uxBitsToWaitFor mask and non-overlapping individual uxBitsToSet masks (one bit per task). The call returns only after every task has set its bit.
The set and the wait are performed without releasing the CPU between them, so no participating task can observe a state in which this task has not yet entered the wait. This matches the FreeRTOS reference implementation guarantee.
Parameters
xEventGroupEvent group handle (must not be NULL).
uxBitsToSetBit(s) this task sets to signal it has reached the sync point (must be a subset of uxBitsToWaitFor).
uxBitsToWaitForBitmask of ALL bits that must be set before any participating task is released (AND semantics).
xTicksToWaitMaximum ticks to wait. portMAX_DELAY = wait forever. NO_WAIT (0) performs a non-blocking test.
Returns
Value of the event group bits at the point the condition was met (before the bits were cleared), or 0 if the timeout expired before all bits were set.
Warning
ISR-unsafe (blocking). Not callable from an ISR context.

Definition at line 3125 of file freertos_stk.cpp.

3129{
3130 // Contract checks that mirror the FreeRTOS reference implementation.
3131 if (xEventGroup == nullptr) return 0U;
3132 if (uxBitsToWaitFor == 0U) return 0U;
3133 if (IsIrqContext()) return 0U; // blocking wait is ISR-unsafe
3134
3135 FrtosEventGroup *eg = static_cast<FrtosEventGroup *>(xEventGroup);
3136 stk::sync::EventFlags &ef = eg->m_ef;
3137
3138 // Step 1: Set this task's rendezvous bit(s).
3139 //
3140 // uxBitsToSet == 0 is legal (observer role: task waits without contributing
3141 // a bit). Only call Set() when there is actually something to set.
3142 if (uxBitsToSet != 0U)
3143 {
3144 uint32_t set_result = ef.Set(static_cast<uint32_t>(uxBitsToSet));
3145
3146 // Treat an ERROR_PARAMETER return as a hard usage fault — the caller
3147 // violated the API (e.g. set bit 31).
3149
3150 if (stk::sync::EventFlags::IsError(set_result))
3151 return 0U;
3152 }
3153
3154 // Step 2 + 3: Wait for ALL bits in uxBitsToWaitFor, clear them on success.
3155 //
3156 // OPT_WAIT_ALL — AND semantics: all bits must be set simultaneously.
3157 // OPT_NO_CLEAR is NOT passed — matched bits are cleared atomically inside
3158 // Wait() when the predicate is first satisfied, exactly matching the
3159 // FreeRTOS "clear bits on exit" contract for xEventGroupSync().
3160 const uint32_t opts = stk::sync::EventFlags::OPT_WAIT_ALL;
3161 // (OPT_NO_CLEAR absent -> clear on success)
3162
3163 uint32_t result = ef.Wait(static_cast<uint32_t>(uxBitsToWaitFor),
3164 opts,
3165 FrtosTimeoutToStk(xTicksToWait));
3166
3167 // On timeout or error, return 0 (matches FreeRTOS reference behaviour).
3168 return StkFlagsToFrtos(result);
3169}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:411
32-bit event flags group for multi-flag synchronization between tasks.
uint32_t Wait(uint32_t flags, uint32_t options=OPT_WAIT_ANY, Timeout timeout_ticks=WAIT_INFINITE)
Wait for one or more flags to be set.
static const uint32_t OPT_WAIT_ALL
Wait for ALL of the specified flags to be set simultaneously (AND semantics).
uint32_t Set(uint32_t flags)
Set one or more flags.

References FrtosTimeoutToStk(), stk::sync::EventFlags::IsError(), IsIrqContext(), FrtosEventGroup::m_ef, stk::sync::EventFlags::OPT_WAIT_ALL, stk::sync::EventFlags::Set(), STK_ASSERT, StkFlagsToFrtos(), and stk::sync::EventFlags::Wait().

Here is the call graph for this function:

◆ xEventGroupWaitBits()

EventBits_t xEventGroupWaitBits ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToWaitFor,
BaseType_t xClearOnExit,
BaseType_t xWaitForAllBits,
TickType_t xTicksToWait )

Block the calling task until the specified bit condition is met.

Parameters
uxBitsToWaitForBitmask of bits to watch.
xClearOnExitpdTRUE = atomically clear matched bits on return.
xWaitForAllBitspdTRUE = AND semantics, pdFALSE = OR semantics.
xTicksToWaitMaximum ticks to block. portMAX_DELAY = wait forever.
Returns
Bits that caused unblocking (before optional clear), or 0 on timeout.

Definition at line 3029 of file freertos_stk.cpp.

3034{
3035 if (IsIrqContext() || (xEventGroup == nullptr) || (uxBitsToWaitFor == 0U))
3036 return 0U;
3037
3038 stk::sync::EventFlags &ef = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef;
3039
3040 uint32_t opts = BuildStkFlagsOpts(xClearOnExit, xWaitForAllBits);
3041 uint32_t result = ef.Wait(static_cast<uint32_t>(uxBitsToWaitFor),
3042 opts,
3043 FrtosTimeoutToStk(xTicksToWait));
3044
3045 // On timeout, FreeRTOS documents that the return value is the flags word
3046 // at the moment the timeout occurred, not zero. ef.Get() is a volatile
3047 // read that is atomic on all supported 32-bit STK targets; no CS needed.
3048 const EventBits_t snapshot = static_cast<EventBits_t>(ef.Get());
3049 return StkFlagsToFrtos(result, snapshot);
3050}
static uint32_t BuildStkFlagsOpts(BaseType_t xClearOnExit, BaseType_t xWaitForAllBits)

References BuildStkFlagsOpts(), FrtosTimeoutToStk(), stk::sync::EventFlags::Get(), IsIrqContext(), StkFlagsToFrtos(), and stk::sync::EventFlags::Wait().

Here is the call graph for this function:

◆ xMessageBufferCreate()

MessageBufferHandle_t xMessageBufferCreate ( size_t xBufferSizeBytes,
size_t xMaxMessageSize )

Create a dynamically allocated message buffer.

Parameters
xBufferSizeBytesTotal storage budget. The implementation derives slot count as floor(xBufferSizeBytes / (AlignBlockSize(xMaxMessageSize)
  • sizeof(envelope))).
xMaxMessageSizeMaximum payload size per message in bytes.
Returns
Handle, or NULL on allocation failure.

Definition at line 4086 of file freertos_stk.cpp.

4088{
4089 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4090 return nullptr;
4091
4092 const size_t count = MsgBufSlotCount(xBufferSizeBytes, xMaxMessageSize);
4093
4094 if (count == 0U)
4095 return nullptr;
4096
4097 FrtosMessageBuffer *mb = ObjAlloc<FrtosMessageBuffer>(xMaxMessageSize, count);
4098
4099 if (mb == nullptr)
4100 return nullptr;
4101
4102 if (!mb->m_pool.IsStorageValid() || !mb->m_eq.IsStorageValid())
4103 {
4104 ObjFreeRaw(mb);
4105 return nullptr;
4106 }
4107
4108 return static_cast<MessageBufferHandle_t>(mb);
4109}
static void ObjFreeRaw(T *obj)
static size_t MsgBufSlotCount(size_t budget_bytes, size_t max_msg_size)
void * MessageBufferHandle_t
Definition FreeRTOS.h:316
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
stk::memory::BlockMemoryPool m_pool
payload block allocator
stk::sync::MessageQueue m_eq
envelope FIFO {len, blk}

References stk::memory::BlockMemoryPool::IsStorageValid(), stk::sync::MessageQueue::IsStorageValid(), FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_pool, MsgBufSlotCount(), ObjAlloc(), and ObjFreeRaw().

Here is the call graph for this function:

◆ xMessageBufferCreateStatic()

MessageBufferHandle_t xMessageBufferCreateStatic ( size_t xMaxMessageSize,
size_t xMessageCount,
uint8_t * pucMessageBufferStorageArea,
StaticMessageBuffer_t * pxStaticMessageBuffer )

Create a statically allocated message buffer (no heap).

Parameters
xMaxMessageSizeMaximum payload size per message.
xMessageCountMaximum number of in-flight messages.
pucMessageBufferStorageAreaCaller-supplied flat buffer of at least xMessageCount * (AlignBlockSize(xMaxMessageSize) + sizeof(envelope)) bytes.
pxStaticMessageBufferCaller-supplied TCB (StaticMessageBuffer_t).
Returns
Handle (always non-NULL if arguments are non-NULL).

Definition at line 4111 of file freertos_stk.cpp.

4116{
4117 if ((pucMessageBufferStorageArea == nullptr) ||
4118 (pxStaticMessageBuffer == nullptr) ||
4119 (xMaxMessageSize == 0U) ||
4120 (xMessageCount == 0U))
4121 return nullptr;
4122
4123 const size_t block_size = stk::memory::BlockMemoryPool::AlignBlockSize(xMaxMessageSize);
4124 const size_t storage_size = xMessageCount * (block_size + FrtosMessageBuffer::ENVELOPE_SIZE);
4125
4126 FrtosMessageBuffer *mb = new (pxStaticMessageBuffer)
4127 FrtosMessageBuffer(xMaxMessageSize, xMessageCount,
4128 pucMessageBufferStorageArea, storage_size);
4129
4130 return static_cast<MessageBufferHandle_t>(mb);
4131}
static constexpr size_t AlignBlockSize(size_t raw_size)
Round a raw block size up to the nearest multiple of BLOCK_ALIGN.
static constexpr size_t ENVELOPE_SIZE

References stk::memory::BlockMemoryPool::AlignBlockSize(), and FrtosMessageBuffer::ENVELOPE_SIZE.

Here is the call graph for this function:

◆ xMessageBufferCreateStaticWithCallback()

MessageBufferHandle_t xMessageBufferCreateStaticWithCallback ( size_t xMaxMessageSize,
size_t xMessageCount,
uint8_t * pucMessageBufferStorageArea,
StaticMessageBuffer_t * pxStaticMessageBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )

Create a statically-allocated message buffer with optional send/receive callbacks.

Identical to xMessageBufferCreateStatic() but registers per-instance callbacks. Either callback may be NULL.

Parameters
xMaxMessageSizeMaximum payload size per message in bytes.
xMessageCountMaximum number of in-flight messages.
pucMessageBufferStorageAreaCaller-supplied flat storage buffer.
pxStaticMessageBufferCaller-supplied TCB (StaticMessageBuffer_t).
pxSendCompletedCallbackCalled after a message is enqueued (or NULL).
pxReceiveCompletedCallbackCalled after a message is dequeued (or NULL).
Returns
Handle, or NULL on invalid arguments.

Definition at line 4178 of file freertos_stk.cpp.

4185{
4186 if ((pucMessageBufferStorageArea == nullptr) ||
4187 (pxStaticMessageBuffer == nullptr) ||
4188 (xMaxMessageSize == 0U) ||
4189 (xMessageCount == 0U))
4190 return nullptr;
4191
4192 static_assert(sizeof(StaticMessageBuffer_t) >= sizeof(FrtosMessageBuffer),
4193 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4194
4195 const size_t block_size = stk::memory::BlockMemoryPool::AlignBlockSize(xMaxMessageSize);
4196 const size_t storage_size = xMessageCount * (block_size + FrtosMessageBuffer::ENVELOPE_SIZE);
4197
4198 FrtosMessageBuffer *mb = new (pxStaticMessageBuffer)
4199 FrtosMessageBuffer(xMaxMessageSize, xMessageCount,
4200 pucMessageBufferStorageArea, storage_size,
4201 pxSendCompletedCallback, pxReceiveCompletedCallback);
4202
4203 return static_cast<MessageBufferHandle_t>(mb);
4204}

References stk::memory::BlockMemoryPool::AlignBlockSize(), and FrtosMessageBuffer::ENVELOPE_SIZE.

Here is the call graph for this function:

◆ xMessageBufferCreateWithCallback()

MessageBufferHandle_t xMessageBufferCreateWithCallback ( size_t xBufferSizeBytes,
size_t xMaxMessageSize,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )

Create a heap-allocated message buffer with optional send/receive callbacks.

Identical to xMessageBufferCreate() but registers per-instance callbacks invoked after a message is successfully enqueued (pxSendCompletedCallback) or dequeued (pxReceiveCompletedCallback). Either callback may be NULL. Callbacks fire outside any critical section, after the transfer completes. The xStreamBuffer argument passed to the callback is the MessageBufferHandle_t cast to StreamBufferHandle_t, matching FreeRTOS convention.

Parameters
xBufferSizeBytesTotal storage budget (slot count derived internally).
xMaxMessageSizeMaximum payload size per message in bytes.
pxSendCompletedCallbackCalled after a message is enqueued (or NULL).
pxReceiveCompletedCallbackCalled after a message is dequeued (or NULL).
Returns
Handle, or NULL on allocation failure.

Definition at line 4144 of file freertos_stk.cpp.

4149{
4150 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4151 return nullptr;
4152
4153 const size_t block_size = stk::memory::BlockMemoryPool::AlignBlockSize(xMaxMessageSize);
4154 const size_t slot_cost = block_size + FrtosMessageBuffer::ENVELOPE_SIZE;
4155 const size_t count = xBufferSizeBytes / slot_cost;
4156
4157 if (count == 0U)
4158 return nullptr;
4159
4161 xMaxMessageSize, count,
4162 pxSendCompletedCallback, pxReceiveCompletedCallback);
4163
4164 if (mb == nullptr)
4165 return nullptr;
4166
4167 // Detect heap failure in the envelope buffer allocation performed by the
4168 // heap constructor (m_eq is backed by a separately ObjAllocArray'd byte array).
4169 if (!mb->m_eq.IsStorageValid())
4170 {
4171 ObjFreeRaw(mb);
4172 return nullptr;
4173 }
4174
4175 return static_cast<MessageBufferHandle_t>(mb);
4176}

References stk::memory::BlockMemoryPool::AlignBlockSize(), FrtosMessageBuffer::ENVELOPE_SIZE, stk::sync::MessageQueue::IsStorageValid(), FrtosMessageBuffer::m_eq, ObjAlloc(), and ObjFreeRaw().

Here is the call graph for this function:

◆ xMessageBufferIsEmpty()

BaseType_t xMessageBufferIsEmpty ( MessageBufferHandle_t xMessageBuffer)

Return pdTRUE if the message buffer contains no messages.

Note
ISR-safe.

Definition at line 4307 of file freertos_stk.cpp.

4308{
4309 if (xMessageBuffer == nullptr)
4310 return pdTRUE;
4311
4312 return static_cast<FrtosMessageBuffer *>(xMessageBuffer)->m_eq.IsEmpty()
4313 ? pdTRUE : pdFALSE;
4314}

References pdFALSE, and pdTRUE.

◆ xMessageBufferIsFull()

BaseType_t xMessageBufferIsFull ( MessageBufferHandle_t xMessageBuffer)

Return pdTRUE if no more messages can be enqueued (pool exhausted).

Note
ISR-safe.

Definition at line 4316 of file freertos_stk.cpp.

4317{
4318 if (xMessageBuffer == nullptr)
4319 return pdTRUE;
4320
4321 return static_cast<FrtosMessageBuffer *>(xMessageBuffer)->m_pool.IsFull()
4322 ? pdTRUE : pdFALSE;
4323}

References pdFALSE, and pdTRUE.

◆ xMessageBufferNextLengthBytes()

size_t xMessageBufferNextLengthBytes ( MessageBufferHandle_t xMessageBuffer)

Return the byte length of the next message that would be returned by xMessageBufferReceive(), without removing it from the buffer.

Backed by stk::sync::MessageQueue::TryPeek(), which copies the oldest envelope atomically without consuming it. No dequeue-and-reinsert pair is needed; the queue state is left unchanged in a single ISR-safe operation.

Returns
Length in bytes of the oldest pending message, or 0 if the buffer is empty.
Note
ISR-safe.

Definition at line 4522 of file freertos_stk.cpp.

4523{
4524 if (xMessageBuffer == nullptr)
4525 return 0U;
4526
4527 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4528
4529 // TryPeek copies the oldest envelope without consuming it. The internal
4530 // ScopedCriticalSection makes this ISR-safe; no outer CS is required.
4531 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4532
4533 if (!mb->m_eq.TryPeek(&env))
4534 return 0U; // buffer is empty — nothing to peek at
4535
4536 return env.len;
4537}
bool TryPeek(void *msg_ptr)
Attempt to peek at the next message without blocking.
size_t len
payload length in bytes

References FrtosMessageBuffer::MsgEnvelope::len, FrtosMessageBuffer::m_eq, and stk::sync::MessageQueue::TryPeek().

Here is the call graph for this function:

◆ xMessageBufferReceive()

size_t xMessageBufferReceive ( MessageBufferHandle_t xMessageBuffer,
void * pvRxData,
size_t xBufferLengthBytes,
TickType_t xTicksToWait )

Receive a message from the message buffer (task context, may block).

Parameters
pvRxDataDestination buffer.
xBufferLengthBytesCapacity of pvRxData; must be >= the oldest message length.
xTicksToWaitTicks to wait for a message. portMAX_DELAY blocks indefinitely.
Returns
Number of bytes written to pvRxData, or 0 on timeout / size violation.
Warning
ISR-unsafe. Use xMessageBufferReceiveFromISR() from ISR context.

Definition at line 4264 of file freertos_stk.cpp.

4268{
4269 if ((xMessageBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
4270 return 0U;
4271
4272 if (IsIrqContext() && (xTicksToWait != 0U))
4273 return 0U;
4274
4275 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4276
4277 // 1. Dequeue the next envelope.
4278 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4279
4280 if (!mb->m_eq.Get(&env, FrtosTimeoutToStk(xTicksToWait)))
4281 return 0U;
4282
4283 // 2. Validate destination capacity.
4284 if (xBufferLengthBytes < env.len)
4285 {
4286 // Destination too small: re-enqueue the envelope so the message is
4287 // not lost (best-effort; if re-enqueue also fails the message is lost).
4288 STK_ASSERT(false); // API contract: pvRxData buffer too small
4289 mb->m_eq.TryPut(&env);
4290 return 0U;
4291 }
4292
4293 // 3. Copy payload out and return the block.
4294 memcpy(pvRxData, env.blk, env.len);
4295 mb->m_pool.Free(env.blk);
4296
4297 // Fire receive-complete callback outside any critical section.
4298 if (mb->m_recv_cb != nullptr)
4299 {
4300 BaseType_t woken = pdFALSE;
4301 mb->m_recv_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4302 }
4303
4304 return env.len;
4305}
void * StreamBufferHandle_t
Definition FreeRTOS.h:315
long BaseType_t
Definition FreeRTOS.h:257
bool Free(void *ptr)
Return a previously allocated block to the pool.
bool TryPut(const void *msg_ptr)
Attempt to put a message into the back of the queue without blocking.
bool Get(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Get a message from the queue.
StreamBufferCallbackFunction_t m_recv_cb
optional callback fired after a successful Receive
void * blk
pointer to block pool block holding the payload

References FrtosMessageBuffer::MsgEnvelope::blk, stk::memory::BlockMemoryPool::Free(), FrtosTimeoutToStk(), stk::sync::MessageQueue::Get(), IsIrqContext(), FrtosMessageBuffer::MsgEnvelope::len, FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_pool, FrtosMessageBuffer::m_recv_cb, pdFALSE, STK_ASSERT, and stk::sync::MessageQueue::TryPut().

Here is the call graph for this function:

◆ xMessageBufferReceiveFromISR()

size_t xMessageBufferReceiveFromISR ( MessageBufferHandle_t xMessageBuffer,
void * pvRxData,
size_t xBufferLengthBytes,
BaseType_t * pxHigherPriorityTaskWoken )

Receive a message from the message buffer from ISR context (non-blocking).

Attempts to dequeue one envelope without blocking. If an envelope is available and fits in the destination buffer the payload is copied out and the pool block is freed.

Parameters
pvRxDataDestination buffer.
xBufferLengthBytesCapacity of pvRxData; must be >= the oldest message length.
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
Number of bytes written to pvRxData, or 0 if empty / destination too small.
Warning
ISR-safe (non-blocking).

Definition at line 4451 of file freertos_stk.cpp.

4455{
4456 if (pxHigherPriorityTaskWoken != nullptr)
4457 *pxHigherPriorityTaskWoken = pdFALSE;
4458
4459 if ((xMessageBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
4460 return 0U;
4461
4462 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4463
4464 // Step 1: non-blocking dequeue of the oldest envelope.
4465 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4466 if (!mb->m_eq.TryGet(&env))
4467 return 0U; // buffer empty
4468
4469 // Step 2: validate destination capacity.
4470 if (xBufferLengthBytes < env.len)
4471 {
4472 // Destination too small: put the envelope back at the front so the
4473 // message is not lost. TryPutFront retreats the tail pointer under
4474 // its own CS — identical to Get never having happened.
4475 STK_ASSERT(false); // API contract: pvRxData buffer too small
4476 mb->m_eq.TryPutFront(&env);
4477 return 0U;
4478 }
4479
4480 // Step 3: copy payload out and release pool block.
4481 memcpy(pvRxData, env.blk, env.len);
4482 mb->m_pool.Free(env.blk);
4483
4484 // Fire receive-complete callback outside any critical section.
4485 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
4486 if (mb->m_recv_cb != nullptr)
4487 {
4488 BaseType_t woken = pdFALSE;
4489 mb->m_recv_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4490 }
4491
4492 return env.len;
4493}
bool TryPutFront(const void *msg_ptr)
Attempt to put a message into the front of the queue without blocking.
bool TryGet(void *msg_ptr)
Attempt to get a message from the queue without blocking.

References FrtosMessageBuffer::MsgEnvelope::blk, stk::memory::BlockMemoryPool::Free(), FrtosMessageBuffer::MsgEnvelope::len, FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_pool, FrtosMessageBuffer::m_recv_cb, pdFALSE, STK_ASSERT, stk::sync::MessageQueue::TryGet(), and stk::sync::MessageQueue::TryPutFront().

Here is the call graph for this function:

◆ xMessageBufferReset()

BaseType_t xMessageBufferReset ( MessageBufferHandle_t xMessageBuffer)

Discard all pending messages, return all blocks to the pool, and reset the envelope queue to the empty state (task context).

Returns
pdPASS always.
Warning
ISR-safe. Prefer xMessageBufferResetFromISR() from interrupt context to properly signal pxHigherPriorityTaskWoken.

Definition at line 4334 of file freertos_stk.cpp.

4335{
4336 if (xMessageBuffer == nullptr)
4337 return pdFAIL;
4338
4339 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4340
4341 // Drain all pending envelopes and return their blocks to the pool.
4342 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4343
4344 while (mb->m_eq.TryGet(&env))
4345 {
4346 if (env.blk != nullptr)
4347 mb->m_pool.Free(env.blk);
4348 }
4349
4350 // Reset the envelope queue (wakes any blocked senders).
4351 mb->m_eq.Reset();
4352
4353 return pdPASS;
4354}
void Reset()
Discard all messages and reset the queue to the empty state.

References FrtosMessageBuffer::MsgEnvelope::blk, stk::memory::BlockMemoryPool::Free(), FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_pool, pdFAIL, pdPASS, stk::sync::MessageQueue::Reset(), and stk::sync::MessageQueue::TryGet().

Here is the call graph for this function:

◆ xMessageBufferResetFromISR()

BaseType_t xMessageBufferResetFromISR ( MessageBufferHandle_t xMessageBuffer,
BaseType_t * pxHigherPriorityTaskWoken )

Discard all pending messages and reset the buffer from ISR context.

Drains every pending envelope, frees its pool block, then resets the envelope queue. Wakes any task blocked in xMessageBufferSend() that was waiting for a free slot.

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
pdPASS always.
Warning
ISR-safe.

Definition at line 4495 of file freertos_stk.cpp.

4497{
4498 if (pxHigherPriorityTaskWoken != nullptr)
4499 *pxHigherPriorityTaskWoken = pdFALSE;
4500
4501 if (xMessageBuffer == nullptr)
4502 return pdFAIL;
4503
4504 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4505
4506 // Drain all pending envelopes, returning every pool block before resetting
4507 // the queue. All three operations are ISR-safe (ScopedCriticalSection).
4508 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4509
4510 while (mb->m_eq.TryGet(&env))
4511 {
4512 if (env.blk != nullptr)
4513 mb->m_pool.Free(env.blk);
4514 }
4515
4516 // Reset the envelope queue; wakes any sender blocked on a full pool.
4517 mb->m_eq.Reset();
4518
4519 return pdPASS;
4520}

References FrtosMessageBuffer::MsgEnvelope::blk, stk::memory::BlockMemoryPool::Free(), FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_pool, pdFAIL, pdFALSE, pdPASS, stk::sync::MessageQueue::Reset(), and stk::sync::MessageQueue::TryGet().

Here is the call graph for this function:

◆ xMessageBufferSend()

size_t xMessageBufferSend ( MessageBufferHandle_t xMessageBuffer,
const void * pvTxData,
size_t xDataLengthBytes,
TickType_t xTicksToWait )

Send a message into the message buffer (task context, may block).

Parameters
pvTxDataPointer to message payload.
xDataLengthBytesPayload size in bytes (must be <= max message size).
xTicksToWaitTicks to wait for a free block + envelope slot. portMAX_DELAY blocks indefinitely.
Returns
xDataLengthBytes on success, 0 on timeout or size violation.
Warning
ISR-unsafe. Use xMessageBufferSendFromISR() from ISR context.

Definition at line 4216 of file freertos_stk.cpp.

4220{
4221 if ((xMessageBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
4222 return 0U;
4223
4224 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4225
4226 if (xDataLengthBytes > mb->m_max_msg_size)
4227 {
4228 STK_ASSERT(false); // API contract: message too large for this buffer
4229 return 0U;
4230 }
4231
4232 const stk::Timeout stk_timeout = FrtosTimeoutToStk(xTicksToWait);
4233
4234 // 1. Acquire a payload block (blocks until one is free or timeout).
4235 void *blk = mb->m_pool.TimedAlloc(stk_timeout);
4236 if (blk == nullptr)
4237 return 0U;
4238
4239 // 2. Copy payload into the block.
4240 memcpy(blk, pvTxData, xDataLengthBytes);
4241
4242 // 3. Enqueue the envelope (should always succeed: pool and eq are 1:1,
4243 // but guard with NO_WAIT to avoid deadlock if they desync).
4244 FrtosMessageBuffer::MsgEnvelope env = { xDataLengthBytes, blk };
4245
4246 if (!mb->m_eq.Put(&env, stk::NO_WAIT))
4247 {
4248 // Envelope queue unexpectedly full — return block and report failure.
4249 STK_ASSERT(false);
4250 mb->m_pool.Free(blk);
4251 return 0U;
4252 }
4253
4254 // Fire send-complete callback outside any critical section.
4255 if (mb->m_send_cb != nullptr)
4256 {
4257 BaseType_t woken = pdFALSE;
4258 mb->m_send_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4259 }
4260
4261 return xDataLengthBytes;
4262}
static constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:189
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:125
void * TimedAlloc(Timeout timeout_ticks=WAIT_INFINITE)
Allocate one block, blocking until one becomes available or the timeout expires.
bool Put(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the back of the queue (FIFO order).
StreamBufferCallbackFunction_t m_send_cb
optional callback fired after a successful Send
size_t m_max_msg_size
max payload bytes per message

References stk::memory::BlockMemoryPool::Free(), FrtosTimeoutToStk(), FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_max_msg_size, FrtosMessageBuffer::m_pool, FrtosMessageBuffer::m_send_cb, stk::NO_WAIT, pdFALSE, stk::sync::MessageQueue::Put(), STK_ASSERT, and stk::memory::BlockMemoryPool::TimedAlloc().

Here is the call graph for this function:

◆ xMessageBufferSendFromISR()

size_t xMessageBufferSendFromISR ( MessageBufferHandle_t xMessageBuffer,
const void * pvTxData,
size_t xDataLengthBytes,
BaseType_t * pxHigherPriorityTaskWoken )

Send a message into the message buffer from ISR context (non-blocking).

Attempts a single non-blocking pool allocation followed by a non-blocking envelope enqueue. Returns 0 immediately if either resource is unavailable.

Parameters
pvTxDataPointer to message payload.
xDataLengthBytesPayload size (must be <= max message size).
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
xDataLengthBytes on success, 0 if the buffer was full or arguments invalid.
Warning
ISR-safe (non-blocking). Must not be called with a non-zero timeout.

Definition at line 4402 of file freertos_stk.cpp.

4406{
4407 if (pxHigherPriorityTaskWoken != nullptr)
4408 *pxHigherPriorityTaskWoken = pdFALSE;
4409
4410 if ((xMessageBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
4411 return 0U;
4412
4413 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4414
4415 if (xDataLengthBytes > mb->m_max_msg_size)
4416 {
4417 STK_ASSERT(false); // API contract: message exceeds max size
4418 return 0U;
4419 }
4420
4421 // Step 1: non-blocking pool allocation.
4422 void *blk = mb->m_pool.TimedAlloc(stk::NO_WAIT);
4423 if (blk == nullptr)
4424 return 0U; // pool full — no block consumed, nothing to free
4425
4426 // Step 2: copy payload.
4427 memcpy(blk, pvTxData, xDataLengthBytes);
4428
4429 // Step 3: non-blocking enqueue.
4430 FrtosMessageBuffer::MsgEnvelope env = { xDataLengthBytes, blk };
4431 if (!mb->m_eq.TryPut(&env))
4432 {
4433 // Pool and eq are 1:1, so this should never happen. Defensively free
4434 // the block to avoid a pool leak and report failure.
4435 STK_ASSERT(false);
4436 mb->m_pool.Free(blk);
4437 return 0U;
4438 }
4439
4440 // Fire send-complete callback outside any critical section.
4441 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
4442 if (mb->m_send_cb != nullptr)
4443 {
4444 BaseType_t woken = pdFALSE;
4445 mb->m_send_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4446 }
4447
4448 return xDataLengthBytes;
4449}

References stk::memory::BlockMemoryPool::Free(), FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_max_msg_size, FrtosMessageBuffer::m_pool, FrtosMessageBuffer::m_send_cb, stk::NO_WAIT, pdFALSE, STK_ASSERT, stk::memory::BlockMemoryPool::TimedAlloc(), and stk::sync::MessageQueue::TryPut().

Here is the call graph for this function:

◆ xMessageBufferSpacesAvailable()

size_t xMessageBufferSpacesAvailable ( MessageBufferHandle_t xMessageBuffer)

Return the number of free envelope slots available for sending.

Note
ISR-safe.

Definition at line 4325 of file freertos_stk.cpp.

4326{
4327 if (xMessageBuffer == nullptr)
4328 return 0U;
4329
4330 // Free pool blocks == available envelope slots (they are 1:1).
4331 return static_cast<FrtosMessageBuffer *>(xMessageBuffer)->m_pool.GetFreeCount();
4332}

◆ xPortGetFreeHeapSize()

size_t xPortGetFreeHeapSize ( void )

Return the number of bytes currently available in the heap.

This is a point-in-time snapshot of stk::memory::MemoryAllocator::Stats::GetAvailable() and may not account for in-flight allocations if called from a non-critical context.

Returns
Free bytes remaining.

Definition at line 223 of file freertos_stk.cpp.

224{
225 return s_MemStats.GetAvailable();
226}

References s_MemStats.

◆ xPortGetMinimumEverFreeHeapSize()

size_t xPortGetMinimumEverFreeHeapSize ( void )

Return the minimum number of free heap bytes recorded since system start.

The watermark is updated inside MemoryAllocator::Allocate() after every successful allocation, so it always reflects the worst-case heap pressure observed up to the point of the call.

Returns
Minimum ever free bytes (heap watermark).

Definition at line 228 of file freertos_stk.cpp.

229{
230 return s_MemStats.min_ever_free;
231}

References s_MemStats.

◆ xQueueAddToSet()

BaseType_t xQueueAddToSet ( QueueSetMemberHandle_t xQueueOrSemaphore,
QueueSetHandle_t xQueueSet )

Register a queue or binary/counting semaphore as a member of a queue set.

The member must be empty at the time it is added. Mutexes are not permitted. A member may belong to at most one set at a time.

Parameters
xQueueOrSemaphoreHandle of the queue or semaphore to add.
xQueueSetHandle of the target queue set.
Returns
pdPASS on success, pdFAIL if any precondition is violated.

Definition at line 2082 of file freertos_stk.cpp.

2084{
2085 if ((xQueueOrSemaphore == nullptr) || (xQueueSet == nullptr))
2086 return pdFAIL;
2087
2088 FrtosQueueSet *qs = static_cast<FrtosQueueSet *>(xQueueSet);
2089
2090 // Type discrimination between FrtosQueue and FrtosSemaphore via
2091 // GetSemKindFromHandle(): returns SemKind::None for queues (and any
2092 // unrecognised handle), SemKind::Counting or SemKind::Mutex for semaphores.
2093 {
2094 const SemKind kind = GetSemKindFromHandle(xQueueOrSemaphore);
2095
2096 if (kind != SemKind::None)
2097 {
2098 // Semaphore or mutex path.
2099 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xQueueOrSemaphore);
2100
2101 // FreeRTOS API contract: mutexes cannot be queue set members.
2102 if (s->m_kind == SemKind::Mutex)
2103 return pdFAIL;
2104
2105 STK_ASSERT(s->m_set == nullptr); // must not already belong to a set
2106 if (s->m_set != nullptr)
2107 return pdFAIL;
2108
2109 STK_ASSERT(s->m_sem->GetCount() == 0U); // must be empty when added
2110 if (s->m_sem->GetCount() != 0U)
2111 return pdFAIL;
2112
2113 s->m_set = qs;
2114 }
2115 else
2116 {
2117 // Queue path.
2118 FrtosQueue *q = static_cast<FrtosQueue *>(xQueueOrSemaphore);
2119
2120 STK_ASSERT(q->m_set == nullptr); // must not already belong to a set
2121 if (q->m_set != nullptr)
2122 return pdFAIL;
2123
2124 STK_ASSERT(q->m_mq.IsEmpty()); // must be empty when added
2125 if (!q->m_mq.IsEmpty())
2126 return pdFAIL;
2127
2128 q->m_set = qs;
2129 }
2130 }
2131
2132 return pdPASS;
2133}
static SemKind GetSemKindFromHandle(const void *obj)
SemKind
@ Mutex
Mutex or recursive mutex (backed by stk::sync::Mutex).
@ None
Sentinel: not a FrtosSemaphore (e.g. plain FrtosQueue).
bool IsEmpty() const
Check whether the queue is currently empty.
FrtosQueueSet * m_set
non-owning ptr to the queue set this member belongs to (nullptr if none)
FrtosQueueSet * m_set
non-owning ptr to the queue set this member belongs to (nullptr if none)

References stk::sync::Semaphore::GetCount(), GetSemKindFromHandle(), stk::sync::MessageQueue::IsEmpty(), FrtosSemaphore::m_kind, FrtosQueue::m_mq, FrtosSemaphore::m_sem, FrtosQueue::m_set, FrtosSemaphore::m_set, Mutex, None, pdFAIL, pdPASS, and STK_ASSERT.

Here is the call graph for this function:

◆ xQueueCreate()

QueueHandle_t xQueueCreate ( UBaseType_t uxQueueLength,
UBaseType_t uxItemSize )

Create a queue capable of holding uxQueueLength items of uxItemSize bytes.

Returns
Queue handle, or NULL on allocation failure.

Definition at line 1640 of file freertos_stk.cpp.

1642{
1643 if (IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1644 return nullptr;
1645
1646 if (uxQueueLength > stk::sync::MessageQueue::CAPACITY_MAX)
1647 return nullptr;
1648
1650 static_cast<uint32_t>(uxQueueLength),
1651 static_cast<uint32_t>(uxItemSize),
1652 nullptr /* name */);
1653
1654 if (q == nullptr)
1655 return nullptr;
1656
1657 if (!q->m_mq.IsStorageValid())
1658 {
1659 ObjFree(q);
1660 return nullptr;
1661 }
1662
1663 return static_cast<QueueHandle_t>(q);
1664}
void * QueueHandle_t
Definition FreeRTOS.h:311
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).

References stk::sync::MessageQueue::CAPACITY_MAX, IsIrqContext(), stk::sync::MessageQueue::IsStorageValid(), FrtosQueue::m_mq, ObjAlloc(), and ObjFree().

Here is the call graph for this function:

◆ xQueueCreateSet()

QueueSetHandle_t xQueueCreateSet ( UBaseType_t uxEventQueueLength)

Create a queue set that can supervise up to uxEventQueueLength simultaneous item-available notifications from its member queues and semaphores.

Parameters
uxEventQueueLengthTotal event capacity. Must be >= the sum of the capacities (uxQueueLength or max_count) of all queues and semaphores that will be added.
Returns
Queue set handle, or NULL on failure.

Definition at line 2063 of file freertos_stk.cpp.

2064{
2065 if (IsIrqContext() || (uxEventQueueLength == 0U))
2066 return nullptr;
2067
2068 if (uxEventQueueLength > stk::sync::MessageQueue::CAPACITY_MAX)
2069 return nullptr;
2070
2071 FrtosQueueSet *qs = ObjAlloc<FrtosQueueSet>(uxEventQueueLength);
2072
2073 if ((qs == nullptr) || !qs->IsValid())
2074 {
2075 ObjFree(qs);
2076 return nullptr;
2077 }
2078
2079 return static_cast<QueueSetHandle_t>(qs);
2080}
void * QueueSetHandle_t
Definition FreeRTOS.h:319
bool IsValid() const

References stk::sync::MessageQueue::CAPACITY_MAX, IsIrqContext(), FrtosQueueSet::IsValid(), ObjAlloc(), and ObjFree().

Here is the call graph for this function:

◆ xQueueCreateStatic()

QueueHandle_t xQueueCreateStatic ( UBaseType_t uxQueueLength,
UBaseType_t uxItemSize,
uint8_t * pucQueueStorage,
StaticQueue_t * pxStaticQueue )

Create a queue using caller-supplied storage — no heap allocation.

Parameters
uxQueueLengthMaximum number of items the queue can hold (>= 1).
uxItemSizeSize of each item in bytes (>= 1).
pucQueueStorageCaller-allocated data buffer of at least uxQueueLength * uxItemSize bytes. Must remain valid for the entire lifetime of the queue.
pxStaticQueueCaller-allocated queue control block (StaticQueue_t). Must remain valid for the entire lifetime of the queue.
Returns
Queue handle. Never NULL if all pointer arguments are non-NULL and uxQueueLength / uxItemSize are within range.

Definition at line 1666 of file freertos_stk.cpp.

1670{
1671 // All pointer arguments are mandatory for static allocation.
1672 if ((pucQueueStorage == nullptr) || (pxStaticQueue == nullptr))
1673 return nullptr;
1674
1675 if (IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1676 return nullptr;
1677
1678 if (uxQueueLength > stk::sync::MessageQueue::CAPACITY_MAX)
1679 return nullptr;
1680
1681 // Placement-new the FrtosQueue control block into the caller-supplied buffer.
1682 // Static assert guards against the buffer being too small.
1683 static_assert(sizeof(StaticQueue_t) >= sizeof(FrtosQueue),
1684 "StaticQueue_t is too small to hold FrtosQueue. "
1685 "Increase STATIC_QUEUE_TCB_SIZE_WORDS in freertos_stk.h.");
1686
1687 // Use the external-storage FrtosQueue constructor: no heap allocation for
1688 // either the control block or the data buffer.
1689 FrtosQueue *q = new (pxStaticQueue) FrtosQueue(
1690 static_cast<uint32_t>(uxQueueLength),
1691 static_cast<uint32_t>(uxItemSize),
1692 nullptr /* name */,
1693 pucQueueStorage);
1694
1695 q->m_cb_owned = false; // caller owns the memory; destructor must not delete
1696
1697 return static_cast<QueueHandle_t>(q);
1698}

References stk::sync::MessageQueue::CAPACITY_MAX, IsIrqContext(), and FrtosQueue::m_cb_owned.

Here is the call graph for this function:

◆ xQueueGetMutexHolder()

TaskHandle_t xQueueGetMutexHolder ( QueueHandle_t xQueue)

Return the handle of the task that currently holds a mutex-semaphore when that semaphore is referenced by a QueueHandle_t alias.

In the FreeRTOS reference implementation mutex semaphores are built on top of the internal queue structure, so xQueueGetMutexHolder() and xSemaphoreGetMutexHolder() are the same function with different handle types. In this STK wrapper the two object types are separate structs:

This function accepts a QueueHandle_t and uses the same one-byte type-discriminant (offset 0: SemKind ≤ 1 → semaphore, otherwise → queue) already used by the Queue Set implementation to decide which path to take:

Parameters
xQueueHandle typed as QueueHandle_t. May point to a mutex semaphore in application code that uses the raw queue handle alias (e.g. FreeRTOS+TCP internal usage).
Returns
Handle of the owning task, or NULL if unlocked / not a mutex.
Warning
Not ISR-safe. Use xQueueGetMutexHolderFromISR() from ISR context.
Note
Requires configUSE_MUTEXES == 1.

Definition at line 2006 of file freertos_stk.cpp.

2007{
2008 // Resolve to FrtosSemaphore (Mutex kind) or bail out.
2010 if (s == nullptr)
2011 return nullptr;
2012
2013 // Delegate to the semaphore variant which acquires a ScopedCriticalSection
2014 // to make the TId snapshot consistent with concurrent Unlock() calls.
2015 return xSemaphoreGetMutexHolder(static_cast<SemaphoreHandle_t>(xQueue));
2016}
static FrtosSemaphore * QueueHandleAsMutex(QueueHandle_t xQueue)
void * SemaphoreHandle_t
Definition FreeRTOS.h:312
TaskHandle_t xSemaphoreGetMutexHolder(SemaphoreHandle_t xMutex)

References QueueHandleAsMutex(), and xSemaphoreGetMutexHolder().

Here is the call graph for this function:

◆ xQueueGetMutexHolderFromISR()

TaskHandle_t xQueueGetMutexHolderFromISR ( QueueHandle_t xQueue)

ISR-safe variant of xQueueGetMutexHolder().

Reads the mutex owner field with a single pointer-sized load, which is naturally atomic on all supported STK architectures (Cortex-M and equivalents) without requiring an additional critical section.

Parameters
xQueueHandle typed as QueueHandle_t.
Returns
Handle of the owning task, or NULL if unlocked / not a mutex.
Warning
ISR-safe.
Note
Requires configUSE_MUTEXES == 1.

Definition at line 2018 of file freertos_stk.cpp.

2019{
2020 // Resolve to FrtosSemaphore (Mutex kind) or bail out.
2022 if (s == nullptr)
2023 return nullptr;
2024
2025 // Delegate to the ISR-safe semaphore variant which reads GetOwner() via a
2026 // single pointer-sized atomic load — no additional critical section needed.
2027 return xSemaphoreGetMutexHolderFromISR(static_cast<SemaphoreHandle_t>(xQueue));
2028}
TaskHandle_t xSemaphoreGetMutexHolderFromISR(SemaphoreHandle_t xMutex)

References QueueHandleAsMutex(), and xSemaphoreGetMutexHolderFromISR().

Here is the call graph for this function:

◆ xQueueIsQueueEmptyFromISR()

BaseType_t xQueueIsQueueEmptyFromISR ( const QueueHandle_t xQueue)

Query whether a queue is empty from ISR context.

Note
ISR-safe on targets where a size_t-aligned read is atomic (per stk::sync::MessageQueue::IsEmpty() contract).
Returns
pdTRUE if the queue contains no items, pdFALSE otherwise.

Definition at line 1936 of file freertos_stk.cpp.

1937{
1938 // IsEmpty() reads m_count which is size_t-aligned; ISR-safe on targets
1939 // where such a read is atomic (per stk::sync::MessageQueue contract).
1940 if (xQueue == nullptr)
1941 return pdTRUE;
1942
1943 return static_cast<const FrtosQueue *>(xQueue)->m_mq.IsEmpty() ? pdTRUE : pdFALSE;
1944}

References pdFALSE, and pdTRUE.

◆ xQueueIsQueueFullFromISR()

BaseType_t xQueueIsQueueFullFromISR ( const QueueHandle_t xQueue)

Query whether a queue is full from ISR context.

Note
ISR-safe on targets where a size_t-aligned read is atomic (per stk::sync::MessageQueue::IsFull() contract).
Returns
pdTRUE if the queue holds capacity items, pdFALSE otherwise.

Definition at line 1946 of file freertos_stk.cpp.

1947{
1948 // IsFull() reads m_count and m_capacity; both are size_t-aligned and
1949 // m_capacity is const, so the read is ISR-safe on naturally-atomic targets
1950 // (per stk::sync::MessageQueue contract).
1951 if (xQueue == nullptr)
1952 return pdTRUE;
1953
1954 return static_cast<const FrtosQueue *>(xQueue)->m_mq.IsFull() ? pdTRUE : pdFALSE;
1955}

References pdFALSE, and pdTRUE.

◆ xQueueOverwrite()

BaseType_t xQueueOverwrite ( QueueHandle_t xQueue,
const void * pvItemToQueue )

Overwrite the value stored in a queue of length 1 (mailbox pattern). If the queue is already full the existing item is discarded before writing.

Note
Intended for length-1 queues only; behaviour is undefined for longer queues.
Returns
pdPASS always (the write always succeeds after the discard).

Definition at line 1833 of file freertos_stk.cpp.

1834{
1835 // Mailbox (length-1 queue) overwrite pattern.
1836 // Reset() atomically discards any existing item and wakes blocked producers,
1837 // guaranteeing TryPut() will always find a free slot immediately after.
1838 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1839 return pdFAIL;
1840
1841 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1842 q->m_mq.Reset();
1843 q->m_mq.TryPut(pvItemToQueue);
1844 QueueSetNotify(xQueue, q);
1845
1846 return pdPASS;
1847}
static void QueueSetNotify(void *member_handle, THost *host)

References FrtosQueue::m_mq, pdFAIL, pdPASS, QueueSetNotify(), stk::sync::MessageQueue::Reset(), and stk::sync::MessageQueue::TryPut().

Here is the call graph for this function:

◆ xQueueOverwriteFromISR()

BaseType_t xQueueOverwriteFromISR ( QueueHandle_t xQueue,
const void * pvItemToQueue,
BaseType_t * pxHigherPriorityTaskWoken )

Overwrite the value stored in a length-1 queue from ISR context.

Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdPASS always.

Definition at line 1849 of file freertos_stk.cpp.

1852{
1853 // ISR-safe variant of xQueueOverwrite. Reset() and TryPut() are both
1854 // ISR-safe per the STK MessageQueue contract.
1855 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1856 return pdFAIL;
1857
1858 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1859 q->m_mq.Reset();
1860 q->m_mq.TryPut(pvItemToQueue);
1861 QueueSetNotify(xQueue, q);
1862
1863 if (pxHigherPriorityTaskWoken != nullptr)
1864 *pxHigherPriorityTaskWoken = pdFALSE;
1865
1866 return pdPASS;
1867}

References FrtosQueue::m_mq, pdFAIL, pdFALSE, pdPASS, QueueSetNotify(), stk::sync::MessageQueue::Reset(), and stk::sync::MessageQueue::TryPut().

Here is the call graph for this function:

◆ xQueuePeek()

BaseType_t xQueuePeek ( QueueHandle_t xQueue,
void * pvBuffer,
TickType_t xTicksToWait )

Peek at the front item without removing it (blocking).

Copies the oldest item into pvBuffer without consuming it, so a subsequent xQueueReceive() will return the same item. The operation is fully atomic — backed by stk::sync::MessageQueue::Peek() which holds an internal critical section for the duration of the copy.

Parameters
xTicksToWaitTicks to wait if the queue is empty. portMAX_DELAY waits indefinitely.
Returns
pdTRUE if an item was peeked, pdFALSE on timeout.
Warning
ISR-safe only with xTicksToWait = 0 (portNO_WAIT). Use xQueuePeekFromISR() for non-blocking ISR access.

Definition at line 1767 of file freertos_stk.cpp.

1770{
1771 // Delegates to Peek(), which copies the oldest message without consuming
1772 // it. The operation is fully atomic and preserves queue ordering — no
1773 // Get + Put-back workaround required.
1774 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1775 return pdFAIL;
1776
1777 if (IsIrqContext() && (xTicksToWait != 0U))
1778 return pdFAIL;
1779
1780 return static_cast<FrtosQueue *>(xQueue)->m_mq.Peek(
1781 pvBuffer, FrtosTimeoutToStk(xTicksToWait))
1782 ? pdPASS : pdFAIL;
1783}

References FrtosTimeoutToStk(), IsIrqContext(), pdFAIL, and pdPASS.

Here is the call graph for this function:

◆ xQueuePeekFromISR()

BaseType_t xQueuePeekFromISR ( QueueHandle_t xQueue,
void * pvBuffer )

Peek at the front item from ISR context without removing it (non-blocking).

Copies the oldest item into pvBuffer atomically without consuming it, backed by stk::sync::MessageQueue::TryPeek() which is ISR-safe.

Returns
pdTRUE if an item was available and peeked, pdFALSE if the queue was empty.
Warning
ISR-safe.

Definition at line 1785 of file freertos_stk.cpp.

1787{
1788 // Delegates to TryPeek() (= Peek(NO_WAIT)), which is ISR-safe and copies
1789 // the oldest message atomically without removing it.
1790 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1791 return pdFAIL;
1792
1793 return static_cast<FrtosQueue *>(xQueue)->m_mq.TryPeek(pvBuffer) ? pdPASS : pdFAIL;
1794}

References pdFAIL, and pdPASS.

◆ xQueueReceive()

BaseType_t xQueueReceive ( QueueHandle_t xQueue,
void * pvBuffer,
TickType_t xTicksToWait )

Receive (dequeue) an item from a queue (blocking).

Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1753 of file freertos_stk.cpp.

1756{
1757 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1758 return pdFAIL;
1759
1760 if (IsIrqContext() && (xTicksToWait != 0U))
1761 return pdFAIL;
1762
1763 return static_cast<FrtosQueue *>(xQueue)->m_mq.Get(pvBuffer, FrtosTimeoutToStk(xTicksToWait))
1764 ? pdPASS : pdFAIL;
1765}

References FrtosTimeoutToStk(), IsIrqContext(), pdFAIL, and pdPASS.

Here is the call graph for this function:

◆ xQueueReceiveFromISR()

BaseType_t xQueueReceiveFromISR ( QueueHandle_t xQueue,
void * pvBuffer,
BaseType_t * pxHigherPriorityTaskWoken )

Receive an item from ISR context (non-blocking).

Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if received, pdFALSE if the queue was empty.

Definition at line 1891 of file freertos_stk.cpp.

1894{
1895 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1896 return pdFAIL;
1897
1898 bool ok = static_cast<FrtosQueue *>(xQueue)->m_mq.TryGet(pvBuffer);
1899
1900 if (pxHigherPriorityTaskWoken != nullptr)
1901 *pxHigherPriorityTaskWoken = pdFALSE;
1902
1903 return ok ? pdPASS : pdFAIL;
1904}

References pdFAIL, pdFALSE, and pdPASS.

◆ xQueueRemoveFromSet()

BaseType_t xQueueRemoveFromSet ( QueueSetMemberHandle_t xQueueOrSemaphore,
QueueSetHandle_t xQueueSet )

Unregister a queue or semaphore from a queue set.

The member must be empty at the time it is removed.

Parameters
xQueueOrSemaphoreHandle of the queue or semaphore to remove.
xQueueSetHandle of the queue set it currently belongs to.
Returns
pdPASS on success, pdFAIL if the member does not belong to this set or is not empty.

Definition at line 2135 of file freertos_stk.cpp.

2137{
2138 if ((xQueueOrSemaphore == nullptr) || (xQueueSet == nullptr))
2139 return pdFAIL;
2140
2141 {
2142 const SemKind kind = GetSemKindFromHandle(xQueueOrSemaphore);
2143
2144 if (kind != SemKind::None)
2145 {
2146 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xQueueOrSemaphore);
2147
2148 // API contract: member must belong to this specific set.
2149 STK_ASSERT(s->m_set == static_cast<FrtosQueueSet *>(xQueueSet));
2150 if (s->m_set != static_cast<FrtosQueueSet *>(xQueueSet))
2151 return pdFAIL;
2152
2153 // API contract: semaphore must be empty when removed.
2154 STK_ASSERT(s->m_sem->GetCount() == 0U);
2155 if (s->m_sem->GetCount() != 0U)
2156 return pdFAIL;
2157
2158 s->m_set = nullptr;
2159 }
2160 else
2161 {
2162 FrtosQueue *q = static_cast<FrtosQueue *>(xQueueOrSemaphore);
2163
2164 STK_ASSERT(q->m_set == static_cast<FrtosQueueSet *>(xQueueSet));
2165 if (q->m_set != static_cast<FrtosQueueSet *>(xQueueSet))
2166 return pdFAIL;
2167
2168 // API contract: queue must be empty when removed.
2169 STK_ASSERT(q->m_mq.IsEmpty());
2170 if (!q->m_mq.IsEmpty())
2171 return pdFAIL;
2172
2173 q->m_set = nullptr;
2174 }
2175 }
2176
2177 return pdPASS;
2178}

References stk::sync::Semaphore::GetCount(), GetSemKindFromHandle(), stk::sync::MessageQueue::IsEmpty(), FrtosQueue::m_mq, FrtosSemaphore::m_sem, FrtosQueue::m_set, FrtosSemaphore::m_set, None, pdFAIL, pdPASS, and STK_ASSERT.

Here is the call graph for this function:

◆ xQueueReset()

BaseType_t xQueueReset ( QueueHandle_t xQueue)

Reset a queue to the empty state, discarding all pending items.

Returns
pdPASS.

Definition at line 1824 of file freertos_stk.cpp.

1825{
1826 if (xQueue == nullptr)
1827 return pdFAIL;
1828
1829 static_cast<FrtosQueue *>(xQueue)->m_mq.Reset();
1830 return pdPASS;
1831}

References pdFAIL, and pdPASS.

◆ xQueueSelectFromSet()

QueueSetMemberHandle_t xQueueSelectFromSet ( QueueSetHandle_t xQueueSet,
TickType_t xTicksToWait )

Block until any member of the queue set receives an item, then return the handle of the member that fired.

After xQueueSelectFromSet() returns a non-NULL handle, the caller must call xQueueReceive() or xSemaphoreTake() on that handle to actually consume the item. The set only unblocks once per item deposited; if multiple items arrive before the caller drains them, xQueueSelectFromSet() will return the same member handle multiple times.

Parameters
xQueueSetHandle of the queue set to wait on.
xTicksToWaitMaximum time to wait. portMAX_DELAY = wait forever, 0 = non-blocking poll.
Returns
Handle of the member that has an item available, or NULL on timeout.
Warning
ISR-safe only with xTicksToWait = 0.

Definition at line 2180 of file freertos_stk.cpp.

2182{
2183 if (xQueueSet == nullptr)
2184 return nullptr;
2185
2186 if (IsIrqContext() && (xTicksToWait != 0U))
2187 return nullptr;
2188
2189 FrtosQueueSet *qs = static_cast<FrtosQueueSet *>(xQueueSet);
2190
2191 // Block until a member handle arrives in the token FIFO or timeout fires.
2192 void *handle = nullptr;
2193 if (!qs->m_token_mq->Get(&handle, FrtosTimeoutToStk(xTicksToWait)))
2194 return nullptr; // timeout
2195
2196 return static_cast<QueueSetMemberHandle_t>(handle);
2197}
void * QueueSetMemberHandle_t
Definition FreeRTOS.h:320
stk::sync::MessageQueue * m_token_mq
FIFO of fired-member handles (void*).

References FrtosTimeoutToStk(), stk::sync::MessageQueue::Get(), IsIrqContext(), and FrtosQueueSet::m_token_mq.

Here is the call graph for this function:

◆ xQueueSelectFromSetFromISR()

QueueSetMemberHandle_t xQueueSelectFromSetFromISR ( QueueSetHandle_t xQueueSet)

Non-blocking ISR-safe variant of xQueueSelectFromSet.

Returns immediately with the handle of a ready member, or NULL if no member currently has an item available.

Parameters
xQueueSetHandle of the queue set to poll.
Returns
Handle of a ready member, or NULL if no member is ready.
Note
ISR-safe.

Definition at line 2199 of file freertos_stk.cpp.

2200{
2201 if (xQueueSet == nullptr)
2202 return nullptr;
2203
2204 FrtosQueueSet *qs = static_cast<FrtosQueueSet *>(xQueueSet);
2205
2206 // Non-blocking: TryGet() is ISR-safe per the STK MessageQueue contract.
2207 void *handle = nullptr;
2208 if (!qs->m_token_mq->TryGet(&handle))
2209 return nullptr; // set is empty
2210
2211 return static_cast<QueueSetMemberHandle_t>(handle);
2212}

References FrtosQueueSet::m_token_mq, and stk::sync::MessageQueue::TryGet().

Here is the call graph for this function:

◆ xQueueSend()

BaseType_t xQueueSend ( QueueHandle_t xQueue,
const void * pvItemToQueue,
TickType_t xTicksToWait )

Post an item to the back of a queue (blocking).

Parameters
xTicksToWaitTicks to wait if full. portMAX_DELAY = wait forever.
Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1708 of file freertos_stk.cpp.

1711{
1712 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1713 return pdFAIL;
1714
1715 if (IsIrqContext() && (xTicksToWait != 0U))
1716 return pdFAIL;
1717
1718 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1719
1720 if (!q->m_mq.Put(pvItemToQueue, FrtosTimeoutToStk(xTicksToWait)))
1721 return pdFAIL;
1722
1723 QueueSetNotify(xQueue, q);
1724 return pdPASS;
1725}

References FrtosTimeoutToStk(), IsIrqContext(), FrtosQueue::m_mq, pdFAIL, pdPASS, stk::sync::MessageQueue::Put(), and QueueSetNotify().

Referenced by xQueueSendToBack().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xQueueSendFromISR()

BaseType_t xQueueSendFromISR ( QueueHandle_t xQueue,
const void * pvItemToQueue,
BaseType_t * pxHigherPriorityTaskWoken )

Post an item from ISR context (non-blocking).

Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if posted, pdFALSE if the queue was full.

Definition at line 1869 of file freertos_stk.cpp.

1872{
1873 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1874 return pdFAIL;
1875
1876 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1877 bool ok = q->m_mq.TryPut(pvItemToQueue);
1878
1879 if (ok)
1880 QueueSetNotify(xQueue, q);
1881
1882 // STK handles the wake-up internally; the wrapper does not need to
1883 // request an explicit yield from ISR because SWRR re-evaluates on the
1884 // next tick. Set the flag to pdFALSE to avoid spurious portYIELD_FROM_ISR.
1885 if (pxHigherPriorityTaskWoken != nullptr)
1886 *pxHigherPriorityTaskWoken = pdFALSE;
1887
1888 return ok ? pdPASS : pdFAIL;
1889}

References FrtosQueue::m_mq, pdFAIL, pdFALSE, pdPASS, QueueSetNotify(), and stk::sync::MessageQueue::TryPut().

Referenced by xQueueSendToBackFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xQueueSendToBack()

BaseType_t xQueueSendToBack ( QueueHandle_t xQueue,
const void * pvItemToQueue,
TickType_t xTicksToWait )

Post an item to the back of a queue (alias of xQueueSend).

Definition at line 1727 of file freertos_stk.cpp.

1730{
1731 return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
1732}
BaseType_t xQueueSend(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)

References xQueueSend().

Here is the call graph for this function:

◆ xQueueSendToBackFromISR()

BaseType_t xQueueSendToBackFromISR ( QueueHandle_t xQueue,
const void * pvItemToQueue,
BaseType_t * pxHigherPriorityTaskWoken )

Post an item to the back of a queue from ISR context (non-blocking). Equivalent to xQueueSendFromISR(); provided for source compatibility with code that explicitly names the insertion end.

Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if posted, pdFALSE if the queue was full.

Definition at line 1906 of file freertos_stk.cpp.

1909{
1910 // Send-to-back from ISR is identical to xQueueSendFromISR: TryPut()
1911 // appends to the back of the ring buffer.
1912 return xQueueSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken);
1913}
BaseType_t xQueueSendFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)

References xQueueSendFromISR().

Here is the call graph for this function:

◆ xQueueSendToFront()

BaseType_t xQueueSendToFront ( QueueHandle_t xQueue,
const void * pvItemToQueue,
TickType_t xTicksToWait )

Post an item to the front of a queue (blocking). The item becomes the next item returned by xQueueReceive().

Parameters
xTicksToWaitTicks to wait if full. portMAX_DELAY = wait forever.
Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1734 of file freertos_stk.cpp.

1737{
1738 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1739 return pdFAIL;
1740
1741 if (IsIrqContext() && (xTicksToWait != 0U))
1742 return pdFAIL;
1743
1744 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1745
1746 if (!q->m_mq.PutFront(pvItemToQueue, FrtosTimeoutToStk(xTicksToWait)))
1747 return pdFAIL;
1748
1749 QueueSetNotify(xQueue, q);
1750 return pdPASS;
1751}
bool PutFront(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the front of the queue (LIFO / priority-insert order).

References FrtosTimeoutToStk(), IsIrqContext(), FrtosQueue::m_mq, pdFAIL, pdPASS, stk::sync::MessageQueue::PutFront(), and QueueSetNotify().

Here is the call graph for this function:

◆ xQueueSendToFrontFromISR()

BaseType_t xQueueSendToFrontFromISR ( QueueHandle_t xQueue,
const void * pvItemToQueue,
BaseType_t * pxHigherPriorityTaskWoken )

Post an item to the front of a queue from ISR context (non-blocking).

The item becomes the next item returned by xQueueReceive() / xQueuePeek(). Backed by stk::sync::MessageQueue::TryPutFront() which retreats the tail pointer atomically under an internal critical section.

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
pdTRUE if posted, pdFALSE if the queue was full.
Warning
ISR-safe.

Definition at line 1915 of file freertos_stk.cpp.

1918{
1919 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1920 return pdFAIL;
1921
1922 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1923 bool ok = q->m_mq.TryPutFront(pvItemToQueue);
1924
1925 if (ok)
1926 QueueSetNotify(xQueue, q);
1927
1928 // STK handles the wake-up internally; set the flag to pdFALSE to avoid
1929 // spurious portYIELD_FROM_ISR.
1930 if (pxHigherPriorityTaskWoken != nullptr)
1931 *pxHigherPriorityTaskWoken = pdFALSE;
1932
1933 return ok ? pdPASS : pdFAIL;
1934}

References FrtosQueue::m_mq, pdFAIL, pdFALSE, pdPASS, QueueSetNotify(), and stk::sync::MessageQueue::TryPutFront().

Here is the call graph for this function:

◆ xSemaphoreCreateBinary()

SemaphoreHandle_t xSemaphoreCreateBinary ( void )

Create a binary semaphore (initial count = 0, max = 1).

Returns
Semaphore handle, or NULL on failure.

Definition at line 2220 of file freertos_stk.cpp.

2221{
2222 // Binary semaphore: max count = 1, initial count = 0.
2225 static_cast<uint16_t>(0U),
2226 static_cast<uint16_t>(1U));
2227
2228 if ((s == nullptr) || (s->m_sem == nullptr))
2229 {
2230 ObjFree(s);
2231 return nullptr;
2232 }
2233 return static_cast<SemaphoreHandle_t>(s);
2234}

References Counting, FrtosSemaphore::m_sem, ObjAlloc(), and ObjFree().

Here is the call graph for this function:

◆ xSemaphoreCreateBinaryStatic()

SemaphoreHandle_t xSemaphoreCreateBinaryStatic ( StaticSemaphore_t * pxSemaphoreBuffer)

Create a binary semaphore using caller-supplied storage — no heap allocation.

Parameters
pxSemaphoreBufferCaller-allocated control block (StaticSemaphore_t). Must remain valid for the lifetime of the semaphore.
Returns
Semaphore handle. Never NULL if pxSemaphoreBuffer is non-NULL.

Definition at line 2236 of file freertos_stk.cpp.

2237{
2238 if (pxSemaphoreBuffer == nullptr)
2239 return nullptr;
2240
2241 // Static assert guards against the buffer being too small.
2242 static_assert(sizeof(StaticSemaphore_t) >= sizeof(FrtosSemaphore),
2243 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2244 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2245
2246 // Placement-new the FrtosSemaphore control block into the caller-supplied
2247 // buffer. Binary semaphore: max count = 1, initial count = 0.
2248 // The inner stk::sync::Semaphore is a value type embedded inside
2249 // FrtosSemaphore, so no additional heap allocation is needed.
2250 FrtosSemaphore *s = new (pxSemaphoreBuffer) FrtosSemaphore(
2252 static_cast<uint16_t>(0U),
2253 static_cast<uint16_t>(1U));
2254
2255 if (s->m_sem == nullptr)
2256 {
2257 s->~FrtosSemaphore(); // clean up without freeing
2258 return nullptr;
2259 }
2260
2261 s->m_cb_owned = false; // caller owns the memory; destructor must not delete
2262
2263 return static_cast<SemaphoreHandle_t>(s);
2264}

References Counting, FrtosSemaphore::m_cb_owned, FrtosSemaphore::m_sem, and FrtosSemaphore::~FrtosSemaphore().

Here is the call graph for this function:

◆ xSemaphoreCreateCounting()

SemaphoreHandle_t xSemaphoreCreateCounting ( UBaseType_t uxMaxCount,
UBaseType_t uxInitialCount )

Create a counting semaphore.

Parameters
uxMaxCountMaximum count value.
uxInitialCountInitial count value (must be <= uxMaxCount).
Returns
Semaphore handle, or NULL on failure.

Definition at line 2268 of file freertos_stk.cpp.

2270{
2271 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2272 return nullptr;
2273
2274 if (uxMaxCount > stk::sync::Semaphore::COUNT_MAX)
2276
2279 static_cast<uint16_t>(uxInitialCount),
2280 static_cast<uint16_t>(uxMaxCount));
2281
2282 if ((s == nullptr) || (s->m_sem == nullptr))
2283 {
2284 ObjFree(s);
2285 return nullptr;
2286 }
2287 return static_cast<SemaphoreHandle_t>(s);
2288}
static const uint16_t COUNT_MAX
Max count value supported.

References stk::sync::Semaphore::COUNT_MAX, Counting, FrtosSemaphore::m_sem, ObjAlloc(), and ObjFree().

Here is the call graph for this function:

◆ xSemaphoreCreateCountingStatic()

SemaphoreHandle_t xSemaphoreCreateCountingStatic ( UBaseType_t uxMaxCount,
UBaseType_t uxInitialCount,
StaticSemaphore_t * pxSemaphoreBuffer )

Create a counting semaphore using caller-supplied storage — no heap allocation.

Parameters
uxMaxCountMaximum count value.
uxInitialCountInitial count value (must be <= uxMaxCount).
pxSemaphoreBufferCaller-allocated control block (StaticSemaphore_t). Must remain valid for the lifetime of the semaphore.
Returns
Semaphore handle. Never NULL if pxSemaphoreBuffer is non-NULL and count arguments are valid.

Definition at line 2290 of file freertos_stk.cpp.

2293{
2294 if (pxSemaphoreBuffer == nullptr)
2295 return nullptr;
2296
2297 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2298 return nullptr;
2299
2300 if (uxMaxCount > stk::sync::Semaphore::COUNT_MAX)
2302
2303 static_assert(sizeof(StaticSemaphore_t) >= sizeof(FrtosSemaphore),
2304 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2305 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2306
2307 FrtosSemaphore *s = new (pxSemaphoreBuffer) FrtosSemaphore(
2309 static_cast<uint16_t>(uxInitialCount),
2310 static_cast<uint16_t>(uxMaxCount));
2311
2312 if (s->m_sem == nullptr)
2313 {
2314 s->~FrtosSemaphore();
2315 return nullptr;
2316 }
2317
2318 s->m_cb_owned = false;
2319 return static_cast<SemaphoreHandle_t>(s);
2320}

References stk::sync::Semaphore::COUNT_MAX, Counting, FrtosSemaphore::m_cb_owned, FrtosSemaphore::m_sem, and FrtosSemaphore::~FrtosSemaphore().

Here is the call graph for this function:

◆ xSemaphoreCreateMutex()

SemaphoreHandle_t xSemaphoreCreateMutex ( void )

Create a mutex.

Note
STK Mutex is always recursive; osMutexRecursive is always effective.
Returns
Mutex handle, or NULL on failure.

Definition at line 2326 of file freertos_stk.cpp.

2327{
2330 static_cast<uint16_t>(0U),
2331 static_cast<uint16_t>(1U));
2332
2333 if ((s == nullptr) || (s->m_mtx == nullptr))
2334 {
2335 ObjFree(s);
2336 return nullptr;
2337 }
2338
2339 return static_cast<SemaphoreHandle_t>(s);
2340}

References FrtosSemaphore::m_mtx, Mutex, ObjAlloc(), and ObjFree().

Referenced by xSemaphoreCreateRecursiveMutex().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSemaphoreCreateMutexStatic()

SemaphoreHandle_t xSemaphoreCreateMutexStatic ( StaticSemaphore_t * pxMutexBuffer)

Create a mutex using caller-supplied storage — no heap allocation.

Parameters
pxMutexBufferCaller-allocated control block (StaticSemaphore_t). Must remain valid for the lifetime of the mutex.
Returns
Mutex handle. Never NULL if pxMutexBuffer is non-NULL.

Definition at line 2342 of file freertos_stk.cpp.

2343{
2344 if (pxMutexBuffer == nullptr)
2345 return nullptr;
2346
2347 static_assert(sizeof(StaticSemaphore_t) >= sizeof(FrtosSemaphore),
2348 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2349 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2350
2351 FrtosSemaphore *s = new (pxMutexBuffer) FrtosSemaphore(
2353 static_cast<uint16_t>(0U),
2354 static_cast<uint16_t>(1U));
2355
2356 if (s->m_mtx == nullptr)
2357 {
2358 s->~FrtosSemaphore();
2359 return nullptr;
2360 }
2361
2362 s->m_cb_owned = false;
2363 return static_cast<SemaphoreHandle_t>(s);
2364}

References FrtosSemaphore::m_cb_owned, FrtosSemaphore::m_mtx, Mutex, and FrtosSemaphore::~FrtosSemaphore().

Referenced by xSemaphoreCreateRecursiveMutexStatic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSemaphoreCreateRecursiveMutex()

SemaphoreHandle_t xSemaphoreCreateRecursiveMutex ( void )

Create a recursive mutex (same implementation as xSemaphoreCreateMutex).

Definition at line 2366 of file freertos_stk.cpp.

2367{
2368 // STK Mutex is always recursive.
2369 return xSemaphoreCreateMutex();
2370}
SemaphoreHandle_t xSemaphoreCreateMutex(void)

References xSemaphoreCreateMutex().

Here is the call graph for this function:

◆ xSemaphoreCreateRecursiveMutexStatic()

SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic ( StaticSemaphore_t * pxMutexBuffer)

Create a recursive mutex using caller-supplied storage — no heap allocation.

Parameters
pxMutexBufferCaller-allocated control block (StaticSemaphore_t). Must remain valid for the lifetime of the mutex.
Returns
Mutex handle. Never NULL if pxMutexBuffer is non-NULL.

Definition at line 2372 of file freertos_stk.cpp.

2373{
2374 // STK Mutex is always recursive; identical to xSemaphoreCreateMutexStatic.
2375 return xSemaphoreCreateMutexStatic(pxMutexBuffer);
2376}
SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t *pxMutexBuffer)

References xSemaphoreCreateMutexStatic().

Here is the call graph for this function:

◆ xSemaphoreGetMutexHolder()

TaskHandle_t xSemaphoreGetMutexHolder ( SemaphoreHandle_t xMutex)

Return the handle of the task that currently holds a mutex.

Reads the owner field of the underlying stk::sync::Mutex under a ScopedCriticalSection so the snapshot is consistent even if a concurrent Unlock() is in progress.

Parameters
xMutexHandle of a mutex created by xSemaphoreCreateMutex() or xSemaphoreCreateRecursiveMutex(). Passing a counting or binary semaphore handle always returns NULL.
Returns
Handle of the owning task, or NULL if the mutex is unlocked or xMutex is not a mutex kind.
Warning
Not ISR-safe. Use xSemaphoreGetMutexHolderFromISR() from ISR context.

Definition at line 2520 of file freertos_stk.cpp.

2521{
2522 // Returns the task that currently owns the mutex, or NULL if the mutex
2523 // is unlocked or xMutex is not a mutex-kind semaphore.
2524 //
2525 // FreeRTOS documents this function as not ISR-safe and requiring the
2526 // scheduler to be running. We guard it with a ScopedCriticalSection
2527 // so that the TId snapshot is consistent: if Unlock() is executing
2528 // concurrently, we see either the old owner or TID_NONE, never a torn
2529 // pointer.
2530 //
2531 // TId -> TaskHandle_t: STK stores task pointers as TId values via
2532 // TId = static_cast<TId>(reinterpret_cast<uintptr_t>(task_ptr))
2533 // so the inverse is:
2534 // task_ptr = reinterpret_cast<FrtosTask *>(static_cast<uintptr_t>(tid))
2535 // TID_NONE maps to nullptr (TaskHandle_t == nullptr means "no owner").
2536 if (xMutex == nullptr)
2537 return nullptr;
2538
2539 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xMutex);
2540
2541 if (s->m_kind != SemKind::Mutex)
2542 return nullptr; // not a mutex — owner concept does not apply
2543
2545
2546 const stk::TId owner = s->m_mtx->GetOwner();
2547
2548 if (owner == stk::TID_NONE)
2549 return nullptr; // mutex is currently unlocked
2550
2551 return reinterpret_cast<TaskHandle_t>(static_cast<uintptr_t>(owner));
2552}
Word TId
Definition stk_common.h:120

References stk::sync::Mutex::GetOwner(), FrtosSemaphore::m_kind, FrtosSemaphore::m_mtx, Mutex, and stk::TID_NONE.

Referenced by xQueueGetMutexHolder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSemaphoreGetMutexHolderFromISR()

TaskHandle_t xSemaphoreGetMutexHolderFromISR ( SemaphoreHandle_t xMutex)

Return the handle of the task that currently holds a mutex (ISR-safe).

Reads the owner field of the underlying stk::sync::Mutex with a single pointer-sized load, which is naturally atomic on all supported STK architectures (Cortex-M and equivalents). No additional critical section is acquired beyond what the caller already holds.

Parameters
xMutexHandle of a mutex. Passing a non-mutex semaphore returns NULL.
Returns
Handle of the owning task, or NULL if the mutex is unlocked or xMutex is not a mutex kind.
Warning
ISR-safe.

Definition at line 2554 of file freertos_stk.cpp.

2555{
2556 // ISR-safe variant. GetOwner() reads a single TId (pointer-sized, aligned)
2557 // which is an atomic read on all supported STK architectures, so no
2558 // ScopedCriticalSection is needed here beyond what the caller already holds.
2559 // We still validate the handle and the semaphore kind before touching the
2560 // mutex state.
2561 if (xMutex == nullptr)
2562 return nullptr;
2563
2564 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xMutex);
2565
2566 if (s->m_kind != SemKind::Mutex)
2567 return nullptr;
2568
2569 const stk::TId owner = s->m_mtx->GetOwner();
2570
2571 if (owner == stk::TID_NONE)
2572 return nullptr;
2573
2574 return reinterpret_cast<TaskHandle_t>(static_cast<uintptr_t>(owner));
2575}

References stk::sync::Mutex::GetOwner(), FrtosSemaphore::m_kind, FrtosSemaphore::m_mtx, Mutex, and stk::TID_NONE.

Referenced by xQueueGetMutexHolderFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSemaphoreGive()

BaseType_t xSemaphoreGive ( SemaphoreHandle_t xSemaphore)

Give (release) a semaphore or mutex.

Returns
pdTRUE on success, pdFALSE if max count would be exceeded.

Definition at line 2442 of file freertos_stk.cpp.

2443{
2444 if (xSemaphore == nullptr)
2445 return pdFAIL;
2446
2447 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2448
2449 if (s->m_kind == SemKind::Mutex)
2450 {
2451#if configUSE_MUTEXES
2452 s->m_mtx->Unlock();
2453 // Mutexes are not eligible for queue sets (FreeRTOS API contract),
2454 // so no QueueSetNotify call is needed here.
2455 return pdPASS;
2456#else
2457 return pdFAIL;
2458#endif
2459 }
2460 else
2461 {
2462 // Guard against overflow: TryWait + Signal pattern.
2464 return pdFAIL;
2465
2466 s->m_sem->Signal();
2467 QueueSetNotify(xSemaphore, s);
2468 return pdPASS;
2469 }
2470}
void Unlock() override
Release lock.
void Signal()
Post a signal (increment counter).

References stk::sync::Semaphore::COUNT_MAX, stk::sync::Semaphore::GetCount(), FrtosSemaphore::m_kind, FrtosSemaphore::m_mtx, FrtosSemaphore::m_sem, Mutex, pdFAIL, pdPASS, QueueSetNotify(), stk::sync::Semaphore::Signal(), and stk::sync::Mutex::Unlock().

Referenced by xSemaphoreGiveRecursive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSemaphoreGiveFromISR()

BaseType_t xSemaphoreGiveFromISR ( SemaphoreHandle_t xSemaphore,
BaseType_t * pxHigherPriorityTaskWoken )

Give a binary or counting semaphore from ISR context.

Note
Mutex give from ISR is not permitted and returns pdFALSE.
Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE on success, pdFALSE on error or max-count overflow.

Definition at line 2477 of file freertos_stk.cpp.

2479{
2480 if (xSemaphore == nullptr)
2481 return pdFAIL;
2482
2483 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2484
2485 if (s->m_kind == SemKind::Mutex)
2486 return pdFAIL; // Mutex give from ISR is not permitted.
2487
2489 return pdFAIL;
2490
2491 s->m_sem->Signal();
2492 QueueSetNotify(xSemaphore, s);
2493
2494 if (pxHigherPriorityTaskWoken != nullptr)
2495 *pxHigherPriorityTaskWoken = pdFALSE;
2496
2497 return pdPASS;
2498}

References stk::sync::Semaphore::COUNT_MAX, stk::sync::Semaphore::GetCount(), FrtosSemaphore::m_kind, FrtosSemaphore::m_sem, Mutex, pdFAIL, pdFALSE, pdPASS, QueueSetNotify(), and stk::sync::Semaphore::Signal().

Here is the call graph for this function:

◆ xSemaphoreGiveRecursive()

BaseType_t xSemaphoreGiveRecursive ( SemaphoreHandle_t xMutex)

Give a recursive mutex.

Definition at line 2472 of file freertos_stk.cpp.

2473{
2474 return xSemaphoreGive(xMutex);
2475}
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore)

References xSemaphoreGive().

Here is the call graph for this function:

◆ xSemaphoreTake()

BaseType_t xSemaphoreTake ( SemaphoreHandle_t xSemaphore,
TickType_t xTicksToWait )

Take (acquire) a semaphore or mutex (blocking).

Parameters
xTicksToWaitTicks to wait. portMAX_DELAY = wait forever.
Returns
pdTRUE if acquired, pdFALSE on timeout.

Definition at line 2388 of file freertos_stk.cpp.

2389{
2390 if (xSemaphore == nullptr)
2391 return pdFAIL;
2392
2393 if (IsIrqContext() && (xTicksToWait != 0U))
2394 return pdFAIL;
2395
2396 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2397 stk::Timeout tmo = FrtosTimeoutToStk(xTicksToWait);
2398
2399 if (s->m_kind == SemKind::Mutex)
2400 {
2401#if configUSE_MUTEXES
2402 return s->m_mtx->TimedLock(tmo) ? pdPASS : pdFAIL;
2403#else
2404 return pdFAIL;
2405#endif
2406 }
2407 else
2408 return s->m_sem->Wait(tmo) ? pdPASS : pdFAIL;
2409}
bool TimedLock(Timeout timeout_ticks)
Acquire lock.

References FrtosTimeoutToStk(), IsIrqContext(), FrtosSemaphore::m_kind, FrtosSemaphore::m_mtx, FrtosSemaphore::m_sem, Mutex, pdFAIL, pdPASS, stk::sync::Mutex::TimedLock(), and stk::sync::Semaphore::Wait().

Referenced by xSemaphoreTakeRecursive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xSemaphoreTakeFromISR()

BaseType_t xSemaphoreTakeFromISR ( SemaphoreHandle_t xSemaphore,
BaseType_t * pxHigherPriorityTaskWoken )

Take (acquire) a binary or counting semaphore from ISR context (non-blocking).

Note
Mutex take from ISR is not permitted and returns pdFALSE.
Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if acquired, pdFALSE if the count was zero.

Definition at line 2411 of file freertos_stk.cpp.

2413{
2414 if (xSemaphore == nullptr)
2415 return pdFAIL;
2416
2417 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2418
2419 // Mutex take from ISR is not permitted — mirrors xSemaphoreGiveFromISR.
2420 if (s->m_kind == SemKind::Mutex)
2421 return pdFAIL;
2422
2423 // TryWait() is Wait(NO_WAIT): decrement count if > 0, return immediately.
2424 // ISR-safe per the STK Semaphore contract.
2425 bool ok = s->m_sem->TryWait();
2426
2427 // STK handles priority re-evaluation internally on the next tick.
2428 // Set pdFALSE to avoid spurious portYIELD_FROM_ISR, matching the
2429 // pattern used by xQueueReceiveFromISR and xSemaphoreGiveFromISR.
2430 if (pxHigherPriorityTaskWoken != nullptr)
2431 *pxHigherPriorityTaskWoken = pdFALSE;
2432
2433 return ok ? pdPASS : pdFAIL;
2434}
bool TryWait()
Poll the semaphore without blocking (decrement counter if available).

References FrtosSemaphore::m_kind, FrtosSemaphore::m_sem, Mutex, pdFAIL, pdFALSE, pdPASS, and stk::sync::Semaphore::TryWait().

Here is the call graph for this function:

◆ xSemaphoreTakeRecursive()

BaseType_t xSemaphoreTakeRecursive ( SemaphoreHandle_t xMutex,
TickType_t xTicksToWait )

Take a recursive mutex (blocking).

Definition at line 2436 of file freertos_stk.cpp.

2437{
2438 // STK Mutex is always recursive; identical to xSemaphoreTake.
2439 return xSemaphoreTake(xMutex, xTicksToWait);
2440}
BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait)

References xSemaphoreTake().

Here is the call graph for this function:

◆ xStreamBufferBytesAvailable()

size_t xStreamBufferBytesAvailable ( StreamBufferHandle_t xStreamBuffer)

Return the number of bytes currently available to read.

Definition at line 3880 of file freertos_stk.cpp.

3881{
3882 if (xStreamBuffer == nullptr)
3883 return 0U;
3884
3885 return static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.GetCount();
3886}

Referenced by xStreamBufferIsEmpty(), and xStreamBufferNextMessageLengthBytes().

Here is the caller graph for this function:

◆ xStreamBufferCreate()

StreamBufferHandle_t xStreamBufferCreate ( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes )

Create a dynamically allocated stream buffer.

Parameters
xBufferSizeBytesTotal byte capacity of the ring buffer.
xTriggerLevelBytesMinimum bytes that must be present before a blocking Receive() wakes (1 = wake on any byte).
Returns
Handle, or NULL on allocation failure.

Definition at line 3708 of file freertos_stk.cpp.

3710{
3711 if (xBufferSizeBytes == 0U)
3712 return nullptr;
3713
3714 uint8_t *buf = ObjAllocArray<uint8_t>(xBufferSizeBytes);
3715 if (buf == nullptr)
3716 return nullptr;
3717
3718 FrtosStreamBuffer *sb = ObjAlloc<FrtosStreamBuffer>(buf, xBufferSizeBytes, xTriggerLevelBytes);
3719 if (sb == nullptr)
3720 {
3721 ObjFreeArray(buf);
3722 return nullptr;
3723 }
3724
3725 sb->m_buf_owned = true;
3726 sb->m_cb_owned = true;
3727
3728 return static_cast<StreamBufferHandle_t>(sb);
3729}
static void ObjFreeArray(void *ptr)
static T * ObjAllocArray(size_t count)
bool m_cb_owned
true -> struct heap-allocated, deleted in vStreamBufferDelete
bool m_buf_owned
true -> data buffer heap-allocated, freed in dtor

References FrtosStreamBuffer::m_buf_owned, FrtosStreamBuffer::m_cb_owned, ObjAlloc(), ObjAllocArray(), and ObjFreeArray().

Here is the call graph for this function:

◆ xStreamBufferCreateStatic()

StreamBufferHandle_t xStreamBufferCreateStatic ( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
uint8_t * pucStreamBufferStorageArea,
StaticStreamBuffer_t * pxStaticStreamBuffer )

Create a statically allocated stream buffer (no heap).

Parameters
xBufferSizeBytesTotal byte capacity.
xTriggerLevelBytesMinimum bytes for Receive() to unblock.
pucStreamBufferStorageAreaCaller-supplied data buffer of at least xBufferSizeBytes bytes.
pxStaticStreamBufferCaller-supplied TCB (StaticStreamBuffer_t).
Returns
Handle (always non-NULL if arguments are non-NULL).

Definition at line 3731 of file freertos_stk.cpp.

3736{
3737 if ((pucStreamBufferStorageArea == nullptr) ||
3738 (pxStaticStreamBuffer == nullptr) ||
3739 (xBufferSizeBytes == 0U))
3740 return nullptr;
3741
3742 static_assert(sizeof(StaticStreamBuffer_t) >= sizeof(FrtosStreamBuffer),
3743 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3744
3745 FrtosStreamBuffer *sb = new (pxStaticStreamBuffer)
3746 FrtosStreamBuffer(pucStreamBufferStorageArea,
3747 xBufferSizeBytes,
3748 xTriggerLevelBytes);
3749
3750 // m_buf_owned = false, m_cb_owned = false already set by the ctor
3751 return static_cast<StreamBufferHandle_t>(sb);
3752}

◆ xStreamBufferCreateStaticWithCallback()

StreamBufferHandle_t xStreamBufferCreateStaticWithCallback ( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
uint8_t * pucStreamBufferStorageArea,
StaticStreamBuffer_t * pxStaticStreamBuffer,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )

Create a statically-allocated stream buffer with optional send/receive callbacks.

Identical to xStreamBufferCreateStatic() but registers per-instance callbacks. Either callback may be NULL.

Parameters
xBufferSizeBytesCapacity of the data buffer in bytes.
xTriggerLevelBytesMinimum bytes before Receive() unblocks.
pucStreamBufferStorageAreaCaller-supplied data buffer (>= xBufferSizeBytes bytes).
pxStaticStreamBufferCaller-supplied TCB (StaticStreamBuffer_t).
pxSendCompletedCallbackCalled after bytes are written (or NULL).
pxReceiveCompletedCallbackCalled after bytes are read (or NULL).
Returns
Handle, or NULL on invalid arguments.

Definition at line 4020 of file freertos_stk.cpp.

4027{
4028 if ((pucStreamBufferStorageArea == nullptr) ||
4029 (pxStaticStreamBuffer == nullptr) ||
4030 (xBufferSizeBytes == 0U))
4031 return nullptr;
4032
4033 static_assert(sizeof(StaticStreamBuffer_t) >= sizeof(FrtosStreamBuffer),
4034 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4035
4036 FrtosStreamBuffer *sb = new (pxStaticStreamBuffer)
4037 FrtosStreamBuffer(pucStreamBufferStorageArea,
4038 xBufferSizeBytes,
4039 xTriggerLevelBytes,
4040 pxSendCompletedCallback,
4041 pxReceiveCompletedCallback);
4042 // m_buf_owned = false, m_cb_owned = false already set by ctor
4043 return static_cast<StreamBufferHandle_t>(sb);
4044}

◆ xStreamBufferCreateWithCallback()

StreamBufferHandle_t xStreamBufferCreateWithCallback ( size_t xBufferSizeBytes,
size_t xTriggerLevelBytes,
StreamBufferCallbackFunction_t pxSendCompletedCallback,
StreamBufferCallbackFunction_t pxReceiveCompletedCallback )

Create a heap-allocated stream buffer with optional send/receive callbacks.

Identical to xStreamBufferCreate() but registers per-instance callbacks invoked after data is successfully written (pxSendCompletedCallback) or read (pxReceiveCompletedCallback). Either callback may be NULL. Callbacks fire outside any critical section, after the transfer completes.

Parameters
xBufferSizeBytesCapacity of the data buffer in bytes.
xTriggerLevelBytesMinimum bytes before Receive() unblocks.
pxSendCompletedCallbackCalled after bytes are written (or NULL).
pxReceiveCompletedCallbackCalled after bytes are read (or NULL).
Returns
Handle, or NULL on allocation failure.

Definition at line 3988 of file freertos_stk.cpp.

3993{
3994 if (xBufferSizeBytes == 0U)
3995 return nullptr;
3996
3997 uint8_t *buf = ObjAllocArray<uint8_t>(xBufferSizeBytes);
3998 if (buf == nullptr)
3999 return nullptr;
4000
4002 buf,
4003 xBufferSizeBytes,
4004 xTriggerLevelBytes,
4005 pxSendCompletedCallback,
4006 pxReceiveCompletedCallback);
4007
4008 if (sb == nullptr)
4009 {
4010 ObjFreeArray(buf);
4011 return nullptr;
4012 }
4013
4014 sb->m_buf_owned = true;
4015 sb->m_cb_owned = true;
4016
4017 return static_cast<StreamBufferHandle_t>(sb);
4018}

References FrtosStreamBuffer::m_buf_owned, FrtosStreamBuffer::m_cb_owned, ObjAlloc(), ObjAllocArray(), and ObjFreeArray().

Here is the call graph for this function:

◆ xStreamBufferGetTriggerLevel()

size_t xStreamBufferGetTriggerLevel ( StreamBufferHandle_t xStreamBuffer)

Return the trigger level currently set on a stream buffer.

Parameters
xStreamBufferHandle returned by xStreamBufferCreate[Static][WithCallback]().
Returns
Current trigger level in bytes (always >= 1), or 0 if handle is NULL.
Note
ISR-safe.

Definition at line 3946 of file freertos_stk.cpp.

3947{
3948 if (xStreamBuffer == nullptr)
3949 return 0U;
3950
3951 // m_trigger is a plain size_t written only under ScopedCriticalSection
3952 // (in xStreamBufferSetTriggerLevel). A size_t-aligned read is atomic on
3953 // all Cortex-M targets — same rationale as Pipe::GetCount().
3954 return static_cast<const FrtosStreamBuffer *>(xStreamBuffer)->m_trigger;
3955}

◆ xStreamBufferIsEmpty()

BaseType_t xStreamBufferIsEmpty ( StreamBufferHandle_t xStreamBuffer)

Return pdTRUE if the stream buffer contains no data.

Definition at line 3896 of file freertos_stk.cpp.

3897{
3898 return (xStreamBufferBytesAvailable(xStreamBuffer) == 0U) ? pdTRUE : pdFALSE;
3899}
size_t xStreamBufferBytesAvailable(StreamBufferHandle_t xStreamBuffer)
Return the number of bytes currently available to read.

References pdFALSE, pdTRUE, and xStreamBufferBytesAvailable().

Here is the call graph for this function:

◆ xStreamBufferIsFull()

BaseType_t xStreamBufferIsFull ( StreamBufferHandle_t xStreamBuffer)

Return pdTRUE if the stream buffer is full (no write space remaining).

Definition at line 3901 of file freertos_stk.cpp.

3902{
3903 return (xStreamBufferSpacesAvailable(xStreamBuffer) == 0U) ? pdTRUE : pdFALSE;
3904}
size_t xStreamBufferSpacesAvailable(StreamBufferHandle_t xStreamBuffer)
Return the number of free bytes available for writing.

References pdFALSE, pdTRUE, and xStreamBufferSpacesAvailable().

Here is the call graph for this function:

◆ xStreamBufferNextMessageLengthBytes()

size_t xStreamBufferNextMessageLengthBytes ( StreamBufferHandle_t xStreamBuffer)

Return the number of bytes available to read from a stream buffer without blocking.

For a stream buffer (pure unframed byte stream) this is equivalent to xStreamBufferBytesAvailable(): the entire readable span is the "next message" because stream buffers carry no length-prefix framing. The function is provided for source compatibility with code written against the FreeRTOS stream/message buffer API where both buffer kinds are used interchangeably.

Parameters
xStreamBufferHandle returned by xStreamBufferCreate[Static][WithCallback]().
Returns
Number of bytes currently available to read (0 if empty or handle is NULL).
Note
ISR-safe (delegates to Pipe::GetCount() which is ISR-safe on targets where a size_t-aligned read is atomic).

Definition at line 3972 of file freertos_stk.cpp.

3973{
3974 // Delegates to xStreamBufferBytesAvailable() which performs the NULL guard
3975 // and returns Pipe::GetCount() — ISR-safe on all supported targets.
3976 return xStreamBufferBytesAvailable(xStreamBuffer);
3977}

References xStreamBufferBytesAvailable().

Here is the call graph for this function:

◆ xStreamBufferReceive()

size_t xStreamBufferReceive ( StreamBufferHandle_t xStreamBuffer,
void * pvRxData,
size_t xBufferLengthBytes,
TickType_t xTicksToWait )

Read bytes from the stream buffer, blocking until trigger level is reached.

Parameters
xStreamBufferHandle.
pvRxDataDestination buffer.
xBufferLengthBytesMaximum bytes to read.
xTicksToWaitTicks to block until at least trigger bytes are available.
Returns
Number of bytes actually read (0 on timeout or empty buffer).

Definition at line 3817 of file freertos_stk.cpp.

3821{
3822 if ((xStreamBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
3823 return 0U;
3824
3825 if (IsIrqContext() && (xTicksToWait != 0U))
3826 return 0U;
3827
3828 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3829
3830 // ReadBulkTriggered handles all cases in one call:
3831 // - NO_WAIT (xTicksToWait == 0): trigger not enforced, returns whatever
3832 // is available immediately (guaranteed by CV NO_WAIT fast-path).
3833 // - Blocking with trigger: waits until m_trigger bytes are present, then
3834 // drains up to xBufferLengthBytes in one atomic CS pass.
3835 // - Timeout before trigger: drains whatever arrived, possibly 0.
3836 const size_t total = sb->m_pipe.ReadBulkTriggered(
3837 static_cast<uint8_t *>(pvRxData),
3838 sb->m_trigger,
3839 xBufferLengthBytes,
3840 FrtosTimeoutToStk(xTicksToWait));
3841
3842 // Fire receive-complete callback outside any critical section.
3843 if ((total > 0U) && (sb->m_recv_cb != nullptr))
3844 {
3845 BaseType_t woken = pdFALSE;
3846 sb->m_recv_cb(xStreamBuffer, &woken);
3847 }
3848
3849 return total;
3850}
size_t ReadBulkTriggered(void *dst, size_t trigger, size_t max_count, Timeout timeout_ticks=WAIT_INFINITE)
Read at least trigger elements, then drain up to max_count without blocking.
stk::sync::Pipe m_pipe
byte ring-buffer (element_size = 1)
StreamBufferCallbackFunction_t m_recv_cb
optional callback fired after a successful Receive
size_t m_trigger
minimum bytes before Receive() unblocks

References FrtosTimeoutToStk(), IsIrqContext(), FrtosStreamBuffer::m_pipe, FrtosStreamBuffer::m_recv_cb, FrtosStreamBuffer::m_trigger, pdFALSE, and stk::sync::Pipe::ReadBulkTriggered().

Here is the call graph for this function:

◆ xStreamBufferReceiveFromISR()

size_t xStreamBufferReceiveFromISR ( StreamBufferHandle_t xStreamBuffer,
void * pvRxData,
size_t xBufferLengthBytes,
BaseType_t * pxHigherPriorityTaskWoken )

Read bytes from ISR context (non-blocking, NO_WAIT).

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
Number of bytes actually read.

Definition at line 3852 of file freertos_stk.cpp.

3856{
3857 if (pxHigherPriorityTaskWoken != nullptr)
3858 *pxHigherPriorityTaskWoken = pdFALSE;
3859
3860 if ((xStreamBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
3861 return 0U;
3862
3863 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3864
3865 const size_t received = sb->m_pipe.TryReadBulk(
3866 static_cast<uint8_t *>(pvRxData),
3867 xBufferLengthBytes);
3868
3869 // Fire receive-complete callback outside any critical section.
3870 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
3871 if ((received > 0U) && (sb->m_recv_cb != nullptr))
3872 {
3873 BaseType_t woken = pdFALSE;
3874 sb->m_recv_cb(xStreamBuffer, &woken);
3875 }
3876
3877 return received;
3878}
size_t TryReadBulk(void *dst, size_t count)
Attempt to read multiple elements from the pipe without blocking.

References FrtosStreamBuffer::m_pipe, FrtosStreamBuffer::m_recv_cb, pdFALSE, and stk::sync::Pipe::TryReadBulk().

Here is the call graph for this function:

◆ xStreamBufferReset()

BaseType_t xStreamBufferReset ( StreamBufferHandle_t xStreamBuffer)

Discard all data and reset the stream buffer to the empty state.

Returns
pdPASS always.

Definition at line 3906 of file freertos_stk.cpp.

3907{
3908 if (xStreamBuffer == nullptr)
3909 return pdFAIL;
3910
3911 static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.Reset();
3912 return pdPASS;
3913}

References pdFAIL, and pdPASS.

◆ xStreamBufferResetFromISR()

BaseType_t xStreamBufferResetFromISR ( StreamBufferHandle_t xStreamBuffer,
BaseType_t * pxHigherPriorityTaskWoken )

Reset a stream buffer to empty from ISR context.

Delegates to Pipe::Reset() which holds a ScopedCriticalSection internally. Data in the buffer is discarded; tasks blocked in xStreamBufferSend() that were waiting for space are woken.

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
pdPASS on success, pdFAIL if the handle is NULL.
Note
ISR-safe.

Definition at line 3932 of file freertos_stk.cpp.

3934{
3935 if (pxHigherPriorityTaskWoken != nullptr)
3936 *pxHigherPriorityTaskWoken = pdFALSE;
3937
3938 if (xStreamBuffer == nullptr)
3939 return pdFAIL;
3940
3941 // Pipe::Reset() acquires ScopedCriticalSection internally — ISR-safe.
3942 static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.Reset();
3943 return pdPASS;
3944}

References pdFAIL, pdFALSE, and pdPASS.

◆ xStreamBufferSend()

size_t xStreamBufferSend ( StreamBufferHandle_t xStreamBuffer,
const void * pvTxData,
size_t xDataLengthBytes,
TickType_t xTicksToWait )

Write bytes into the stream buffer.

Parameters
xStreamBufferHandle.
pvTxDataPointer to source data.
xDataLengthBytesNumber of bytes to write.
xTicksToWaitTicks to wait for space (0 = non-blocking).
Returns
Number of bytes actually written (may be less than requested on timeout).

Definition at line 3764 of file freertos_stk.cpp.

3768{
3769 if ((xStreamBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
3770 return 0U;
3771
3772 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3773
3774 const size_t sent = sb->m_pipe.WriteBulk(
3775 static_cast<const uint8_t *>(pvTxData),
3776 xDataLengthBytes,
3777 FrtosTimeoutToStk(xTicksToWait));
3778
3779 // Fire send-complete callback outside any critical section.
3780 if ((sent > 0U) && (sb->m_send_cb != nullptr))
3781 {
3782 BaseType_t woken = pdFALSE;
3783 sb->m_send_cb(xStreamBuffer, &woken);
3784 }
3785
3786 return sent;
3787}
size_t WriteBulk(const void *src, size_t count, Timeout timeout_ticks=WAIT_INFINITE)
Write multiple elements to the pipe.
StreamBufferCallbackFunction_t m_send_cb
optional callback fired after a successful Send

References FrtosTimeoutToStk(), FrtosStreamBuffer::m_pipe, FrtosStreamBuffer::m_send_cb, pdFALSE, and stk::sync::Pipe::WriteBulk().

Here is the call graph for this function:

◆ xStreamBufferSendFromISR()

size_t xStreamBufferSendFromISR ( StreamBufferHandle_t xStreamBuffer,
const void * pvTxData,
size_t xDataLengthBytes,
BaseType_t * pxHigherPriorityTaskWoken )

Write bytes from ISR context (non-blocking, NO_WAIT).

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK handles scheduling).
Returns
Number of bytes actually written.

Definition at line 3789 of file freertos_stk.cpp.

3793{
3794 if (pxHigherPriorityTaskWoken != nullptr)
3795 *pxHigherPriorityTaskWoken = pdFALSE;
3796
3797 if ((xStreamBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
3798 return 0U;
3799
3800 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3801
3802 const size_t sent = sb->m_pipe.TryWriteBulk(
3803 static_cast<const uint8_t *>(pvTxData),
3804 xDataLengthBytes);
3805
3806 // Fire send-complete callback outside any critical section.
3807 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
3808 if ((sent > 0U) && (sb->m_send_cb != nullptr))
3809 {
3810 BaseType_t woken = pdFALSE;
3811 sb->m_send_cb(xStreamBuffer, &woken);
3812 }
3813
3814 return sent;
3815}
size_t TryWriteBulk(const void *src, size_t count)
Attempt to write multiple elements to the pipe without blocking.

References FrtosStreamBuffer::m_pipe, FrtosStreamBuffer::m_send_cb, pdFALSE, and stk::sync::Pipe::TryWriteBulk().

Here is the call graph for this function:

◆ xStreamBufferSetTriggerLevel()

BaseType_t xStreamBufferSetTriggerLevel ( StreamBufferHandle_t xStreamBuffer,
size_t xTriggerLevelBytes )

Change the trigger level for a stream buffer.

Parameters
xTriggerLevelBytesNew minimum bytes for Receive() to unblock (>= 1).
Returns
pdTRUE on success, pdFALSE if xTriggerLevelBytes > buffer capacity.

Definition at line 3915 of file freertos_stk.cpp.

3917{
3918 if (xStreamBuffer == nullptr)
3919 return pdFALSE;
3920
3921 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3922
3923 if (xTriggerLevelBytes > sb->m_pipe.GetCapacity())
3924 return pdFALSE;
3925
3927 sb->m_trigger = (xTriggerLevelBytes >= 1U ? xTriggerLevelBytes : 1U);
3928
3929 return pdTRUE;
3930}
size_t GetCapacity() const
Get the maximum number of elements the pipe can hold.

References stk::sync::Pipe::GetCapacity(), FrtosStreamBuffer::m_pipe, FrtosStreamBuffer::m_trigger, pdFALSE, and pdTRUE.

Here is the call graph for this function:

◆ xStreamBufferSpacesAvailable()

size_t xStreamBufferSpacesAvailable ( StreamBufferHandle_t xStreamBuffer)

Return the number of free bytes available for writing.

Definition at line 3888 of file freertos_stk.cpp.

3889{
3890 if (xStreamBuffer == nullptr)
3891 return 0U;
3892
3893 return static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.GetSpace();
3894}

Referenced by xStreamBufferIsFull().

Here is the caller graph for this function:

◆ xTaskAbortDelay()

BaseType_t xTaskAbortDelay ( TaskHandle_t xTask)

Abort a delay that the target task is currently blocked in (vTaskDelay, vTaskDelayUntil, or any timed sync primitive wait). The task is made immediately runnable; its next Wait/Sleep will not be affected.

Returns
pdPASS if the task was in a delayed state and the abort was issued, pdFAIL if the task was not delayed.
Note
ISR-safe (delegates to stk::AbortSleep which is ISR-safe).

Definition at line 1257 of file freertos_stk.cpp.

1258{
1259 if (xTask == nullptr)
1260 return pdFALSE;
1261
1262 // Resolve NULL -> calling task (same convention used throughout the wrapper).
1263 const stk::TId tid = static_cast<stk::TId>(reinterpret_cast<uintptr_t>(xTask));
1264
1265 const FrtosTask *t = static_cast<const FrtosTask *>(xTask);
1267 return pdFAIL; // suspended or otherwise not in a delay-able state
1268
1269 stk::SleepCancel(tid);
1270 return pdPASS;
1271}
void SleepCancel(TId task_id)
Cancel sleep of the task.
Definition stk_helper.h:377

References FrtosTask::m_state, pdFAIL, pdFALSE, pdPASS, FrtosTask::Ready, and stk::SleepCancel().

Here is the call graph for this function:

◆ xTaskCreate()

BaseType_t xTaskCreate ( TaskFunction_t pvTaskCode,
const char * pcName,
uint32_t usStackDepth,
void * pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * pxCreatedTask )

Create a new dynamic task.

Parameters
pvTaskCodeTask function pointer.
pcNameDescriptive name for debugging.
usStackDepthStack depth in Words (not bytes).
pvParametersArgument passed to pvTaskCode.
uxPriorityPriority: 0 = lowest, configMAX_PRIORITIES-1 = highest.
pxCreatedTaskOptional: receives the handle of the created task.
Returns
pdPASS on success, pdFAIL if the task could not be created.

Definition at line 1106 of file freertos_stk.cpp.

1112{
1113 if (pvTaskCode == nullptr)
1114 return pdFAIL;
1115
1117 if (t == nullptr)
1118 return pdFAIL;
1119
1120 t->m_func = pvTaskCode;
1121 t->m_argument = pvParameters;
1122 t->m_name = pcName;
1123 t->m_weight = FrtosPrioToStkWeight(uxPriority);
1124
1125 // Determine stack size in Words.
1126 size_t stack_words = (usStackDepth > 0U)
1127 ? static_cast<size_t>(usStackDepth)
1129
1130 if (stack_words < FREERTOS_STK_MIN_STACK_WORDS)
1131 stack_words = FREERTOS_STK_MIN_STACK_WORDS;
1132
1133 t->m_stack = ObjAllocArray<stk::Word>(stack_words);
1134 if (t->m_stack == nullptr)
1135 {
1136 ObjFree(t);
1137 return pdFAIL;
1138 }
1139
1140 t->m_stack_size = stack_words;
1141 t->m_stack_owned = true;
1142
1144
1145 g_StkKernel.AddTask(t);
1146
1147 if (pxCreatedTask != nullptr)
1148 *pxCreatedTask = static_cast<TaskHandle_t>(t);
1149
1150 return pdPASS;
1151}
#define FREERTOS_STK_MIN_STACK_WORDS
#define FREERTOS_STK_DEFAULT_STACK_WORDS
Default stack depth in Words when the caller passes usStackDepth = 0.
Definition FreeRTOS.h:215
TaskFunction_t m_func
size_t m_stack_size
void * m_argument

References EnsureKernelInitialized(), FREERTOS_STK_DEFAULT_STACK_WORDS, FREERTOS_STK_MIN_STACK_WORDS, FrtosPrioToStkWeight(), g_StkKernel, FrtosTask::m_argument, FrtosTask::m_func, FrtosTask::m_name, FrtosTask::m_stack, FrtosTask::m_stack_owned, FrtosTask::m_stack_size, FrtosTask::m_weight, ObjAlloc(), ObjAllocArray(), ObjFree(), pdFAIL, and pdPASS.

Referenced by xTaskCreateRestricted().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskCreateRestricted()

BaseType_t xTaskCreateRestricted ( const TaskParameters_restricted_t * pxTaskDefinition,
TaskHandle_t * pxCreatedTask )

Create a task with optional MPU region descriptors, allocating the TCB and stack from the heap (source-compatible with the FreeRTOS heap variant of xTaskCreateRestricted).

Note
STK does not implement MPU support. This function extracts pvTaskCode, usStackDepth, pvParameters, and uxPriority from pxTaskDefinition and delegates to xTaskCreate(), silently ignoring puxStackBuffer (a heap stack is allocated instead) and the xRegions table. When STK gains MPU support the implementation will be extended to program the region descriptors.
Parameters
pxTaskDefinitionPointer to a TaskParameters_restricted_t descriptor. Must not be NULL.
pxCreatedTaskOptional: receives the handle of the created task.
Returns
pdPASS on success, pdFAIL if pxTaskDefinition is NULL or heap allocation fails.

Definition at line 1507 of file freertos_stk.cpp.

1509{
1510 // Mandatory pointer guard (only pvTaskCode is required; the caller need not
1511 // supply puxStackBuffer or pxTaskBuffer — both are heap-allocated here).
1512 if ((pxTaskDefinition == nullptr) ||
1513 (pxTaskDefinition->pvTaskCode == nullptr))
1514 return pdFAIL;
1515
1516 // STK does not implement MPU support. Forward to xTaskCreate() which
1517 // heap-allocates both the TCB and the task stack, accepting but ignoring
1518 // the xRegions MPU region table.
1519 // TODO: program pxTaskDefinition->xRegions into the MPU when STK gains
1520 // hardware MPU support.
1521 return xTaskCreate(
1522 pxTaskDefinition->pvTaskCode,
1523 pxTaskDefinition->pcName,
1524 pxTaskDefinition->usStackDepth,
1525 pxTaskDefinition->pvParameters,
1526 pxTaskDefinition->uxPriority,
1527 pxCreatedTask);
1528}
BaseType_t xTaskCreate(TaskFunction_t pvTaskCode, const char *pcName, uint32_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask)
TaskFunction_t pvTaskCode
Definition FreeRTOS.h:573

References TaskParameters_restricted_t::pcName, pdFAIL, TaskParameters_restricted_t::pvParameters, TaskParameters_restricted_t::pvTaskCode, TaskParameters_restricted_t::usStackDepth, TaskParameters_restricted_t::uxPriority, and xTaskCreate().

Here is the call graph for this function:

◆ xTaskCreateRestrictedStatic()

BaseType_t xTaskCreateRestrictedStatic ( const TaskParameters_restricted_t * pxTaskDefinition,
TaskHandle_t * pxCreatedTask )

Create a task with caller-supplied static memory and optional MPU region descriptors (source-compatible with xTaskCreateRestricted).

Note
STK does not implement MPU support. This function is a forward- compatibility stub: it extracts the function, stack, priority, and pxTaskBuffer from pxTaskDefinition and delegates to xTaskCreateStatic(), silently ignoring the xRegions table. When STK gains MPU support the implementation will be extended to program the region descriptors.
Parameters
pxTaskDefinitionPointer to a TaskParameters_restricted_t descriptor. Must not be NULL. puxStackBuffer and pxTaskBuffer inside the struct must also be non-NULL.
pxCreatedTaskOptional: receives the handle of the created task.
Returns
pdPASS on success, pdFAIL if any mandatory pointer is NULL.

Definition at line 1475 of file freertos_stk.cpp.

1477{
1478 // Mandatory pointer guard.
1479 if ((pxTaskDefinition == nullptr) ||
1480 (pxTaskDefinition->pvTaskCode == nullptr) ||
1481 (pxTaskDefinition->puxStackBuffer == nullptr) ||
1482 (pxTaskDefinition->pxTaskBuffer == nullptr))
1483 return pdFAIL;
1484
1485 // STK does not implement MPU support. Forward to xTaskCreateStatic(),
1486 // accepting but ignoring the xRegions MPU region table.
1487 // TODO: program pxTaskDefinition->xRegions into the MPU when STK gains
1488 // hardware MPU support.
1490 pxTaskDefinition->pvTaskCode,
1491 pxTaskDefinition->pcName,
1492 pxTaskDefinition->usStackDepth,
1493 pxTaskDefinition->pvParameters,
1494 pxTaskDefinition->uxPriority,
1495 pxTaskDefinition->puxStackBuffer,
1496 pxTaskDefinition->pxTaskBuffer);
1497
1498 if (h == nullptr)
1499 return pdFAIL;
1500
1501 if (pxCreatedTask != nullptr)
1502 *pxCreatedTask = h;
1503
1504 return pdPASS;
1505}
TaskHandle_t xTaskCreateStatic(TaskFunction_t pvTaskCode, const char *pcName, uint32_t ulStackDepth, void *pvParameters, UBaseType_t uxPriority, StackType_t *puxStackBuffer, StaticTask_t *pxTaskBuffer)
StackType_t * puxStackBuffer
Definition FreeRTOS.h:578
StaticTask_t * pxTaskBuffer
Definition FreeRTOS.h:579

References TaskParameters_restricted_t::pcName, pdFAIL, pdPASS, TaskParameters_restricted_t::puxStackBuffer, TaskParameters_restricted_t::pvParameters, TaskParameters_restricted_t::pvTaskCode, TaskParameters_restricted_t::pxTaskBuffer, TaskParameters_restricted_t::usStackDepth, TaskParameters_restricted_t::uxPriority, and xTaskCreateStatic().

Here is the call graph for this function:

◆ xTaskCreateStatic()

TaskHandle_t xTaskCreateStatic ( TaskFunction_t pvTaskCode,
const char * pcName,
uint32_t ulStackDepth,
void * pvParameters,
UBaseType_t uxPriority,
StackType_t * puxStackBuffer,
StaticTask_t * pxTaskBuffer )

Create a task using caller-supplied stack and TCB memory (no heap allocation).

Parameters
pvTaskCodeTask function pointer.
pcNameDescriptive name for debugging.
ulStackDepthStack depth in Words (not bytes). Must be >= configMINIMAL_STACK_SIZE.
pvParametersArgument passed to pvTaskCode.
uxPriorityPriority: 0 = lowest, configMAX_PRIORITIES-1 = highest.
puxStackBufferCaller-allocated stack buffer of ulStackDepth Words. Must remain valid for the lifetime of the task.
pxTaskBufferCaller-allocated TCB buffer (StaticTask_t). Must remain valid for the lifetime of the task.
Returns
Task handle. Never NULL if all pointer arguments are non-NULL.

Definition at line 1153 of file freertos_stk.cpp.

1160{
1161 // All three pointer arguments are mandatory for static allocation.
1162 if ((pvTaskCode == nullptr) || (puxStackBuffer == nullptr) || (pxTaskBuffer == nullptr))
1163 return nullptr;
1164
1165 // Placement-new the FrtosTask control block into the caller-supplied TCB
1166 // buffer. Static assert guards against the buffer being too small.
1167 static_assert(sizeof(StaticTask_t) >= sizeof(FrtosTask),
1168 "StaticTask_t is too small to hold FrtosTask. "
1169 "Increase STATIC_TASK_TCB_SIZE_WORDS in freertos_stk.h.");
1170
1171 FrtosTask *t = new (pxTaskBuffer) FrtosTask();
1172
1173 t->m_func = pvTaskCode;
1174 t->m_argument = pvParameters;
1175 t->m_name = pcName;
1176 t->m_weight = FrtosPrioToStkWeight(uxPriority);
1177 t->m_stack = static_cast<stk::Word *>(static_cast<void *>(puxStackBuffer));
1178 t->m_stack_size = (ulStackDepth >= FREERTOS_STK_MIN_STACK_WORDS)
1179 ? static_cast<size_t>(ulStackDepth)
1181 t->m_stack_owned = false; // caller owns both the stack and the TCB
1182 t->m_cb_owned = false; // destructor must not delete — caller owns memory
1183
1185
1186 g_StkKernel.AddTask(t);
1187
1188 return static_cast<TaskHandle_t>(t);
1189}
uintptr_t Word
Native processor word type.
Definition stk_common.h:115

References EnsureKernelInitialized(), FREERTOS_STK_MIN_STACK_WORDS, FrtosPrioToStkWeight(), g_StkKernel, FrtosTask::m_argument, FrtosTask::m_cb_owned, FrtosTask::m_func, FrtosTask::m_name, FrtosTask::m_stack, FrtosTask::m_stack_owned, FrtosTask::m_stack_size, and FrtosTask::m_weight.

Referenced by xTaskCreateRestrictedStatic().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskDelayUntil()

BaseType_t xTaskDelayUntil ( TickType_t * pxPreviousWakeTime,
TickType_t xTimeIncrement )

Delay until an absolute tick deadline (FreeRTOS 10.2+ name for vTaskDelayUntil). Updates *pxPreviousWakeTime on each call.

Returns
pdTRUE if the task delayed, pdFALSE if the deadline had already passed before the call was made (the task did not block).

Definition at line 1286 of file freertos_stk.cpp.

1287{
1288 if (IsIrqContext() || (pxPreviousWakeTime == nullptr))
1289 return pdFALSE;
1290
1291 const stk::Ticks wake_at = static_cast<stk::Ticks>(*pxPreviousWakeTime) +
1292 static_cast<stk::Ticks>(xTimeIncrement);
1293
1294 *pxPreviousWakeTime = static_cast<TickType_t>(wake_at);
1295
1296 return stk::SleepUntil(wake_at) ? pdTRUE : pdFALSE;
1297}
int64_t Ticks
Ticks value.
Definition stk_common.h:130
bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:367

References IsIrqContext(), pdFALSE, pdTRUE, and stk::SleepUntil().

Referenced by vTaskDelayUntil().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskGetCurrentTaskHandle()

TaskHandle_t xTaskGetCurrentTaskHandle ( void )

Return the handle of the currently executing task.

Definition at line 1346 of file freertos_stk.cpp.

1347{
1348 if (IsIrqContext())
1349 return nullptr;
1350
1351 return reinterpret_cast<TaskHandle_t>(static_cast<uintptr_t>(stk::GetTid()));
1352}

References stk::GetTid(), and IsIrqContext().

Referenced by pvTaskGetThreadLocalStoragePointer(), ResolveNotifyTarget(), and vTaskSetThreadLocalStoragePointer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskGetHandle()

TaskHandle_t xTaskGetHandle ( const char * pcNameToQuery)

Look up a task handle by name string (O(n) scan).

Returns
Handle of the first matching task, or NULL if not found.

Definition at line 1354 of file freertos_stk.cpp.

1355{
1356 if (pcNameToQuery == nullptr)
1357 return nullptr;
1358
1359 // Enumerate all tasks and compare names.
1360 TaskHandle_t found = nullptr;
1361
1362 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *task) -> bool
1363 {
1364 if ((task->GetTraceName() != nullptr) &&
1365 (strcmp(task->GetTraceName(), pcNameToQuery) == 0))
1366 {
1367 found = static_cast<TaskHandle_t>(task);
1368 return false; // stop iteration
1369 }
1370 return true;
1371 });
1372
1373 return found;
1374}

References FREERTOS_STK_MAX_TASKS, and g_StkKernel.

◆ xTaskGetSchedulerState()

BaseType_t xTaskGetSchedulerState ( void )

Return the current state of the FreeRTOS/STK scheduler.

Returns
One of taskSCHEDULER_NOT_STARTED, taskSCHEDULER_RUNNING, or taskSCHEDULER_SUSPENDED.

< Scheduler is running normally (STATE_RUNNING).

< Scheduler is suspended via vTaskSuspendAll() (STATE_SUSPENDED).

< Scheduler has not yet been started (STATE_INACTIVE / STATE_READY).

Definition at line 1088 of file freertos_stk.cpp.

1089{
1090 // Map the four STK kernel states onto the three FreeRTOS scheduler states:
1091 // STATE_INACTIVE / STATE_READY -> NOT_STARTED (scheduler never ran)
1092 // STATE_RUNNING -> RUNNING
1093 // STATE_SUSPENDED -> SUSPENDED
1094 switch (g_StkKernel.GetState())
1095 {
1098 default: return taskSCHEDULER_NOT_STARTED;
1099 }
1100}
#define taskSCHEDULER_NOT_STARTED
Definition FreeRTOS.h:427
#define taskSCHEDULER_SUSPENDED
Definition FreeRTOS.h:429
#define taskSCHEDULER_RUNNING
Definition FreeRTOS.h:428
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().

References g_StkKernel, stk::IKernel::KSTATE_RUNNING, stk::IKernel::KSTATE_SUSPENDED, taskSCHEDULER_NOT_STARTED, taskSCHEDULER_RUNNING, and taskSCHEDULER_SUSPENDED.

◆ xTaskGetTickCount()

TickType_t xTaskGetTickCount ( void )

Return the tick count since the scheduler started.

Definition at line 1072 of file freertos_stk.cpp.

1073{
1074 return static_cast<TickType_t>(stk::GetTicks());
1075}
Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:274

References stk::GetTicks().

Here is the call graph for this function:

◆ xTaskGetTickCountFromISR()

TickType_t xTaskGetTickCountFromISR ( void )

Return the tick count from ISR context (ISR-safe).

Definition at line 1077 of file freertos_stk.cpp.

1078{
1079 return static_cast<TickType_t>(stk::GetTicks()); // GetTicks() is ISR-safe
1080}

References stk::GetTicks().

Here is the call graph for this function:

◆ xTaskNotify()

BaseType_t xTaskNotify ( TaskHandle_t xTaskToNotify,
uint32_t ulValue,
eNotifyAction eAction )

Send a notification to a task (slot 0) with a specific action on its value.

Parameters
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the task's notification value.
Returns
pdPASS, or pdFAIL if eSetValueWithoutOverwrite and already pending.

Definition at line 3386 of file freertos_stk.cpp.

3389{
3390 return xTaskNotifyIndexed(xTaskToNotify, 0U, ulValue, eAction);
3391}
BaseType_t xTaskNotifyIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction)

References xTaskNotifyIndexed().

Here is the call graph for this function:

◆ xTaskNotifyAndQuery()

BaseType_t xTaskNotifyAndQuery ( TaskHandle_t xTaskToNotify,
uint32_t ulValue,
eNotifyAction eAction,
uint32_t * pulPreviousNotifyValue )

Send a notification to a task (slot 0) and return the previous notification value before the action was applied.

Parameters
xTaskToNotifyTarget task handle (must not be NULL).
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the notification value.
pulPreviousNotifyValueReceives the slot value before the action is applied. May be NULL.
Returns
pdPASS, or pdFAIL if eSetValueWithoutOverwrite and notification was already pending.
Note
ISR-safe.

Definition at line 3474 of file freertos_stk.cpp.

3478{
3479 return xTaskNotifyAndQueryIndexed(xTaskToNotify, 0U, ulValue, eAction,
3480 pulPreviousNotifyValue);
3481}
BaseType_t xTaskNotifyAndQueryIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue)

References xTaskNotifyAndQueryIndexed().

Here is the call graph for this function:

◆ xTaskNotifyAndQueryFromISR()

BaseType_t xTaskNotifyAndQueryFromISR ( TaskHandle_t xTaskToNotify,
uint32_t ulValue,
eNotifyAction eAction,
uint32_t * pulPreviousNotifyValue,
BaseType_t * pxHigherPriorityTaskWoken )

ISR-safe variant of xTaskNotifyAndQuery (slot 0).

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK handles wake internally).
Note
ISR-safe.

Definition at line 3508 of file freertos_stk.cpp.

3513{
3514 return xTaskNotifyAndQueryFromISRIndexed(xTaskToNotify, 0U, ulValue, eAction,
3515 pulPreviousNotifyValue,
3516 pxHigherPriorityTaskWoken);
3517}
BaseType_t xTaskNotifyAndQueryFromISRIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken)

References xTaskNotifyAndQueryFromISRIndexed().

Here is the call graph for this function:

◆ xTaskNotifyAndQueryFromISRIndexed()

BaseType_t xTaskNotifyAndQueryFromISRIndexed ( TaskHandle_t xTaskToNotify,
UBaseType_t uxIndexToNotify,
uint32_t ulValue,
eNotifyAction eAction,
uint32_t * pulPreviousNotifyValue,
BaseType_t * pxHigherPriorityTaskWoken )

ISR-safe indexed variant of xTaskNotifyAndQuery.

Parameters
uxIndexToNotifyNotification slot index.
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Note
ISR-safe.

Definition at line 3487 of file freertos_stk.cpp.

3493{
3494 BaseType_t result = xTaskNotifyAndQueryIndexed(xTaskToNotify, uxIndexToNotify,
3495 ulValue, eAction,
3496 pulPreviousNotifyValue);
3497
3498 if (pxHigherPriorityTaskWoken != nullptr)
3499 *pxHigherPriorityTaskWoken = pdFALSE; // STK handles the context switch internally
3500
3501 return result;
3502}

References pdFALSE, and xTaskNotifyAndQueryIndexed().

Referenced by xTaskNotifyAndQueryFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskNotifyAndQueryIndexed()

BaseType_t xTaskNotifyAndQueryIndexed ( TaskHandle_t xTaskToNotify,
UBaseType_t uxIndexToNotify,
uint32_t ulValue,
eNotifyAction eAction,
uint32_t * pulPreviousNotifyValue )

Indexed variant of xTaskNotifyAndQuery.

Parameters
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
Note
ISR-safe.

Definition at line 3440 of file freertos_stk.cpp.

3445{
3446 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3447 if (t == nullptr)
3448 return pdFAIL;
3449
3450 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToNotify];
3451 BaseType_t result = pdPASS;
3452
3453 {
3455
3456 // Snapshot the value *before* the action — this is the only difference
3457 // from xTaskNotifyIndexed.
3458 if (pulPreviousNotifyValue != nullptr)
3459 *pulPreviousNotifyValue = slot.value;
3460
3461 result = NotifyApplyAction(slot, ulValue, eAction);
3462 }
3463
3464 if (result == pdPASS)
3465 slot.sem.Signal();
3466
3467 return result;
3468}
static BaseType_t NotifyApplyAction(FrtosTask::NotifySlot &slot, uint32_t ulValue, eNotifyAction eAction)

References FrtosTask::m_notify, NotifyApplyAction(), pdFAIL, pdPASS, ResolveNotifyTarget(), FrtosTask::NotifySlot::sem, stk::sync::Semaphore::Signal(), and FrtosTask::NotifySlot::value.

Referenced by xTaskNotifyAndQuery(), and xTaskNotifyAndQueryFromISRIndexed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskNotifyFromISR()

BaseType_t xTaskNotifyFromISR ( TaskHandle_t xTaskToNotify,
uint32_t ulValue,
eNotifyAction eAction,
BaseType_t * pxHigherPriorityTaskWoken )

Send a notification (slot 0) from ISR context.

Parameters
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed (always pdFALSE in STK wrapper).

Definition at line 3402 of file freertos_stk.cpp.

3406{
3407 return xTaskNotifyFromISRIndexed(xTaskToNotify, 0U, ulValue, eAction,
3408 pxHigherPriorityTaskWoken);
3409}
BaseType_t xTaskNotifyFromISRIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken)

References xTaskNotifyFromISRIndexed().

Here is the call graph for this function:

◆ xTaskNotifyFromISRIndexed()

BaseType_t xTaskNotifyFromISRIndexed ( TaskHandle_t xTaskToNotify,
UBaseType_t uxIndexToNotify,
uint32_t ulValue,
eNotifyAction eAction,
BaseType_t * pxHigherPriorityTaskWoken )

Send a notification to a specific slot from ISR context.

Parameters
uxIndexToNotifyNotification slot index.
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK handles wake internally).

Definition at line 3358 of file freertos_stk.cpp.

3363{
3364 BaseType_t result = xTaskNotifyIndexed(xTaskToNotify, uxIndexToNotify, ulValue, eAction);
3365
3366 if (pxHigherPriorityTaskWoken != nullptr)
3367 *pxHigherPriorityTaskWoken = pdFALSE;
3368
3369 return result;
3370}

References pdFALSE, and xTaskNotifyIndexed().

Referenced by xTaskNotifyFromISR().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskNotifyGive()

BaseType_t xTaskNotifyGive ( TaskHandle_t xTaskToNotify)

Send a notification to a task (slot 0), incrementing its notification value by 1. Equivalent to xTaskNotify(xTaskToNotify, 0, eIncrement).

Returns
pdPASS.

Definition at line 3376 of file freertos_stk.cpp.

3377{
3378 return xTaskNotifyGiveIndexed(xTaskToNotify, 0U);
3379}
BaseType_t xTaskNotifyGiveIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify)

References xTaskNotifyGiveIndexed().

Here is the call graph for this function:

◆ xTaskNotifyGiveIndexed()

BaseType_t xTaskNotifyGiveIndexed ( TaskHandle_t xTaskToNotify,
UBaseType_t uxIndexToNotify )

Send a notification to a specific slot of a task, incrementing the slot's value by 1.

Parameters
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
Returns
pdPASS, or pdFAIL if the index is out of range.

Definition at line 3253 of file freertos_stk.cpp.

3255{
3256 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3257 if (t == nullptr)
3258 return pdFAIL;
3259
3260 t->m_notify[uxIndexToNotify].sem.Signal(); // ISR-safe
3261 return pdPASS;
3262}

References FrtosTask::m_notify, pdFAIL, pdPASS, ResolveNotifyTarget(), FrtosTask::NotifySlot::sem, and stk::sync::Semaphore::Signal().

Referenced by xTaskNotifyGive().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskNotifyIndexed()

BaseType_t xTaskNotifyIndexed ( TaskHandle_t xTaskToNotify,
UBaseType_t uxIndexToNotify,
uint32_t ulValue,
eNotifyAction eAction )

Send a notification to a specific slot of a task with a chosen action.

Parameters
uxIndexToNotifyNotification slot index.
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the slot's value.
Returns
pdPASS, or pdFAIL on bad index or eSetValueWithoutOverwrite conflict.

Definition at line 3296 of file freertos_stk.cpp.

3300{
3301 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3302 if (t == nullptr)
3303 return pdFAIL;
3304
3305 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToNotify];
3306 BaseType_t result = pdPASS;
3307
3308 {
3310 result = NotifyApplyAction(slot, ulValue, eAction);
3311 }
3312
3313 if (result == pdPASS)
3314 slot.sem.Signal();
3315
3316 return result;
3317}

References FrtosTask::m_notify, NotifyApplyAction(), pdFAIL, pdPASS, ResolveNotifyTarget(), FrtosTask::NotifySlot::sem, and stk::sync::Semaphore::Signal().

Referenced by xTaskNotify(), and xTaskNotifyFromISRIndexed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskNotifyStateClear()

BaseType_t xTaskNotifyStateClear ( TaskHandle_t xTask)

Clear the pending notification state for slot 0 of a task.

If a notification was pending (i.e. the task had been notified but had not yet called xTaskNotifyWait() or ulTaskNotifyTake() to consume it), this function clears the pending state and returns pdTRUE. If no notification was pending it returns pdFALSE.

Parameters
xTaskHandle of the task whose notification state is to be cleared. NULL selects the calling task.
Returns
pdTRUE if a notification was pending and has been cleared, pdFALSE if no notification was pending.
Note
ISR-safe.

Definition at line 3577 of file freertos_stk.cpp.

3578{
3579 return xTaskNotifyStateClearIndexed(xTask, 0U);
3580}
BaseType_t xTaskNotifyStateClearIndexed(TaskHandle_t xTask, UBaseType_t uxIndexToClear)

References xTaskNotifyStateClearIndexed().

Here is the call graph for this function:

◆ xTaskNotifyStateClearIndexed()

BaseType_t xTaskNotifyStateClearIndexed ( TaskHandle_t xTask,
UBaseType_t uxIndexToClear )

Indexed variant of xTaskNotifyStateClear.

Parameters
xTaskHandle of the task. NULL selects the calling task.
uxIndexToClearNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
Returns
pdTRUE if a notification was pending, pdFALSE otherwise.
Note
ISR-safe.

Definition at line 3542 of file freertos_stk.cpp.

3544{
3545 FrtosTask *t = ResolveNotifyTarget(xTask, uxIndexToClear);
3546 if (t == nullptr)
3547 return pdFALSE;
3548
3549 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToClear];
3550
3552
3553 // Determine whether a notification was pending before we clear anything.
3554 // A notification is considered "pending" when the semaphore has a count
3555 // (i.e. Signal() was called but Wait/Take has not yet consumed it) OR
3556 // when the value-without-overwrite guard flag is set.
3557 const bool was_pending = (slot.sem.GetCount() != 0U) || slot.pending;
3558
3559 if (was_pending)
3560 {
3561 // Drain the semaphore (binary, at most 1 token to consume).
3562 slot.sem.TryWait();
3563
3564 // Clear the eSetValueWithoutOverwrite pending guard so that a
3565 // subsequent xTaskNotify(eSetValueWithoutOverwrite) can write a new
3566 // value without being rejected.
3567 slot.pending = false;
3568 }
3569
3570 return was_pending ? pdTRUE : pdFALSE;
3571}
volatile bool pending
true if a value was set but not yet consumed

References stk::sync::Semaphore::GetCount(), FrtosTask::m_notify, pdFALSE, pdTRUE, FrtosTask::NotifySlot::pending, ResolveNotifyTarget(), FrtosTask::NotifySlot::sem, and stk::sync::Semaphore::TryWait().

Referenced by xTaskNotifyStateClear().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskNotifyWait()

BaseType_t xTaskNotifyWait ( uint32_t ulBitsToClearOnEntry,
uint32_t ulBitsToClearOnExit,
uint32_t * pulNotificationValue,
TickType_t xTicksToWait )

Wait for a notification (slot 0), with optional bit-masking on entry and exit.

Parameters
ulBitsToClearOnEntryBits cleared before blocking.
ulBitsToClearOnExitBits cleared before returning.
pulNotificationValueReceives the value before the exit-clear (may be NULL).
xTicksToWaitTicks to wait.
Returns
pdTRUE if notified, pdFALSE on timeout.

Definition at line 3393 of file freertos_stk.cpp.

3397{
3398 return xTaskNotifyWaitIndexed(0U, ulBitsToClearOnEntry, ulBitsToClearOnExit,
3399 pulNotificationValue, xTicksToWait);
3400}
BaseType_t xTaskNotifyWaitIndexed(UBaseType_t uxIndexToWait, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait)

References xTaskNotifyWaitIndexed().

Here is the call graph for this function:

◆ xTaskNotifyWaitIndexed()

BaseType_t xTaskNotifyWaitIndexed ( UBaseType_t uxIndexToWait,
uint32_t ulBitsToClearOnEntry,
uint32_t ulBitsToClearOnExit,
uint32_t * pulNotificationValue,
TickType_t xTicksToWait )

Wait for a notification on a specific slot of the calling task.

Parameters
uxIndexToWaitNotification slot index.
ulBitsToClearOnEntryBits cleared in the slot value before blocking.
ulBitsToClearOnExitBits cleared in the slot value before returning.
pulNotificationValueReceives the slot value before the exit-clear (may be NULL).
xTicksToWaitTicks to wait.
Returns
pdTRUE if notified, pdFALSE on timeout or bad index.

Definition at line 3319 of file freertos_stk.cpp.

3324{
3325 if (IsIrqContext())
3326 return pdFAIL;
3327
3328 FrtosTask *t = ResolveNotifyTarget(nullptr, uxIndexToWait);
3329 if (t == nullptr)
3330 return pdFAIL;
3331
3332 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToWait];
3333
3334 // Clear entry bits before blocking.
3335 {
3337 slot.value &= ~ulBitsToClearOnEntry;
3338 }
3339
3340 // Block until notified or timeout.
3341 if (!slot.sem.Wait(FrtosTimeoutToStk(xTicksToWait)))
3342 return pdFAIL;
3343
3344 // Read and apply exit-clear.
3345 {
3347
3348 if (pulNotificationValue != nullptr)
3349 *pulNotificationValue = slot.value;
3350
3351 slot.value &= ~ulBitsToClearOnExit;
3352 slot.pending = false;
3353 }
3354
3355 return pdPASS;
3356}

References FrtosTimeoutToStk(), IsIrqContext(), FrtosTask::m_notify, pdFAIL, pdPASS, FrtosTask::NotifySlot::pending, ResolveNotifyTarget(), FrtosTask::NotifySlot::sem, FrtosTask::NotifySlot::value, and stk::sync::Semaphore::Wait().

Referenced by xTaskNotifyWait().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTaskResumeAll()

BaseType_t xTaskResumeAll ( void )

Resume a previously suspended scheduler.

Returns
pdTRUE if a context switch is pending, pdFALSE otherwise.

Definition at line 1066 of file freertos_stk.cpp.

1067{
1069 return pdFALSE; // no pending switch tracked at wrapper level
1070}

References stk::hw::CriticalSection::Exit(), and pdFALSE.

Here is the call graph for this function:

◆ xTaskResumeFromISR()

BaseType_t xTaskResumeFromISR ( TaskHandle_t xTaskToResume)

Resume a previously suspended task from ISR context.

Returns
pdTRUE if the task was successfully resumed.

Definition at line 1239 of file freertos_stk.cpp.

1240{
1241 if (xTaskToResume == nullptr)
1242 return pdFALSE;
1243
1244 FrtosTask *t = static_cast<FrtosTask *>(xTaskToResume);
1245
1247
1249 return pdFALSE;
1250
1251 g_StkKernel.ResumeTask(t);
1253
1254 return pdTRUE;
1255}

References g_StkKernel, FrtosTask::m_state, pdFALSE, pdTRUE, FrtosTask::Ready, and FrtosTask::Suspended.

◆ xTimerChangePeriod()

BaseType_t xTimerChangePeriod ( TimerHandle_t xTimer,
TickType_t xNewPeriod,
TickType_t xTicksToWait )

Change the period of a timer and restart it immediately.

Returns
pdPASS on success.

Definition at line 2687 of file freertos_stk.cpp.

2690{
2691 if ((xTimer == nullptr) || (xNewPeriod == 0U))
2692 return pdFAIL;
2693
2694 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2695 t->m_period = xNewPeriod;
2696
2697 return xTimerStart(xTimer, xTicksToWait);
2698}
BaseType_t xTimerStart(TimerHandle_t xTimer, TickType_t)
TickType_t m_period

References FrtosTimer::m_period, pdFAIL, and xTimerStart().

Here is the call graph for this function:

◆ xTimerChangePeriodFromISR()

BaseType_t xTimerChangePeriodFromISR ( TimerHandle_t xTimer,
TickType_t xNewPeriod,
BaseType_t * pxHigherPriorityTaskWoken )

Change the period of a timer and restart it from ISR context.

Parameters
xNewPeriodNew timer period in ticks (must be > 0).
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the command queue is full or arguments are invalid.

Definition at line 2761 of file freertos_stk.cpp.

2764{
2765 if (pxHigherPriorityTaskWoken != nullptr)
2766 *pxHigherPriorityTaskWoken = pdFALSE;
2767
2768 if ((xTimer == nullptr) || (xNewPeriod == 0U) || (g_TimerHost == nullptr))
2769 return pdFAIL;
2770
2771 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2772 t->m_period = xNewPeriod;
2773
2774 // Restart with the new period, taking effect immediately.
2775 uint32_t period = t->m_auto_reload ? static_cast<uint32_t>(xNewPeriod) : 0U;
2776
2777 return g_TimerHost->Restart(*t, static_cast<uint32_t>(xNewPeriod), period) ? pdPASS : pdFAIL;
2778}
static stk::time::TimerHost * g_TimerHost

References g_TimerHost, FrtosTimer::m_auto_reload, FrtosTimer::m_period, pdFAIL, pdFALSE, and pdPASS.

◆ xTimerCreate()

TimerHandle_t xTimerCreate ( const char * pcTimerName,
TickType_t xTimerPeriodInTicks,
UBaseType_t uxAutoReload,
void * pvTimerID,
TimerCallbackFunction_t pxCallbackFunction )

Create a software timer.

Parameters
pcTimerNameName for debugging.
xTimerPeriodInTicksPeriod in ticks (must be > 0).
uxAutoReloadpdTRUE = periodic, pdFALSE = one-shot.
pvTimerIDApplication-defined value stored in the timer.
pxCallbackFunctionCallback invoked on expiry.
Returns
Timer handle, or NULL on failure.

Definition at line 2585 of file freertos_stk.cpp.

2590{
2591 if (IsIrqContext() || (pxCallbackFunction == nullptr) || (xTimerPeriodInTicks == 0U))
2592 return nullptr;
2593
2595 return nullptr;
2596
2598 pcTimerName,
2599 xTimerPeriodInTicks,
2600 (uxAutoReload == pdTRUE),
2601 pvTimerID,
2602 pxCallbackFunction);
2603
2604 return static_cast<TimerHandle_t>(t);
2605}
void * TimerHandle_t
Definition FreeRTOS.h:313
static bool EnsureTimerHost()

References FrtosTimer::EnsureTimerHost(), IsIrqContext(), ObjAlloc(), and pdTRUE.

Here is the call graph for this function:

◆ xTimerCreateStatic()

TimerHandle_t xTimerCreateStatic ( const char * pcTimerName,
TickType_t xTimerPeriodInTicks,
UBaseType_t uxAutoReload,
void * pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
StaticTimer_t * pxTimerBuffer )

Create a software timer using caller-supplied storage — no heap allocation.

Parameters
pcTimerNameName for debugging.
xTimerPeriodInTicksPeriod in ticks (must be > 0).
uxAutoReloadpdTRUE = periodic, pdFALSE = one-shot.
pvTimerIDApplication-defined value stored in the timer.
pxCallbackFunctionCallback invoked on expiry.
pxTimerBufferCaller-allocated control block (StaticTimer_t). Must remain valid for the lifetime of the timer.
Returns
Timer handle. Never NULL if pxTimerBuffer is non-NULL, pxCallbackFunction is non-NULL and xTimerPeriodInTicks > 0.

Definition at line 2607 of file freertos_stk.cpp.

2613{
2614 if (pxTimerBuffer == nullptr)
2615 return nullptr;
2616
2617 if (IsIrqContext() || (pxCallbackFunction == nullptr) || (xTimerPeriodInTicks == 0U))
2618 return nullptr;
2619
2621 return nullptr;
2622
2623 static_assert(sizeof(StaticTimer_t) >= sizeof(FrtosTimer),
2624 "StaticTimer_t is too small to hold FrtosTimer. "
2625 "Increase STATIC_TIMER_TCB_SIZE_WORDS in freertos_stk.h.");
2626
2627 // Placement-new the FrtosTimer into the caller-supplied buffer.
2628 FrtosTimer *t = new (pxTimerBuffer) FrtosTimer(
2629 pcTimerName,
2630 xTimerPeriodInTicks,
2631 (uxAutoReload == pdTRUE),
2632 pvTimerID,
2633 pxCallbackFunction);
2634
2635 t->m_cb_owned = false; // caller owns the memory; xTimerDelete must not delete it
2636
2637 return static_cast<TimerHandle_t>(t);
2638}

References FrtosTimer::EnsureTimerHost(), IsIrqContext(), FrtosTimer::m_cb_owned, and pdTRUE.

Here is the call graph for this function:

◆ xTimerDelete()

BaseType_t xTimerDelete ( TimerHandle_t xTimer,
TickType_t xTicksToWait )

Delete a software timer and free its memory.

Returns
pdPASS.

Definition at line 2640 of file freertos_stk.cpp.

2641{
2642 if (xTimer == nullptr)
2643 return pdFAIL;
2644
2645 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2646
2647 if ((g_TimerHost != nullptr) && t->IsActive())
2648 g_TimerHost->Stop(*t);
2649
2650 ObjFree(t);
2651 return pdPASS;
2652}
bool IsActive() const
Check whether the timer is currently active.

References g_TimerHost, stk::time::TimerHost::Timer::IsActive(), ObjFree(), pdFAIL, and pdPASS.

Here is the call graph for this function:

◆ xTimerGetExpiryTime()

TickType_t xTimerGetExpiryTime ( TimerHandle_t xTimer)

Return the absolute tick count at which the timer will next expire. Returns 0 if the timer is not currently running.

Definition at line 2915 of file freertos_stk.cpp.

2916{
2917 if ((xTimer == nullptr) || (g_TimerHost == nullptr))
2918 return 0U;
2919
2920 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2921 return t->IsActive() ? static_cast<TickType_t>(t->GetDeadline()) : 0U;
2922}
Ticks GetDeadline() const
Get the absolute time in ticks at which the timer will expire.

References g_TimerHost, stk::time::TimerHost::Timer::GetDeadline(), and stk::time::TimerHost::Timer::IsActive().

Here is the call graph for this function:

◆ xTimerGetPeriod()

TickType_t xTimerGetPeriod ( TimerHandle_t xTimer)

Return the period of a timer in ticks.

Definition at line 2907 of file freertos_stk.cpp.

2908{
2909 if (xTimer == nullptr)
2910 return 0U;
2911
2912 return static_cast<FrtosTimer *>(xTimer)->m_period;
2913}

◆ xTimerIsTimerActive()

BaseType_t xTimerIsTimerActive ( TimerHandle_t xTimer)

Query whether a timer is currently active (running).

Returns
pdTRUE if active, pdFALSE if stopped or expired.

Definition at line 2875 of file freertos_stk.cpp.

2876{
2877 if (xTimer == nullptr)
2878 return pdFALSE;
2879
2880 return static_cast<FrtosTimer *>(xTimer)->IsActive() ? pdTRUE : pdFALSE;
2881}

References pdFALSE, and pdTRUE.

◆ xTimerPendFunctionCall()

BaseType_t xTimerPendFunctionCall ( PendedFunction_t xFunctionToPend,
void * pvParameter1,
uint32_t ulParameter2,
TickType_t xTicksToWait )

Defer execution of a function to the timer-task context (task-context variant).

Writes a PendCall record {xFunctionToPend, pvParameter1, ulParameter2} into the static g_PendCallPipe (PipeT<PendCall, FREERTOS_STK_PEND_CALL_QUEUE_SIZE>). The TimerHost handler task drains the pipe on each wake cycle and invokes every callback directly — no heap allocation is performed, no self-deleting timer object is created.

Note
Requires the TimerHost to have been started (at least one timer created or xTimerPendFunctionCall called after vTaskStartScheduler). If the TimerHost has not yet been initialized this function initializes it implicitly, matching FreeRTOS behaviour.
If the static pipe is full this function blocks for up to xTicksToWait ticks waiting for a free slot (PipeT::Write blocking semantics). Pass 0 for a non-blocking attempt.
Parameters
xFunctionToPendCallback to invoke in the timer-task context. Signature: void cb(void *pvParam1, uint32_t ulParam2).
pvParameter1First argument forwarded to the callback.
ulParameter2Second argument forwarded to the callback.
xTicksToWaitTicks to wait if the pipe is full. portMAX_DELAY blocks indefinitely.
Returns
pdPASS on success, pdFAIL if the pipe was full and the timeout expired.
Warning
ISR-unsafe. Use xTimerPendFunctionCallFromISR() from interrupt context.

Definition at line 2816 of file freertos_stk.cpp.

2820{
2821 // API contract: must not be called from ISR context.
2822 if (IsIrqContext())
2823 return pdFAIL;
2824
2825 if (xFunctionToPend == nullptr)
2826 return pdFAIL;
2827
2828 // Ensure the TimerHost (and hence the drainer's scheduling context) exists.
2830 return pdFAIL;
2831
2832 // Write the call record into the static pipe (blocking with timeout).
2833 // PipeT::Write() acquires a ScopedCriticalSection internally.
2834 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2835 if (!g_PendCallPipe.Write(call, FrtosTimeoutToStk(xTicksToWait)))
2836 return pdFAIL;
2837
2838 // (Re-)start the singleton drainer so it wakes within 1 tick.
2839 // EnsurePendDrainer() constructs the drainer on first call and
2840 // calls TimerHost::Restart() which is task-safe.
2842
2843 return pdPASS;
2844}
static stk::sync::PipeT< PendCall, 8U > g_PendCallPipe
static bool EnsurePendDrainer()

References EnsurePendDrainer(), FrtosTimer::EnsureTimerHost(), FrtosTimeoutToStk(), g_PendCallPipe, IsIrqContext(), pdFAIL, and pdPASS.

Here is the call graph for this function:

◆ xTimerPendFunctionCallFromISR()

BaseType_t xTimerPendFunctionCallFromISR ( PendedFunction_t xFunctionToPend,
void * pvParameter1,
uint32_t ulParameter2,
BaseType_t * pxHigherPriorityTaskWoken )

Defer execution of a function to the timer-task context (ISR-safe variant).

Identical in effect to xTimerPendFunctionCall() but safe to call from an interrupt service routine. The call record is written into a static PipeT<PendCall, FREERTOS_STK_PEND_CALL_QUEUE_SIZE> with NO_WAIT semantics — no heap allocation is performed. If the pipe is full the function returns pdFAIL immediately.

Parameters
xFunctionToPendCallback to invoke in the timer-task context.
pvParameter1First argument forwarded to the callback.
ulParameter2Second argument forwarded to the callback.
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK wakes the timer task internally; no manual yield required).
Returns
pdPASS on success, pdFAIL if the static queue was full.

Definition at line 2846 of file freertos_stk.cpp.

2850{
2851 // STK wakes the tick task internally; no manual context switch needed.
2852 if (pxHigherPriorityTaskWoken != nullptr)
2853 *pxHigherPriorityTaskWoken = pdFALSE;
2854
2855 if (xFunctionToPend == nullptr)
2856 return pdFAIL;
2857
2858 // From ISR the TimerHost must already be running (a timer was created
2859 // before the ISR fired — the only realistic usage pattern).
2860 if (g_TimerHost == nullptr)
2861 return pdFAIL;
2862
2863 // Non-blocking enqueue: TryWrite() holds a ScopedCriticalSection internally
2864 // — unconditionally ISR-safe, no allocator call, no blocking.
2865 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2866 if (!g_PendCallPipe.TryWrite(call))
2867 return pdFAIL;
2868
2869 // Kick the drainer via ISR-safe TimerHost::Restart().
2871
2872 return pdPASS;
2873}
static void KickPendDrainerFromISR()

References g_PendCallPipe, g_TimerHost, KickPendDrainerFromISR(), pdFAIL, pdFALSE, and pdPASS.

Here is the call graph for this function:

◆ xTimerReset()

BaseType_t xTimerReset ( TimerHandle_t xTimer,
TickType_t xTicksToWait )

Reset a timer (restart its period from the current tick).

Returns
pdPASS on success.

Definition at line 2682 of file freertos_stk.cpp.

2683{
2684 return xTimerStart(xTimer, xTicksToWait); // Restart restarts from now
2685}

References xTimerStart().

Here is the call graph for this function:

◆ xTimerResetFromISR()

BaseType_t xTimerResetFromISR ( TimerHandle_t xTimer,
BaseType_t * pxHigherPriorityTaskWoken )

Reset (restart the period of) a timer from ISR context.

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the command queue is full or handle is invalid.

Definition at line 2754 of file freertos_stk.cpp.

2756{
2757 // Reset = Restart from now, same as xTimerStart.
2758 return xTimerStartFromISR(xTimer, pxHigherPriorityTaskWoken);
2759}
BaseType_t xTimerStartFromISR(TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)

References xTimerStartFromISR().

Here is the call graph for this function:

◆ xTimerStart()

BaseType_t xTimerStart ( TimerHandle_t xTimer,
TickType_t xTicksToWait )

Start (or restart) a timer from the current tick.

Returns
pdPASS on success, pdFAIL on error.

Definition at line 2654 of file freertos_stk.cpp.

2655{
2656 if (IsIrqContext() || (xTimer == nullptr) || (g_TimerHost == nullptr))
2657 return pdFAIL;
2658
2659 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2660
2661 uint32_t period = t->m_auto_reload
2662 ? static_cast<uint32_t>(t->m_period)
2663 : 0U; // 0 = one-shot (no reload period)
2664
2665 return g_TimerHost->Restart(*t, static_cast<uint32_t>(t->m_period), period)
2666 ? pdPASS : pdFAIL;
2667}

References g_TimerHost, IsIrqContext(), FrtosTimer::m_auto_reload, FrtosTimer::m_period, pdFAIL, and pdPASS.

Referenced by xTimerChangePeriod(), and xTimerReset().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xTimerStartFromISR()

BaseType_t xTimerStartFromISR ( TimerHandle_t xTimer,
BaseType_t * pxHigherPriorityTaskWoken )

Start (or restart) a timer from ISR context.

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the command queue is full or handle is invalid.

Definition at line 2721 of file freertos_stk.cpp.

2723{
2724 if (pxHigherPriorityTaskWoken != nullptr)
2725 *pxHigherPriorityTaskWoken = pdFALSE;
2726
2727 if ((xTimer == nullptr) || (g_TimerHost == nullptr))
2728 return pdFAIL;
2729
2730 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2731 uint32_t period = t->m_auto_reload ? static_cast<uint32_t>(t->m_period) : 0U;
2732
2733 return g_TimerHost->Restart(*t, static_cast<uint32_t>(t->m_period), period)
2734 ? pdPASS : pdFAIL;
2735}

References g_TimerHost, FrtosTimer::m_auto_reload, FrtosTimer::m_period, pdFAIL, pdFALSE, and pdPASS.

Referenced by xTimerResetFromISR().

Here is the caller graph for this function:

◆ xTimerStop()

BaseType_t xTimerStop ( TimerHandle_t xTimer,
TickType_t xTicksToWait )

Stop a running timer.

Returns
pdPASS on success, pdFAIL if the timer was not running.

Definition at line 2669 of file freertos_stk.cpp.

2670{
2671 if (IsIrqContext() || (xTimer == nullptr) || (g_TimerHost == nullptr))
2672 return pdFAIL;
2673
2674 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2675
2676 if (!t->IsActive())
2677 return pdFAIL;
2678
2679 return g_TimerHost->Stop(*t) ? pdPASS : pdFAIL;
2680}

References g_TimerHost, stk::time::TimerHost::Timer::IsActive(), IsIrqContext(), pdFAIL, and pdPASS.

Here is the call graph for this function:

◆ xTimerStopFromISR()

BaseType_t xTimerStopFromISR ( TimerHandle_t xTimer,
BaseType_t * pxHigherPriorityTaskWoken )

Stop a running timer from ISR context.

Parameters
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the timer is not running or handle is invalid.

Definition at line 2737 of file freertos_stk.cpp.

2739{
2740 if (pxHigherPriorityTaskWoken != nullptr)
2741 *pxHigherPriorityTaskWoken = pdFALSE;
2742
2743 if ((xTimer == nullptr) || (g_TimerHost == nullptr))
2744 return pdFAIL;
2745
2746 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2747
2748 if (!t->IsActive())
2749 return pdFAIL;
2750
2751 return g_TimerHost->Stop(*t) ? pdPASS : pdFAIL;
2752}

References g_TimerHost, stk::time::TimerHost::Timer::IsActive(), pdFAIL, pdFALSE, and pdPASS.

Here is the call graph for this function: