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

1346{
1347 if (xTask == nullptr)
1348 return eInvalid;
1349
1350 FrtosTask *t = static_cast<FrtosTask *>(xTask);
1351
1353 return eDeleted;
1354
1356 return eSuspended;
1357
1358 // Check whether this is the currently running task.
1359 if (static_cast<uintptr_t>(stk::GetTid()) == reinterpret_cast<uintptr_t>(t))
1360 return eRunning;
1361
1362 return eReady;
1363}
static TId GetTid()
Get task/thread Id of the calling task.
Definition stk_helper.h:243
volatile State m_state

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

Here is the call graph for this function:

◆ pcTaskGetName()

const char * pcTaskGetName ( TaskHandle_t xTaskToQuery)

Return the name string of a task.

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

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

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

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

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

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

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

◆ 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:408

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

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

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

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

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

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

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

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

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

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

2520{
2521 if (xSemaphore == nullptr)
2522 return 0U;
2523
2524 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2525
2526 if (s->m_kind == SemKind::Counting)
2527 return static_cast<UBaseType_t>(s->m_sem->GetCount());
2528
2529#if configUSE_MUTEXES
2530 // For a mutex, count = 0 means locked, 1 means unlocked.
2531 return (s->m_mtx->GetOwner() == stk::TID_NONE) ? 1U : 0U;
2532#else
2533 return 0U;
2534#endif
2535}
@ 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:177
TId GetOwner() const
Get owner of the mutex.
uint16_t GetCount() const
Get current counter value.
stk::sync::Mutex * m_mtx
stk::sync::Semaphore * m_sem

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

Here is the call graph for this function:

◆ uxTaskGetNumberOfTasks()

UBaseType_t uxTaskGetNumberOfTasks ( void )

Return the number of tasks currently under kernel management.

Definition at line 1101 of file freertos_stk.cpp.

1102{
1104 return static_cast<UBaseType_t>(g_StkKernel.GetSwitchStrategy()->GetSize());
1105}
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 1403 of file freertos_stk.cpp.

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

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

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

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

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

1341{
1342 return uxTaskPriorityGet(xTask); // same implementation; GetTid() is ISR-safe
1343}
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 3011 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

1301{
1302 static_cast<void>(xTaskDelayUntil(pxPreviousWakeTime, xTimeIncrement));
1303}
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 1210 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

1243{
1244 if (xTaskToResume == nullptr)
1245 return;
1246
1247 FrtosTask *t = static_cast<FrtosTask *>(xTaskToResume);
1248
1250
1252 return;
1253
1254 g_StkKernel.ResumeTask(t);
1256}

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

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

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

1063{
1065
1066 g_StkKernel.Start(); // does not return for KERNEL_DYNAMIC until all tasks exit
1067}
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 1228 of file freertos_stk.cpp.

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

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

1081{
1083}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

4354{
4355 if (xMessageBuffer == nullptr)
4356 return pdFAIL;
4357
4358 FrtosMessageBuffer *mb = static_cast<FrtosMessageBuffer *>(xMessageBuffer);
4359
4360 // Drain all pending envelopes and return their blocks to the pool.
4361 FrtosMessageBuffer::MsgEnvelope env = { 0U, nullptr };
4362
4363 while (mb->m_eq.TryGet(&env))
4364 {
4365 if (env.blk != nullptr)
4366 mb->m_pool.Free(env.blk);
4367 }
4368
4369 // Reset the envelope queue (wakes any blocked senders).
4370 mb->m_eq.Reset();
4371
4372 return pdPASS;
4373}
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 4514 of file freertos_stk.cpp.

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

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

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

References stk::memory::BlockMemoryPool::Free(), FrtosTimeoutToStk(), FrtosMessageBuffer::m_eq, FrtosMessageBuffer::m_max_msg_size, FrtosMessageBuffer::m_pool, FrtosMessageBuffer::m_send_cb, stk::NO_WAIT, pdFALSE, stk::sync::MessageQueue::Put(), STK_ASSERT, 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 4421 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1853{
1854 // Mailbox (length-1 queue) overwrite pattern.
1855 // Reset() atomically discards any existing item and wakes blocked producers,
1856 // guaranteeing TryPut() will always find a free slot immediately after.
1857 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1858 return pdFAIL;
1859
1860 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1861 q->m_mq.Reset();
1862 q->m_mq.TryPut(pvItemToQueue);
1863 QueueSetNotify(xQueue, q);
1864
1865 return pdPASS;
1866}
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 1868 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

