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)
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)
void vTaskResume (TaskHandle_t xTaskToResume)
BaseType_t xTaskResumeFromISR (TaskHandle_t xTaskToResume)
BaseType_t xTaskAbortDelay (TaskHandle_t xTask)
void vTaskDelay (TickType_t xTicksToDelay)
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)
UBaseType_t uxTaskPriorityGet (TaskHandle_t xTask)
UBaseType_t uxTaskPriorityGetFromISR (TaskHandle_t xTask)
eTaskState eTaskGetState (TaskHandle_t xTask)
TaskHandle_t xTaskGetCurrentTaskHandle (void)
TaskHandle_t xTaskGetHandle (const char *pcNameToQuery)
const char * pcTaskGetName (TaskHandle_t xTaskToQuery)
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)
BaseType_t xQueueSend (QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
BaseType_t xQueueSendToBack (QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
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)
UBaseType_t uxQueueMessagesWaitingFromISR (QueueHandle_t xQueue)
UBaseType_t uxQueueSpacesAvailable (QueueHandle_t xQueue)
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)
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)
BaseType_t xSemaphoreGive (SemaphoreHandle_t xSemaphore)
BaseType_t xSemaphoreGiveRecursive (SemaphoreHandle_t xMutex)
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)
void vTimerSetTimerID (TimerHandle_t xTimer, void *pvNewID)
const char * pcTimerGetName (TimerHandle_t xTimer)
TickType_t xTimerGetPeriod (TimerHandle_t xTimer)
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)
EventBits_t xEventGroupSetBits (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet)
EventBits_t xEventGroupClearBits (EventGroupHandle_t xEventGroup, EventBits_t uxBitsToClear)
EventBits_t xEventGroupGetBits (EventGroupHandle_t xEventGroup)
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)
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)
size_t xStreamBufferSpacesAvailable (StreamBufferHandle_t xStreamBuffer)
BaseType_t xStreamBufferIsEmpty (StreamBufferHandle_t xStreamBuffer)
BaseType_t xStreamBufferIsFull (StreamBufferHandle_t xStreamBuffer)
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)
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 2207 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 570 of file FreeRTOS.h.

◆ portYIELD

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

Definition at line 408 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 518 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 540 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 486 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 497 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 529 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 475 of file FreeRTOS.h.

475#define STATIC_TASK_TCB_SIZE_WORDS (19U + configNUM_THREAD_LOCAL_STORAGE_POINTERS \
476 + (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 508 of file FreeRTOS.h.

◆ taskDISABLE_INTERRUPTS

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

Definition at line 405 of file FreeRTOS.h.

◆ taskENABLE_INTERRUPTS

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

Definition at line 406 of file FreeRTOS.h.

◆ taskENTER_CRITICAL

#define taskENTER_CRITICAL ( )
Value:

Definition at line 403 of file FreeRTOS.h.

◆ taskEXIT_CRITICAL

#define taskEXIT_CRITICAL ( )
Value:

Definition at line 404 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 438 of file FreeRTOS.h.

Referenced by xTaskGetSchedulerState().

◆ taskSCHEDULER_RUNNING

#define taskSCHEDULER_RUNNING   ((BaseType_t)1)

Scheduler is running normally (STATE_RUNNING).

Definition at line 439 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 440 of file FreeRTOS.h.

Referenced by xTaskGetSchedulerState().

◆ taskYIELD

#define taskYIELD ( )
Value:

Definition at line 407 of file FreeRTOS.h.

◆ tskIDLE_PRIORITY

#define tskIDLE_PRIORITY   ((UBaseType_t)0U)

Idle task priority.

Definition at line 2208 of file FreeRTOS.h.

Referenced by FrtosTask::FrtosTask().

◆ xTaskHandle

#define xTaskHandle   TaskHandle_t

Legacy handle alias.

Definition at line 2209 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.

Parameters
xTaskHandle of the task to query.
Returns
One of eRunning, eReady, eBlocked, eSuspended, eDeleted, or eInvalid.

Definition at line 1344 of file freertos_stk.cpp.

1345{
1346 if (xTask == nullptr)
1347 return eInvalid;
1348
1349 FrtosTask *t = static_cast<FrtosTask *>(xTask);
1350
1352 return eDeleted;
1353
1355 return eSuspended;
1356
1357 // Check whether this is the currently running task.
1358 if (static_cast<uintptr_t>(stk::GetTid()) == reinterpret_cast<uintptr_t>(t))
1359 return eRunning;
1360
1361 return eReady;
1362}
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:237
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.

Parameters
xTaskToQueryHandle of the task to query, or NULL for the calling task.
Returns
Pointer to the task's name string (not a copy; valid for the task's lifetime).

Definition at line 1394 of file freertos_stk.cpp.

1395{
1396 if (xTaskToQuery == nullptr)
1397 return nullptr;
1398
1399 return static_cast<FrtosTask *>(xTaskToQuery)->m_name;
1400}

◆ pcTimerGetName()

const char * pcTimerGetName ( TimerHandle_t xTimer)

Return the name string of a timer.

Parameters
xTimerHandle of the timer to query.
Returns
Pointer to the timer's name string (not a copy; valid for the timer's lifetime).

Definition at line 2917 of file freertos_stk.cpp.

2918{
2919 if (xTimer == nullptr)
2920 return nullptr;
2921
2922 return static_cast<FrtosTimer *>(xTimer)->m_name;
2923}

◆ 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 203 of file freertos_stk.cpp.

204{
205 return stk::memory::MemoryAllocator::Allocate(xWantedSize);
206}
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 3681 of file freertos_stk.cpp.

3683{
3684 if (xIndex < 0 || static_cast<size_t>(xIndex) >= configNUM_THREAD_LOCAL_STORAGE_POINTERS)
3685 return nullptr;
3686
3687 // Resolve NULL -> calling task.
3688 if (xTaskToQuery == nullptr)
3689 xTaskToQuery = xTaskGetCurrentTaskHandle();
3690
3691 if (xTaskToQuery == nullptr)
3692 return nullptr;
3693
3694 const FrtosTask *t = static_cast<const FrtosTask *>(xTaskToQuery);
3695
3697 return t->m_tls[static_cast<size_t>(xIndex)];
3698}
TaskHandle_t xTaskGetCurrentTaskHandle(void)
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.

Parameters
xTimerHandle of the timer to query.
Returns
The ID value set at creation or by vTimerSetTimerID().

Definition at line 2901 of file freertos_stk.cpp.

2902{
2903 if (xTimer == nullptr)
2904 return nullptr;
2905
2906 return static_cast<FrtosTimer *>(xTimer)->m_timer_id;
2907}

◆ taskYIELD_impl()

void taskYIELD_impl ( void )

Request an immediate context switch to the highest-priority ready task. Called by the taskYIELD() and portYIELD() macros.

Note
May trigger a preemption; safe only from task context.

Definition at line 380 of file freertos_stk.cpp.

381{
382 stk::Yield();
383}
static void Yield()
Notify scheduler to switch to the next runnable task.
Definition stk_helper.h:402

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 3399 of file freertos_stk.cpp.

3400{
3401 return ulTaskNotifyTakeIndexed(0U, ulClearCountOnExit, xTicksToWait);
3402}
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 3282 of file freertos_stk.cpp.

3285{
3286 if (IsIrqContext())
3287 return 0U;
3288
3289 FrtosTask *t = ResolveNotifyTarget(nullptr, uxIndexToWait);
3290 if (t == nullptr)
3291 return 0U;
3292
3293 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToWait];
3294
3295 if (!slot.sem.Wait(FrtosTimeoutToStk(xTicksToWait)))
3296 return 0U;
3297
3298 uint32_t val = 0U;
3299
3300 {
3302 val = slot.value;
3303
3304 if (ulClearCountOnExit == pdTRUE)
3305 slot.value = 0U;
3306 else
3307 if (slot.value > 0U)
3308 slot.value--;
3309 }
3310
3311 return val + 1U; // +1: the semaphore signal itself counts
3312}
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 3634 of file freertos_stk.cpp.

3636{
3637 return ulTaskNotifyValueClearIndexed(xTask, 0U, ulBitsToClear);
3638}
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 3612 of file freertos_stk.cpp.

3615{
3616 FrtosTask *t = ResolveNotifyTarget(xTask, uxIndexToClear);
3617 if (t == nullptr)
3618 return 0U;
3619
3620 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToClear];
3621
3623
3624 const uint32_t prev = slot.value;
3625 slot.value &= ~ulBitsToClear;
3626
3627 return prev;
3628}

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.

Parameters
xQueueHandle of the queue to inspect.
Returns
Number of items currently stored in the queue.

Definition at line 1814 of file freertos_stk.cpp.

1815{
1816 if (xQueue == nullptr)
1817 return 0U;
1818
1819 return static_cast<UBaseType_t>(
1820 static_cast<FrtosQueue *>(xQueue)->m_mq.GetCount());
1821}
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.

Parameters
xQueueHandle of the queue to inspect.
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 1823 of file freertos_stk.cpp.

1824{
1825 // GetCount() is ISR-safe on targets where a size_t-aligned read is atomic
1826 // (per the STK MessageQueue documentation).
1827 if (xQueue == nullptr)
1828 return 0U;
1829
1830 return static_cast<UBaseType_t>(static_cast<FrtosQueue *>(xQueue)->m_mq.GetCount());
1831}

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.

Parameters
xQueueHandle of the queue to inspect.
Returns
Number of items that can still be enqueued without blocking.

Definition at line 1833 of file freertos_stk.cpp.

1834{
1835 if (xQueue == nullptr)
1836 return 0U;
1837
1838 return static_cast<UBaseType_t>(
1839 static_cast<FrtosQueue *>(xQueue)->m_mq.GetSpace());
1840}
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).

Parameters
xSemaphoreHandle of the semaphore or mutex to query.
Returns
Current count value.

Definition at line 2518 of file freertos_stk.cpp.

2519{
2520 if (xSemaphore == nullptr)
2521 return 0U;
2522
2523 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2524
2525 if (s->m_kind == SemKind::Counting)
2526 return static_cast<UBaseType_t>(s->m_sem->GetCount());
2527
2528#if configUSE_MUTEXES
2529 // For a mutex, count = 0 means locked, 1 means unlocked.
2530 return (s->m_mtx->GetOwner() == stk::TID_NONE) ? 1U : 0U;
2531#else
2532 return 0U;
2533#endif
2534}
@ Counting
Binary or counting semaphore (backed by stk::sync::Semaphore).
constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Definition stk_common.h:198
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 1100 of file freertos_stk.cpp.

1101{
1103 return static_cast<UBaseType_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
1104}
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.

Parameters
xTaskHandle of the task to query, or NULL for the calling task.
Returns
Minimum free stack space observed since task creation, in Words.

Definition at line 1402 of file freertos_stk.cpp.

1403{
1404 const FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<const FrtosTask *>(
1405 static_cast<uintptr_t>(stk::GetTid())) : static_cast<const FrtosTask *>(xTask);
1406
1407 if (t == nullptr)
1408 return 0U;
1409
1410 return static_cast<UBaseType_t>(t->GetStackHighWaterMark());
1411}
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.

Parameters
xTaskHandle of the task to query, or NULL for the calling task.
Returns
Minimum free stack space observed since task creation, in Words (returned as configSTACK_DEPTH_TYPE for extended range on 32-bit targets).

< Stack depth word type.

< Stack depth word type.

Definition at line 1413 of file freertos_stk.cpp.

1414{
1415 const FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<const FrtosTask *>(
1416 static_cast<uintptr_t>(stk::GetTid())) : static_cast<const FrtosTask *>(xTask);
1417
1418 if (t == nullptr)
1419 return 0U;
1420
1421 return static_cast<configSTACK_DEPTH_TYPE>(t->GetStackHighWaterMark());
1422}
#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 1424 of file freertos_stk.cpp.

1427{
1428 // STK has no global CPU run-time accumulator; report 0 per the FreeRTOS
1429 // convention for targets that do not implement run-time statistics.
1430 if (pulTotalRunTime != nullptr)
1431 *pulTotalRunTime = 0U;
1432
1433 if ((pxTaskStatusArray == nullptr) || (uxArraySize == 0U))
1434 return 0U;
1435
1436 UBaseType_t filled = 0U;
1437
1438 // Identify the currently running task once, outside the enumeration
1439 // loop, so the eRunning check is consistent across all entries.
1440 const uintptr_t running_tid = static_cast<uintptr_t>(stk::GetTid());
1441
1442 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *itask) -> bool
1443 {
1444 if (filled >= uxArraySize)
1445 return false; // array full — stop enumeration
1446
1447 const FrtosTask *t = static_cast<const FrtosTask *>(itask);
1448 TaskStatus_t &s = pxTaskStatusArray[filled];
1449
1450 // xHandle — the FrtosTask pointer cast to an opaque handle.
1451 s.xHandle = static_cast<TaskHandle_t>(const_cast<FrtosTask *>(t));
1452
1453 // pcTaskName — direct pointer into the task's name buffer (not a copy).
1454 s.pcTaskName = (t->m_name != nullptr) ? t->m_name : "";
1455
1456 // eCurrentState — mirrors eTaskGetState() logic.
1459 else
1462 else
1463 if (reinterpret_cast<uintptr_t>(t) == running_tid)
1465 else
1467
1468 // uxCurrentPriority / uxBasePriority — same value: STK has no
1469 // priority inheritance so the current and base priority are identical.
1472
1473 // ulRunTimeCounter — always 0 (STK has no per-task CPU accounting).
1474 s.ulRunTimeCounter = 0U;
1475
1476 // pxStackBase — bottom of the stack array (index 0).
1477 s.pxStackBase = reinterpret_cast<StackType_t *>(t->m_stack);
1478
1479 // usStackHighWaterMark — minimum observed free Words (watermark scan).
1482
1483 // xTaskNumber — monotonic serial assigned at construction.
1485
1486 ++filled;
1487 return true; // continue enumeration
1488 });
1489
1490 return filled;
1491}
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:670
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.

Parameters
xTaskHandle of the task to query, or NULL for the calling task.
Returns
Current priority level of the task.

Definition at line 1328 of file freertos_stk.cpp.

1329{
1330 const FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<const FrtosTask *>(
1331 static_cast<uintptr_t>(stk::GetTid())) : static_cast<const FrtosTask *>(xTask);
1332
1333 if (t == nullptr)
1334 return 0U;
1335
1336 return StkWeightToFrtosPrio(t->m_weight);
1337}

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).

