25#define FREERTOS_STK_WRAPPER_VERSION "FreeRTOS-STK Wrapper v1.0"
32#ifndef FREERTOS_STK_MAX_TASKS
33# define FREERTOS_STK_MAX_TASKS 16U
36#ifndef FREERTOS_STK_DEFAULT_STACK_WORDS
37# define FREERTOS_STK_DEFAULT_STACK_WORDS 256U
41#define FREERTOS_STK_MIN_STACK_WORDS STK_STACK_SIZE_MIN
56 while ((str1[index] !=
'\0') && (str2[index] !=
'\0') && (str1[index] == str2[index]))
63 result =
static_cast<int32_t
>(str1[index]) -
static_cast<int32_t
>(str2[index]);
75extern "C" void free(
void *ptr);
85 const size_t alignment =
alignof(size_t);
88 size = (size +
sizeof(size_t) + (alignment - 1)) & ~(alignment - 1);
95 size_t *region =
static_cast<size_t *
>(
malloc(size));
96 if (region !=
nullptr)
115 stk::hw::CriticalSection::ScopedLock cs_;
118 size_t *region =
static_cast<size_t *
>(ptr) - 1;
119 size_t size = region[0];
136template <
typename T,
typename... Args>
143 obj =
new (ptr) T(
static_cast<Args &&
>(args)...);
170 return static_cast<T *
>(ptr);
254 if (pxHeapStats ==
nullptr)
297 "configMAX_PRIORITIES exceeds SwitchStrategyFP32's 32 priority levels. "
298 "Reduce configMAX_PRIORITIES or instantiate SwitchStrategyFixedPriority "
299 "with a larger MAX_PRIORITIES template parameter and update FrtosKernel.");
308 return static_cast<int32_t
>(p);
473#if configUSE_TASK_NOTIFICATIONS
514 explicit FrtosQueue(uint32_t cap, uint32_t msg_size,
const char *name,
516 :
m_mq(ext_buf, static_cast<size_t>(cap), static_cast<size_t>(msg_size)),
522 m_mq.SetTraceName(name);
526 explicit FrtosQueue(uint32_t cap, uint32_t msg_size,
const char *name)
528 static_cast<size_t>(cap),
529 static_cast<size_t>(msg_size)),
535 m_mq.SetTraceName(name);
553#if configUSE_QUEUE_SETS
603 const uint8_t first_byte = *
static_cast<const uint8_t *
>(obj);
648#if configUSE_QUEUE_SETS
690 const size_t buf_bytes =
691 static_cast<size_t>(uxEventQueueLength) *
sizeof(
void *);
694 if (
m_buf ==
nullptr)
699 static_cast<size_t>(uxEventQueueLength),
733template <
typename THost>
736#if configUSE_QUEUE_SETS
739 if (host->m_set !=
nullptr)
740 host->m_set->m_token_mq->TryPut(&member_handle);
899#if configUSE_EVENT_GROUPS
930#if configUSE_STREAM_BUFFERS
943 :
m_pipe(buf, capacity, 1U),
997 stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size)),
1012 size_t storage_size,
1016 stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size),
1018 msg_count *
stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size)),
1019 m_eq(storage + msg_count *
stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size),
1126 uint32_t usStackDepth,
1131 if (pvTaskCode ==
nullptr)
1144 size_t stack_words = (usStackDepth > 0U)
1145 ?
static_cast<size_t>(usStackDepth)
1165 if (pxCreatedTask !=
nullptr)
1173 uint32_t ulStackDepth,
1180 if ((pvTaskCode ==
nullptr) || (puxStackBuffer ==
nullptr) || (pxTaskBuffer ==
nullptr))
1186 "StaticTask_t is too small to hold FrtosTask. "
1187 "Increase STATIC_TASK_TCB_SIZE_WORDS in freertos_stk.h.");
1195 t->
m_stack =
static_cast<stk::Word *
>(
static_cast<void *
>(puxStackBuffer));
1197 ?
static_cast<size_t>(ulStackDepth)
1213 static_cast<FrtosTask *
>(xTaskToDelete);
1231 static_cast<FrtosTask *
>(xTaskToSuspend);
1236 bool already =
false;
1243 if (xTaskToResume ==
nullptr)
1259 if (xTaskToResume ==
nullptr)
1277 if (xTask ==
nullptr)
1281 const stk::TId tid =
static_cast<stk::TId>(
reinterpret_cast<uintptr_t
>(xTask));
1301 static_cast<void>(
xTaskDelayUntil(pxPreviousWakeTime, xTimeIncrement));
1312 *pxPreviousWakeTime =
static_cast<TickType_t>(wake_at);
1346 if (xTask ==
nullptr)
1358 if (
static_cast<uintptr_t
>(
stk::GetTid()) ==
reinterpret_cast<uintptr_t
>(t))
1374 if (pcNameToQuery ==
nullptr)
1382 if ((task->GetTraceName() !=
nullptr) &&
1396 if (xTaskToQuery ==
nullptr)
1399 return static_cast<FrtosTask *
>(xTaskToQuery)->m_name;
1426 uint32_t *pulTotalRunTime)
1430 if (pulTotalRunTime !=
nullptr)
1431 *pulTotalRunTime = 0U;
1433 if ((pxTaskStatusArray ==
nullptr) || (uxArraySize == 0U))
1440 const uintptr_t running_tid =
static_cast<uintptr_t
>(
stk::GetTid());
1444 if (filled >= uxArraySize)
1463 if (
reinterpret_cast<uintptr_t
>(t) == running_tid)
1497 if ((pxTaskDefinition ==
nullptr) ||
1509 pxTaskDefinition->
pcName,
1519 if (pxCreatedTask !=
nullptr)
1530 if ((pxTaskDefinition ==
nullptr) ||
1541 pxTaskDefinition->
pcName,
1550 if (pcWriteBuffer ==
nullptr)
1555 int off = snprintf(pcWriteBuffer, 64U,
1556 "%-12s %c %4s %6s %4s\r\n",
1557 "Name",
'S',
"Prio",
"Stack",
"Num");
1559 if (off < 0) off = 0;
1560 char *p = pcWriteBuffer + off;
1579 if (
static_cast<uintptr_t
>(
stk::GetTid()) ==
reinterpret_cast<uintptr_t
>(t))
1584 const char *name = (t->
m_name !=
nullptr) ? t->
m_name :
"(unnamed)";
1588 int n = snprintf(p, 48U,
"%-12s %c %4u %6u %4u\r\n",
1590 static_cast<unsigned>(prio),
1591 static_cast<unsigned>(hwm),
1592 static_cast<unsigned>(task_num));
1621 if (pcWriteBuffer ==
nullptr)
1627 int off = snprintf(pcWriteBuffer, 64U,
1628 "%-12s %12s %8s\r\n",
1629 "Task",
"Abs Time",
"% Time");
1631 if (off < 0) off = 0;
1632 char *p = pcWriteBuffer + off;
1637 const char *name = (t->
m_name !=
nullptr) ? t->
m_name :
"(unnamed)";
1642 int n = snprintf(p, 48U,
"%-12s %12lu %7lu%%\r\n",
1661 if (
IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1668 static_cast<uint32_t
>(uxQueueLength),
1669 static_cast<uint32_t
>(uxItemSize),
1686 uint8_t *pucQueueStorage,
1690 if ((pucQueueStorage ==
nullptr) || (pxStaticQueue ==
nullptr))
1693 if (
IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1702 "StaticQueue_t is too small to hold FrtosQueue. "
1703 "Increase STATIC_QUEUE_TCB_SIZE_WORDS in freertos_stk.h.");
1708 static_cast<uint32_t
>(uxQueueLength),
1709 static_cast<uint32_t
>(uxItemSize),
1720 if (xQueue ==
nullptr)
1727 const void *pvItemToQueue,
1730 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1746 const void *pvItemToQueue,
1749 return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
1753 const void *pvItemToQueue,
1756 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1775 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1792 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1798 return static_cast<FrtosQueue *
>(xQueue)->m_mq.Peek(
1808 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1816 if (xQueue ==
nullptr)
1827 if (xQueue ==
nullptr)
1835 if (xQueue ==
nullptr)
1844 if (xQueue ==
nullptr)
1847 static_cast<FrtosQueue *
>(xQueue)->m_mq.Reset();
1856 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1868 const void *pvItemToQueue,
1873 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1881 if (pxHigherPriorityTaskWoken !=
nullptr)
1882 *pxHigherPriorityTaskWoken =
pdFALSE;
1888 const void *pvItemToQueue,
1891 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1903 if (pxHigherPriorityTaskWoken !=
nullptr)
1904 *pxHigherPriorityTaskWoken =
pdFALSE;
1913 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1916 bool ok =
static_cast<FrtosQueue *
>(xQueue)->m_mq.TryGet(pvBuffer);
1918 if (pxHigherPriorityTaskWoken !=
nullptr)
1919 *pxHigherPriorityTaskWoken =
pdFALSE;
1925 const void *pvItemToQueue,
1934 const void *pvItemToQueue,
1937 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1948 if (pxHigherPriorityTaskWoken !=
nullptr)
1949 *pxHigherPriorityTaskWoken =
pdFALSE;
1958 if (xQueue ==
nullptr)
1969 if (xQueue ==
nullptr)
2006#if configUSE_MUTEXES
2012 if (xQueue ==
nullptr)
2079#if configUSE_QUEUE_SETS
2091 if ((qs ==
nullptr) || !qs->
IsValid())
2103 if ((xQueueOrSemaphore ==
nullptr) || (xQueueSet ==
nullptr))
2124 if (s->
m_set !=
nullptr)
2139 if (q->
m_set !=
nullptr)
2156 if ((xQueueOrSemaphore ==
nullptr) || (xQueueSet ==
nullptr))
2201 if (xQueueSet ==
nullptr)
2210 void *handle =
nullptr;
2219 if (xQueueSet ==
nullptr)
2225 void *handle =
nullptr;
2243 static_cast<uint16_t
>(0U),
2244 static_cast<uint16_t
>(1U));
2246 if ((s ==
nullptr) || (s->
m_sem ==
nullptr))
2256 if (pxSemaphoreBuffer ==
nullptr)
2261 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2262 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2270 static_cast<uint16_t
>(0U),
2271 static_cast<uint16_t
>(1U));
2273 if (s->
m_sem ==
nullptr)
2284#if configUSE_COUNTING_SEMAPHORES
2289 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2297 static_cast<uint16_t
>(uxInitialCount),
2298 static_cast<uint16_t
>(uxMaxCount));
2300 if ((s ==
nullptr) || (s->
m_sem ==
nullptr))
2312 if (pxSemaphoreBuffer ==
nullptr)
2315 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2322 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2323 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2327 static_cast<uint16_t
>(uxInitialCount),
2328 static_cast<uint16_t
>(uxMaxCount));
2330 if (s->
m_sem ==
nullptr)
2342#if configUSE_MUTEXES
2348 static_cast<uint16_t
>(0U),
2349 static_cast<uint16_t
>(1U));
2351 if ((s ==
nullptr) || (s->
m_mtx ==
nullptr))
2362 if (pxMutexBuffer ==
nullptr)
2366 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2367 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2371 static_cast<uint16_t
>(0U),
2372 static_cast<uint16_t
>(1U));
2374 if (s->
m_mtx ==
nullptr)
2400 if (xSemaphore ==
nullptr)
2408 if (xSemaphore ==
nullptr)
2419#if configUSE_MUTEXES
2432 if (xSemaphore ==
nullptr)
2448 if (pxHigherPriorityTaskWoken !=
nullptr)
2449 *pxHigherPriorityTaskWoken =
pdFALSE;
2462 if (xSemaphore ==
nullptr)
2469#if configUSE_MUTEXES
2498 if (xSemaphore ==
nullptr)
2512 if (pxHigherPriorityTaskWoken !=
nullptr)
2513 *pxHigherPriorityTaskWoken =
pdFALSE;
2520 if (xSemaphore ==
nullptr)
2528#if configUSE_MUTEXES
2536#if configUSE_MUTEXES
2554 if (xMutex ==
nullptr)
2569 return reinterpret_cast<TaskHandle_t>(
static_cast<uintptr_t
>(owner));
2579 if (xMutex ==
nullptr)
2592 return reinterpret_cast<TaskHandle_t>(
static_cast<uintptr_t
>(owner));
2609 if (
IsIrqContext() || (pxCallbackFunction ==
nullptr) || (xTimerPeriodInTicks == 0U))
2617 xTimerPeriodInTicks,
2618 (uxAutoReload ==
pdTRUE),
2620 pxCallbackFunction);
2632 if (pxTimerBuffer ==
nullptr)
2635 if (
IsIrqContext() || (pxCallbackFunction ==
nullptr) || (xTimerPeriodInTicks == 0U))
2642 "StaticTimer_t is too small to hold FrtosTimer. "
2643 "Increase STATIC_TIMER_TCB_SIZE_WORDS in freertos_stk.h.");
2648 xTimerPeriodInTicks,
2649 (uxAutoReload ==
pdTRUE),
2651 pxCallbackFunction);
2660 if (xTimer ==
nullptr)
2680 ?
static_cast<uint32_t
>(t->
m_period)
2709 if ((xTimer ==
nullptr) || (xNewPeriod == 0U))
2742 if (pxHigherPriorityTaskWoken !=
nullptr)
2743 *pxHigherPriorityTaskWoken =
pdFALSE;
2745 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2758 if (pxHigherPriorityTaskWoken !=
nullptr)
2759 *pxHigherPriorityTaskWoken =
pdFALSE;
2761 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2783 if (pxHigherPriorityTaskWoken !=
nullptr)
2784 *pxHigherPriorityTaskWoken =
pdFALSE;
2786 if ((xTimer ==
nullptr) || (xNewPeriod == 0U) || (
g_TimerHost ==
nullptr))
2793 uint32_t period = t->
m_auto_reload ?
static_cast<uint32_t
>(xNewPeriod) : 0U;
2836 uint32_t ulParameter2,
2843 if (xFunctionToPend ==
nullptr)
2852 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2866 uint32_t ulParameter2,
2870 if (pxHigherPriorityTaskWoken !=
nullptr)
2871 *pxHigherPriorityTaskWoken =
pdFALSE;
2873 if (xFunctionToPend ==
nullptr)
2883 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2895 if (xTimer ==
nullptr)
2903 if (xTimer ==
nullptr)
2906 return static_cast<FrtosTimer *
>(xTimer)->m_timer_id;
2911 if (xTimer ==
nullptr)
2914 static_cast<FrtosTimer *
>(xTimer)->m_timer_id = pvNewID;
2919 if (xTimer ==
nullptr)
2922 return static_cast<FrtosTimer *
>(xTimer)->m_name;
2927 if (xTimer ==
nullptr)
2930 return static_cast<FrtosTimer *
>(xTimer)->m_period;
2935 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2948#if configUSE_EVENT_GROUPS
2974 if (xWaitForAllBits ==
pdTRUE)
2994 if (pxEventGroupBuffer ==
nullptr)
3001 "StaticEventGroup_t is too small to hold FrtosEventGroup. "
3002 "Increase STATIC_EVENT_GROUP_TCB_SIZE_WORDS in freertos_stk.h.");
3012 if (xEventGroup ==
nullptr)
3021 if (xEventGroup ==
nullptr)
3024 uint32_t result =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Set(uxBitsToSet);
3031 if (xEventGroup ==
nullptr)
3035 uint32_t prev =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Clear(uxBitsToClear);
3041 if (xEventGroup ==
nullptr)
3053 if (
IsIrqContext() || (xEventGroup ==
nullptr) || (uxBitsToWaitFor == 0U))
3059 uint32_t result = ef.
Wait(
static_cast<uint32_t
>(uxBitsToWaitFor),
3074 if (xEventGroup ==
nullptr)
3077 uint32_t result =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Set(
3078 static_cast<uint32_t
>(uxBitsToSet));
3080 if (pxHigherPriorityTaskWoken !=
nullptr)
3081 *pxHigherPriorityTaskWoken =
pdFALSE;
3089 if (xEventGroup ==
nullptr)
3092 uint32_t prev =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Clear(
3093 static_cast<uint32_t
>(uxBitsToClear));
3149 if (xEventGroup ==
nullptr)
return 0U;
3150 if (uxBitsToWaitFor == 0U)
return 0U;
3160 if (uxBitsToSet != 0U)
3162 uint32_t set_result = ef.
Set(
static_cast<uint32_t
>(uxBitsToSet));
3181 uint32_t result = ef.
Wait(
static_cast<uint32_t
>(uxBitsToWaitFor),
3209#if configUSE_TASK_NOTIFICATIONS
3222 if (xTask ==
nullptr)
3242 slot.
value |= ulValue;
3250 slot.
value = ulValue;
3256 slot.
value = ulValue;
3304 if (ulClearCountOnExit ==
pdTRUE)
3307 if (slot.
value > 0U)
3338 uint32_t ulBitsToClearOnEntry,
3339 uint32_t ulBitsToClearOnExit,
3340 uint32_t *pulNotificationValue,
3355 slot.
value &= ~ulBitsToClearOnEntry;
3366 if (pulNotificationValue !=
nullptr)
3367 *pulNotificationValue = slot.
value;
3369 slot.
value &= ~ulBitsToClearOnExit;
3384 if (pxHigherPriorityTaskWoken !=
nullptr)
3385 *pxHigherPriorityTaskWoken =
pdFALSE;
3412 uint32_t ulBitsToClearOnExit,
3413 uint32_t *pulNotificationValue,
3417 pulNotificationValue, xTicksToWait);
3426 pxHigherPriorityTaskWoken);
3462 uint32_t *pulPreviousNotifyValue)
3476 if (pulPreviousNotifyValue !=
nullptr)
3477 *pulPreviousNotifyValue = slot.
value;
3495 uint32_t *pulPreviousNotifyValue)
3498 pulPreviousNotifyValue);
3509 uint32_t *pulPreviousNotifyValue,
3514 pulPreviousNotifyValue);
3516 if (pxHigherPriorityTaskWoken !=
nullptr)
3517 *pxHigherPriorityTaskWoken =
pdFALSE;
3529 uint32_t *pulPreviousNotifyValue,
3533 pulPreviousNotifyValue,
3534 pxHigherPriorityTaskWoken);
3614 uint32_t ulBitsToClear)
3624 const uint32_t prev = slot.
value;
3625 slot.
value &= ~ulBitsToClear;
3635 uint32_t ulBitsToClear)
3666 if (xTaskToSet ==
nullptr)
3669 if (xTaskToSet ==
nullptr)
3678 t->
m_tls[
static_cast<size_t>(xIndex)] = pvValue;
3688 if (xTaskToQuery ==
nullptr)
3691 if (xTaskToQuery ==
nullptr)
3697 return t->
m_tls[
static_cast<size_t>(xIndex)];
3721#if configUSE_STREAM_BUFFERS
3723static_assert(
sizeof(StaticStreamBuffer_t) >=
sizeof(FrtosStreamBuffer),
3724 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3727 size_t xTriggerLevelBytes)
3729 if (xBufferSizeBytes == 0U)
3750 size_t xBufferSizeBytes,
3751 size_t xTriggerLevelBytes,
3752 uint8_t *pucStreamBufferStorageArea,
3755 if ((pucStreamBufferStorageArea ==
nullptr) ||
3756 (pxStaticStreamBuffer ==
nullptr) ||
3757 (xBufferSizeBytes == 0U))
3761 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3766 xTriggerLevelBytes);
3774 if (xStreamBuffer ==
nullptr)
3783 const void *pvTxData,
3784 size_t xDataLengthBytes,
3787 if ((xStreamBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
3793 static_cast<const uint8_t *
>(pvTxData),
3798 if ((sent > 0U) && (sb->
m_send_cb !=
nullptr))
3808 const void *pvTxData,
3809 size_t xDataLengthBytes,
3812 if (pxHigherPriorityTaskWoken !=
nullptr)
3813 *pxHigherPriorityTaskWoken =
pdFALSE;
3815 if ((xStreamBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
3821 static_cast<const uint8_t *
>(pvTxData),
3826 if ((sent > 0U) && (sb->
m_send_cb !=
nullptr))
3837 size_t xBufferLengthBytes,
3840 if ((xStreamBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
3855 static_cast<uint8_t *
>(pvRxData),
3861 if ((total > 0U) && (sb->
m_recv_cb !=
nullptr))
3872 size_t xBufferLengthBytes,
3875 if (pxHigherPriorityTaskWoken !=
nullptr)
3876 *pxHigherPriorityTaskWoken =
pdFALSE;
3878 if ((xStreamBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
3884 static_cast<uint8_t *
>(pvRxData),
3885 xBufferLengthBytes);
3889 if ((received > 0U) && (sb->
m_recv_cb !=
nullptr))
3900 if (xStreamBuffer ==
nullptr)
3908 if (xStreamBuffer ==
nullptr)
3926 if (xStreamBuffer ==
nullptr)
3934 size_t xTriggerLevelBytes)
3936 if (xStreamBuffer ==
nullptr)
3945 sb->
m_trigger = (xTriggerLevelBytes >= 1U ? xTriggerLevelBytes : 1U);
3953 if (pxHigherPriorityTaskWoken !=
nullptr)
3954 *pxHigherPriorityTaskWoken =
pdFALSE;
3956 if (xStreamBuffer ==
nullptr)
3966 if (xStreamBuffer ==
nullptr)
4007 size_t xBufferSizeBytes,
4008 size_t xTriggerLevelBytes,
4012 if (xBufferSizeBytes == 0U)
4023 pxSendCompletedCallback,
4024 pxReceiveCompletedCallback);
4039 size_t xBufferSizeBytes,
4040 size_t xTriggerLevelBytes,
4041 uint8_t *pucStreamBufferStorageArea,
4046 if ((pucStreamBufferStorageArea ==
nullptr) ||
4047 (pxStaticStreamBuffer ==
nullptr) ||
4048 (xBufferSizeBytes == 0U))
4052 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4058 pxSendCompletedCallback,
4059 pxReceiveCompletedCallback);
4089static_assert(
sizeof(StaticMessageBuffer_t) >=
sizeof(FrtosMessageBuffer),
4090 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4098 if (slot_cost == 0U)
4101 return budget_bytes / slot_cost;
4105 size_t xMaxMessageSize)
4107 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4110 const size_t count =
MsgBufSlotCount(xBufferSizeBytes, xMaxMessageSize);
4130 size_t xMaxMessageSize,
4131 size_t xMessageCount,
4132 uint8_t *pucMessageBufferStorageArea,
4135 if ((pucMessageBufferStorageArea ==
nullptr) ||
4136 (pxStaticMessageBuffer ==
nullptr) ||
4137 (xMaxMessageSize == 0U) ||
4138 (xMessageCount == 0U))
4146 pucMessageBufferStorageArea, storage_size);
4163 size_t xBufferSizeBytes,
4164 size_t xMaxMessageSize,
4168 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4173 const size_t count = xBufferSizeBytes / slot_cost;
4179 xMaxMessageSize, count,
4180 pxSendCompletedCallback, pxReceiveCompletedCallback);
4197 size_t xMaxMessageSize,
4198 size_t xMessageCount,
4199 uint8_t *pucMessageBufferStorageArea,
4204 if ((pucMessageBufferStorageArea ==
nullptr) ||
4205 (pxStaticMessageBuffer ==
nullptr) ||
4206 (xMaxMessageSize == 0U) ||
4207 (xMessageCount == 0U))
4211 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4218 pucMessageBufferStorageArea, storage_size,
4219 pxSendCompletedCallback, pxReceiveCompletedCallback);
4226 if (xMessageBuffer ==
nullptr)
4235 const void *pvTxData,
4236 size_t xDataLengthBytes,
4239 if ((xMessageBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
4279 return xDataLengthBytes;
4284 size_t xBufferLengthBytes,
4287 if ((xMessageBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4302 if (xBufferLengthBytes < env.
len)
4327 if (xMessageBuffer ==
nullptr)
4336 if (xMessageBuffer ==
nullptr)
4345 if (xMessageBuffer ==
nullptr)
4354 if (xMessageBuffer ==
nullptr)
4364 if (env.
blk !=
nullptr)
4421 const void *pvTxData,
4422 size_t xDataLengthBytes,
4425 if (pxHigherPriorityTaskWoken !=
nullptr)
4426 *pxHigherPriorityTaskWoken =
pdFALSE;
4428 if ((xMessageBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
4466 return xDataLengthBytes;
4471 size_t xBufferLengthBytes,
4474 if (pxHigherPriorityTaskWoken !=
nullptr)
4475 *pxHigherPriorityTaskWoken =
pdFALSE;
4477 if ((xMessageBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4488 if (xBufferLengthBytes < env.
len)
4516 if (pxHigherPriorityTaskWoken !=
nullptr)
4517 *pxHigherPriorityTaskWoken =
pdFALSE;
4519 if (xMessageBuffer ==
nullptr)
4530 if (env.
blk !=
nullptr)
4542 if (xMessageBuffer ==
nullptr)
Collection of memory-related primitives (stk::memory namespace).
Top-level STK include. Provides the Kernel class template and all built-in task-switching strategies.
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.
#define STK_UNUSED(X)
Explicitly marks a variable as unused to suppress compiler warnings.
#define STK_ASSERT(e)
Runtime assertion. Halts execution if the expression e evaluates to false.
#define __stk_weak
Marks a function or variable as weak, allowing it to be overridden by the user.
Collection of synchronization primitives (stk::sync namespace).
Collection of time-related primitives (stk::time namespace).
static constexpr size_t StkGetWordCountForType()
void * malloc(size_t size)
static StkKernel g_StkKernel
static __stk_forceinline bool IsIrqContext()
static stk::time::TimerHost * g_TimerHost
static stk::Word g_TimerHostBuf[StkGetWordCountForType< stk::time::TimerHost >()]
FreeRTOS interface for SuperTinyKernel RTOS.
static FrtosKernel g_StkKernel
static FrtosSemaphore * QueueHandleAsMutex(QueueHandle_t xQueue)
static void ObjFreeRaw(T *obj)
static stk::sync::PipeT< PendCall, 8U > g_PendCallPipe
static void KickPendDrainerFromISR()
static stk::memory::MemoryAllocator::Stats s_MemStats(10240U)
static stk::Timeout FrtosTimeoutToStk(TickType_t t)
static int32_t FreertosStrcmp(const char str1[], const char str2[])
static bool EnsurePendDrainer()
static uint32_t BuildStkFlagsOpts(BaseType_t xClearOnExit, BaseType_t xWaitForAllBits)
static void QueueSetNotify(void *member_handle, THost *host)
static stk::time::TimerHost * g_TimerHost
#define FREERTOS_STK_MIN_STACK_WORDS
static constexpr size_t StkGetWordCountForType()
static stk::Word g_TimerHostBuf[StkGetWordCountForType< stk::time::TimerHost >()]
static int32_t FrtosPrioToStkWeight(UBaseType_t p)
static size_t MsgBufSlotCount(size_t budget_bytes, size_t max_msg_size)
static EventBits_t StkFlagsToFrtos(uint32_t result, EventBits_t snapshot=0U)
static void EnsureKernelInitialized()
static stk::Word g_PendDrainerBuf[StkGetWordCountForType< stk::time::TimerHost::Timer >()]
static SemKind GetSemKindFromHandle(const void *obj)
static stk::time::TimerHost::Timer * g_PendDrainer
void * malloc(size_t size)
static BaseType_t NotifyApplyAction(FrtosTask::NotifySlot &slot, uint32_t ulValue, eNotifyAction eAction)
stk::Kernel< stk::KERNEL_DYNAMIC|stk::KERNEL_SYNC|stk::KERNEL_TICKLESS, 16U, stk::SwitchStrategyFP32, stk::PlatformDefault > FrtosKernel
static void ObjFreeArray(void *ptr)
static void ObjFree(T *obj)
static UBaseType_t StkWeightToFrtosPrio(int32_t w)
static T * ObjAllocArray(size_t count)
static T * ObjAlloc(Args &&...args)
@ Mutex
Mutex or recursive mutex (backed by stk::sync::Mutex).
@ None
Sentinel: not a FrtosSemaphore (e.g. plain FrtosQueue).
@ Counting
Binary or counting semaphore (backed by stk::sync::Semaphore).
static FrtosTask * ResolveNotifyTarget(TaskHandle_t xTask, UBaseType_t uxIndex)
BaseType_t xTaskCreateRestrictedStatic(const TaskParameters_restricted_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask)
#define FREERTOS_STK_MAX_TASKS
Maximum number of concurrent tasks managed by the kernel. Increase if your application creates more t...
void * StreamBufferHandle_t
BaseType_t xSemaphoreTakeFromISR(SemaphoreHandle_t xSemaphore, BaseType_t *pxHigherPriorityTaskWoken)
#define FREERTOS_STK_DEFAULT_STACK_WORDS
Default stack depth in Words when the caller passes usStackDepth = 0.
BaseType_t xTimerStartFromISR(TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xStreamBufferReset(StreamBufferHandle_t xStreamBuffer)
void vTaskSuspendAll(void)
Suspend the scheduler (disables preemption; interrupts remain enabled).
#define taskSCHEDULER_NOT_STARTED
SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t *pxMutexBuffer)
StreamBufferHandle_t xStreamBufferCreate(size_t xBufferSizeBytes, size_t xTriggerLevelBytes)
size_t xPortGetFreeHeapSize(void)
#define taskSCHEDULER_SUSPENDED
size_t xMessageBufferSpacesAvailable(MessageBufferHandle_t xMessageBuffer)
BaseType_t xTaskAbortDelay(TaskHandle_t xTask)
BaseType_t xQueuePeek(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
eTaskState
Task execution state, returned by eTaskGetState().
BaseType_t xEventGroupSetBitsFromISR(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskResumeFromISR(TaskHandle_t xTaskToResume)
BaseType_t xQueueSendToFront(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
QueueHandle_t xQueueCreate(UBaseType_t uxQueueLength, UBaseType_t uxItemSize)
BaseType_t xTaskNotifyAndQueryIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue)
SemaphoreHandle_t xSemaphoreCreateBinary(void)
BaseType_t xTimerChangePeriod(TimerHandle_t xTimer, TickType_t xNewPeriod, TickType_t xTicksToWait)
size_t xMessageBufferNextLengthBytes(MessageBufferHandle_t xMessageBuffer)
EventBits_t xEventGroupSync(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet, EventBits_t uxBitsToWaitFor, TickType_t xTicksToWait)
void vTimerSetTimerID(TimerHandle_t xTimer, void *pvNewID)
QueueSetMemberHandle_t xQueueSelectFromSetFromISR(QueueSetHandle_t xQueueSet)
StreamBufferHandle_t xStreamBufferCreateWithCallback(size_t xBufferSizeBytes, size_t xTriggerLevelBytes, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
TaskHandle_t xTaskGetCurrentTaskHandle(void)
BaseType_t xTaskNotifyFromISR(TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken)
EventGroupHandle_t xEventGroupCreate(void)
void vPortEnterCritical(void)
BaseType_t xTimerStart(TimerHandle_t xTimer, TickType_t xTicksToWait)
SemaphoreHandle_t xSemaphoreCreateRecursiveMutex(void)
Create a recursive mutex (same implementation as xSemaphoreCreateMutex).
BaseType_t xQueueOverwriteFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
void vQueueDelete(QueueHandle_t xQueue)
void vTaskPrioritySet(TaskHandle_t xTask, UBaseType_t uxNewPriority)
StreamBufferHandle_t xStreamBufferCreateStaticWithCallback(size_t xBufferSizeBytes, size_t xTriggerLevelBytes, uint8_t *pucStreamBufferStorageArea, StaticStreamBuffer_t *pxStaticStreamBuffer, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
BaseType_t xTimerStopFromISR(TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)
void(* PendedFunction_t)(void *pvParameter1, uint32_t ulParameter2)
BaseType_t xQueueReceiveFromISR(QueueHandle_t xQueue, void *pvBuffer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTimerReset(TimerHandle_t xTimer, TickType_t xTicksToWait)
BaseType_t xMessageBufferReset(MessageBufferHandle_t xMessageBuffer)
UBaseType_t uxTaskGetNumberOfTasks(void)
Return the number of tasks currently under kernel management.
BaseType_t xTaskNotifyStateClear(TaskHandle_t xTask)
BaseType_t xTaskNotifyIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction)
BaseType_t xQueueSendToBackFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
void * EventGroupHandle_t
MessageBufferHandle_t xMessageBufferCreateWithCallback(size_t xBufferSizeBytes, size_t xMaxMessageSize, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
#define configTASK_NOTIFICATION_ARRAY_ENTRIES
#define configUSE_MUTEXES
QueueSetHandle_t xQueueCreateSet(UBaseType_t uxEventQueueLength)
UBaseType_t uxQueueSpacesAvailable(QueueHandle_t xQueue)
void vTaskStartScheduler(void)
TaskHandle_t xSemaphoreGetMutexHolderFromISR(SemaphoreHandle_t xMutex)
SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount, UBaseType_t uxInitialCount, StaticSemaphore_t *pxSemaphoreBuffer)
size_t xStreamBufferBytesAvailable(StreamBufferHandle_t xStreamBuffer)
TaskHandle_t xQueueGetMutexHolderFromISR(QueueHandle_t xQueue)
void(* TimerCallbackFunction_t)(TimerHandle_t xTimer)
BaseType_t xTimerPendFunctionCall(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, TickType_t xTicksToWait)
UBaseType_t uxTaskGetSystemState(TaskStatus_t *pxTaskStatusArray, UBaseType_t uxArraySize, uint32_t *pulTotalRunTime)
BaseType_t xTaskNotifyStateClearIndexed(TaskHandle_t xTask, UBaseType_t uxIndexToClear)
TickType_t xTaskGetTickCount(void)
Return the tick count since the scheduler started.
UBaseType_t uxSemaphoreGetCount(SemaphoreHandle_t xSemaphore)
EventBits_t xEventGroupGetBits(EventGroupHandle_t xEventGroup)
BaseType_t xQueueSendFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
size_t xMessageBufferReceive(MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait)
unsigned long UBaseType_t
uint32_t ulTaskNotifyTake(BaseType_t ulClearCountOnExit, TickType_t xTicksToWait)
BaseType_t xTaskNotifyAndQueryFromISR(TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken)
void vEventGroupDelete(EventGroupHandle_t xEventGroup)
const char * pcTimerGetName(TimerHandle_t xTimer)
void * QueueSetMemberHandle_t
void(* TaskFunction_t)(void *pvParameters)
TaskHandle_t xSemaphoreGetMutexHolder(SemaphoreHandle_t xMutex)
BaseType_t xTaskDelayUntil(TickType_t *pxPreviousWakeTime, TickType_t xTimeIncrement)
BaseType_t xQueueIsQueueFullFromISR(const QueueHandle_t xQueue)
BaseType_t xStreamBufferIsFull(StreamBufferHandle_t xStreamBuffer)
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength, UBaseType_t uxItemSize, uint8_t *pucQueueStorage, StaticQueue_t *pxStaticQueue)
BaseType_t xTimerStop(TimerHandle_t xTimer, TickType_t xTicksToWait)
SemaphoreHandle_t xSemaphoreCreateBinaryStatic(StaticSemaphore_t *pxSemaphoreBuffer)
BaseType_t xTaskNotifyAndQuery(TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue)
#define configUSE_QUEUE_SETS
void * pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex)
BaseType_t xTaskNotifyWait(uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait)
size_t xMessageBufferSendFromISR(MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueIsQueueEmptyFromISR(const QueueHandle_t xQueue)
BaseType_t xTaskNotifyGive(TaskHandle_t xTaskToNotify)
void vTaskDelay(TickType_t xTicksToDelay)
void vStreamBufferDelete(StreamBufferHandle_t xStreamBuffer)
MessageBufferHandle_t xMessageBufferCreateStatic(size_t xMaxMessageSize, size_t xMessageCount, uint8_t *pucMessageBufferStorageArea, StaticMessageBuffer_t *pxStaticMessageBuffer)
TimerHandle_t xTimerCreate(const char *pcTimerName, TickType_t xTimerPeriodInTicks, UBaseType_t uxAutoReload, void *pvTimerID, TimerCallbackFunction_t pxCallbackFunction)
void vTaskSuspend(TaskHandle_t xTaskToSuspend)
uint32_t ulTaskNotifyTakeIndexed(UBaseType_t uxIndexToWait, BaseType_t ulClearCountOnExit, TickType_t xTicksToWait)
BaseType_t xQueueRemoveFromSet(QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet)
SemaphoreHandle_t xSemaphoreCreateMutex(void)
TaskHandle_t xTaskGetHandle(const char *pcNameToQuery)
BaseType_t xStreamBufferResetFromISR(StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xStreamBufferSetTriggerLevel(StreamBufferHandle_t xStreamBuffer, size_t xTriggerLevelBytes)
BaseType_t xMessageBufferResetFromISR(MessageBufferHandle_t xMessageBuffer, BaseType_t *pxHigherPriorityTaskWoken)
SemaphoreHandle_t xSemaphoreCreateCounting(UBaseType_t uxMaxCount, UBaseType_t uxInitialCount)
void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue)
SemaphoreHandle_t xSemaphoreCreateRecursiveMutexStatic(StaticSemaphore_t *pxMutexBuffer)
BaseType_t xQueueAddToSet(QueueSetMemberHandle_t xQueueOrSemaphore, QueueSetHandle_t xQueueSet)
void taskYIELD_impl(void)
#define configNUM_THREAD_LOCAL_STORAGE_POINTERS
MessageBufferHandle_t xMessageBufferCreateStaticWithCallback(size_t xMaxMessageSize, size_t xMessageCount, uint8_t *pucMessageBufferStorageArea, StaticMessageBuffer_t *pxStaticMessageBuffer, StreamBufferCallbackFunction_t pxSendCompletedCallback, StreamBufferCallbackFunction_t pxReceiveCompletedCallback)
size_t xStreamBufferSpacesAvailable(StreamBufferHandle_t xStreamBuffer)
uint32_t ulTaskNotifyValueClearIndexed(TaskHandle_t xTask, UBaseType_t uxIndexToClear, uint32_t ulBitsToClear)
UBaseType_t uxTaskGetStackHighWaterMark(TaskHandle_t xTask)
UBaseType_t uxTaskPriorityGetFromISR(TaskHandle_t xTask)
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore)
BaseType_t xQueuePeekFromISR(QueueHandle_t xQueue, void *pvBuffer)
BaseType_t xStreamBufferIsEmpty(StreamBufferHandle_t xStreamBuffer)
BaseType_t xTaskGetSchedulerState(void)
BaseType_t xSemaphoreGiveFromISR(SemaphoreHandle_t xSemaphore, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskNotifyFromISRIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, BaseType_t *pxHigherPriorityTaskWoken)
#define configMAX_PRIORITIES
BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait)
void vTaskList(char *pcWriteBuffer)
EventGroupHandle_t xEventGroupCreateStatic(StaticEventGroup_t *pxEventGroupBuffer)
UBaseType_t uxQueueMessagesWaiting(QueueHandle_t xQueue)
BaseType_t xMessageBufferIsEmpty(MessageBufferHandle_t xMessageBuffer)
#define configTOTAL_HEAP_SIZE
BaseType_t xQueueSend(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
EventBits_t xEventGroupClearBitsFromISR(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToClear)
void vMessageBufferDelete(MessageBufferHandle_t xMessageBuffer)
BaseType_t xQueueReset(QueueHandle_t xQueue)
BaseType_t xMessageBufferIsFull(MessageBufferHandle_t xMessageBuffer)
BaseType_t xTimerDelete(TimerHandle_t xTimer, TickType_t xTicksToWait)
eTaskState eTaskGetState(TaskHandle_t xTask)
BaseType_t xTaskNotifyAndQueryFromISRIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify, uint32_t ulValue, eNotifyAction eAction, uint32_t *pulPreviousNotifyValue, BaseType_t *pxHigherPriorityTaskWoken)
TickType_t xTimerGetPeriod(TimerHandle_t xTimer)
size_t xMessageBufferReceiveFromISR(MessageBufferHandle_t xMessageBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
QueueSetMemberHandle_t xQueueSelectFromSet(QueueSetHandle_t xQueueSet, TickType_t xTicksToWait)
TickType_t xTimerGetExpiryTime(TimerHandle_t xTimer)
size_t xPortGetMinimumEverFreeHeapSize(void)
void(* StreamBufferCallbackFunction_t)(StreamBufferHandle_t xStreamBuffer, BaseType_t *pxHigherPriorityTaskWoken)
void vTaskDelayUntil(TickType_t *pxPreviousWakeTime, TickType_t xTimeIncrement)
EventBits_t xEventGroupClearBits(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToClear)
void vSemaphoreDelete(SemaphoreHandle_t xSemaphore)
void vPortGetHeapStats(HeapStats_t *pxHeapStats)
MessageBufferHandle_t xMessageBufferCreate(size_t xBufferSizeBytes, size_t xMaxMessageSize)
BaseType_t xQueueSendToBack(QueueHandle_t xQueue, const void *pvItemToQueue, TickType_t xTicksToWait)
BaseType_t xTimerIsTimerActive(TimerHandle_t xTimer)
void * pvPortMalloc(size_t xWantedSize)
BaseType_t xTaskCreateRestricted(const TaskParameters_restricted_t *pxTaskDefinition, TaskHandle_t *pxCreatedTask)
const char * pcTaskGetName(TaskHandle_t xTaskToQuery)
BaseType_t xTaskNotifyGiveIndexed(TaskHandle_t xTaskToNotify, UBaseType_t uxIndexToNotify)
size_t xStreamBufferSendFromISR(StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
#define taskSCHEDULER_RUNNING
TimerHandle_t xTimerCreateStatic(const char *pcTimerName, TickType_t xTimerPeriodInTicks, UBaseType_t uxAutoReload, void *pvTimerID, TimerCallbackFunction_t pxCallbackFunction, StaticTimer_t *pxTimerBuffer)
BaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t xMutex)
TickType_t xTaskGetTickCountFromISR(void)
Return the tick count from ISR context (ISR-safe).
BaseType_t xTaskNotifyWaitIndexed(UBaseType_t uxIndexToWait, uint32_t ulBitsToClearOnEntry, uint32_t ulBitsToClearOnExit, uint32_t *pulNotificationValue, TickType_t xTicksToWait)
TaskHandle_t xQueueGetMutexHolder(QueueHandle_t xQueue)
void vTaskResume(TaskHandle_t xTaskToResume)
UBaseType_t uxTaskPriorityGet(TaskHandle_t xTask)
BaseType_t xTimerChangePeriodFromISR(TimerHandle_t xTimer, TickType_t xNewPeriod, BaseType_t *pxHigherPriorityTaskWoken)
UBaseType_t uxQueueMessagesWaitingFromISR(QueueHandle_t xQueue)
BaseType_t xTimerResetFromISR(TimerHandle_t xTimer, BaseType_t *pxHigherPriorityTaskWoken)
uint32_t ulTaskNotifyValueClear(TaskHandle_t xTask, uint32_t ulBitsToClear)
EventBits_t xEventGroupWaitBits(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToWaitFor, BaseType_t xClearOnExit, BaseType_t xWaitForAllBits, TickType_t xTicksToWait)
void * pvTimerGetTimerID(TimerHandle_t xTimer)
size_t xStreamBufferSend(StreamBufferHandle_t xStreamBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait)
BaseType_t xTaskResumeAll(void)
BaseType_t xTaskCreate(TaskFunction_t pvTaskCode, const char *pcName, uint32_t usStackDepth, void *pvParameters, UBaseType_t uxPriority, TaskHandle_t *pxCreatedTask)
StreamBufferHandle_t xStreamBufferCreateStatic(size_t xBufferSizeBytes, size_t xTriggerLevelBytes, uint8_t *pucStreamBufferStorageArea, StaticStreamBuffer_t *pxStaticStreamBuffer)
size_t xStreamBufferGetTriggerLevel(StreamBufferHandle_t xStreamBuffer)
StackType_t uxTaskGetStackHighWaterMark2(TaskHandle_t xTask)
size_t xMessageBufferSend(MessageBufferHandle_t xMessageBuffer, const void *pvTxData, size_t xDataLengthBytes, TickType_t xTicksToWait)
#define configSTACK_DEPTH_TYPE
BaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t xMutex, TickType_t xTicksToWait)
void * MessageBufferHandle_t
eNotifyAction
Action applied to a task's notification value by xTaskNotify().
void vTaskGetRunTimeStats(char *pcWriteBuffer)
void vTaskEndScheduler(void)
End scheduling (KERNEL_DYNAMIC only). Included for API completeness.
void vPortExitCritical(void)
EventBits_t xEventGroupSetBits(EventGroupHandle_t xEventGroup, EventBits_t uxBitsToSet)
BaseType_t xTimerPendFunctionCallFromISR(PendedFunction_t xFunctionToPend, void *pvParameter1, uint32_t ulParameter2, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xQueueSendToFrontFromISR(QueueHandle_t xQueue, const void *pvItemToQueue, BaseType_t *pxHigherPriorityTaskWoken)
BaseType_t xTaskNotify(TaskHandle_t xTaskToNotify, uint32_t ulValue, eNotifyAction eAction)
BaseType_t xQueueReceive(QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait)
size_t xStreamBufferReceiveFromISR(StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, BaseType_t *pxHigherPriorityTaskWoken)
void vTaskDelete(TaskHandle_t xTaskToDelete)
size_t xStreamBufferReceive(StreamBufferHandle_t xStreamBuffer, void *pvRxData, size_t xBufferLengthBytes, TickType_t xTicksToWait)
BaseType_t xQueueOverwrite(QueueHandle_t xQueue, const void *pvItemToQueue)
size_t xStreamBufferNextMessageLengthBytes(StreamBufferHandle_t xStreamBuffer)
TaskHandle_t xTaskCreateStatic(TaskFunction_t pvTaskCode, const char *pcName, uint32_t ulStackDepth, void *pvParameters, UBaseType_t uxPriority, StackType_t *puxStackBuffer, StaticTask_t *pxTaskBuffer)
@ eSetValueWithoutOverwrite
Namespace of STK package.
uintptr_t Word
Native processor word type.
static void Yield()
Notify scheduler to switch to the next runnable task.
SwitchStrategyFixedPriority< 32 > SwitchStrategyFP32
Shorthand alias for SwitchStrategyFixedPriority<32>: 32 priority levels (0..31), using a single 32-bi...
static void Sleep(Timeout tick_count)
Put calling process into a sleep state.
static void SleepCancel(TId task_id)
Cancel sleep of the task.
EAccessMode
Hardware access modes by the task.
@ ACCESS_PRIVILEGED
Privileged access mode (access to hardware is fully unrestricted).
constexpr Timeout NO_WAIT
Timeout value: return immediately if the synchronization object is not yet signaled (non-blocking pol...
int64_t Ticks
Ticks value.
int32_t Timeout
Timeout time (ticks).
static bool SleepUntil(Ticks timestamp)
Put calling process into a sleep state until the specified timestamp.
static Ticks GetTicks()
Get number of ticks elapsed since kernel start.
PlatformArmCortexM PlatformDefault
Default platform implementation.
constexpr Timeout WAIT_INFINITE
Timeout value: block indefinitely until the synchronization object is signaled.
static TId GetTid()
Get task/thread Id of the calling task.
constexpr TId TID_NONE
Reserved task/thread id representing zero/none thread id.
Word TId
Task (thread) id.
@ KERNEL_TICKLESS
Tickless mode. To use this mode STK_TICKLESS_IDLE must be defined to 1 in stk_config....
@ KERNEL_SYNC
Synchronization support (see Event).
@ KERNEL_DYNAMIC
Tasks can be added or removed and therefore exit when done.
bool IsInsideISR()
Check whether the CPU is currently executing inside a hardware interrupt service routine (ISR).
static void Free(void *ptr) __stk_weak
Free the memory chunk.
static void * Allocate(size_t size) __stk_weak
Allocate the memory chunk.
static Stats GetStats() __stk_weak
Get stats of memory allocation.
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).
void RecordFree(size_t size)
Record sucessful deallocation.
Fixed-size block allocator with O(1) alloc/free and proper task-blocking semantics.
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
bool Free(void *ptr)
Return a previously allocated block to the pool.
static constexpr size_t AlignBlockSize(size_t raw_size)
Round a raw block size up to the nearest multiple of BLOCK_ALIGN.
void * TimedAlloc(Timeout timeout_ticks=WAIT_INFINITE)
Allocate one block, blocking until one becomes available or the timeout expires.
Concrete implementation of IKernel.
static void Enter()
Enter a critical section.
static void Exit()
Exit a critical section.
RAII guard that enters the critical section on construction and exits it on destruction.
virtual size_t GetStackSpace() const
Get available stack space.
Interface for a user task.
@ KSTATE_RUNNING
Initialized and running, IKernel::Start() was called successfully.
@ KSTATE_SUSPENDED
Scheduling is suspended with IKernelService::Suspend().
@ KSTATE_INACTIVE
Not ready, IKernel::Initialize() must be called.
RAII-style low-level synchronization primitive for atomic code execution. Used as building brick for ...
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.
uint32_t Get() const
Read the current flags word without modifying it.
static bool IsError(uint32_t result)
Checks if a return value from Set(), Clear(), or Wait() is an error.
static const uint32_t OPT_NO_CLEAR
Do not clear matched flags after a successful wait.
static const uint32_t OPT_WAIT_ALL
Wait for ALL of the specified flags to be set simultaneously (AND semantics).
static const uint32_t OPT_WAIT_ANY
Wait for ANY of the specified flags to be set (OR semantics, default).
uint32_t Set(uint32_t flags)
Set one or more flags.
Fixed-capacity, fixed-message-size FIFO queue for inter-task communication.
bool TryPeek(void *msg_ptr)
Attempt to peek at the next message without blocking.
bool IsEmpty() const
Check whether the queue is currently empty.
static const size_t CAPACITY_MAX
Max capacity supported (number of messages).
bool TryPutFront(const void *msg_ptr)
Attempt to put a message into the front of the queue without blocking.
bool TryPut(const void *msg_ptr)
Attempt to put a message into the back of the queue without blocking.
size_t GetSpace() const
Get the number of free slots currently available.
size_t GetCount() const
Get the current number of messages in the queue.
bool TryGet(void *msg_ptr)
Attempt to get a message from the queue without blocking.
bool PutFront(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the front of the queue (LIFO / priority-insert order).
bool IsStorageValid() const
Verify that the backing storage is valid and the pool is ready for use.
bool Put(const void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Put a message into the back of the queue (FIFO order).
bool Get(void *msg_ptr, Timeout timeout_ticks=WAIT_INFINITE)
Get a message from the queue.
void Reset()
Discard all messages and reset the queue to the empty state.
Recursive mutex primitive that allows the same thread to acquire the lock multiple times.
bool TimedLock(Timeout timeout_ticks)
Acquire lock.
TId GetOwner() const
Get owner of the mutex.
void Unlock() override
Release lock.
Thread-safe FIFO communication pipe for inter-task data passing.
size_t WriteBulk(const void *src, size_t count, Timeout timeout_ticks=WAIT_INFINITE)
Write multiple elements to the pipe.
size_t TryWriteBulk(const void *src, size_t count)
Attempt to write multiple elements to the pipe without blocking.
size_t GetCapacity() const
Get the maximum number of elements the pipe can hold.
size_t TryReadBulk(void *dst, size_t count)
Attempt to read multiple elements from the pipe without blocking.
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.
Thread-safe, type-safe FIFO communication pipe with internal storage.
Counting semaphore primitive for resource management and signaling.
void Signal()
Post a signal (increment counter).
uint16_t GetCount() const
Get current counter value.
static const uint16_t COUNT_MAX
Max count value supported.
bool Wait(Timeout timeout_ticks=WAIT_INFINITE)
Wait for a signal (decrement counter).
bool TryWait()
Poll the semaphore without blocking (decrement counter if available).
Software timer multiplexer that manages multiple Timer instances on top of a small fixed set of kerne...
bool Stop(Timer &tmr)
Stop running timer.
Abstract base class for a timer managed by TimerHost.
Ticks GetDeadline() const
Get the absolute time in ticks at which the timer will expire.
bool IsActive() const
Check whether the timer is currently active.
StackType_t * pxStackBase
StackType_t usStackHighWaterMark
UBaseType_t uxBasePriority
UBaseType_t uxCurrentPriority
uint32_t ulRunTimeCounter
StackType_t * puxStackBuffer
TaskFunction_t pvTaskCode
StaticTask_t * pxTaskBuffer
size_t xSizeOfSmallestFreeBlockInBytes
size_t xMinimumEverFreeBytesRemaining
size_t xNumberOfSuccessfulAllocations
size_t xSizeOfLargestFreeBlockInBytes
size_t xNumberOfFreeBlocks
size_t xNumberOfSuccessfulFrees
size_t xAvailableHeapSpaceInBytes
void Run() override
Entry point of the user task.
int32_t GetWeight() const override
Get static base weight of the task.
const stk::Word * GetStack() const override
Get pointer to the stack memory.
volatile int32_t m_weight
void OnDeadlineMissed(uint32_t) override
Called by the scheduler if deadline of the task is missed when Kernel is operating in Hard Real-Time ...
void OnExit() override
Called by the kernel before removal from the scheduling (see stk::KERNEL_DYNAMIC).
size_t GetStackHighWaterMark() const
size_t GetStackSize() const override
Get number of elements of the stack memory array.
const char * GetTraceName() const override
Get task trace name set by application.
static uint32_t s_task_counter
stk::EAccessMode GetAccessMode() const override
Get hardware access mode of the user task.
volatile bool pending
true if a value was set but not yet consumed
STK_NONCOPYABLE_CLASS(NotifySlot)
stk::sync::Semaphore sem
binary semaphore: blocks the waiter, signaled by notifier
volatile uint32_t value
notification value word
stk::sync::MessageQueue m_mq
FrtosQueue(uint32_t cap, uint32_t msg_size, const char *name)
FrtosQueueSet * m_set
non-owning ptr to the queue set this member belongs to (nullptr if none)
static uint8_t * AllocBuffer(uint32_t cap, uint32_t msg_size)
FrtosQueue(uint32_t cap, uint32_t msg_size, const char *name, uint8_t *ext_buf)
FrtosSemaphore(SemKind kind, uint16_t initial, uint16_t max_count)
stk::sync::Semaphore * m_sem
FrtosQueueSet * m_set
non-owning ptr to the queue set this member belongs to (nullptr if none)
bool m_cb_owned
true = heap-allocated, delete in ObjFree
stk::sync::MessageQueue * m_token_mq
FIFO of fired-member handles (void*).
FrtosQueueSet(UBaseType_t uxEventQueueLength)
uint8_t * m_buf
raw backing store for m_token_mq
static bool EnsureTimerHost()
FrtosTimer(const char *name, TickType_t period, bool auto_reload, void *timer_id, TimerCallbackFunction_t cb)
void OnExpired(stk::time::TimerHost *) override
Callback invoked by the handler task when this timer expires.
TimerCallbackFunction_t m_callback
void OnExpired(stk::time::TimerHost *host) override
Callback invoked by the handler task when this timer expires.
stk::sync::EventFlags m_ef
stk::sync::Pipe m_pipe
byte ring-buffer (element_size = 1)
FrtosStreamBuffer(uint8_t *buf, size_t capacity, size_t trigger, StreamBufferCallbackFunction_t pSendCb=nullptr, StreamBufferCallbackFunction_t pRecvCb=nullptr)
StreamBufferCallbackFunction_t m_recv_cb
optional callback fired after a successful Receive
size_t m_trigger
minimum bytes before Receive() unblocks
bool m_cb_owned
true -> struct heap-allocated, deleted in vStreamBufferDelete
bool m_buf_owned
true -> data buffer heap-allocated, freed in dtor
StreamBufferCallbackFunction_t m_send_cb
optional callback fired after a successful Send
bool m_eq_buf_owned
true -> envelope buffer heap-allocated
static constexpr size_t ENVELOPE_SIZE
stk::memory::BlockMemoryPool m_pool
payload block allocator
FrtosMessageBuffer(size_t max_msg_size, size_t msg_count, uint8_t *storage, size_t storage_size, StreamBufferCallbackFunction_t pSendCb=nullptr, StreamBufferCallbackFunction_t pRecvCb=nullptr)
bool m_cb_owned
true -> struct heap-allocated
FrtosMessageBuffer(size_t max_msg_size, size_t msg_count, StreamBufferCallbackFunction_t pSendCb=nullptr, StreamBufferCallbackFunction_t pRecvCb=nullptr)
stk::sync::MessageQueue m_eq
envelope FIFO {len, blk}
StreamBufferCallbackFunction_t m_send_cb
optional callback fired after a successful Send
StreamBufferCallbackFunction_t m_recv_cb
optional callback fired after a successful Receive
size_t m_max_msg_size
max payload bytes per message
void * blk
pointer to block pool block holding the payload
size_t len
payload length in bytes