1749{
1750 return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
1751}
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 1925 of file freertos_stk.cpp.

1928{
1929 // Send-to-back from ISR is identical to xQueueSendFromISR: TryPut()
1930 // appends to the back of the ring buffer.
1931 return xQueueSendFromISR(xQueue, pvItemToQueue, pxHigherPriorityTaskWoken);
1932}
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 1753 of file freertos_stk.cpp.

1756{
1757 if ((xQueue == nullptr) || (pvItemToQueue == nullptr))
1758 return pdFAIL;
1759
1760 if (IsIrqContext() && (xTicksToWait != 0U))
1761 return pdFAIL;
1762
1763 FrtosQueue *q = static_cast<FrtosQueue *>(xQueue);
1764
1765 if (!q->m_mq.PutFront(pvItemToQueue, FrtosTimeoutToStk(xTicksToWait)))
1766 return pdFAIL;
1767
1768 QueueSetNotify(xQueue, q);
1769 return pdPASS;
1770}
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 1934 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Referenced by xQueueGetMutexHolder().

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

◆ xSemaphoreGetMutexHolderFromISR()

TaskHandle_t xSemaphoreGetMutexHolderFromISR ( SemaphoreHandle_t xMutex)

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

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

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

Definition at line 2573 of file freertos_stk.cpp.

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

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

2462{
2463 if (xSemaphore == nullptr)
2464 return pdFAIL;
2465
2466 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2467
2468 if (s->m_kind == SemKind::Mutex)
2469 {
2470#if configUSE_MUTEXES
2471 s->m_mtx->Unlock();
2472 // Mutexes are not eligible for queue sets (FreeRTOS API contract),
2473 // so no QueueSetNotify call is needed here.
2474 return pdPASS;
2475#else
2476 return pdFAIL;
2477#endif
2478 }
2479 else
2480 {
2481 // Guard against overflow: TryWait + Signal pattern.
2483 return pdFAIL;
2484
2485 s->m_sem->Signal();
2486 QueueSetNotify(xSemaphore, s);
2487 return pdPASS;
2488 }
2489}
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 2496 of file freertos_stk.cpp.

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

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

2492{
2493 return xSemaphoreGive(xMutex);
2494}
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 2407 of file freertos_stk.cpp.

2408{
2409 if (xSemaphore == nullptr)
2410 return pdFAIL;
2411
2412 if (IsIrqContext() && (xTicksToWait != 0U))
2413 return pdFAIL;
2414
2415 FrtosSemaphore *s = static_cast<FrtosSemaphore *>(xSemaphore);
2416 stk::Timeout tmo = FrtosTimeoutToStk(xTicksToWait);
2417
2418 if (s->m_kind == SemKind::Mutex)
2419 {
2420#if configUSE_MUTEXES
2421 return s->m_mtx->TimedLock(tmo) ? pdPASS : pdFAIL;
2422#else
2423 return pdFAIL;
2424#endif
2425 }
2426 else
2427 return s->m_sem->Wait(tmo) ? pdPASS : pdFAIL;
2428}
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 2430 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

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

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

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

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

3916{
3917 return (xStreamBufferBytesAvailable(xStreamBuffer) == 0U) ? pdTRUE : pdFALSE;
3918}
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 3920 of file freertos_stk.cpp.

3921{
3922 return (xStreamBufferSpacesAvailable(xStreamBuffer) == 0U) ? pdTRUE : pdFALSE;
3923}
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 3991 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