Parameters
xTaskHandle of the task to query.
Returns
Current priority level of the task.

Definition at line 1339 of file freertos_stk.cpp.

1340{
1341 return uxTaskPriorityGet(xTask); // same implementation; GetTid() is ISR-safe
1342}
UBaseType_t uxTaskPriorityGet(TaskHandle_t xTask)

References uxTaskPriorityGet().

Here is the call graph for this function:

◆ vEventGroupDelete()

void vEventGroupDelete ( EventGroupHandle_t xEventGroup)

Delete an event group and free its memory.

Parameters
xEventGroupHandle of the event group to delete.

Definition at line 3010 of file freertos_stk.cpp.

3011{
3012 if (xEventGroup == nullptr)
3013 return;
3014
3015 ObjFree(static_cast<FrtosEventGroup *>(xEventGroup));
3016}
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).

Parameters
xMessageBufferHandle of the message buffer to delete.

Definition at line 4224 of file freertos_stk.cpp.

4225{
4226 if (xMessageBuffer == nullptr)
4227 return;
4228
4229 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4230
4231 ObjFree(mb);
4232}

References ObjFree().

Here is the call graph for this function:

◆ vPortEnterCritical()

void vPortEnterCritical ( void )

Enter a critical section by disabling preemption and interrupts. Calls may be nested; each call must be balanced by a matching vPortExitCritical().

Note
Not ISR-safe; must only be called from task context.

Definition at line 370 of file freertos_stk.cpp.

371{
373}
static void Enter()
Enter a critical section.

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

Here is the call graph for this function:

◆ vPortExitCritical()

void vPortExitCritical ( void )

Exit a critical section previously entered with vPortEnterCritical(). Re-enables preemption and interrupts only when the outermost nesting level is exited.

Note
Not ISR-safe; must only be called from task context.

Definition at line 375 of file freertos_stk.cpp.

376{
378}
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 208 of file freertos_stk.cpp.

209{
211}
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 252 of file freertos_stk.cpp.

253{
254 if (pxHeapStats == nullptr)
255 return;
256
258 const size_t free_now = snap.GetAvailable();
259
260 (*pxHeapStats) = {};
261
262 // Fields derived directly from s_MemStats accounting.
263 pxHeapStats->xAvailableHeapSpaceInBytes = free_now;
266 pxHeapStats->xNumberOfSuccessfulFrees = snap.free_count;
267
268 // Fields that require free-block-list traversal are unavailable without a
269 // block-list allocator (we delegate to malloc). Report conservative values:
270 // - largest free block : current free bytes (treat heap as one region)
271 // - smallest free block : 0 (unknown subdivision)
272 // - number of free blocks: 1 (at least one region exists while free > 0)
273 pxHeapStats->xSizeOfLargestFreeBlockInBytes = free_now;
274 pxHeapStats->xSizeOfSmallestFreeBlockInBytes = (free_now > 0U) ? 1U : 0U;
275 pxHeapStats->xNumberOfFreeBlocks = (free_now > 0U) ? 1U : 0U;
276}
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:2158
size_t xMinimumEverFreeBytesRemaining
Definition FreeRTOS.h:2160
size_t xNumberOfSuccessfulAllocations
Definition FreeRTOS.h:2161
size_t xSizeOfLargestFreeBlockInBytes
Definition FreeRTOS.h:2157
size_t xNumberOfFreeBlocks
Definition FreeRTOS.h:2159
size_t xNumberOfSuccessfulFrees
Definition FreeRTOS.h:2162
size_t xAvailableHeapSpaceInBytes
Definition FreeRTOS.h:2156

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.

Parameters
xQueueHandle of the queue to delete.

Definition at line 1718 of file freertos_stk.cpp.

1719{
1720 if (xQueue == nullptr)
1721 return;
1722
1723 ObjFree(static_cast<FrtosQueue *>(xQueue));
1724}

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.

Parameters
xSemaphoreHandle of the semaphore or mutex to delete.

Definition at line 2398 of file freertos_stk.cpp.

2399{
2400 if (xSemaphore == nullptr)
2401 return;
2402
2403 ObjFree(static_cast<FrtosSemaphore *>(xSemaphore));
2404}

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).

Parameters
xStreamBufferHandle of the stream buffer to delete.

Definition at line 3772 of file freertos_stk.cpp.

3773{
3774 if (xStreamBuffer == nullptr)
3775 return;
3776
3777 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3778
3779 ObjFree(sb);
3780}

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.

Parameters
xTicksToDelayNumber of ticks to block. 0 yields without blocking.

Definition at line 1291 of file freertos_stk.cpp.

1292{
1293 if (IsIrqContext())
1294 return;
1295
1296 stk::Sleep(FrtosTimeoutToStk(xTicksToDelay));
1297}
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
Definition stk_helper.h:358

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.

Parameters
pxPreviousWakeTimeIn/out: tick count at the last wake point; updated on return.
xTimeIncrementPeriod in ticks between successive wake points.

Definition at line 1299 of file freertos_stk.cpp.

1300{
1301 static_cast<void>(xTaskDelayUntil(pxPreviousWakeTime, xTimeIncrement));
1302}
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.

Parameters
xTaskToDeleteHandle of the task to delete, or NULL to delete the calling task.

Definition at line 1209 of file freertos_stk.cpp.

1210{
1211 FrtosTask *t = (xTaskToDelete == nullptr) ? static_cast<FrtosTask *>(
1212 reinterpret_cast<FrtosTask *>(static_cast<uintptr_t>(stk::GetTid()))) :
1213 static_cast<FrtosTask *>(xTaskToDelete);
1214
1215 if (t == nullptr)
1216 return;
1217
1219
1220 g_StkKernel.ScheduleTaskRemoval(t);
1221
1222 // Detached tasks are freed when the slot is released.
1223 // For this wrapper, all tasks are considered detached (no join semantics).
1224 ObjFree(t);
1225}

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 1068 of file freertos_stk.cpp.

1069{
1070 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *task) -> bool
1071 {
1072 g_StkKernel.ScheduleTaskRemoval(task);
1073 return true;
1074 });
1075
1076 stk::Yield();
1077}

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 1619 of file freertos_stk.cpp.

1620{
1621 if (pcWriteBuffer == nullptr)
1622 return;
1623
1624 // Column header matching FreeRTOS vTaskGetRunTimeStats() output format so
1625 // that existing log parsers (SystemView, Tracealyzer, custom scripts) find
1626 // the layout they expect.
1627 int off = snprintf(pcWriteBuffer, 64U,
1628 "%-12s %12s %8s\r\n",
1629 "Task", "Abs Time", "% Time");
1630
1631 if (off < 0) off = 0;
1632 char *p = pcWriteBuffer + off;
1633
1634 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *itask) -> bool
1635 {
1636 const FrtosTask *t = static_cast<const FrtosTask *>(itask);
1637 const char *name = (t->m_name != nullptr) ? t->m_name : "(unnamed)";
1638
1639 // ulRunTimeCounter is always 0: STK has no per-task CPU accounting.
1640 // Percentage is therefore also 0. Emit "<1%" only when a non-zero
1641 // total is available; here total is always 0 so we emit "0%".
1642 int n = snprintf(p, 48U, "%-12s %12lu %7lu%%\r\n",
1643 name,
1644 0UL, // ulRunTimeCounter
1645 0UL); // percentage
1646 if (n > 0) p += n;
1647
1648 return true; // continue enumeration
1649 });
1650
1651 *p = '\0'; // null-terminate
1652}

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 1548 of file freertos_stk.cpp.

1549{
1550 if (pcWriteBuffer == nullptr)
1551 return;
1552
1553 // Write the column header that FreeRTOS vTaskList() produces, so that
1554 // existing log parsers find what they expect.
1555 int off = snprintf(pcWriteBuffer, 64U,
1556 "%-12s %c %4s %6s %4s\r\n",
1557 "Name", 'S', "Prio", "Stack", "Num");
1558
1559 if (off < 0) off = 0;
1560 char *p = pcWriteBuffer + off;
1561
1562 // Enumerate all tasks and fill one row per task.
1563 UBaseType_t task_num = 0U;
1564
1565 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *itask) -> bool
1566 {
1567 ++task_num;
1568 FrtosTask *t = static_cast<FrtosTask *>(itask);
1569
1570 // Determine state letter, matching FreeRTOS convention:
1571 // X = Running, R = Ready, B = Blocked, S = Suspended, D = Deleted
1572 char state_letter;
1574 state_letter = 'D';
1575 else
1577 state_letter = 'S';
1578 else
1579 if (static_cast<uintptr_t>(stk::GetTid()) == reinterpret_cast<uintptr_t>(t))
1580 state_letter = 'X';
1581 else
1582 state_letter = 'R';
1583
1584 const char *name = (t->m_name != nullptr) ? t->m_name : "(unnamed)";
1586 size_t hwm = t->GetStackHighWaterMark();
1587
1588 int n = snprintf(p, 48U, "%-12s %c %4u %6u %4u\r\n",
1589 name, state_letter,
1590 static_cast<unsigned>(prio),
1591 static_cast<unsigned>(hwm),
1592 static_cast<unsigned>(task_num));
1593 if (n > 0) p += n;
1594
1595 return true; // continue enumeration
1596 });
1597
1598 *p = '\0'; // null-terminate
1599}

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.

Parameters
xTaskHandle of the task to modify, or NULL for the calling task.
uxNewPriorityNew priority level (0 = lowest, configMAX_PRIORITIES-1 = highest).

Definition at line 1317 of file freertos_stk.cpp.

1318{
1319 FrtosTask *t = (xTask == nullptr) ? reinterpret_cast<FrtosTask *>(
1320 static_cast<uintptr_t>(stk::GetTid())) : static_cast<FrtosTask *>(xTask);
1321
1322 if (t == nullptr)
1323 return;
1324
1325 t->m_weight = FrtosPrioToStkWeight(uxNewPriority);
1326}
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.

Parameters
xTaskToResumeHandle of the task to resume.

Definition at line 1241 of file freertos_stk.cpp.

1242{
1243 if (xTaskToResume == nullptr)
1244 return;
1245
1246 FrtosTask *t = static_cast<FrtosTask *>(xTaskToResume);
1247
1249
1251 return;
1252
1253 g_StkKernel.ResumeTask(t);
1255}

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 3658 of file freertos_stk.cpp.

3661{
3662 if (xIndex < 0 || static_cast<size_t>(xIndex) >= configNUM_THREAD_LOCAL_STORAGE_POINTERS)
3663 return;
3664
3665 // Resolve NULL -> calling task.
3666 if (xTaskToSet == nullptr)
3667 xTaskToSet = xTaskGetCurrentTaskHandle();
3668
3669 if (xTaskToSet == nullptr)
3670 return;
3671
3672 FrtosTask *t = static_cast<FrtosTask *>(xTaskToSet);
3673
3674 // A critical section is not strictly required for a pointer-sized store on
3675 // aligned memory on single-issue cores, but we guard anyway for strict
3676 // correctness on SMP targets (RP2040, dual-core Cortex-M33).
3678 t->m_tls[static_cast<size_t>(xIndex)] = pvValue;
3679}

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 1061 of file freertos_stk.cpp.

1062{
1064
1065 g_StkKernel.Start(); // does not return for KERNEL_DYNAMIC until all tasks exit
1066}
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.

Parameters
xTaskToSuspendHandle of the task to suspend, or NULL for the calling task.

Definition at line 1227 of file freertos_stk.cpp.

1228{
1229 FrtosTask *t = (xTaskToSuspend == nullptr) ? static_cast<FrtosTask *>(
1230 reinterpret_cast<FrtosTask *>(static_cast<uintptr_t>(stk::GetTid()))) :
1231 static_cast<FrtosTask *>(xTaskToSuspend);
1232
1233 if (t == nullptr)
1234 return;
1235
1236 bool already = false;
1237 g_StkKernel.SuspendTask(t, already);
1239}

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 1079 of file freertos_stk.cpp.

1080{
1082}

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.

Parameters
xTimerHandle of the timer to modify.
pvNewIDNew ID value to store in the timer.

Definition at line 2909 of file freertos_stk.cpp.

2910{
2911 if (xTimer == nullptr)
2912 return;
2913
2914 static_cast<FrtosTimer *>(xTimer)->m_timer_id = pvNewID;
2915}

◆ xEventGroupClearBits()

EventBits_t xEventGroupClearBits ( EventGroupHandle_t xEventGroup,
EventBits_t uxBitsToClear )

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

Parameters
xEventGroupHandle of the event group to modify.
uxBitsToClearBitmask of bits to clear (ANDed with complement into the current value).
Returns
Value of the bits BEFORE clearing.

Definition at line 3028 of file freertos_stk.cpp.

3030{
3031 if (xEventGroup == nullptr)
3032 return 0U;
3033
3034 // STK Clear() returns the value BEFORE clearing - matches FreeRTOS contract.
3035 uint32_t prev = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Clear(uxBitsToClear);
3036 return StkFlagsToFrtos(prev);
3037}
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.

Parameters
xEventGroupHandle of the event group to modify.
uxBitsToClearBitmask of bits to clear.
Returns
Value of the bits BEFORE clearing.

Definition at line 3086 of file freertos_stk.cpp.

3088{
3089 if (xEventGroup == nullptr)
3090 return 0U;
3091
3092 uint32_t prev = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Clear(
3093 static_cast<uint32_t>(uxBitsToClear));
3094 return StkFlagsToFrtos(prev);
3095}

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 2983 of file freertos_stk.cpp.

2984{
2985 if (IsIrqContext())
2986 return nullptr;
2987
2989 return static_cast<EventGroupHandle_t>(eg);
2990}
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 2992 of file freertos_stk.cpp.

2993{
2994 if (pxEventGroupBuffer == nullptr)
2995 return nullptr;
2996
2997 if (IsIrqContext())
2998 return nullptr;
2999
3000 static_assert(sizeof(StaticEventGroup_t) >= sizeof(FrtosEventGroup),
3001 "StaticEventGroup_t is too small to hold FrtosEventGroup. "
3002 "Increase STATIC_EVENT_GROUP_TCB_SIZE_WORDS in freertos_stk.h.");
3003
3004 FrtosEventGroup *eg = new (pxEventGroupBuffer) FrtosEventGroup();
3005 eg->m_cb_owned = false; // caller owns the memory; vEventGroupDelete must not delete it
3006
3007 return static_cast<EventGroupHandle_t>(eg);
3008}

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.

Parameters
xEventGroupHandle of the event group to read.
Returns
Current bitmask value of the event group.

Definition at line 3039 of file freertos_stk.cpp.

3040{
3041 if (xEventGroup == nullptr)
3042 return 0U;
3043
3044 return static_cast<EventBits_t>(static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Get());
3045}
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).

Parameters
xEventGroupHandle of the event group to modify.
uxBitsToSetBitmask of bits to set (OR'd into the current value).
Returns
Value of the event group bits after the set operation.

Definition at line 3018 of file freertos_stk.cpp.

3020{
3021 if (xEventGroup == nullptr)
3022 return 0U;
3023
3024 uint32_t result = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Set(uxBitsToSet);
3025 return StkFlagsToFrtos(result);
3026}

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
xEventGroupHandle of the event group to modify.
uxBitsToSetBitmask of bits to set.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdPASS on success, pdFAIL on invalid bits argument.

Definition at line 3070 of file freertos_stk.cpp.

3073{
3074 if (xEventGroup == nullptr)
3075 return pdFAIL;
3076
3077 uint32_t result = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef.Set(
3078 static_cast<uint32_t>(uxBitsToSet));
3079
3080 if (pxHigherPriorityTaskWoken != nullptr)
3081 *pxHigherPriorityTaskWoken = pdFALSE;
3082
3083 return stk::sync::EventFlags::IsError(result) ? pdFAIL : pdPASS;
3084}
#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 3143 of file freertos_stk.cpp.

3147{
3148 // Contract checks that mirror the FreeRTOS reference implementation.
3149 if (xEventGroup == nullptr) return 0U;
3150 if (uxBitsToWaitFor == 0U) return 0U;
3151 if (IsIrqContext()) return 0U; // blocking wait is ISR-unsafe
3152
3153 FrtosEventGroup *eg = static_cast<FrtosEventGroup *>(xEventGroup);
3154 stk::sync::EventFlags &ef = eg->m_ef;
3155
3156 // Step 1: Set this task's rendezvous bit(s).
3157 //
3158 // uxBitsToSet == 0 is legal (observer role: task waits without contributing
3159 // a bit). Only call Set() when there is actually something to set.
3160 if (uxBitsToSet != 0U)
3161 {
3162 uint32_t set_result = ef.Set(static_cast<uint32_t>(uxBitsToSet));
3163
3164 // Treat an ERROR_PARAMETER return as a hard usage fault — the caller
3165 // violated the API (e.g. set bit 31).
3167
3168 if (stk::sync::EventFlags::IsError(set_result))
3169 return 0U;
3170 }
3171
3172 // Step 2 + 3: Wait for ALL bits in uxBitsToWaitFor, clear them on success.
3173 //
3174 // OPT_WAIT_ALL — AND semantics: all bits must be set simultaneously.
3175 // OPT_NO_CLEAR is NOT passed — matched bits are cleared atomically inside
3176 // Wait() when the predicate is first satisfied, exactly matching the
3177 // FreeRTOS "clear bits on exit" contract for xEventGroupSync().
3178 const uint32_t opts = stk::sync::EventFlags::OPT_WAIT_ALL;
3179 // (OPT_NO_CLEAR absent -> clear on success)
3180
3181 uint32_t result = ef.Wait(static_cast<uint32_t>(uxBitsToWaitFor),
3182 opts,
3183 FrtosTimeoutToStk(xTicksToWait));
3184
3185 // On timeout or error, return 0 (matches FreeRTOS reference behaviour).
3186 return StkFlagsToFrtos(result);
3187}
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
Definition stk_defs.h:409
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
xEventGroupHandle of the event group to wait on.
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 3047 of file freertos_stk.cpp.

3052{
3053 if (IsIrqContext() || (xEventGroup == nullptr) || (uxBitsToWaitFor == 0U))
3054 return 0U;
3055
3056 stk::sync::EventFlags &ef = static_cast<FrtosEventGroup *>(xEventGroup)->m_ef;
3057
3058 uint32_t opts = BuildStkFlagsOpts(xClearOnExit, xWaitForAllBits);
3059 uint32_t result = ef.Wait(static_cast<uint32_t>(uxBitsToWaitFor),
3060 opts,
3061 FrtosTimeoutToStk(xTicksToWait));
3062
3063 // On timeout, FreeRTOS documents that the return value is the flags word
3064 // at the moment the timeout occurred, not zero. ef.Get() is a volatile
3065 // read that is atomic on all supported 32-bit STK targets; no CS needed.
3066 const EventBits_t snapshot = static_cast<EventBits_t>(ef.Get());
3067 return StkFlagsToFrtos(result, snapshot);
3068}
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 4104 of file freertos_stk.cpp.

4106{
4107 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4108 return nullptr;
4109
4110 const size_t count = MsgBufSlotCount(xBufferSizeBytes, xMaxMessageSize);
4111
4112 if (count == 0U)
4113 return nullptr;
4114
4115 FrtosMessageBuffer *mb = ObjAlloc<FrtosMessageBuffer>(xMaxMessageSize, count);
4116
4117 if (mb == nullptr)
4118 return nullptr;
4119
4120 if (!mb->m_pool.IsStorageValid() || !mb->m_eq.IsStorageValid())
4121 {
4122 ObjFreeRaw(mb);
4123 return nullptr;
4124 }
4125
4126 return static_cast<MessageBufferHandle_t>(mb);
4127}
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 4129 of file freertos_stk.cpp.

4134{
4135 if ((pucMessageBufferStorageArea == nullptr) ||
4136 (pxStaticMessageBuffer == nullptr) ||
4137 (xMaxMessageSize == 0U) ||
4138 (xMessageCount == 0U))
4139 return nullptr;
4140
4141 const size_t block_size = stk::memory::BlockMemoryPool::AlignBlockSize(xMaxMessageSize);
4142 const size_t storage_size = xMessageCount * (block_size + FrtosMessageBuffer::ENVELOPE_SIZE);
4143
4144 FrtosMessageBuffer *mb = new (pxStaticMessageBuffer)
4145 FrtosMessageBuffer(xMaxMessageSize, xMessageCount,
4146 pucMessageBufferStorageArea, storage_size);
4147
4148 return static_cast<MessageBufferHandle_t>(mb);
4149}
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 4196 of file freertos_stk.cpp.

4203{
4204 if ((pucMessageBufferStorageArea == nullptr) ||
4205 (pxStaticMessageBuffer == nullptr) ||
4206 (xMaxMessageSize == 0U) ||
4207 (xMessageCount == 0U))
4208 return nullptr;
4209
4210 static_assert(sizeof(StaticMessageBuffer_t) >= sizeof(FrtosMessageBuffer),
4211 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4212
4213 const size_t block_size = stk::memory::BlockMemoryPool::AlignBlockSize(xMaxMessageSize);
4214 const size_t storage_size = xMessageCount * (block_size + FrtosMessageBuffer::ENVELOPE_SIZE);
4215
4216 FrtosMessageBuffer *mb = new (pxStaticMessageBuffer)
4217 FrtosMessageBuffer(xMaxMessageSize, xMessageCount,
4218 pucMessageBufferStorageArea, storage_size,
4219 pxSendCompletedCallback, pxReceiveCompletedCallback);
4220
4221 return static_cast<MessageBufferHandle_t>(mb);
4222}

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 4162 of file freertos_stk.cpp.

4167{
4168 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4169 return nullptr;
4170
4171 const size_t block_size = stk::memory::BlockMemoryPool::AlignBlockSize(xMaxMessageSize);
4172 const size_t slot_cost = block_size + FrtosMessageBuffer::ENVELOPE_SIZE;
4173 const size_t count = xBufferSizeBytes / slot_cost;
4174
4175 if (count == 0U)
4176 return nullptr;
4177
4179 xMaxMessageSize, count,
4180 pxSendCompletedCallback, pxReceiveCompletedCallback);
4181
4182 if (mb == nullptr)
4183 return nullptr;
4184
4185 // Detect heap failure in the envelope buffer allocation performed by the
4186 // heap constructor (m_eq is backed by a separately ObjAllocArray'd byte array).
4187 if (!mb->m_eq.IsStorageValid())
4188 {
4189 ObjFreeRaw(mb);
4190 return nullptr;
4191 }
4192
4193 return static_cast<MessageBufferHandle_t>(mb);
4194}

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.

Parameters
xMessageBufferHandle of the message buffer.
Note
ISR-safe.

Definition at line 4325 of file freertos_stk.cpp.

4326{
4327 if (xMessageBuffer == nullptr)
4328 return pdTRUE;
4329
4330 return static_cast<FrtosMessageBuffer *>(xMessageBuffer)->m_eq.IsEmpty()
4331 ? pdTRUE : pdFALSE;
4332}

References pdFALSE, and pdTRUE.

◆ xMessageBufferIsFull()

BaseType_t xMessageBufferIsFull ( MessageBufferHandle_t xMessageBuffer)

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

Parameters
xMessageBufferHandle of the message buffer.
Note
ISR-safe.

Definition at line 4334 of file freertos_stk.cpp.

4335{
4336 if (xMessageBuffer == nullptr)
4337 return pdTRUE;
4338
4339 return static_cast<FrtosMessageBuffer *>(xMessageBuffer)->m_pool.IsFull()
4340 ? pdTRUE : pdFALSE;
4341}

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.

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

Definition at line 4540 of file freertos_stk.cpp.

4541{
4542 if (xMessageBuffer == nullptr)
4543 return 0U;
4544
4545 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4546
4547 // TryPeek copies the oldest envelope without consuming it. The internal
4548 // ScopedCriticalSection makes this ISR-safe; no outer CS is required.
4549 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4550
4551 if (!mb->m_eq.TryPeek(&env))
4552 return 0U; // buffer is empty — nothing to peek at
4553
4554 return env.len;
4555}
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
xMessageBufferHandle of the message buffer to receive from.
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 4282 of file freertos_stk.cpp.

4286{
4287 if ((xMessageBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
4288 return 0U;
4289
4290 if (IsIrqContext() && (xTicksToWait != 0U))
4291 return 0U;
4292
4293 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4294
4295 // 1. Dequeue the next envelope.
4296 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4297
4298 if (!mb->m_eq.Get(&env, FrtosTimeoutToStk(xTicksToWait)))
4299 return 0U;
4300
4301 // 2. Validate destination capacity.
4302 if (xBufferLengthBytes < env.len)
4303 {
4304 // Destination too small: re-enqueue the envelope so the message is
4305 // not lost (best-effort; if re-enqueue also fails the message is lost).
4306 STK_ASSERT(false); // API contract: pvRxData buffer too small
4307 mb->m_eq.TryPut(&env);
4308 return 0U;
4309 }
4310
4311 // 3. Copy payload out and return the block.
4312 STK_MEMCPY(pvRxData, env.blk, env.len);
4313 mb->m_pool.Free(env.blk);
4314
4315 // Fire receive-complete callback outside any critical section.
4316 if (mb->m_recv_cb != nullptr)
4317 {
4318 BaseType_t woken = pdFALSE;
4319 mb->m_recv_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4320 }
4321
4322 return env.len;
4323}
static __stk_forceinline void STK_MEMCPY(void *const dest, const void *const src, const size_t size)
A wrapper for a built-in memcpy, redefine to your own if required.
Definition stk_arch.h:540
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, STK_MEMCPY(), 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
xMessageBufferHandle of the message buffer to receive from.
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 4469 of file freertos_stk.cpp.

4473{
4474 if (pxHigherPriorityTaskWoken != nullptr)
4475 *pxHigherPriorityTaskWoken = pdFALSE;
4476
4477 if ((xMessageBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
4478 return 0U;
4479
4480 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4481
4482 // Step 1: non-blocking dequeue of the oldest envelope.
4483 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4484 if (!mb->m_eq.TryGet(&env))
4485 return 0U; // buffer empty
4486
4487 // Step 2: validate destination capacity.
4488 if (xBufferLengthBytes < env.len)
4489 {
4490 // Destination too small: put the envelope back at the front so the
4491 // message is not lost. TryPutFront retreats the tail pointer under
4492 // its own CS — identical to Get never having happened.
4493 STK_ASSERT(false); // API contract: pvRxData buffer too small
4494 mb->m_eq.TryPutFront(&env);
4495 return 0U;
4496 }
4497
4498 // Step 3: copy payload out and release pool block.
4499 STK_MEMCPY(pvRxData, env.blk, env.len);
4500 mb->m_pool.Free(env.blk);
4501
4502 // Fire receive-complete callback outside any critical section.
4503 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
4504 if (mb->m_recv_cb != nullptr)
4505 {
4506 BaseType_t woken = pdFALSE;
4507 mb->m_recv_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4508 }
4509
4510 return env.len;
4511}
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_MEMCPY(), 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 4352 of file freertos_stk.cpp.

4353{
4354 if (xMessageBuffer == nullptr)
4355 return pdFAIL;
4356
4357 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4358
4359 // Drain all pending envelopes and return their blocks to the pool.
4360 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4361
4362 while (mb->m_eq.TryGet(&env))
4363 {
4364 if (env.blk != nullptr)
4365 mb->m_pool.Free(env.blk);
4366 }
4367
4368 // Reset the envelope queue (wakes any blocked senders).
4369 mb->m_eq.Reset();
4370
4371 return pdPASS;
4372}
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
xMessageBufferHandle of the message buffer.
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
pdPASS always.
Warning
ISR-safe.

Definition at line 4513 of file freertos_stk.cpp.

4515{
4516 if (pxHigherPriorityTaskWoken != nullptr)
4517 *pxHigherPriorityTaskWoken = pdFALSE;
4518
4519 if (xMessageBuffer == nullptr)
4520 return pdFAIL;
4521
4522 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4523
4524 // Drain all pending envelopes, returning every pool block before resetting
4525 // the queue. All three operations are ISR-safe (ScopedCriticalSection).
4526 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4527
4528 while (mb->m_eq.TryGet(&env))
4529 {
4530 if (env.blk != nullptr)
4531 mb->m_pool.Free(env.blk);
4532 }
4533
4534 // Reset the envelope queue; wakes any sender blocked on a full pool.
4535 mb->m_eq.Reset();
4536
4537 return pdPASS;
4538}

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
xMessageBufferHandle of the message buffer to send to.
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 4234 of file freertos_stk.cpp.

4238{
4239 if ((xMessageBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
4240 return 0U;
4241
4242 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4243
4244 if (xDataLengthBytes > mb->m_max_msg_size)
4245 {
4246 STK_ASSERT(false); // API contract: message too large for this buffer
4247 return 0U;
4248 }
4249
4250 const stk::Timeout stk_timeout = FrtosTimeoutToStk(xTicksToWait);
4251
4252 // 1. Acquire a payload block (blocks until one is free or timeout).
4253 void *blk = mb->m_pool.TimedAlloc(stk_timeout);
4254 if (blk == nullptr)
4255 return 0U;
4256
4257 // 2. Copy payload into the block.
4258 STK_MEMCPY(blk, pvTxData, xDataLengthBytes);
4259
4260 // 3. Enqueue the envelope (should always succeed: pool and eq are 1:1,
4261 // but guard with NO_WAIT to avoid deadlock if they desync).
4262 FrtosMessageBuffer::MsgEnvelope env = { xDataLengthBytes, blk };
4263
4264 if (!mb->m_eq.Put(&env, stk::NO_WAIT))
4265 {
4266 // Envelope queue unexpectedly full — return block and report failure.
4267 STK_ASSERT(false);
4268 mb->m_pool.Free(blk);
4269 return 0U;
4270 }
4271
4272 // Fire send-complete callback outside any critical section.
4273 if (mb->m_send_cb != nullptr)
4274 {
4275 BaseType_t woken = pdFALSE;
4276 mb->m_send_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4277 }
4278
4279 return xDataLengthBytes;
4280}
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
Definition stk_common.h:210
int32_t Timeout
Timeout time (ticks).
Definition stk_common.h:146
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, STK_MEMCPY(), 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
xMessageBufferHandle of the message buffer to send to.
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 4420 of file freertos_stk.cpp.

4424{
4425 if (pxHigherPriorityTaskWoken != nullptr)
4426 *pxHigherPriorityTaskWoken = pdFALSE;
4427
4428 if ((xMessageBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
4429 return 0U;
4430
4431 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4432
4433 if (xDataLengthBytes > mb->m_max_msg_size)
4434 {
4435 STK_ASSERT(false); // API contract: message exceeds max size
4436 return 0U;
4437 }
4438
4439 // Step 1: non-blocking pool allocation.
4440 void *blk = mb->m_pool.TimedAlloc(stk::NO_WAIT);
4441 if (blk == nullptr)
4442 return 0U; // pool full — no block consumed, nothing to free
4443
4444 // Step 2: copy payload.
4445 STK_MEMCPY(blk, pvTxData, xDataLengthBytes);
4446
4447 // Step 3: non-blocking enqueue.
4448 FrtosMessageBuffer::MsgEnvelope env = { xDataLengthBytes, blk };
4449 if (!mb->m_eq.TryPut(&env))
4450 {
4451 // Pool and eq are 1:1, so this should never happen. Defensively free
4452 // the block to avoid a pool leak and report failure.
4453 STK_ASSERT(false);
4454 mb->m_pool.Free(blk);
4455 return 0U;
4456 }
4457
4458 // Fire send-complete callback outside any critical section.
4459 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
4460 if (mb->m_send_cb != nullptr)
4461 {
4462 BaseType_t woken = pdFALSE;
4463 mb->m_send_cb(static_cast<StreamBufferHandle_t>(xMessageBuffer), &woken);
4464 }
4465
4466 return xDataLengthBytes;
4467}

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_MEMCPY(), 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.

Parameters
xMessageBufferHandle of the message buffer.
Note
ISR-safe.

Definition at line 4343 of file freertos_stk.cpp.

4344{
4345 if (xMessageBuffer == nullptr)
4346 return 0U;
4347
4348 // Free pool blocks == available envelope slots (they are 1:1).
4349 return static_cast<FrtosMessageBuffer *>(xMessageBuffer)->m_pool.GetFreeCount();
4350}

◆ 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 242 of file freertos_stk.cpp.

243{
244 return s_MemStats.GetAvailable();
245}

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 247 of file freertos_stk.cpp.

248{
249 return s_MemStats.min_ever_free;
250}

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 2100 of file freertos_stk.cpp.

2102{
2103 if ((xQueueOrSemaphore == nullptr) || (xQueueSet == nullptr))
2104 return pdFAIL;
2105
2106 FrtosQueueSet *qs = static_cast<FrtosQueueSet *>(xQueueSet);
2107
2108 // Type discrimination between FrtosQueue and FrtosSemaphore via
2109 // GetSemKindFromHandle(): returns SemKind::None for queues (and any
2110 // unrecognised handle), SemKind::Counting or SemKind::Mutex for semaphores.
2111 {
2112 const SemKind kind = GetSemKindFromHandle(xQueueOrSemaphore);
2113
2114 if (kind != SemKind::None)
2115 {
2116 // Semaphore or mutex path.
2117 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xQueueOrSemaphore);
2118
2119 // FreeRTOS API contract: mutexes cannot be queue set members.
2120 if (s->m_kind == SemKind::Mutex)
2121 return pdFAIL;
2122
2123 STK_ASSERT(s->m_set == nullptr); // must not already belong to a set
2124 if (s->m_set != nullptr)
2125 return pdFAIL;
2126
2127 STK_ASSERT(s->m_sem->GetCount() == 0U); // must be empty when added
2128 if (s->m_sem->GetCount() != 0U)
2129 return pdFAIL;
2130
2131 s->m_set = qs;
2132 }
2133 else
2134 {
2135 // Queue path.
2136 FrtosQueue *q = static_cast<FrtosQueue *>(xQueueOrSemaphore);
2137
2138 STK_ASSERT(q->m_set == nullptr); // must not already belong to a set
2139 if (q->m_set != nullptr)
2140 return pdFAIL;
2141
2142 STK_ASSERT(q->m_mq.IsEmpty()); // must be empty when added
2143 if (!q->m_mq.IsEmpty())
2144 return pdFAIL;
2145
2146 q->m_set = qs;
2147 }
2148 }
2149
2150 return pdPASS;
2151}
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 1658 of file freertos_stk.cpp.

1660{
1661 if (IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1662 return nullptr;
1663
1664 if (uxQueueLength > stk::sync::MessageQueue::CAPACITY_MAX)
1665 return nullptr;
1666
1668 static_cast<uint32_t>(uxQueueLength),
1669 static_cast<uint32_t>(uxItemSize),
1670 nullptr /* name */);
1671
1672 if (q == nullptr)
1673 return nullptr;
1674
1675 if (!q->m_mq.IsStorageValid())
1676 {
1677 ObjFree(q);
1678 return nullptr;
1679 }
1680
1681 return static_cast<QueueHandle_t>(q);
1682}
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 2081 of file freertos_stk.cpp.

2082{
2083 if (IsIrqContext() || (uxEventQueueLength == 0U))
2084 return nullptr;
2085
2086 if (uxEventQueueLength > stk::sync::MessageQueue::CAPACITY_MAX)
2087 return nullptr;
2088
2089 FrtosQueueSet *qs = ObjAlloc<FrtosQueueSet>(uxEventQueueLength);
2090
2091 if ((qs == nullptr) || !qs->IsValid())
2092 {
2093 ObjFree(qs);
2094 return nullptr;
2095 }
2096
2097 return static_cast<QueueSetHandle_t>(qs);
2098}
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 1684 of file freertos_stk.cpp.

1688{
1689 // All pointer arguments are mandatory for static allocation.
1690 if ((pucQueueStorage == nullptr) || (pxStaticQueue == nullptr))
1691 return nullptr;
1692
1693 if (IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1694 return nullptr;
1695
1696 if (uxQueueLength > stk::sync::MessageQueue::CAPACITY_MAX)
1697 return nullptr;
1698
1699 // Placement-new the FrtosQueue control block into the caller-supplied buffer.
1700 // Static assert guards against the buffer being too small.
1701 static_assert(sizeof(StaticQueue_t) >= sizeof(FrtosQueue),
1702 "StaticQueue_t is too small to hold FrtosQueue. "
1703 "Increase STATIC_QUEUE_TCB_SIZE_WORDS in freertos_stk.h.");
1704
1705 // Use the external-storage FrtosQueue constructor: no heap allocation for
1706 // either the control block or the data buffer.
1707 FrtosQueue *q = new (pxStaticQueue) FrtosQueue(
1708 static_cast<uint32_t>(uxQueueLength),
1709 static_cast<uint32_t>(uxItemSize),
1710 nullptr /* name */,
1711 pucQueueStorage);
1712
1713 q->m_cb_owned = false; // caller owns the memory; destructor must not delete
1714
1715 return static_cast<QueueHandle_t>(q);
1716}

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 2024 of file freertos_stk.cpp.

2025{
2026 // Resolve to FrtosSemaphore (Mutex kind) or bail out.
2028 if (s == nullptr)
2029 return nullptr;
2030
2031 // Delegate to the semaphore variant which acquires a ScopedCriticalSection
2032 // to make the TId snapshot consistent with concurrent Unlock() calls.
2033 return xSemaphoreGetMutexHolder(static_cast<SemaphoreHandle_t>(xQueue));
2034}
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 2036 of file freertos_stk.cpp.

2037{
2038 // Resolve to FrtosSemaphore (Mutex kind) or bail out.
2040 if (s == nullptr)
2041 return nullptr;
2042
2043 // Delegate to the ISR-safe semaphore variant which reads GetOwner() via a
2044 // single pointer-sized atomic load — no additional critical section needed.
2045 return xSemaphoreGetMutexHolderFromISR(static_cast<SemaphoreHandle_t>(xQueue));
2046}
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.

Parameters
xQueueHandle of the queue to query.
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 1954 of file freertos_stk.cpp.

1955{
1956 // IsEmpty() reads m_count which is size_t-aligned; ISR-safe on targets
1957 // where such a read is atomic (per stk::sync::MessageQueue contract).
1958 if (xQueue == nullptr)
1959 return pdTRUE;
1960
1961 return static_cast<const FrtosQueue *>(xQueue)->m_mq.IsEmpty() ? pdTRUE : pdFALSE;
1962}

References pdFALSE, and pdTRUE.

◆ xQueueIsQueueFullFromISR()

BaseType_t xQueueIsQueueFullFromISR ( const QueueHandle_t xQueue)

Query whether a queue is full from ISR context.

Parameters
xQueueHandle of the queue to query.
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 1964 of file freertos_stk.cpp.

1965{
1966 // IsFull() reads m_count and m_capacity; both are size_t-aligned and
1967 // m_capacity is const, so the read is ISR-safe on naturally-atomic targets
1968 // (per stk::sync::MessageQueue contract).
1969 if (xQueue == nullptr)
1970 return pdTRUE;
1971
1972 return static_cast<const FrtosQueue *>(xQueue)->m_mq.IsFull() ? pdTRUE : pdFALSE;
1973}

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.

Parameters
xQueueHandle of the length-1 queue to overwrite.
pvItemToQueuePointer to the item to write into the queue.
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 1851 of file freertos_stk.cpp.

1852{
1853 // Mailbox (length-1 queue) overwrite pattern.
1854 // Reset() atomically discards any existing item and wakes blocked producers,
1855 // guaranteeing TryPut() will always find a free slot immediately after.
1856 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1857 return pdFAIL;
1858
1859 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1860 q->m_mq.Reset();
1861 q->m_mq.TryPut(pvItemToQueue);
1862 QueueSetNotify(xQueue, q);
1863
1864 return pdPASS;
1865}
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
xQueueHandle of the length-1 queue to overwrite.
pvItemToQueuePointer to the item to write.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdPASS always.

Definition at line 1867 of file freertos_stk.cpp.

1870{
1871 // ISR-safe variant of xQueueOverwrite. Reset() and TryPut() are both
1872 // ISR-safe per the STK MessageQueue contract.
1873 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1874 return pdFAIL;
1875
1876 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1877 q->m_mq.Reset();
1878 q->m_mq.TryPut(pvItemToQueue);
1879 QueueSetNotify(xQueue, q);
1880
1881 if (pxHigherPriorityTaskWoken != nullptr)
1882 *pxHigherPriorityTaskWoken = pdFALSE;
1883
1884 return pdPASS;
1885}

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
xQueueHandle of the queue to peek.
pvBufferDestination buffer; must be at least uxItemSize bytes.
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 1785 of file freertos_stk.cpp.

1788{
1789 // Delegates to Peek(), which copies the oldest message without consuming
1790 // it. The operation is fully atomic and preserves queue ordering — no
1791 // Get + Put-back workaround required.
1792 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1793 return pdFAIL;
1794
1795 if (IsIrqContext() && (xTicksToWait != 0U))
1796 return pdFAIL;
1797
1798 return static_cast<FrtosQueue *>(xQueue)->m_mq.Peek(
1799 pvBuffer, FrtosTimeoutToStk(xTicksToWait))
1800 ? pdPASS : pdFAIL;
1801}

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.

Parameters
xQueueHandle of the queue to peek.
pvBufferDestination buffer; must be at least uxItemSize bytes.
Returns
pdTRUE if an item was available and peeked, pdFALSE if the queue was empty.
Warning
ISR-safe.

Definition at line 1803 of file freertos_stk.cpp.

1805{
1806 // Delegates to TryPeek() (= Peek(NO_WAIT)), which is ISR-safe and copies
1807 // the oldest message atomically without removing it.
1808 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1809 return pdFAIL;
1810
1811 return static_cast<FrtosQueue *>(xQueue)->m_mq.TryPeek(pvBuffer) ? pdPASS : pdFAIL;
1812}

References pdFAIL, and pdPASS.

◆ xQueueReceive()

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

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

Parameters
xQueueHandle of the source queue.
pvBufferDestination buffer; must be at least uxItemSize bytes.
xTicksToWaitTicks to wait if the queue is empty. portMAX_DELAY = wait forever.
Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1771 of file freertos_stk.cpp.

1774{
1775 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1776 return pdFAIL;
1777
1778 if (IsIrqContext() && (xTicksToWait != 0U))
1779 return pdFAIL;
1780
1781 return static_cast<FrtosQueue *>(xQueue)->m_mq.Get(pvBuffer, FrtosTimeoutToStk(xTicksToWait))
1782 ? pdPASS : pdFAIL;
1783}

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
xQueueHandle of the source queue.
pvBufferDestination buffer; must be at least uxItemSize bytes.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if received, pdFALSE if the queue was empty.

Definition at line 1909 of file freertos_stk.cpp.

1912{
1913 if ((xQueue == nullptr) || (pvBuffer == nullptr))
1914 return pdFAIL;
1915
1916 bool ok = static_cast<FrtosQueue *>(xQueue)->m_mq.TryGet(pvBuffer);
1917
1918 if (pxHigherPriorityTaskWoken != nullptr)
1919 *pxHigherPriorityTaskWoken = pdFALSE;
1920
1921 return ok ? pdPASS : pdFAIL;
1922}

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 2153 of file freertos_stk.cpp.

2155{
2156 if ((xQueueOrSemaphore == nullptr) || (xQueueSet == nullptr))
2157 return pdFAIL;
2158
2159 {
2160 const SemKind kind = GetSemKindFromHandle(xQueueOrSemaphore);
2161
2162 if (kind != SemKind::None)
2163 {
2164 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xQueueOrSemaphore);
2165
2166 // API contract: member must belong to this specific set.
2167 STK_ASSERT(s->m_set == static_cast<FrtosQueueSet *>(xQueueSet));
2168 if (s->m_set != static_cast<FrtosQueueSet *>(xQueueSet))
2169 return pdFAIL;
2170
2171 // API contract: semaphore must be empty when removed.
2172 STK_ASSERT(s->m_sem->GetCount() == 0U);
2173 if (s->m_sem->GetCount() != 0U)
2174 return pdFAIL;
2175
2176 s->m_set = nullptr;
2177 }
2178 else
2179 {
2180 FrtosQueue *q = static_cast<FrtosQueue *>(xQueueOrSemaphore);
2181
2182 STK_ASSERT(q->m_set == static_cast<FrtosQueueSet *>(xQueueSet));
2183 if (q->m_set != static_cast<FrtosQueueSet *>(xQueueSet))
2184 return pdFAIL;
2185
2186 // API contract: queue must be empty when removed.
2187 STK_ASSERT(q->m_mq.IsEmpty());
2188 if (!q->m_mq.IsEmpty())
2189 return pdFAIL;
2190
2191 q->m_set = nullptr;
2192 }
2193 }
2194
2195 return pdPASS;
2196}

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.

Parameters
xQueueHandle of the queue to reset.
Returns
pdPASS.

Definition at line 1842 of file freertos_stk.cpp.

1843{
1844 if (xQueue == nullptr)
1845 return pdFAIL;
1846
1847 static_cast<FrtosQueue *>(xQueue)->m_mq.Reset();
1848 return pdPASS;
1849}

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 2198 of file freertos_stk.cpp.

2200{
2201 if (xQueueSet == nullptr)
2202 return nullptr;
2203
2204 if (IsIrqContext() && (xTicksToWait != 0U))
2205 return nullptr;
2206
2207 FrtosQueueSet *qs = static_cast<FrtosQueueSet *>(xQueueSet);
2208
2209 // Block until a member handle arrives in the token FIFO or timeout fires.
2210 void *handle = nullptr;
2211 if (!qs->m_token_mq->Get(&handle, FrtosTimeoutToStk(xTicksToWait)))
2212 return nullptr; // timeout
2213
2214 return static_cast<QueueSetMemberHandle_t>(handle);
2215}
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 2217 of file freertos_stk.cpp.

2218{
2219 if (xQueueSet == nullptr)
2220 return nullptr;
2221
2222 FrtosQueueSet *qs = static_cast<FrtosQueueSet *>(xQueueSet);
2223
2224 // Non-blocking: TryGet() is ISR-safe per the STK MessageQueue contract.
2225 void *handle = nullptr;
2226 if (!qs->m_token_mq->TryGet(&handle))
2227 return nullptr; // set is empty
2228
2229 return static_cast<QueueSetMemberHandle_t>(handle);
2230}

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
xQueueHandle of the target queue.
pvItemToQueuePointer to the item to copy into the queue.
xTicksToWaitTicks to wait if full. portMAX_DELAY = wait forever.
Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1726 of file freertos_stk.cpp.

1729{
1730 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1731 return pdFAIL;
1732
1733 if (IsIrqContext() && (xTicksToWait != 0U))
1734 return pdFAIL;
1735
1736 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1737
1738 if (!q->m_mq.Put(pvItemToQueue, FrtosTimeoutToStk(xTicksToWait)))
1739 return pdFAIL;
1740
1741 QueueSetNotify(xQueue, q);
1742 return pdPASS;
1743}

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
xQueueHandle of the target queue.
pvItemToQueuePointer to the item to copy into the queue.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if posted, pdFALSE if the queue was full.

Definition at line 1887 of file freertos_stk.cpp.

1890{
1891 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1892 return pdFAIL;
1893
1894 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1895 bool ok = q->m_mq.TryPut(pvItemToQueue);
1896
1897 if (ok)
1898 QueueSetNotify(xQueue, q);
1899
1900 // STK handles the wake-up internally; the wrapper does not need to
1901 // request an explicit yield from ISR because SWRR re-evaluates on the
1902 // next tick. Set the flag to pdFALSE to avoid spurious portYIELD_FROM_ISR.
1903 if (pxHigherPriorityTaskWoken != nullptr)
1904 *pxHigherPriorityTaskWoken = pdFALSE;
1905
1906 return ok ? pdPASS : pdFAIL;
1907}

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).

Parameters
xQueueHandle of the target queue.
pvItemToQueuePointer to the item to copy into the queue.
xTicksToWaitTicks to wait if full. portMAX_DELAY = wait forever.
Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1745 of file freertos_stk.cpp.

1748{
1749 return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
1750}
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
xQueueHandle of the target queue.
pvItemToQueuePointer to the item to copy into the queue.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if posted, pdFALSE if the queue was full.

Definition at line 1924 of file freertos_stk.cpp.

1927{
1928 // Send-to-back from ISR is identical to xQueueSendFromISR: TryPut()
1929 // appends to the back of the ring buffer.
1930 return xQueueSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken);
1931}
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
xQueueHandle of the target queue.
pvItemToQueuePointer to the item to copy into the queue.
xTicksToWaitTicks to wait if full. portMAX_DELAY = wait forever.
Returns
pdTRUE on success, pdFALSE on timeout.

Definition at line 1752 of file freertos_stk.cpp.

1755{
1756 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1757 return pdFAIL;
1758
1759 if (IsIrqContext() && (xTicksToWait != 0U))
1760 return pdFAIL;
1761
1762 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1763
1764 if (!q->m_mq.PutFront(pvItemToQueue, FrtosTimeoutToStk(xTicksToWait)))
1765 return pdFAIL;
1766
1767 QueueSetNotify(xQueue, q);
1768 return pdPASS;
1769}
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
xQueueHandle of the target queue.
pvItemToQueuePointer to the item to copy into the queue.
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
pdTRUE if posted, pdFALSE if the queue was full.
Warning
ISR-safe.

Definition at line 1933 of file freertos_stk.cpp.

1936{
1937 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1938 return pdFAIL;
1939
1940 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1941 bool ok = q->m_mq.TryPutFront(pvItemToQueue);
1942
1943 if (ok)
1944 QueueSetNotify(xQueue, q);
1945
1946 // STK handles the wake-up internally; set the flag to pdFALSE to avoid
1947 // spurious portYIELD_FROM_ISR.
1948 if (pxHigherPriorityTaskWoken != nullptr)
1949 *pxHigherPriorityTaskWoken = pdFALSE;
1950
1951 return ok ? pdPASS : pdFAIL;
1952}

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 2238 of file freertos_stk.cpp.

2239{
2240 // Binary semaphore: max count = 1, initial count = 0.
2243 static_cast<uint16_t>(0U),
2244 static_cast<uint16_t>(1U));
2245
2246 if ((s == nullptr) || (s->m_sem == nullptr))
2247 {
2248 ObjFree(s);
2249 return nullptr;
2250 }
2251 return static_cast<SemaphoreHandle_t>(s);
2252}

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 2254 of file freertos_stk.cpp.

2255{
2256 if (pxSemaphoreBuffer == nullptr)
2257 return nullptr;
2258
2259 // Static assert guards against the buffer being too small.
2260 static_assert(sizeof(StaticSemaphore_t) >= sizeof(FrtosSemaphore),
2261 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2262 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2263
2264 // Placement-new the FrtosSemaphore control block into the caller-supplied
2265 // buffer. Binary semaphore: max count = 1, initial count = 0.
2266 // The inner stk::sync::Semaphore is a value type embedded inside
2267 // FrtosSemaphore, so no additional heap allocation is needed.
2268 FrtosSemaphore *s = new (pxSemaphoreBuffer) FrtosSemaphore(
2270 static_cast<uint16_t>(0U),
2271 static_cast<uint16_t>(1U));
2272
2273 if (s->m_sem == nullptr)
2274 {
2275 s->~FrtosSemaphore(); // clean up without freeing
2276 return nullptr;
2277 }
2278
2279 s->m_cb_owned = false; // caller owns the memory; destructor must not delete
2280
2281 return static_cast<SemaphoreHandle_t>(s);
2282}

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 2286 of file freertos_stk.cpp.

2288{
2289 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2290 return nullptr;
2291
2292 if (uxMaxCount > stk::sync::Semaphore::COUNT_MAX)
2294
2297 static_cast<uint16_t>(uxInitialCount),
2298 static_cast<uint16_t>(uxMaxCount));
2299
2300 if ((s == nullptr) || (s->m_sem == nullptr))
2301 {
2302 ObjFree(s);
2303 return nullptr;
2304 }
2305 return static_cast<SemaphoreHandle_t>(s);
2306}
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 2308 of file freertos_stk.cpp.

2311{
2312 if (pxSemaphoreBuffer == nullptr)
2313 return nullptr;
2314
2315 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2316 return nullptr;
2317
2318 if (uxMaxCount > stk::sync::Semaphore::COUNT_MAX)
2320
2321 static_assert(sizeof(StaticSemaphore_t) >= sizeof(FrtosSemaphore),
2322 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2323 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2324
2325 FrtosSemaphore *s = new (pxSemaphoreBuffer) FrtosSemaphore(
2327 static_cast<uint16_t>(uxInitialCount),
2328 static_cast<uint16_t>(uxMaxCount));
2329
2330 if (s->m_sem == nullptr)
2331 {
2332 s->~FrtosSemaphore();
2333 return nullptr;
2334 }
2335
2336 s->m_cb_owned = false;
2337 return static_cast<SemaphoreHandle_t>(s);
2338}

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 2344 of file freertos_stk.cpp.

2345{
2348 static_cast<uint16_t>(0U),
2349 static_cast<uint16_t>(1U));
2350
2351 if ((s == nullptr) || (s->m_mtx == nullptr))
2352 {
2353 ObjFree(s);
2354 return nullptr;
2355 }
2356
2357 return static_cast<SemaphoreHandle_t>(s);
2358}

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 2360 of file freertos_stk.cpp.

2361{
2362 if (pxMutexBuffer == nullptr)
2363 return nullptr;
2364
2365 static_assert(sizeof(StaticSemaphore_t) >= sizeof(FrtosSemaphore),
2366 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2367 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2368
2369 FrtosSemaphore *s = new (pxMutexBuffer) FrtosSemaphore(
2371 static_cast<uint16_t>(0U),
2372 static_cast<uint16_t>(1U));
2373
2374 if (s->m_mtx == nullptr)
2375 {
2376 s->~FrtosSemaphore();
2377 return nullptr;
2378 }
2379
2380 s->m_cb_owned = false;
2381 return static_cast<SemaphoreHandle_t>(s);
2382}

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 2384 of file freertos_stk.cpp.

2385{
2386 // STK Mutex is always recursive.
2387 return xSemaphoreCreateMutex();
2388}
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 2390 of file freertos_stk.cpp.

2391{
2392 // STK Mutex is always recursive; identical to xSemaphoreCreateMutexStatic.
2393 return xSemaphoreCreateMutexStatic(pxMutexBuffer);
2394}
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 2538 of file freertos_stk.cpp.

2539{
2540 // Returns the task that currently owns the mutex, or NULL if the mutex
2541 // is unlocked or xMutex is not a mutex-kind semaphore.
2542 //
2543 // FreeRTOS documents this function as not ISR-safe and requiring the
2544 // scheduler to be running. We guard it with a ScopedCriticalSection
2545 // so that the TId snapshot is consistent: if Unlock() is executing
2546 // concurrently, we see either the old owner or TID_NONE, never a torn
2547 // pointer.
2548 //
2549 // TId -> TaskHandle_t: STK stores task pointers as TId values via
2550 // TId = static_cast<TId>(reinterpret_cast<uintptr_t>(task_ptr))
2551 // so the inverse is:
2552 // task_ptr = reinterpret_cast<FrtosTask *>(static_cast<uintptr_t>(tid))
2553 // TID_NONE maps to nullptr (TaskHandle_t == nullptr means "no owner").
2554 if (xMutex == nullptr)
2555 return nullptr;
2556
2557 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xMutex);
2558
2559 if (s->m_kind != SemKind::Mutex)
2560 return nullptr; // not a mutex — owner concept does not apply
2561
2563
2564 const stk::TId owner = s->m_mtx->GetOwner();
2565
2566 if (owner == stk::TID_NONE)
2567 return nullptr; // mutex is currently unlocked
2568
2569 return reinterpret_cast<TaskHandle_t>(static_cast<uintptr_t>(owner));
2570}
Word TId
Task (thread) id.
Definition stk_common.h:141

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 2572 of file freertos_stk.cpp.

2573{
2574 // ISR-safe variant. GetOwner() reads a single TId (pointer-sized, aligned)
2575 // which is an atomic read on all supported STK architectures, so no
2576 // ScopedCriticalSection is needed here beyond what the caller already holds.
2577 // We still validate the handle and the semaphore kind before touching the
2578 // mutex state.
2579 if (xMutex == nullptr)
2580 return nullptr;
2581
2582 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xMutex);
2583
2584 if (s->m_kind != SemKind::Mutex)
2585 return nullptr;
2586
2587 const stk::TId owner = s->m_mtx->GetOwner();
2588
2589 if (owner == stk::TID_NONE)
2590 return nullptr;
2591
2592 return reinterpret_cast<TaskHandle_t>(static_cast<uintptr_t>(owner));
2593}

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.

Parameters
xSemaphoreHandle of the semaphore or mutex to release.
Returns
pdTRUE on success, pdFALSE if max count would be exceeded.

Definition at line 2460 of file freertos_stk.cpp.

2461{
2462 if (xSemaphore == nullptr)
2463 return pdFAIL;
2464
2465 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2466
2467 if (s->m_kind == SemKind::Mutex)
2468 {
2469#if configUSE_MUTEXES
2470 s->m_mtx->Unlock();
2471 // Mutexes are not eligible for queue sets (FreeRTOS API contract),
2472 // so no QueueSetNotify call is needed here.
2473 return pdPASS;
2474#else
2475 return pdFAIL;
2476#endif
2477 }
2478 else
2479 {
2480 // Guard against overflow: TryWait + Signal pattern.
2482 return pdFAIL;
2483
2484 s->m_sem->Signal();
2485 QueueSetNotify(xSemaphore, s);
2486 return pdPASS;
2487 }
2488}
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
xSemaphoreHandle of the semaphore to release.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE on success, pdFALSE on error or max-count overflow.

Definition at line 2495 of file freertos_stk.cpp.

2497{
2498 if (xSemaphore == nullptr)
2499 return pdFAIL;
2500
2501 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2502
2503 if (s->m_kind == SemKind::Mutex)
2504 return pdFAIL; // Mutex give from ISR is not permitted.
2505
2507 return pdFAIL;
2508
2509 s->m_sem->Signal();
2510 QueueSetNotify(xSemaphore, s);
2511
2512 if (pxHigherPriorityTaskWoken != nullptr)
2513 *pxHigherPriorityTaskWoken = pdFALSE;
2514
2515 return pdPASS;
2516}

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.

Parameters
xMutexHandle of the recursive mutex to release.
Returns
pdTRUE on success, pdFALSE if the calling task does not own the mutex.

Definition at line 2490 of file freertos_stk.cpp.

2491{
2492 return xSemaphoreGive(xMutex);
2493}
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
xSemaphoreHandle of the semaphore or mutex to acquire.
xTicksToWaitTicks to wait. portMAX_DELAY = wait forever.
Returns
pdTRUE if acquired, pdFALSE on timeout.

Definition at line 2406 of file freertos_stk.cpp.

2407{
2408 if (xSemaphore == nullptr)
2409 return pdFAIL;
2410
2411 if (IsIrqContext() && (xTicksToWait != 0U))
2412 return pdFAIL;
2413
2414 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2415 stk::Timeout tmo = FrtosTimeoutToStk(xTicksToWait);
2416
2417 if (s->m_kind == SemKind::Mutex)
2418 {
2419#if configUSE_MUTEXES
2420 return s->m_mtx->TimedLock(tmo) ? pdPASS : pdFAIL;
2421#else
2422 return pdFAIL;
2423#endif
2424 }
2425 else
2426 return s->m_sem->Wait(tmo) ? pdPASS : pdFAIL;
2427}
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
xSemaphoreHandle of the semaphore to acquire.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed.
Returns
pdTRUE if acquired, pdFALSE if the count was zero.

Definition at line 2429 of file freertos_stk.cpp.

2431{
2432 if (xSemaphore == nullptr)
2433 return pdFAIL;
2434
2435 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2436
2437 // Mutex take from ISR is not permitted — mirrors xSemaphoreGiveFromISR.
2438 if (s->m_kind == SemKind::Mutex)
2439 return pdFAIL;
2440
2441 // TryWait() is Wait(NO_WAIT): decrement count if > 0, return immediately.
2442 // ISR-safe per the STK Semaphore contract.
2443 bool ok = s->m_sem->TryWait();
2444
2445 // STK handles priority re-evaluation internally on the next tick.
2446 // Set pdFALSE to avoid spurious portYIELD_FROM_ISR, matching the
2447 // pattern used by xQueueReceiveFromISR and xSemaphoreGiveFromISR.
2448 if (pxHigherPriorityTaskWoken != nullptr)
2449 *pxHigherPriorityTaskWoken = pdFALSE;
2450
2451 return ok ? pdPASS : pdFAIL;
2452}
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).

Parameters
xMutexHandle of the recursive mutex to acquire.
xTicksToWaitTicks to wait. portMAX_DELAY = wait forever.
Returns
pdTRUE if the mutex was acquired, pdFALSE on timeout.

Definition at line 2454 of file freertos_stk.cpp.

2455{
2456 // STK Mutex is always recursive; identical to xSemaphoreTake.
2457 return xSemaphoreTake(xMutex, xTicksToWait);
2458}
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.

Parameters
xStreamBufferHandle of the stream buffer to query.
Returns
Number of bytes that can be read without blocking.

Definition at line 3898 of file freertos_stk.cpp.

3899{
3900 if (xStreamBuffer == nullptr)
3901 return 0U;
3902
3903 return static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.GetCount();
3904}

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 3726 of file freertos_stk.cpp.

3728{
3729 if (xBufferSizeBytes == 0U)
3730 return nullptr;
3731
3732 uint8_t *buf = ObjAllocArray<uint8_t>(xBufferSizeBytes);
3733 if (buf == nullptr)
3734 return nullptr;
3735
3736 FrtosStreamBuffer *sb = ObjAlloc<FrtosStreamBuffer>(buf, xBufferSizeBytes, xTriggerLevelBytes);
3737 if (sb == nullptr)
3738 {
3739 ObjFreeArray(buf);
3740 return nullptr;
3741 }
3742
3743 sb->m_buf_owned = true;
3744 sb->m_cb_owned = true;
3745
3746 return static_cast<StreamBufferHandle_t>(sb);
3747}
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 3749 of file freertos_stk.cpp.

3754{
3755 if ((pucStreamBufferStorageArea == nullptr) ||
3756 (pxStaticStreamBuffer == nullptr) ||
3757 (xBufferSizeBytes == 0U))
3758 return nullptr;
3759
3760 static_assert(sizeof(StaticStreamBuffer_t) >= sizeof(FrtosStreamBuffer),
3761 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3762
3763 FrtosStreamBuffer *sb = new (pxStaticStreamBuffer)
3764 FrtosStreamBuffer(pucStreamBufferStorageArea,
3765 xBufferSizeBytes,
3766 xTriggerLevelBytes);
3767
3768 // m_buf_owned = false, m_cb_owned = false already set by the ctor
3769 return static_cast<StreamBufferHandle_t>(sb);
3770}

◆ 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 4038 of file freertos_stk.cpp.

4045{
4046 if ((pucStreamBufferStorageArea == nullptr) ||
4047 (pxStaticStreamBuffer == nullptr) ||
4048 (xBufferSizeBytes == 0U))
4049 return nullptr;
4050
4051 static_assert(sizeof(StaticStreamBuffer_t) >= sizeof(FrtosStreamBuffer),
4052 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4053
4054 FrtosStreamBuffer *sb = new (pxStaticStreamBuffer)
4055 FrtosStreamBuffer(pucStreamBufferStorageArea,
4056 xBufferSizeBytes,
4057 xTriggerLevelBytes,
4058 pxSendCompletedCallback,
4059 pxReceiveCompletedCallback);
4060 // m_buf_owned = false, m_cb_owned = false already set by ctor
4061 return static_cast<StreamBufferHandle_t>(sb);
4062}

◆ 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 4006 of file freertos_stk.cpp.

4011{
4012 if (xBufferSizeBytes == 0U)
4013 return nullptr;
4014
4015 uint8_t *buf = ObjAllocArray<uint8_t>(xBufferSizeBytes);
4016 if (buf == nullptr)
4017 return nullptr;
4018
4020 buf,
4021 xBufferSizeBytes,
4022 xTriggerLevelBytes,
4023 pxSendCompletedCallback,
4024 pxReceiveCompletedCallback);
4025
4026 if (sb == nullptr)
4027 {
4028 ObjFreeArray(buf);
4029 return nullptr;
4030 }
4031
4032 sb->m_buf_owned = true;
4033 sb->m_cb_owned = true;
4034
4035 return static_cast<StreamBufferHandle_t>(sb);
4036}

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 3964 of file freertos_stk.cpp.

3965{
3966 if (xStreamBuffer == nullptr)
3967 return 0U;
3968
3969 // m_trigger is a plain size_t written only under ScopedCriticalSection
3970 // (in xStreamBufferSetTriggerLevel). A size_t-aligned read is atomic on
3971 // all Cortex-M targets — same rationale as Pipe::GetCount().
3972 return static_cast<const FrtosStreamBuffer *>(xStreamBuffer)->m_trigger;
3973}

◆ xStreamBufferIsEmpty()

BaseType_t xStreamBufferIsEmpty ( StreamBufferHandle_t xStreamBuffer)

Return pdTRUE if the stream buffer contains no data.

Parameters
xStreamBufferHandle of the stream buffer to query.
Returns
pdTRUE if empty, pdFALSE if at least one byte is available.

Definition at line 3914 of file freertos_stk.cpp.

3915{
3916 return (xStreamBufferBytesAvailable(xStreamBuffer) == 0U) ? pdTRUE : pdFALSE;
3917}
size_t xStreamBufferBytesAvailable(StreamBufferHandle_t xStreamBuffer)

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).

Parameters
xStreamBufferHandle of the stream buffer to query.
Returns
pdTRUE if full, pdFALSE if at least one byte of write space remains.

Definition at line 3919 of file freertos_stk.cpp.

3920{
3921 return (xStreamBufferSpacesAvailable(xStreamBuffer) == 0U) ? pdTRUE : pdFALSE;
3922}
size_t xStreamBufferSpacesAvailable(StreamBufferHandle_t xStreamBuffer)

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 3990 of file freertos_stk.cpp.

3991{
3992 // Delegates to xStreamBufferBytesAvailable() which performs the NULL guard
3993 // and returns Pipe::GetCount() — ISR-safe on all supported targets.
3994 return xStreamBufferBytesAvailable(xStreamBuffer);
3995}

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 3835 of file freertos_stk.cpp.

3839{
3840 if ((xStreamBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
3841 return 0U;
3842
3843 if (IsIrqContext() && (xTicksToWait != 0U))
3844 return 0U;
3845
3846 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3847
3848 // ReadBulkTriggered handles all cases in one call:
3849 // - NO_WAIT (xTicksToWait == 0): trigger not enforced, returns whatever
3850 // is available immediately (guaranteed by CV NO_WAIT fast-path).
3851 // - Blocking with trigger: waits until m_trigger bytes are present, then
3852 // drains up to xBufferLengthBytes in one atomic CS pass.
3853 // - Timeout before trigger: drains whatever arrived, possibly 0.
3854 const size_t total = sb->m_pipe.ReadBulkTriggered(
3855 static_cast<uint8_t *>(pvRxData),
3856 sb->m_trigger,
3857 xBufferLengthBytes,
3858 FrtosTimeoutToStk(xTicksToWait));
3859
3860 // Fire receive-complete callback outside any critical section.
3861 if ((total > 0U) && (sb->m_recv_cb != nullptr))
3862 {
3863 BaseType_t woken = pdFALSE;
3864 sb->m_recv_cb(xStreamBuffer, &woken);
3865 }
3866
3867 return total;
3868}
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
xStreamBufferHandle of the stream buffer to read from.
pvRxDataDestination buffer.
xBufferLengthBytesMaximum bytes to read.
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
Number of bytes actually read.

Definition at line 3870 of file freertos_stk.cpp.

3874{
3875 if (pxHigherPriorityTaskWoken != nullptr)
3876 *pxHigherPriorityTaskWoken = pdFALSE;
3877
3878 if ((xStreamBuffer == nullptr) || (pvRxData == nullptr) || (xBufferLengthBytes == 0U))
3879 return 0U;
3880
3881 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3882
3883 const size_t received = sb->m_pipe.TryReadBulk(
3884 static_cast<uint8_t *>(pvRxData),
3885 xBufferLengthBytes);
3886
3887 // Fire receive-complete callback outside any critical section.
3888 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
3889 if ((received > 0U) && (sb->m_recv_cb != nullptr))
3890 {
3891 BaseType_t woken = pdFALSE;
3892 sb->m_recv_cb(xStreamBuffer, &woken);
3893 }
3894
3895 return received;
3896}
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.

Parameters
xStreamBufferHandle of the stream buffer to reset.
Returns
pdPASS always.

Definition at line 3924 of file freertos_stk.cpp.

3925{
3926 if (xStreamBuffer == nullptr)
3927 return pdFAIL;
3928
3929 static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.Reset();
3930 return pdPASS;
3931}

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
xStreamBufferHandle of the stream buffer to reset.
pxHigherPriorityTaskWokenAlways set to pdFALSE; STK handles scheduling.
Returns
pdPASS on success, pdFAIL if the handle is NULL.
Note
ISR-safe.

Definition at line 3950 of file freertos_stk.cpp.

3952{
3953 if (pxHigherPriorityTaskWoken != nullptr)
3954 *pxHigherPriorityTaskWoken = pdFALSE;
3955
3956 if (xStreamBuffer == nullptr)
3957 return pdFAIL;
3958
3959 // Pipe::Reset() acquires ScopedCriticalSection internally — ISR-safe.
3960 static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.Reset();
3961 return pdPASS;
3962}

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 3782 of file freertos_stk.cpp.

3786{
3787 if ((xStreamBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
3788 return 0U;
3789
3790 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3791
3792 const size_t sent = sb->m_pipe.WriteBulk(
3793 static_cast<const uint8_t *>(pvTxData),
3794 xDataLengthBytes,
3795 FrtosTimeoutToStk(xTicksToWait));
3796
3797 // Fire send-complete callback outside any critical section.
3798 if ((sent > 0U) && (sb->m_send_cb != nullptr))
3799 {
3800 BaseType_t woken = pdFALSE;
3801 sb->m_send_cb(xStreamBuffer, &woken);
3802 }
3803
3804 return sent;
3805}
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
xStreamBufferHandle of the stream buffer to write to.
pvTxDataPointer to source data.
xDataLengthBytesNumber of bytes to write.
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK handles scheduling).
Returns
Number of bytes actually written.

Definition at line 3807 of file freertos_stk.cpp.

3811{
3812 if (pxHigherPriorityTaskWoken != nullptr)
3813 *pxHigherPriorityTaskWoken = pdFALSE;
3814
3815 if ((xStreamBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
3816 return 0U;
3817
3818 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3819
3820 const size_t sent = sb->m_pipe.TryWriteBulk(
3821 static_cast<const uint8_t *>(pvTxData),
3822 xDataLengthBytes);
3823
3824 // Fire send-complete callback outside any critical section.
3825 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
3826 if ((sent > 0U) && (sb->m_send_cb != nullptr))
3827 {
3828 BaseType_t woken = pdFALSE;
3829 sb->m_send_cb(xStreamBuffer, &woken);
3830 }
3831
3832 return sent;
3833}
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
xStreamBufferHandle of the stream buffer to modify.
xTriggerLevelBytesNew minimum bytes for Receive() to unblock (>= 1).
Returns
pdTRUE on success, pdFALSE if xTriggerLevelBytes > buffer capacity.

Definition at line 3933 of file freertos_stk.cpp.

3935{
3936 if (xStreamBuffer == nullptr)
3937 return pdFALSE;
3938
3939 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3940
3941 if (xTriggerLevelBytes > sb->m_pipe.GetCapacity())
3942 return pdFALSE;
3943
3945 sb->m_trigger = (xTriggerLevelBytes >= 1U ? xTriggerLevelBytes : 1U);
3946
3947 return pdTRUE;
3948}
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.

Parameters
xStreamBufferHandle of the stream buffer to query.
Returns
Number of bytes that can be written without blocking.

Definition at line 3906 of file freertos_stk.cpp.

3907{
3908 if (xStreamBuffer == nullptr)
3909 return 0U;
3910
3911 return static_cast<FrtosStreamBuffer *>(xStreamBuffer)->m_pipe.GetSpace();
3912}

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.

Parameters
xTaskHandle of the task whose delay is to be aborted.
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 1275 of file freertos_stk.cpp.

1276{
1277 if (xTask == nullptr)
1278 return pdFALSE;
1279
1280 // Resolve NULL -> calling task (same convention used throughout the wrapper).
1281 const stk::TId tid = static_cast<stk::TId>(reinterpret_cast<uintptr_t>(xTask));
1282
1283 const FrtosTask *t = static_cast<const FrtosTask *>(xTask);
1285 return pdFAIL; // suspended or otherwise not in a delay-able state
1286
1287 stk::SleepCancel(tid);
1288 return pdPASS;
1289}
static void SleepCancel(TId task_id)
Cancel sleep of the task.
Definition stk_helper.h:393

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 1124 of file freertos_stk.cpp.

1130{
1131 if (pvTaskCode == nullptr)
1132 return pdFAIL;
1133
1135 if (t == nullptr)
1136 return pdFAIL;
1137
1138 t->m_func = pvTaskCode;
1139 t->m_argument = pvParameters;
1140 t->m_name = pcName;
1141 t->m_weight = FrtosPrioToStkWeight(uxPriority);
1142
1143 // Determine stack size in Words.
1144 size_t stack_words = (usStackDepth > 0U)
1145 ? static_cast<size_t>(usStackDepth)
1147
1148 if (stack_words < FREERTOS_STK_MIN_STACK_WORDS)
1149 stack_words = FREERTOS_STK_MIN_STACK_WORDS;
1150
1151 t->m_stack = ObjAllocArray<stk::Word>(stack_words);
1152 if (t->m_stack == nullptr)
1153 {
1154 ObjFree(t);
1155 return pdFAIL;
1156 }
1157
1158 t->m_stack_size = stack_words;
1159 t->m_stack_owned = true;
1160
1162
1163 g_StkKernel.AddTask(t);
1164
1165 if (pxCreatedTask != nullptr)
1166 *pxCreatedTask = static_cast<TaskHandle_t>(t);
1167
1168 return pdPASS;
1169}
#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 1525 of file freertos_stk.cpp.

1527{
1528 // Mandatory pointer guard (only pvTaskCode is required; the caller need not
1529 // supply puxStackBuffer or pxTaskBuffer — both are heap-allocated here).
1530 if ((pxTaskDefinition == nullptr) ||
1531 (pxTaskDefinition->pvTaskCode == nullptr))
1532 return pdFAIL;
1533
1534 // STK does not implement MPU support. Forward to xTaskCreate() which
1535 // heap-allocates both the TCB and the task stack, accepting but ignoring
1536 // the xRegions MPU region table.
1537 // TODO: program pxTaskDefinition->xRegions into the MPU when STK gains
1538 // hardware MPU support.
1539 return xTaskCreate(
1540 pxTaskDefinition->pvTaskCode,
1541 pxTaskDefinition->pcName,
1542 pxTaskDefinition->usStackDepth,
1543 pxTaskDefinition->pvParameters,
1544 pxTaskDefinition->uxPriority,
1545 pxCreatedTask);
1546}
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:585

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 1493 of file freertos_stk.cpp.

1495{
1496 // Mandatory pointer guard.
1497 if ((pxTaskDefinition == nullptr) ||
1498 (pxTaskDefinition->pvTaskCode == nullptr) ||
1499 (pxTaskDefinition->puxStackBuffer == nullptr) ||
1500 (pxTaskDefinition->pxTaskBuffer == nullptr))
1501 return pdFAIL;
1502
1503 // STK does not implement MPU support. Forward to xTaskCreateStatic(),
1504 // accepting but ignoring the xRegions MPU region table.
1505 // TODO: program pxTaskDefinition->xRegions into the MPU when STK gains
1506 // hardware MPU support.
1508 pxTaskDefinition->pvTaskCode,
1509 pxTaskDefinition->pcName,
1510 pxTaskDefinition->usStackDepth,
1511 pxTaskDefinition->pvParameters,
1512 pxTaskDefinition->uxPriority,
1513 pxTaskDefinition->puxStackBuffer,
1514 pxTaskDefinition->pxTaskBuffer);
1515
1516 if (h == nullptr)
1517 return pdFAIL;
1518
1519 if (pxCreatedTask != nullptr)
1520 *pxCreatedTask = h;
1521
1522 return pdPASS;
1523}
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:590
StaticTask_t * pxTaskBuffer
Definition FreeRTOS.h:591

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 1171 of file freertos_stk.cpp.

1178{
1179 // All three pointer arguments are mandatory for static allocation.
1180 if ((pvTaskCode == nullptr) || (puxStackBuffer == nullptr) || (pxTaskBuffer == nullptr))
1181 return nullptr;
1182
1183 // Placement-new the FrtosTask control block into the caller-supplied TCB
1184 // buffer. Static assert guards against the buffer being too small.
1185 static_assert(sizeof(StaticTask_t) >= sizeof(FrtosTask),
1186 "StaticTask_t is too small to hold FrtosTask. "
1187 "Increase STATIC_TASK_TCB_SIZE_WORDS in freertos_stk.h.");
1188
1189 FrtosTask *t = new (pxTaskBuffer) FrtosTask();
1190
1191 t->m_func = pvTaskCode;
1192 t->m_argument = pvParameters;
1193 t->m_name = pcName;
1194 t->m_weight = FrtosPrioToStkWeight(uxPriority);
1195 t->m_stack = static_cast<stk::Word *>(static_cast<void *>(puxStackBuffer));
1196 t->m_stack_size = (ulStackDepth >= FREERTOS_STK_MIN_STACK_WORDS)
1197 ? static_cast<size_t>(ulStackDepth)
1199 t->m_stack_owned = false; // caller owns both the stack and the TCB
1200 t->m_cb_owned = false; // destructor must not delete — caller owns memory
1201
1203
1204 g_StkKernel.AddTask(t);
1205
1206 return static_cast<TaskHandle_t>(t);
1207}
uintptr_t Word
Native processor word type.
Definition stk_common.h:136

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.

Parameters
pxPreviousWakeTimeIn/out: tick count at the last wake point; updated on return.
xTimeIncrementPeriod in ticks between successive wake points.
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 1304 of file freertos_stk.cpp.

1305{
1306 if (IsIrqContext() || (pxPreviousWakeTime == nullptr))
1307 return pdFALSE;
1308
1309 const stk::Ticks wake_at = static_cast<stk::Ticks>(*pxPreviousWakeTime) +
1310 static_cast<stk::Ticks>(xTimeIncrement);
1311
1312 *pxPreviousWakeTime = static_cast<TickType_t>(wake_at);
1313
1314 return stk::SleepUntil(wake_at) ? pdTRUE : pdFALSE;
1315}
int64_t Ticks
Ticks value.
Definition stk_common.h:151
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
Definition stk_helper.h:383

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.

Returns
Handle of the task that is currently running on the CPU.

Definition at line 1364 of file freertos_stk.cpp.

1365{
1366 if (IsIrqContext())
1367 return nullptr;
1368
1369 return reinterpret_cast<TaskHandle_t>(static_cast<uintptr_t>(stk::GetTid()));
1370}

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).

Parameters
pcNameToQueryName string to search for (exact match).
Returns
Handle of the first matching task, or NULL if not found.

Definition at line 1372 of file freertos_stk.cpp.

1373{
1374 if (pcNameToQuery == nullptr)
1375 return nullptr;
1376
1377 // Enumerate all tasks and compare names.
1378 TaskHandle_t found = nullptr;
1379
1380 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *task) -> bool
1381 {
1382 if ((task->GetTraceName() != nullptr) &&
1383 (FreertosStrcmp(task->GetTraceName(), pcNameToQuery) == 0))
1384 {
1385 found = static_cast<TaskHandle_t>(task);
1386 return false; // stop iteration
1387 }
1388 return true;
1389 });
1390
1391 return found;
1392}
static int32_t FreertosStrcmp(const char str1[], const char str2[])

References FREERTOS_STK_MAX_TASKS, FreertosStrcmp(), and g_StkKernel.

Here is the call graph for this function:

◆ 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 1106 of file freertos_stk.cpp.

1107{
1108 // Map the four STK kernel states onto the three FreeRTOS scheduler states:
1109 // STATE_INACTIVE / STATE_READY -> NOT_STARTED (scheduler never ran)
1110 // STATE_RUNNING -> RUNNING
1111 // STATE_SUSPENDED -> SUSPENDED
1112 switch (g_StkKernel.GetState())
1113 {
1116 default: return taskSCHEDULER_NOT_STARTED;
1117 }
1118}
#define taskSCHEDULER_NOT_STARTED
Definition FreeRTOS.h:438
#define taskSCHEDULER_SUSPENDED
Definition FreeRTOS.h:440
#define taskSCHEDULER_RUNNING
Definition FreeRTOS.h:439
@ 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 1090 of file freertos_stk.cpp.

1091{
1092 return static_cast<TickType_t>(stk::GetTicks());
1093}
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
Definition stk_helper.h:313

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 1095 of file freertos_stk.cpp.

1096{
1097 return static_cast<TickType_t>(stk::GetTicks()); // GetTicks() is ISR-safe
1098}

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
xTaskToNotifyHandle of the task to notify (must not be NULL).
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 3404 of file freertos_stk.cpp.

3407{
3408 return xTaskNotifyIndexed(xTaskToNotify, 0U, ulValue, eAction);
3409}
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 3492 of file freertos_stk.cpp.

3496{
3497 return xTaskNotifyAndQueryIndexed(xTaskToNotify, 0U, ulValue, eAction,
3498 pulPreviousNotifyValue);
3499}
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
xTaskToNotifyTarget task handle (must not be NULL).
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the task's notification value.
pulPreviousNotifyValueReceives the slot value before the action is applied. May be NULL.
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK handles wake internally).
Returns
pdPASS, or pdFAIL if eSetValueWithoutOverwrite and notification was already pending.
Note
ISR-safe.

Definition at line 3526 of file freertos_stk.cpp.

3531{
3532 return xTaskNotifyAndQueryFromISRIndexed(xTaskToNotify, 0U, ulValue, eAction,
3533 pulPreviousNotifyValue,
3534 pxHigherPriorityTaskWoken);
3535}
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
xTaskToNotifyTarget task handle (must not be NULL).
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the slot's notification value.
pulPreviousNotifyValueReceives the slot value before the action is applied. May be NULL.
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS, or pdFAIL if eSetValueWithoutOverwrite and notification was already pending.
Note
ISR-safe.

Definition at line 3505 of file freertos_stk.cpp.

3511{
3512 BaseType_t result = xTaskNotifyAndQueryIndexed(xTaskToNotify, uxIndexToNotify,
3513 ulValue, eAction,
3514 pulPreviousNotifyValue);
3515
3516 if (pxHigherPriorityTaskWoken != nullptr)
3517 *pxHigherPriorityTaskWoken = pdFALSE; // STK handles the context switch internally
3518
3519 return result;
3520}

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
xTaskToNotifyTarget task handle (must not be NULL).
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the slot's 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 3458 of file freertos_stk.cpp.

3463{
3464 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3465 if (t == nullptr)
3466 return pdFAIL;
3467
3468 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToNotify];
3469 BaseType_t result = pdPASS;
3470
3471 {
3473
3474 // Snapshot the value *before* the action — this is the only difference
3475 // from xTaskNotifyIndexed.
3476 if (pulPreviousNotifyValue != nullptr)
3477 *pulPreviousNotifyValue = slot.value;
3478
3479 result = NotifyApplyAction(slot, ulValue, eAction);
3480 }
3481
3482 if (result == pdPASS)
3483 slot.sem.Signal();
3484
3485 return result;
3486}
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
xTaskToNotifyHandle of the task to notify (must not be NULL).
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the task's notification value.
pxHigherPriorityTaskWokenSet pdTRUE if a context switch is needed (always pdFALSE in STK wrapper).
Returns
pdPASS, or pdFAIL if eSetValueWithoutOverwrite and a notification was already pending.

Definition at line 3420 of file freertos_stk.cpp.

3424{
3425 return xTaskNotifyFromISRIndexed(xTaskToNotify, 0U, ulValue, eAction,
3426 pxHigherPriorityTaskWoken);
3427}
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
xTaskToNotifyHandle of the task to notify (must not be NULL).
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
ulValueValue applied according to eAction.
eActionHow ulValue is applied to the slot's notification value.
pxHigherPriorityTaskWokenAlways set to pdFALSE (STK handles wake internally).
Returns
pdPASS, or pdFAIL if eSetValueWithoutOverwrite and notification was already pending.

Definition at line 3376 of file freertos_stk.cpp.

3381{
3382 BaseType_t result = xTaskNotifyIndexed(xTaskToNotify, uxIndexToNotify, ulValue, eAction);
3383
3384 if (pxHigherPriorityTaskWoken != nullptr)
3385 *pxHigherPriorityTaskWoken = pdFALSE;
3386
3387 return result;
3388}

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).

Parameters
xTaskToNotifyHandle of the task to notify (must not be NULL).
Returns
pdPASS.

Definition at line 3394 of file freertos_stk.cpp.

3395{
3396 return xTaskNotifyGiveIndexed(xTaskToNotify, 0U);
3397}
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
xTaskToNotifyHandle of the task to notify (must not be NULL).
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
Returns
pdPASS, or pdFAIL if the index is out of range.

Definition at line 3271 of file freertos_stk.cpp.

3273{
3274 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3275 if (t == nullptr)
3276 return pdFAIL;
3277
3278 t->m_notify[uxIndexToNotify].sem.Signal(); // ISR-safe
3279 return pdPASS;
3280}

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
xTaskToNotifyHandle of the task to notify (must not be NULL).
uxIndexToNotifyNotification slot index (0 .. configTASK_NOTIFICATION_ARRAY_ENTRIES-1).
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 3314 of file freertos_stk.cpp.

3318{
3319 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3320 if (t == nullptr)
3321 return pdFAIL;
3322
3323 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToNotify];
3324 BaseType_t result = pdPASS;
3325
3326 {
3328 result = NotifyApplyAction(slot, ulValue, eAction);
3329 }
3330
3331 if (result == pdPASS)
3332 slot.sem.Signal();
3333
3334 return result;
3335}

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 3595 of file freertos_stk.cpp.

3596{
3597 return xTaskNotifyStateClearIndexed(xTask, 0U);
3598}
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 3560 of file freertos_stk.cpp.

3562{
3563 FrtosTask *t = ResolveNotifyTarget(xTask, uxIndexToClear);
3564 if (t == nullptr)
3565 return pdFALSE;
3566
3567 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToClear];
3568
3570
3571 // Determine whether a notification was pending before we clear anything.
3572 // A notification is considered "pending" when the semaphore has a count
3573 // (i.e. Signal() was called but Wait/Take has not yet consumed it) OR
3574 // when the value-without-overwrite guard flag is set.
3575 const bool was_pending = (slot.sem.GetCount() != 0U) || slot.pending;
3576
3577 if (was_pending)
3578 {
3579 // Drain the semaphore (binary, at most 1 token to consume).
3580 slot.sem.TryWait();
3581
3582 // Clear the eSetValueWithoutOverwrite pending guard so that a
3583 // subsequent xTaskNotify(eSetValueWithoutOverwrite) can write a new
3584 // value without being rejected.
3585 slot.pending = false;
3586 }
3587
3588 return was_pending ? pdTRUE : pdFALSE;
3589}
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 3411 of file freertos_stk.cpp.

3415{
3416 return xTaskNotifyWaitIndexed(0U, ulBitsToClearOnEntry, ulBitsToClearOnExit,
3417 pulNotificationValue, xTicksToWait);
3418}
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 3337 of file freertos_stk.cpp.

3342{
3343 if (IsIrqContext())
3344 return pdFAIL;
3345
3346 FrtosTask *t = ResolveNotifyTarget(nullptr, uxIndexToWait);
3347 if (t == nullptr)
3348 return pdFAIL;
3349
3350 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToWait];
3351
3352 // Clear entry bits before blocking.
3353 {
3355 slot.value &= ~ulBitsToClearOnEntry;
3356 }
3357
3358 // Block until notified or timeout.
3359 if (!slot.sem.Wait(FrtosTimeoutToStk(xTicksToWait)))
3360 return pdFAIL;
3361
3362 // Read and apply exit-clear.
3363 {
3365
3366 if (pulNotificationValue != nullptr)
3367 *pulNotificationValue = slot.value;
3368
3369 slot.value &= ~ulBitsToClearOnExit;
3370 slot.pending = false;
3371 }
3372
3373 return pdPASS;
3374}

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 1084 of file freertos_stk.cpp.

1085{
1087 return pdFALSE; // no pending switch tracked at wrapper level
1088}

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.

Parameters
xTaskToResumeHandle of the task to resume.
Returns
pdTRUE if the task was successfully resumed.

Definition at line 1257 of file freertos_stk.cpp.

1258{
1259 if (xTaskToResume == nullptr)
1260 return pdFALSE;
1261
1262 FrtosTask *t = static_cast<FrtosTask *>(xTaskToResume);
1263
1265
1267 return pdFALSE;
1268
1269 g_StkKernel.ResumeTask(t);
1271
1272 return pdTRUE;
1273}

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.

Parameters
xTimerHandle of the timer to modify.
xNewPeriodNew timer period in ticks (must be > 0).
xTicksToWaitAccepted for API compatibility; ignored (command queue write is non-blocking).
Returns
pdPASS on success.

Definition at line 2705 of file freertos_stk.cpp.

2708{
2709 if ((xTimer == nullptr) || (xNewPeriod == 0U))
2710 return pdFAIL;
2711
2712 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2713 t->m_period = xNewPeriod;
2714
2715 return xTimerStart(xTimer, xTicksToWait);
2716}
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
xTimerHandle of the timer to modify.
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 2779 of file freertos_stk.cpp.

2782{
2783 if (pxHigherPriorityTaskWoken != nullptr)
2784 *pxHigherPriorityTaskWoken = pdFALSE;
2785
2786 if ((xTimer == nullptr) || (xNewPeriod == 0U) || (g_TimerHost == nullptr))
2787 return pdFAIL;
2788
2789 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2790 t->m_period = xNewPeriod;
2791
2792 // Restart with the new period, taking effect immediately.
2793 uint32_t period = t->m_auto_reload ? static_cast<uint32_t>(xNewPeriod) : 0U;
2794
2795 return g_TimerHost->Restart(*t, static_cast<uint32_t>(xNewPeriod), period) ? pdPASS : pdFAIL;
2796}
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 2603 of file freertos_stk.cpp.

2608{
2609 if (IsIrqContext() || (pxCallbackFunction == nullptr) || (xTimerPeriodInTicks == 0U))
2610 return nullptr;
2611
2613 return nullptr;
2614
2616 pcTimerName,
2617 xTimerPeriodInTicks,
2618 (uxAutoReload == pdTRUE),
2619 pvTimerID,
2620 pxCallbackFunction);
2621
2622 return static_cast<TimerHandle_t>(t);
2623}
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 2625 of file freertos_stk.cpp.

2631{
2632 if (pxTimerBuffer == nullptr)
2633 return nullptr;
2634
2635 if (IsIrqContext() || (pxCallbackFunction == nullptr) || (xTimerPeriodInTicks == 0U))
2636 return nullptr;
2637
2639 return nullptr;
2640
2641 static_assert(sizeof(StaticTimer_t) >= sizeof(FrtosTimer),
2642 "StaticTimer_t is too small to hold FrtosTimer. "
2643 "Increase STATIC_TIMER_TCB_SIZE_WORDS in freertos_stk.h.");
2644
2645 // Placement-new the FrtosTimer into the caller-supplied buffer.
2646 FrtosTimer *t = new (pxTimerBuffer) FrtosTimer(
2647 pcTimerName,
2648 xTimerPeriodInTicks,
2649 (uxAutoReload == pdTRUE),
2650 pvTimerID,
2651 pxCallbackFunction);
2652
2653 t->m_cb_owned = false; // caller owns the memory; xTimerDelete must not delete it
2654
2655 return static_cast<TimerHandle_t>(t);
2656}

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.

Parameters
xTimerHandle of the timer to delete.
xTicksToWaitAccepted for API compatibility; ignored (command queue write is non-blocking).
Returns
pdPASS.

Definition at line 2658 of file freertos_stk.cpp.

2659{
2660 if (xTimer == nullptr)
2661 return pdFAIL;
2662
2663 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2664
2665 if ((g_TimerHost != nullptr) && t->IsActive())
2666 g_TimerHost->Stop(*t);
2667
2668 ObjFree(t);
2669 return pdPASS;
2670}
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.

Parameters
xTimerHandle of the timer to query.
Returns
Absolute tick value of the next expiry, or 0 if the timer is stopped.

Definition at line 2933 of file freertos_stk.cpp.

2934{
2935 if ((xTimer == nullptr) || (g_TimerHost == nullptr))
2936 return 0U;
2937
2938 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2939 return t->IsActive() ? static_cast<TickType_t>(t->GetDeadline()) : 0U;
2940}
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.

Parameters
xTimerHandle of the timer to query.
Returns
Timer period in ticks as set at creation or by xTimerChangePeriod().

Definition at line 2925 of file freertos_stk.cpp.

2926{
2927 if (xTimer == nullptr)
2928 return 0U;
2929
2930 return static_cast<FrtosTimer *>(xTimer)->m_period;
2931}

◆ xTimerIsTimerActive()

BaseType_t xTimerIsTimerActive ( TimerHandle_t xTimer)

Query whether a timer is currently active (running).

Parameters
xTimerHandle of the timer to query.
Returns
pdTRUE if active, pdFALSE if stopped or expired.

Definition at line 2893 of file freertos_stk.cpp.

2894{
2895 if (xTimer == nullptr)
2896 return pdFALSE;
2897
2898 return static_cast<FrtosTimer *>(xTimer)->IsActive() ? pdTRUE : pdFALSE;
2899}

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 2834 of file freertos_stk.cpp.

2838{
2839 // API contract: must not be called from ISR context.
2840 if (IsIrqContext())
2841 return pdFAIL;
2842
2843 if (xFunctionToPend == nullptr)
2844 return pdFAIL;
2845
2846 // Ensure the TimerHost (and hence the drainer's scheduling context) exists.
2848 return pdFAIL;
2849
2850 // Write the call record into the static pipe (blocking with timeout).
2851 // PipeT::Write() acquires a ScopedCriticalSection internally.
2852 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2853 if (!g_PendCallPipe.Write(call, FrtosTimeoutToStk(xTicksToWait)))
2854 return pdFAIL;
2855
2856 // (Re-)start the singleton drainer so it wakes within 1 tick.
2857 // EnsurePendDrainer() constructs the drainer on first call and
2858 // calls TimerHost::Restart() which is task-safe.
2860
2861 return pdPASS;
2862}
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 2864 of file freertos_stk.cpp.

2868{
2869 // STK wakes the tick task internally; no manual context switch needed.
2870 if (pxHigherPriorityTaskWoken != nullptr)
2871 *pxHigherPriorityTaskWoken = pdFALSE;
2872
2873 if (xFunctionToPend == nullptr)
2874 return pdFAIL;
2875
2876 // From ISR the TimerHost must already be running (a timer was created
2877 // before the ISR fired — the only realistic usage pattern).
2878 if (g_TimerHost == nullptr)
2879 return pdFAIL;
2880
2881 // Non-blocking enqueue: TryWrite() holds a ScopedCriticalSection internally
2882 // — unconditionally ISR-safe, no allocator call, no blocking.
2883 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2884 if (!g_PendCallPipe.TryWrite(call))
2885 return pdFAIL;
2886
2887 // Kick the drainer via ISR-safe TimerHost::Restart().
2889
2890 return pdPASS;
2891}
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).

Parameters
xTimerHandle of the timer to reset.
xTicksToWaitAccepted for API compatibility; ignored (command queue write is non-blocking).
Returns
pdPASS on success.

Definition at line 2700 of file freertos_stk.cpp.

2701{
2702 return xTimerStart(xTimer, xTicksToWait); // Restart restarts from now
2703}

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
xTimerHandle of the timer to reset.
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the command queue is full or handle is invalid.

Definition at line 2772 of file freertos_stk.cpp.

2774{
2775 // Reset = Restart from now, same as xTimerStart.
2776 return xTimerStartFromISR(xTimer, pxHigherPriorityTaskWoken);
2777}
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.

Parameters
xTimerHandle of the timer to start.
xTicksToWaitAccepted for API compatibility; ignored (command queue write is non-blocking).
Returns
pdPASS on success, pdFAIL on error.

Definition at line 2672 of file freertos_stk.cpp.

2673{
2674 if (IsIrqContext() || (xTimer == nullptr) || (g_TimerHost == nullptr))
2675 return pdFAIL;
2676
2677 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2678
2679 uint32_t period = t->m_auto_reload
2680 ? static_cast<uint32_t>(t->m_period)
2681 : 0U; // 0 = one-shot (no reload period)
2682
2683 return g_TimerHost->Restart(*t, static_cast<uint32_t>(t->m_period), period)
2684 ? pdPASS : pdFAIL;
2685}

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
xTimerHandle of the timer to start.
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the command queue is full or handle is invalid.

Definition at line 2739 of file freertos_stk.cpp.

2741{
2742 if (pxHigherPriorityTaskWoken != nullptr)
2743 *pxHigherPriorityTaskWoken = pdFALSE;
2744
2745 if ((xTimer == nullptr) || (g_TimerHost == nullptr))
2746 return pdFAIL;
2747
2748 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2749 uint32_t period = t->m_auto_reload ? static_cast<uint32_t>(t->m_period) : 0U;
2750
2751 return g_TimerHost->Restart(*t, static_cast<uint32_t>(t->m_period), period)
2752 ? pdPASS : pdFAIL;
2753}

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.

Parameters
xTimerHandle of the timer to stop.
xTicksToWaitAccepted for API compatibility; ignored (command queue write is non-blocking).
Returns
pdPASS on success, pdFAIL if the timer was not running.

Definition at line 2687 of file freertos_stk.cpp.

2688{
2689 if (IsIrqContext() || (xTimer == nullptr) || (g_TimerHost == nullptr))
2690 return pdFAIL;
2691
2692 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2693
2694 if (!t->IsActive())
2695 return pdFAIL;
2696
2697 return g_TimerHost->Stop(*t) ? pdPASS : pdFAIL;
2698}

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
xTimerHandle of the timer to stop.
pxHigherPriorityTaskWokenAlways set to pdFALSE.
Returns
pdPASS on success, pdFAIL if the timer is not running or handle is invalid.

Definition at line 2755 of file freertos_stk.cpp.

2757{
2758 if (pxHigherPriorityTaskWoken != nullptr)
2759 *pxHigherPriorityTaskWoken = pdFALSE;
2760
2761 if ((xTimer == nullptr) || (g_TimerHost == nullptr))
2762 return pdFAIL;
2763
2764 FrtosTimer *t = static_cast<FrtosTimer *>(xTimer);
2765
2766 if (!t->IsActive())
2767 return pdFAIL;
2768
2769 return g_TimerHost->Stop(*t) ? pdPASS : pdFAIL;
2770}

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

Here is the call graph for this function: