25#define FREERTOS_STK_WRAPPER_VERSION "FreeRTOS-STK Wrapper v1.1"
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
607 const uint8_t first_byte = *
static_cast<const uint8_t *
>(obj);
661 return m_mutex.TimedLock(timeout);
710#if configUSE_QUEUE_SETS
752 const size_t buf_bytes =
753 static_cast<size_t>(uxEventQueueLength) *
sizeof(
void *);
756 if (
m_buf ==
nullptr)
761 static_cast<size_t>(uxEventQueueLength),
795template <
typename THost>
798#if configUSE_QUEUE_SETS
801 if (host->m_set !=
nullptr)
802 host->m_set->m_token_mq->TryPut(&member_handle);
961#if configUSE_EVENT_GROUPS
992#if configUSE_STREAM_BUFFERS
1005 :
m_pipe(buf, capacity, 1U),
1006 m_trigger(trigger >= 1U ? trigger : 1U),
1059 stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size)),
1074 size_t storage_size,
1078 stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size),
1080 msg_count *
stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size)),
1081 m_eq(storage + msg_count *
stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size),
1188 uint32_t usStackDepth,
1193 if (pvTaskCode ==
nullptr)
1206 size_t stack_words = (usStackDepth > 0U)
1207 ?
static_cast<size_t>(usStackDepth)
1227 if (pxCreatedTask !=
nullptr)
1235 uint32_t ulStackDepth,
1242 if ((pvTaskCode ==
nullptr) || (puxStackBuffer ==
nullptr) || (pxTaskBuffer ==
nullptr))
1248 "StaticTask_t is too small to hold FrtosTask. "
1249 "Increase STATIC_TASK_TCB_SIZE_WORDS in freertos_stk.h.");
1257 t->
m_stack =
static_cast<stk::Word *
>(
static_cast<void *
>(puxStackBuffer));
1259 ?
static_cast<size_t>(ulStackDepth)
1275 static_cast<FrtosTask *
>(xTaskToDelete);
1293 static_cast<FrtosTask *
>(xTaskToSuspend);
1298 bool already =
false;
1305 if (xTaskToResume ==
nullptr)
1321 if (xTaskToResume ==
nullptr)
1339 if (xTask ==
nullptr)
1343 const stk::TId tid =
static_cast<stk::TId>(
reinterpret_cast<uintptr_t
>(xTask));
1372 static_cast<void>(
xTaskDelayUntil(pxPreviousWakeTime, xTimeIncrement));
1383 *pxPreviousWakeTime =
static_cast<TickType_t>(wake_at);
1417 if (xTask ==
nullptr)
1429 if (
static_cast<uintptr_t
>(
stk::GetTid()) ==
reinterpret_cast<uintptr_t
>(t))
1445 if (pcNameToQuery ==
nullptr)
1453 if ((task->GetTraceName() !=
nullptr) &&
1467 if (xTaskToQuery ==
nullptr)
1470 return static_cast<FrtosTask *
>(xTaskToQuery)->m_name;
1497 uint32_t *pulTotalRunTime)
1501 if (pulTotalRunTime !=
nullptr)
1502 *pulTotalRunTime = 0U;
1504 if ((pxTaskStatusArray ==
nullptr) || (uxArraySize == 0U))
1511 const uintptr_t running_tid =
static_cast<uintptr_t
>(
stk::GetTid());
1515 if (filled >= uxArraySize)
1534 if (
reinterpret_cast<uintptr_t
>(t) == running_tid)
1568 if ((pxTaskDefinition ==
nullptr) ||
1580 pxTaskDefinition->
pcName,
1590 if (pxCreatedTask !=
nullptr)
1601 if ((pxTaskDefinition ==
nullptr) ||
1612 pxTaskDefinition->
pcName,
1621 if (pcWriteBuffer ==
nullptr)
1626 int off = snprintf(pcWriteBuffer, 64U,
1627 "%-12s %c %4s %6s %4s\r\n",
1628 "Name",
'S',
"Prio",
"Stack",
"Num");
1630 if (off < 0) off = 0;
1631 char *p = pcWriteBuffer + off;
1650 if (
static_cast<uintptr_t
>(
stk::GetTid()) ==
reinterpret_cast<uintptr_t
>(t))
1655 const char *name = (t->
m_name !=
nullptr) ? t->
m_name :
"(unnamed)";
1659 int n = snprintf(p, 48U,
"%-12s %c %4u %6u %4u\r\n",
1661 static_cast<unsigned>(prio),
1662 static_cast<unsigned>(hwm),
1663 static_cast<unsigned>(task_num));
1692 if (pcWriteBuffer ==
nullptr)
1698 int off = snprintf(pcWriteBuffer, 64U,
1699 "%-12s %12s %8s\r\n",
1700 "Task",
"Abs Time",
"% Time");
1702 if (off < 0) off = 0;
1703 char *p = pcWriteBuffer + off;
1708 const char *name = (t->
m_name !=
nullptr) ? t->
m_name :
"(unnamed)";
1713 int n = snprintf(p, 48U,
"%-12s %12lu %7lu%%\r\n",
1732 if (
IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1739 static_cast<uint32_t
>(uxQueueLength),
1740 static_cast<uint32_t
>(uxItemSize),
1757 uint8_t *pucQueueStorage,
1761 if ((pucQueueStorage ==
nullptr) || (pxStaticQueue ==
nullptr))
1764 if (
IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1773 "StaticQueue_t is too small to hold FrtosQueue. "
1774 "Increase STATIC_QUEUE_TCB_SIZE_WORDS in freertos_stk.h.");
1779 static_cast<uint32_t
>(uxQueueLength),
1780 static_cast<uint32_t
>(uxItemSize),
1791 if (xQueue ==
nullptr)
1798 const void *pvItemToQueue,
1801 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1817 const void *pvItemToQueue,
1820 return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
1824 const void *pvItemToQueue,
1827 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1846 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1863 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1869 return static_cast<FrtosQueue *
>(xQueue)->m_mq.Peek(
1879 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1887 if (xQueue ==
nullptr)
1898 if (xQueue ==
nullptr)
1906 if (xQueue ==
nullptr)
1915 if (xQueue ==
nullptr)
1918 static_cast<FrtosQueue *
>(xQueue)->m_mq.Reset();
1927 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1939 const void *pvItemToQueue,
1944 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1952 if (pxHigherPriorityTaskWoken !=
nullptr)
1953 *pxHigherPriorityTaskWoken =
pdFALSE;
1959 const void *pvItemToQueue,
1962 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1974 if (pxHigherPriorityTaskWoken !=
nullptr)
1975 *pxHigherPriorityTaskWoken =
pdFALSE;
1984 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1987 bool ok =
static_cast<FrtosQueue *
>(xQueue)->m_mq.TryGet(pvBuffer);
1989 if (pxHigherPriorityTaskWoken !=
nullptr)
1990 *pxHigherPriorityTaskWoken =
pdFALSE;
1996 const void *pvItemToQueue,
2005 const void *pvItemToQueue,
2008 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
2019 if (pxHigherPriorityTaskWoken !=
nullptr)
2020 *pxHigherPriorityTaskWoken =
pdFALSE;
2029 if (xQueue ==
nullptr)
2040 if (xQueue ==
nullptr)
2077#if configUSE_MUTEXES
2083 if (xQueue ==
nullptr)
2150#if configUSE_QUEUE_SETS
2162 if ((qs ==
nullptr) || !qs->
IsValid())
2174 if ((xQueueOrSemaphore ==
nullptr) || (xQueueSet ==
nullptr))
2195 if (s->
m_set !=
nullptr)
2210 if (q->
m_set !=
nullptr)
2227 if ((xQueueOrSemaphore ==
nullptr) || (xQueueSet ==
nullptr))
2272 if (xQueueSet ==
nullptr)
2281 void *handle =
nullptr;
2290 if (xQueueSet ==
nullptr)
2296 void *handle =
nullptr;
2314 static_cast<uint16_t
>(0U),
2315 static_cast<uint16_t
>(1U));
2317 if ((s ==
nullptr) || (s->
m_sem ==
nullptr))
2327 if (pxSemaphoreBuffer ==
nullptr)
2332 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2333 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2341 static_cast<uint16_t
>(0U),
2342 static_cast<uint16_t
>(1U));
2344 if (s->
m_sem ==
nullptr)
2355#if configUSE_COUNTING_SEMAPHORES
2360 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2368 static_cast<uint16_t
>(uxInitialCount),
2369 static_cast<uint16_t
>(uxMaxCount));
2371 if ((s ==
nullptr) || (s->
m_sem ==
nullptr))
2383 if (pxSemaphoreBuffer ==
nullptr)
2386 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2393 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2394 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2398 static_cast<uint16_t
>(uxInitialCount),
2399 static_cast<uint16_t
>(uxMaxCount));
2401 if (s->
m_sem ==
nullptr)
2413#if configUSE_MUTEXES
2420 static_cast<uint16_t
>(0U),
2421 static_cast<uint16_t
>(1U),
2424 if ((s ==
nullptr) || (s->
m_mtx ==
nullptr))
2436 if (pxMutexBuffer ==
nullptr)
2440 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2441 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2445 static_cast<uint16_t
>(0U),
2446 static_cast<uint16_t
>(1U),
2449 if (s->
m_mtx ==
nullptr)
2487 if (xSemaphore ==
nullptr)
2495 if (xSemaphore ==
nullptr)
2506#if configUSE_MUTEXES
2519 if (xSemaphore ==
nullptr)
2535 if (pxHigherPriorityTaskWoken !=
nullptr)
2536 *pxHigherPriorityTaskWoken =
pdFALSE;
2543 if (xMutex ==
nullptr)
2546#if configUSE_MUTEXES
2561 if (xSemaphore ==
nullptr)
2568#if configUSE_MUTEXES
2597 if (xMutex ==
nullptr)
2600#if configUSE_MUTEXES
2616 if (xSemaphore ==
nullptr)
2630 if (pxHigherPriorityTaskWoken !=
nullptr)
2631 *pxHigherPriorityTaskWoken =
pdFALSE;
2638 if (xSemaphore ==
nullptr)
2646#if configUSE_MUTEXES
2654#if configUSE_MUTEXES
2672 if (xMutex ==
nullptr)
2687 return reinterpret_cast<TaskHandle_t>(
static_cast<uintptr_t
>(owner));
2697 if (xMutex ==
nullptr)
2710 return reinterpret_cast<TaskHandle_t>(
static_cast<uintptr_t
>(owner));
2727 if (
IsIrqContext() || (pxCallbackFunction ==
nullptr) || (xTimerPeriodInTicks == 0U))
2735 xTimerPeriodInTicks,
2736 (uxAutoReload ==
pdTRUE),
2738 pxCallbackFunction);
2750 if (pxTimerBuffer ==
nullptr)
2753 if (
IsIrqContext() || (pxCallbackFunction ==
nullptr) || (xTimerPeriodInTicks == 0U))
2760 "StaticTimer_t is too small to hold FrtosTimer. "
2761 "Increase STATIC_TIMER_TCB_SIZE_WORDS in freertos_stk.h.");
2766 xTimerPeriodInTicks,
2767 (uxAutoReload ==
pdTRUE),
2769 pxCallbackFunction);
2778 if (xTimer ==
nullptr)
2798 ?
static_cast<uint32_t
>(t->
m_period)
2827 if ((xTimer ==
nullptr) || (xNewPeriod == 0U))
2860 if (pxHigherPriorityTaskWoken !=
nullptr)
2861 *pxHigherPriorityTaskWoken =
pdFALSE;
2863 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2876 if (pxHigherPriorityTaskWoken !=
nullptr)
2877 *pxHigherPriorityTaskWoken =
pdFALSE;
2879 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2901 if (pxHigherPriorityTaskWoken !=
nullptr)
2902 *pxHigherPriorityTaskWoken =
pdFALSE;
2904 if ((xTimer ==
nullptr) || (xNewPeriod == 0U) || (
g_TimerHost ==
nullptr))
2911 uint32_t period = t->
m_auto_reload ?
static_cast<uint32_t
>(xNewPeriod) : 0U;
2954 uint32_t ulParameter2,
2961 if (xFunctionToPend ==
nullptr)
2970 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2984 uint32_t ulParameter2,
2988 if (pxHigherPriorityTaskWoken !=
nullptr)
2989 *pxHigherPriorityTaskWoken =
pdFALSE;
2991 if (xFunctionToPend ==
nullptr)
3001 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
3013 if (xTimer ==
nullptr)
3021 if (xTimer ==
nullptr)
3024 return static_cast<FrtosTimer *
>(xTimer)->m_timer_id;
3029 if (xTimer ==
nullptr)
3032 static_cast<FrtosTimer *
>(xTimer)->m_timer_id = pvNewID;
3037 if (xTimer ==
nullptr)
3040 return static_cast<FrtosTimer *
>(xTimer)->m_name;
3045 if (xTimer ==
nullptr)
3048 return static_cast<FrtosTimer *
>(xTimer)->m_period;
3053 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
3066#if configUSE_EVENT_GROUPS
3093 if (xWaitForAllBits ==
pdTRUE)
3113 if (pxEventGroupBuffer ==
nullptr)
3120 "StaticEventGroup_t is too small to hold FrtosEventGroup. "
3121 "Increase STATIC_EVENT_GROUP_TCB_SIZE_WORDS in freertos_stk.h.");
3131 if (xEventGroup ==
nullptr)
3140 if (xEventGroup ==
nullptr)
3143 uint32_t result =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Set(uxBitsToSet);
3150 if (xEventGroup ==
nullptr)
3154 uint32_t prev =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Clear(uxBitsToClear);
3160 if (xEventGroup ==
nullptr)
3172 if (
IsIrqContext() || (xEventGroup ==
nullptr) || (uxBitsToWaitFor == 0U))
3178 uint32_t result = ef.
Wait(
static_cast<uint32_t
>(uxBitsToWaitFor),
3193 if (xEventGroup ==
nullptr)
3196 uint32_t result =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Set(
3197 static_cast<uint32_t
>(uxBitsToSet));
3199 if (pxHigherPriorityTaskWoken !=
nullptr)
3200 *pxHigherPriorityTaskWoken =
pdFALSE;
3208 if (xEventGroup ==
nullptr)
3211 uint32_t prev =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Clear(
3212 static_cast<uint32_t
>(uxBitsToClear));
3268 if (xEventGroup ==
nullptr)
return 0U;
3269 if (uxBitsToWaitFor == 0U)
return 0U;
3279 if (uxBitsToSet != 0U)
3281 uint32_t set_result = ef.
Set(
static_cast<uint32_t
>(uxBitsToSet));
3300 uint32_t result = ef.
Wait(
static_cast<uint32_t
>(uxBitsToWaitFor),
3328#if configUSE_TASK_NOTIFICATIONS
3341 if (xTask ==
nullptr)
3361 slot.
value |= ulValue;
3369 slot.
value = ulValue;
3375 slot.
value = ulValue;
3423 if (ulClearCountOnExit ==
pdTRUE)
3426 if (slot.
value > 0U)
3457 uint32_t ulBitsToClearOnEntry,
3458 uint32_t ulBitsToClearOnExit,
3459 uint32_t *pulNotificationValue,
3474 slot.
value &= ~ulBitsToClearOnEntry;
3485 if (pulNotificationValue !=
nullptr)
3486 *pulNotificationValue = slot.
value;
3488 slot.
value &= ~ulBitsToClearOnExit;
3503 if (pxHigherPriorityTaskWoken !=
nullptr)
3504 *pxHigherPriorityTaskWoken =
pdFALSE;
3531 uint32_t ulBitsToClearOnExit,
3532 uint32_t *pulNotificationValue,
3536 pulNotificationValue, xTicksToWait);
3545 pxHigherPriorityTaskWoken);
3581 uint32_t *pulPreviousNotifyValue)
3595 if (pulPreviousNotifyValue !=
nullptr)
3596 *pulPreviousNotifyValue = slot.
value;
3614 uint32_t *pulPreviousNotifyValue)
3617 pulPreviousNotifyValue);
3628 uint32_t *pulPreviousNotifyValue,
3633 pulPreviousNotifyValue);
3635 if (pxHigherPriorityTaskWoken !=
nullptr)
3636 *pxHigherPriorityTaskWoken =
pdFALSE;
3648 uint32_t *pulPreviousNotifyValue,
3652 pulPreviousNotifyValue,
3653 pxHigherPriorityTaskWoken);
3733 uint32_t ulBitsToClear)
3743 const uint32_t prev = slot.
value;
3744 slot.
value &= ~ulBitsToClear;
3754 uint32_t ulBitsToClear)
3785 if (xTaskToSet ==
nullptr)
3788 if (xTaskToSet ==
nullptr)
3797 t->
m_tls[
static_cast<size_t>(xIndex)] = pvValue;
3807 if (xTaskToQuery ==
nullptr)
3810 if (xTaskToQuery ==
nullptr)
3816 return t->
m_tls[
static_cast<size_t>(xIndex)];
3840#if configUSE_STREAM_BUFFERS
3842static_assert(
sizeof(StaticStreamBuffer_t) >=
sizeof(FrtosStreamBuffer),
3843 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3846 size_t xTriggerLevelBytes)
3848 if (xBufferSizeBytes == 0U)
3869 size_t xBufferSizeBytes,
3870 size_t xTriggerLevelBytes,
3871 uint8_t *pucStreamBufferStorageArea,
3874 if ((pucStreamBufferStorageArea ==
nullptr) ||
3875 (pxStaticStreamBuffer ==
nullptr) ||
3876 (xBufferSizeBytes == 0U))
3880 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3885 xTriggerLevelBytes);
3893 if (xStreamBuffer ==
nullptr)
3902 const void *pvTxData,
3903 size_t xDataLengthBytes,
3906 if ((xStreamBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
3912 static_cast<const uint8_t *
>(pvTxData),
3917 if ((sent > 0U) && (sb->
m_send_cb !=
nullptr))
3927 const void *pvTxData,
3928 size_t xDataLengthBytes,
3931 if (pxHigherPriorityTaskWoken !=
nullptr)
3932 *pxHigherPriorityTaskWoken =
pdFALSE;
3934 if ((xStreamBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
3940 static_cast<const uint8_t *
>(pvTxData),
3945 if ((sent > 0U) && (sb->
m_send_cb !=
nullptr))
3956 size_t xBufferLengthBytes,
3959 if ((xStreamBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
3974 static_cast<uint8_t *
>(pvRxData),
3980 if ((total > 0U) && (sb->
m_recv_cb !=
nullptr))
3991 size_t xBufferLengthBytes,
3994 if (pxHigherPriorityTaskWoken !=
nullptr)
3995 *pxHigherPriorityTaskWoken =
pdFALSE;
3997 if ((xStreamBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4003 static_cast<uint8_t *
>(pvRxData),
4004 xBufferLengthBytes);
4008 if ((received > 0U) && (sb->
m_recv_cb !=
nullptr))
4019 if (xStreamBuffer ==
nullptr)
4027 if (xStreamBuffer ==
nullptr)
4045 if (xStreamBuffer ==
nullptr)
4053 size_t xTriggerLevelBytes)
4055 if (xStreamBuffer ==
nullptr)
4064 sb->
m_trigger = (xTriggerLevelBytes >= 1U ? xTriggerLevelBytes : 1U);
4072 if (pxHigherPriorityTaskWoken !=
nullptr)
4073 *pxHigherPriorityTaskWoken =
pdFALSE;
4075 if (xStreamBuffer ==
nullptr)
4085 if (xStreamBuffer ==
nullptr)
4126 size_t xBufferSizeBytes,
4127 size_t xTriggerLevelBytes,
4131 if (xBufferSizeBytes == 0U)
4142 pxSendCompletedCallback,
4143 pxReceiveCompletedCallback);
4158 size_t xBufferSizeBytes,
4159 size_t xTriggerLevelBytes,
4160 uint8_t *pucStreamBufferStorageArea,
4165 if ((pucStreamBufferStorageArea ==
nullptr) ||
4166 (pxStaticStreamBuffer ==
nullptr) ||
4167 (xBufferSizeBytes == 0U))
4171 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4177 pxSendCompletedCallback,
4178 pxReceiveCompletedCallback);
4208static_assert(
sizeof(StaticMessageBuffer_t) >=
sizeof(FrtosMessageBuffer),
4209 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4217 if (slot_cost == 0U)
4220 return budget_bytes / slot_cost;
4224 size_t xMaxMessageSize)
4226 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4229 const size_t count =
MsgBufSlotCount(xBufferSizeBytes, xMaxMessageSize);
4249 size_t xMaxMessageSize,
4250 size_t xMessageCount,
4251 uint8_t *pucMessageBufferStorageArea,
4254 if ((pucMessageBufferStorageArea ==
nullptr) ||
4255 (pxStaticMessageBuffer ==
nullptr) ||
4256 (xMaxMessageSize == 0U) ||
4257 (xMessageCount == 0U))
4265 pucMessageBufferStorageArea, storage_size);
4282 size_t xBufferSizeBytes,
4283 size_t xMaxMessageSize,
4287 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4292 const size_t count = xBufferSizeBytes / slot_cost;
4298 xMaxMessageSize, count,
4299 pxSendCompletedCallback, pxReceiveCompletedCallback);
4316 size_t xMaxMessageSize,
4317 size_t xMessageCount,
4318 uint8_t *pucMessageBufferStorageArea,
4323 if ((pucMessageBufferStorageArea ==
nullptr) ||
4324 (pxStaticMessageBuffer ==
nullptr) ||
4325 (xMaxMessageSize == 0U) ||
4326 (xMessageCount == 0U))
4330 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4337 pucMessageBufferStorageArea, storage_size,
4338 pxSendCompletedCallback, pxReceiveCompletedCallback);
4345 if (xMessageBuffer ==
nullptr)
4354 const void *pvTxData,
4355 size_t xDataLengthBytes,
4358 if ((xMessageBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
4398 return xDataLengthBytes;
4403 size_t xBufferLengthBytes,
4406 if ((xMessageBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4421 if (xBufferLengthBytes < env.
len)
4446 if (xMessageBuffer ==
nullptr)
4455 if (xMessageBuffer ==
nullptr)
4464 if (xMessageBuffer ==
nullptr)
4473 if (xMessageBuffer ==
nullptr)
4483 if (env.
blk !=
nullptr)
4540 const void *pvTxData,
4541 size_t xDataLengthBytes,
4544 if (pxHigherPriorityTaskWoken !=
nullptr)
4545 *pxHigherPriorityTaskWoken =
pdFALSE;
4547 if ((xMessageBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
4585 return xDataLengthBytes;
4590 size_t xBufferLengthBytes,
4593 if (pxHigherPriorityTaskWoken !=
nullptr)
4594 *pxHigherPriorityTaskWoken =
pdFALSE;
4596 if ((xMessageBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4607 if (xBufferLengthBytes < env.
len)
4635 if (pxHigherPriorityTaskWoken !=
nullptr)
4636 *pxHigherPriorityTaskWoken =
pdFALSE;
4638 if (xMessageBuffer ==
nullptr)
4649 if (env.
blk !=
nullptr)
4661 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 void STK_MEMCPY(void *const dest, const void *const src, const size_t size)
Implementation of STK_MEMCPY.
#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 SemaphoreHandle_t CreateMutexInternal(bool recursive)
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 SemaphoreHandle_t CreateMutexStaticInternal(StaticSemaphore_t *pxMutexBuffer, bool recursive)
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::FastMutex or 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).
static 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.
static 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.
static 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 * Allocate(size_t size) __stk_weak
Allocate the memory chunk.
static void Free(void *ptr) __stk_weak
Free 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 Session Enter(const Session ses=DEFAULT_SESSION)
Enter a critical section.
static void Exit(const Session ses=DEFAULT_SESSION)
Exit a critical section.
RAII instance 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.
Non-recursive (binary) mutex primitive with ownership tracking.
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.
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 pointer to the stack memory.
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)
virtual stk::TId GetOwner() const =0
virtual ~FrtosMutexBase()
virtual bool Take(stk::Timeout timeout)=0
virtual bool IsRecursive() const =0
bool IsRecursive() const override
stk::TId GetOwner() const override
bool Take(stk::Timeout timeout) override
bool Take(stk::Timeout timeout) override
stk::TId GetOwner() const override
bool IsRecursive() const override
stk::sync::FastMutex m_mutex
stk::sync::Semaphore * m_sem
FrtosQueueSet * m_set
non-owning ptr to the queue set this member belongs to (nullptr if none)
FrtosSemaphore(SemKind kind, uint16_t initial, uint16_t max_count, bool recursive=false)
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