3787{
3788 if ((xStreamBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
3789 return 0U;
3790
3791 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3792
3793 const size_t sent = sb->m_pipe.WriteBulk(
3794 static_cast<const uint8_t *>(pvTxData),
3795 xDataLengthBytes,
3796 FrtosTimeoutToStk(xTicksToWait));
3797
3798 // Fire send-complete callback outside any critical section.
3799 if ((sent > 0U) && (sb->m_send_cb != nullptr))
3800 {
3801 BaseType_t woken = pdFALSE;
3802 sb->m_send_cb(xStreamBuffer, &woken);
3803 }
3804
3805 return sent;
3806}
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 3808 of file freertos_stk.cpp.

3812{
3813 if (pxHigherPriorityTaskWoken != nullptr)
3814 *pxHigherPriorityTaskWoken = pdFALSE;
3815
3816 if ((xStreamBuffer == nullptr) || (pvTxData == nullptr) || (xDataLengthBytes == 0U))
3817 return 0U;
3818
3819 FrtosStreamBuffer *sb = static_cast<FrtosStreamBuffer *>(xStreamBuffer);
3820
3821 const size_t sent = sb->m_pipe.TryWriteBulk(
3822 static_cast<const uint8_t *>(pvTxData),
3823 xDataLengthBytes);
3824
3825 // Fire send-complete callback outside any critical section.
3826 // pxHigherPriorityTaskWoken is always pdFALSE per STK convention.
3827 if ((sent > 0U) && (sb->m_send_cb != nullptr))
3828 {
3829 BaseType_t woken = pdFALSE;
3830 sb->m_send_cb(xStreamBuffer, &woken);
3831 }
3832
3833 return sent;
3834}
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 3934 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

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

Referenced by xTaskCreateRestrictedStatic().

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

◆ xTaskDelayUntil()

BaseType_t xTaskDelayUntil ( TickType_t * pxPreviousWakeTime,
TickType_t xTimeIncrement )

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

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

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

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

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

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

1374{
1375 if (pcNameToQuery == nullptr)
1376 return nullptr;
1377
1378 // Enumerate all tasks and compare names.
1379 TaskHandle_t found = nullptr;
1380
1381 g_StkKernel.EnumerateTasksT<FREERTOS_STK_MAX_TASKS>([&](stk::ITask *task) -> bool
1382 {
1383 if ((task->GetTraceName() != nullptr) &&
1384 (FreertosStrcmp(task->GetTraceName(), pcNameToQuery) == 0))
1385 {
1386 found = static_cast<TaskHandle_t>(task);
1387 return false; // stop iteration
1388 }
1389 return true;
1390 });
1391
1392 return found;
1393}
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 1107 of file freertos_stk.cpp.

1108{
1109 // Map the four STK kernel states onto the three FreeRTOS scheduler states:
1110 // STATE_INACTIVE / STATE_READY -> NOT_STARTED (scheduler never ran)
1111 // STATE_RUNNING -> RUNNING
1112 // STATE_SUSPENDED -> SUSPENDED
1113 switch (g_StkKernel.GetState())
1114 {
1117 default: return taskSCHEDULER_NOT_STARTED;
1118 }
1119}
#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 1091 of file freertos_stk.cpp.

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

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

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

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

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

3497{
3498 return xTaskNotifyAndQueryIndexed(xTaskToNotify, 0U, ulValue, eAction,
3499 pulPreviousNotifyValue);
3500}
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 3527 of file freertos_stk.cpp.

3532{
3533 return xTaskNotifyAndQueryFromISRIndexed(xTaskToNotify, 0U, ulValue, eAction,
3534 pulPreviousNotifyValue,
3535 pxHigherPriorityTaskWoken);
3536}
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 3506 of file freertos_stk.cpp.

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

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

3464{
3465 FrtosTask *t = ResolveNotifyTarget(xTaskToNotify, uxIndexToNotify);
3466 if (t == nullptr)
3467 return pdFAIL;
3468
3469 FrtosTask::NotifySlot &slot = t->m_notify[uxIndexToNotify];
3470 BaseType_t result = pdPASS;
3471
3472 {
3474
3475 // Snapshot the value *before* the action — this is the only difference
3476 // from xTaskNotifyIndexed.
3477 if (pulPreviousNotifyValue != nullptr)
3478 *pulPreviousNotifyValue = slot.value;
3479
3480 result = NotifyApplyAction(slot, ulValue, eAction);
3481 }
3482
3483 if (result == pdPASS)
3484 slot.sem.Signal();
3485
3486 return result;
3487}
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 3421 of file freertos_stk.cpp.

3425{
3426 return xTaskNotifyFromISRIndexed(xTaskToNotify, 0U, ulValue, eAction,
3427 pxHigherPriorityTaskWoken);
3428}
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 3377 of file freertos_stk.cpp.

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

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

3396{
3397 return xTaskNotifyGiveIndexed(xTaskToNotify, 0U);
3398}
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 3272 of file freertos_stk.cpp.

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

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

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

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

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

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

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

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

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

1086{
1088 return pdFALSE; // no pending switch tracked at wrapper level
1089}

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

1259{
1260 if (xTaskToResume == nullptr)
1261 return pdFALSE;
1262
1263 FrtosTask *t = static_cast<FrtosTask *>(xTaskToResume);
1264
1266
1268 return pdFALSE;
1269
1270 g_StkKernel.ResumeTask(t);
1272
1273 return pdTRUE;
1274}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Here is the call graph for this function: