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);
474#if configUSE_TASK_NOTIFICATIONS
515 explicit FrtosQueue(uint32_t cap, uint32_t msg_size,
const char *name,
517 :
m_mq(ext_buf, static_cast<size_t>(cap), static_cast<size_t>(msg_size)),
523 m_mq.SetTraceName(name);
527 explicit FrtosQueue(uint32_t cap, uint32_t msg_size,
const char *name)
529 static_cast<size_t>(cap),
530 static_cast<size_t>(msg_size)),
536 m_mq.SetTraceName(name);
554#if configUSE_QUEUE_SETS
604 const uint8_t first_byte = *
static_cast<const uint8_t *
>(obj);
649#if configUSE_QUEUE_SETS
691 const size_t buf_bytes =
692 static_cast<size_t>(uxEventQueueLength) *
sizeof(
void *);
695 if (
m_buf ==
nullptr)
700 static_cast<size_t>(uxEventQueueLength),
734template <
typename THost>
737#if configUSE_QUEUE_SETS
740 if (host->m_set !=
nullptr)
741 host->m_set->m_token_mq->TryPut(&member_handle);
900#if configUSE_EVENT_GROUPS
931#if configUSE_STREAM_BUFFERS
944 :
m_pipe(buf, capacity, 1U),
998 stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size)),
1013 size_t storage_size,
1017 stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size),
1019 msg_count *
stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size)),
1020 m_eq(storage + msg_count *
stk::memory::BlockMemoryPool::AlignBlockSize(max_msg_size),
1127 uint32_t usStackDepth,
1132 if (pvTaskCode ==
nullptr)
1145 size_t stack_words = (usStackDepth > 0U)
1146 ?
static_cast<size_t>(usStackDepth)
1166 if (pxCreatedTask !=
nullptr)
1174 uint32_t ulStackDepth,
1181 if ((pvTaskCode ==
nullptr) || (puxStackBuffer ==
nullptr) || (pxTaskBuffer ==
nullptr))
1187 "StaticTask_t is too small to hold FrtosTask. "
1188 "Increase STATIC_TASK_TCB_SIZE_WORDS in freertos_stk.h.");
1196 t->
m_stack =
static_cast<stk::Word *
>(
static_cast<void *
>(puxStackBuffer));
1198 ?
static_cast<size_t>(ulStackDepth)
1214 static_cast<FrtosTask *
>(xTaskToDelete);
1232 static_cast<FrtosTask *
>(xTaskToSuspend);
1237 bool already =
false;
1244 if (xTaskToResume ==
nullptr)
1260 if (xTaskToResume ==
nullptr)
1278 if (xTask ==
nullptr)
1282 const stk::TId tid =
static_cast<stk::TId>(
reinterpret_cast<uintptr_t
>(xTask));
1302 static_cast<void>(
xTaskDelayUntil(pxPreviousWakeTime, xTimeIncrement));
1313 *pxPreviousWakeTime =
static_cast<TickType_t>(wake_at);
1347 if (xTask ==
nullptr)
1359 if (
static_cast<uintptr_t
>(
stk::GetTid()) ==
reinterpret_cast<uintptr_t
>(t))
1375 if (pcNameToQuery ==
nullptr)
1383 if ((task->GetTraceName() !=
nullptr) &&
1397 if (xTaskToQuery ==
nullptr)
1400 return static_cast<FrtosTask *
>(xTaskToQuery)->m_name;
1427 uint32_t *pulTotalRunTime)
1431 if (pulTotalRunTime !=
nullptr)
1432 *pulTotalRunTime = 0U;
1434 if ((pxTaskStatusArray ==
nullptr) || (uxArraySize == 0U))
1441 const uintptr_t running_tid =
static_cast<uintptr_t
>(
stk::GetTid());
1445 if (filled >= uxArraySize)
1464 if (
reinterpret_cast<uintptr_t
>(t) == running_tid)
1498 if ((pxTaskDefinition ==
nullptr) ||
1510 pxTaskDefinition->
pcName,
1520 if (pxCreatedTask !=
nullptr)
1531 if ((pxTaskDefinition ==
nullptr) ||
1542 pxTaskDefinition->
pcName,
1551 if (pcWriteBuffer ==
nullptr)
1556 int off = snprintf(pcWriteBuffer, 64U,
1557 "%-12s %c %4s %6s %4s\r\n",
1558 "Name",
'S',
"Prio",
"Stack",
"Num");
1560 if (off < 0) off = 0;
1561 char *p = pcWriteBuffer + off;
1580 if (
static_cast<uintptr_t
>(
stk::GetTid()) ==
reinterpret_cast<uintptr_t
>(t))
1585 const char *name = (t->
m_name !=
nullptr) ? t->
m_name :
"(unnamed)";
1589 int n = snprintf(p, 48U,
"%-12s %c %4u %6u %4u\r\n",
1591 static_cast<unsigned>(prio),
1592 static_cast<unsigned>(hwm),
1593 static_cast<unsigned>(task_num));
1622 if (pcWriteBuffer ==
nullptr)
1628 int off = snprintf(pcWriteBuffer, 64U,
1629 "%-12s %12s %8s\r\n",
1630 "Task",
"Abs Time",
"% Time");
1632 if (off < 0) off = 0;
1633 char *p = pcWriteBuffer + off;
1638 const char *name = (t->
m_name !=
nullptr) ? t->
m_name :
"(unnamed)";
1643 int n = snprintf(p, 48U,
"%-12s %12lu %7lu%%\r\n",
1662 if (
IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1669 static_cast<uint32_t
>(uxQueueLength),
1670 static_cast<uint32_t
>(uxItemSize),
1687 uint8_t *pucQueueStorage,
1691 if ((pucQueueStorage ==
nullptr) || (pxStaticQueue ==
nullptr))
1694 if (
IsIrqContext() || (uxQueueLength == 0U) || (uxItemSize == 0U))
1703 "StaticQueue_t is too small to hold FrtosQueue. "
1704 "Increase STATIC_QUEUE_TCB_SIZE_WORDS in freertos_stk.h.");
1709 static_cast<uint32_t
>(uxQueueLength),
1710 static_cast<uint32_t
>(uxItemSize),
1721 if (xQueue ==
nullptr)
1728 const void *pvItemToQueue,
1731 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1747 const void *pvItemToQueue,
1750 return xQueueSend(xQueue, pvItemToQueue, xTicksToWait);
1754 const void *pvItemToQueue,
1757 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1776 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1793 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1799 return static_cast<FrtosQueue *
>(xQueue)->m_mq.Peek(
1809 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1817 if (xQueue ==
nullptr)
1828 if (xQueue ==
nullptr)
1836 if (xQueue ==
nullptr)
1845 if (xQueue ==
nullptr)
1848 static_cast<FrtosQueue *
>(xQueue)->m_mq.Reset();
1857 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1869 const void *pvItemToQueue,
1874 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1882 if (pxHigherPriorityTaskWoken !=
nullptr)
1883 *pxHigherPriorityTaskWoken =
pdFALSE;
1889 const void *pvItemToQueue,
1892 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1904 if (pxHigherPriorityTaskWoken !=
nullptr)
1905 *pxHigherPriorityTaskWoken =
pdFALSE;
1914 if ((xQueue ==
nullptr) || (pvBuffer ==
nullptr))
1917 bool ok =
static_cast<FrtosQueue *
>(xQueue)->m_mq.TryGet(pvBuffer);
1919 if (pxHigherPriorityTaskWoken !=
nullptr)
1920 *pxHigherPriorityTaskWoken =
pdFALSE;
1926 const void *pvItemToQueue,
1935 const void *pvItemToQueue,
1938 if ((xQueue ==
nullptr) || (pvItemToQueue ==
nullptr))
1949 if (pxHigherPriorityTaskWoken !=
nullptr)
1950 *pxHigherPriorityTaskWoken =
pdFALSE;
1959 if (xQueue ==
nullptr)
1970 if (xQueue ==
nullptr)
2007#if configUSE_MUTEXES
2013 if (xQueue ==
nullptr)
2080#if configUSE_QUEUE_SETS
2092 if ((qs ==
nullptr) || !qs->
IsValid())
2104 if ((xQueueOrSemaphore ==
nullptr) || (xQueueSet ==
nullptr))
2125 if (s->
m_set !=
nullptr)
2140 if (q->
m_set !=
nullptr)
2157 if ((xQueueOrSemaphore ==
nullptr) || (xQueueSet ==
nullptr))
2202 if (xQueueSet ==
nullptr)
2211 void *handle =
nullptr;
2220 if (xQueueSet ==
nullptr)
2226 void *handle =
nullptr;
2244 static_cast<uint16_t
>(0U),
2245 static_cast<uint16_t
>(1U));
2247 if ((s ==
nullptr) || (s->
m_sem ==
nullptr))
2257 if (pxSemaphoreBuffer ==
nullptr)
2262 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2263 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2271 static_cast<uint16_t
>(0U),
2272 static_cast<uint16_t
>(1U));
2274 if (s->
m_sem ==
nullptr)
2285#if configUSE_COUNTING_SEMAPHORES
2290 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2298 static_cast<uint16_t
>(uxInitialCount),
2299 static_cast<uint16_t
>(uxMaxCount));
2301 if ((s ==
nullptr) || (s->
m_sem ==
nullptr))
2313 if (pxSemaphoreBuffer ==
nullptr)
2316 if (uxMaxCount == 0U || uxInitialCount > uxMaxCount)
2323 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2324 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2328 static_cast<uint16_t
>(uxInitialCount),
2329 static_cast<uint16_t
>(uxMaxCount));
2331 if (s->
m_sem ==
nullptr)
2343#if configUSE_MUTEXES
2349 static_cast<uint16_t
>(0U),
2350 static_cast<uint16_t
>(1U));
2352 if ((s ==
nullptr) || (s->
m_mtx ==
nullptr))
2363 if (pxMutexBuffer ==
nullptr)
2367 "StaticSemaphore_t is too small to hold FrtosSemaphore. "
2368 "Increase STATIC_SEMAPHORE_TCB_SIZE_WORDS in freertos_stk.h.");
2372 static_cast<uint16_t
>(0U),
2373 static_cast<uint16_t
>(1U));
2375 if (s->
m_mtx ==
nullptr)
2401 if (xSemaphore ==
nullptr)
2409 if (xSemaphore ==
nullptr)
2420#if configUSE_MUTEXES
2433 if (xSemaphore ==
nullptr)
2449 if (pxHigherPriorityTaskWoken !=
nullptr)
2450 *pxHigherPriorityTaskWoken =
pdFALSE;
2463 if (xSemaphore ==
nullptr)
2470#if configUSE_MUTEXES
2499 if (xSemaphore ==
nullptr)
2513 if (pxHigherPriorityTaskWoken !=
nullptr)
2514 *pxHigherPriorityTaskWoken =
pdFALSE;
2521 if (xSemaphore ==
nullptr)
2529#if configUSE_MUTEXES
2537#if configUSE_MUTEXES
2555 if (xMutex ==
nullptr)
2570 return reinterpret_cast<TaskHandle_t>(
static_cast<uintptr_t
>(owner));
2580 if (xMutex ==
nullptr)
2593 return reinterpret_cast<TaskHandle_t>(
static_cast<uintptr_t
>(owner));
2610 if (
IsIrqContext() || (pxCallbackFunction ==
nullptr) || (xTimerPeriodInTicks == 0U))
2618 xTimerPeriodInTicks,
2619 (uxAutoReload ==
pdTRUE),
2621 pxCallbackFunction);
2633 if (pxTimerBuffer ==
nullptr)
2636 if (
IsIrqContext() || (pxCallbackFunction ==
nullptr) || (xTimerPeriodInTicks == 0U))
2643 "StaticTimer_t is too small to hold FrtosTimer. "
2644 "Increase STATIC_TIMER_TCB_SIZE_WORDS in freertos_stk.h.");
2649 xTimerPeriodInTicks,
2650 (uxAutoReload ==
pdTRUE),
2652 pxCallbackFunction);
2661 if (xTimer ==
nullptr)
2681 ?
static_cast<uint32_t
>(t->
m_period)
2710 if ((xTimer ==
nullptr) || (xNewPeriod == 0U))
2743 if (pxHigherPriorityTaskWoken !=
nullptr)
2744 *pxHigherPriorityTaskWoken =
pdFALSE;
2746 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2759 if (pxHigherPriorityTaskWoken !=
nullptr)
2760 *pxHigherPriorityTaskWoken =
pdFALSE;
2762 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2784 if (pxHigherPriorityTaskWoken !=
nullptr)
2785 *pxHigherPriorityTaskWoken =
pdFALSE;
2787 if ((xTimer ==
nullptr) || (xNewPeriod == 0U) || (
g_TimerHost ==
nullptr))
2794 uint32_t period = t->
m_auto_reload ?
static_cast<uint32_t
>(xNewPeriod) : 0U;
2837 uint32_t ulParameter2,
2844 if (xFunctionToPend ==
nullptr)
2853 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2867 uint32_t ulParameter2,
2871 if (pxHigherPriorityTaskWoken !=
nullptr)
2872 *pxHigherPriorityTaskWoken =
pdFALSE;
2874 if (xFunctionToPend ==
nullptr)
2884 const PendCall call = { xFunctionToPend, pvParameter1, ulParameter2 };
2896 if (xTimer ==
nullptr)
2904 if (xTimer ==
nullptr)
2907 return static_cast<FrtosTimer *
>(xTimer)->m_timer_id;
2912 if (xTimer ==
nullptr)
2915 static_cast<FrtosTimer *
>(xTimer)->m_timer_id = pvNewID;
2920 if (xTimer ==
nullptr)
2923 return static_cast<FrtosTimer *
>(xTimer)->m_name;
2928 if (xTimer ==
nullptr)
2931 return static_cast<FrtosTimer *
>(xTimer)->m_period;
2936 if ((xTimer ==
nullptr) || (
g_TimerHost ==
nullptr))
2949#if configUSE_EVENT_GROUPS
2975 if (xWaitForAllBits ==
pdTRUE)
2995 if (pxEventGroupBuffer ==
nullptr)
3002 "StaticEventGroup_t is too small to hold FrtosEventGroup. "
3003 "Increase STATIC_EVENT_GROUP_TCB_SIZE_WORDS in freertos_stk.h.");
3013 if (xEventGroup ==
nullptr)
3022 if (xEventGroup ==
nullptr)
3025 uint32_t result =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Set(uxBitsToSet);
3032 if (xEventGroup ==
nullptr)
3036 uint32_t prev =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Clear(uxBitsToClear);
3042 if (xEventGroup ==
nullptr)
3054 if (
IsIrqContext() || (xEventGroup ==
nullptr) || (uxBitsToWaitFor == 0U))
3060 uint32_t result = ef.
Wait(
static_cast<uint32_t
>(uxBitsToWaitFor),
3075 if (xEventGroup ==
nullptr)
3078 uint32_t result =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Set(
3079 static_cast<uint32_t
>(uxBitsToSet));
3081 if (pxHigherPriorityTaskWoken !=
nullptr)
3082 *pxHigherPriorityTaskWoken =
pdFALSE;
3090 if (xEventGroup ==
nullptr)
3093 uint32_t prev =
static_cast<FrtosEventGroup *
>(xEventGroup)->m_ef.Clear(
3094 static_cast<uint32_t
>(uxBitsToClear));
3150 if (xEventGroup ==
nullptr)
return 0U;
3151 if (uxBitsToWaitFor == 0U)
return 0U;
3161 if (uxBitsToSet != 0U)
3163 uint32_t set_result = ef.
Set(
static_cast<uint32_t
>(uxBitsToSet));
3182 uint32_t result = ef.
Wait(
static_cast<uint32_t
>(uxBitsToWaitFor),
3210#if configUSE_TASK_NOTIFICATIONS
3223 if (xTask ==
nullptr)
3243 slot.
value |= ulValue;
3251 slot.
value = ulValue;
3257 slot.
value = ulValue;
3305 if (ulClearCountOnExit ==
pdTRUE)
3308 if (slot.
value > 0U)
3339 uint32_t ulBitsToClearOnEntry,
3340 uint32_t ulBitsToClearOnExit,
3341 uint32_t *pulNotificationValue,
3356 slot.
value &= ~ulBitsToClearOnEntry;
3367 if (pulNotificationValue !=
nullptr)
3368 *pulNotificationValue = slot.
value;
3370 slot.
value &= ~ulBitsToClearOnExit;
3385 if (pxHigherPriorityTaskWoken !=
nullptr)
3386 *pxHigherPriorityTaskWoken =
pdFALSE;
3413 uint32_t ulBitsToClearOnExit,
3414 uint32_t *pulNotificationValue,
3418 pulNotificationValue, xTicksToWait);
3427 pxHigherPriorityTaskWoken);
3463 uint32_t *pulPreviousNotifyValue)
3477 if (pulPreviousNotifyValue !=
nullptr)
3478 *pulPreviousNotifyValue = slot.
value;
3496 uint32_t *pulPreviousNotifyValue)
3499 pulPreviousNotifyValue);
3510 uint32_t *pulPreviousNotifyValue,
3515 pulPreviousNotifyValue);
3517 if (pxHigherPriorityTaskWoken !=
nullptr)
3518 *pxHigherPriorityTaskWoken =
pdFALSE;
3530 uint32_t *pulPreviousNotifyValue,
3534 pulPreviousNotifyValue,
3535 pxHigherPriorityTaskWoken);
3615 uint32_t ulBitsToClear)
3625 const uint32_t prev = slot.
value;
3626 slot.
value &= ~ulBitsToClear;
3636 uint32_t ulBitsToClear)
3667 if (xTaskToSet ==
nullptr)
3670 if (xTaskToSet ==
nullptr)
3679 t->
m_tls[
static_cast<size_t>(xIndex)] = pvValue;
3689 if (xTaskToQuery ==
nullptr)
3692 if (xTaskToQuery ==
nullptr)
3698 return t->
m_tls[
static_cast<size_t>(xIndex)];
3722#if configUSE_STREAM_BUFFERS
3724static_assert(
sizeof(StaticStreamBuffer_t) >=
sizeof(FrtosStreamBuffer),
3725 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3728 size_t xTriggerLevelBytes)
3730 if (xBufferSizeBytes == 0U)
3751 size_t xBufferSizeBytes,
3752 size_t xTriggerLevelBytes,
3753 uint8_t *pucStreamBufferStorageArea,
3756 if ((pucStreamBufferStorageArea ==
nullptr) ||
3757 (pxStaticStreamBuffer ==
nullptr) ||
3758 (xBufferSizeBytes == 0U))
3762 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
3767 xTriggerLevelBytes);
3775 if (xStreamBuffer ==
nullptr)
3784 const void *pvTxData,
3785 size_t xDataLengthBytes,
3788 if ((xStreamBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
3794 static_cast<const uint8_t *
>(pvTxData),
3799 if ((sent > 0U) && (sb->
m_send_cb !=
nullptr))
3809 const void *pvTxData,
3810 size_t xDataLengthBytes,
3813 if (pxHigherPriorityTaskWoken !=
nullptr)
3814 *pxHigherPriorityTaskWoken =
pdFALSE;
3816 if ((xStreamBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
3822 static_cast<const uint8_t *
>(pvTxData),
3827 if ((sent > 0U) && (sb->
m_send_cb !=
nullptr))
3838 size_t xBufferLengthBytes,
3841 if ((xStreamBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
3856 static_cast<uint8_t *
>(pvRxData),
3862 if ((total > 0U) && (sb->
m_recv_cb !=
nullptr))
3873 size_t xBufferLengthBytes,
3876 if (pxHigherPriorityTaskWoken !=
nullptr)
3877 *pxHigherPriorityTaskWoken =
pdFALSE;
3879 if ((xStreamBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
3885 static_cast<uint8_t *
>(pvRxData),
3886 xBufferLengthBytes);
3890 if ((received > 0U) && (sb->
m_recv_cb !=
nullptr))
3901 if (xStreamBuffer ==
nullptr)
3909 if (xStreamBuffer ==
nullptr)
3927 if (xStreamBuffer ==
nullptr)
3935 size_t xTriggerLevelBytes)
3937 if (xStreamBuffer ==
nullptr)
3946 sb->
m_trigger = (xTriggerLevelBytes >= 1U ? xTriggerLevelBytes : 1U);
3954 if (pxHigherPriorityTaskWoken !=
nullptr)
3955 *pxHigherPriorityTaskWoken =
pdFALSE;
3957 if (xStreamBuffer ==
nullptr)
3967 if (xStreamBuffer ==
nullptr)
4008 size_t xBufferSizeBytes,
4009 size_t xTriggerLevelBytes,
4013 if (xBufferSizeBytes == 0U)
4024 pxSendCompletedCallback,
4025 pxReceiveCompletedCallback);
4040 size_t xBufferSizeBytes,
4041 size_t xTriggerLevelBytes,
4042 uint8_t *pucStreamBufferStorageArea,
4047 if ((pucStreamBufferStorageArea ==
nullptr) ||
4048 (pxStaticStreamBuffer ==
nullptr) ||
4049 (xBufferSizeBytes == 0U))
4053 "Increase STATIC_STREAM_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4059 pxSendCompletedCallback,
4060 pxReceiveCompletedCallback);
4090static_assert(
sizeof(StaticMessageBuffer_t) >=
sizeof(FrtosMessageBuffer),
4091 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4099 if (slot_cost == 0U)
4102 return budget_bytes / slot_cost;
4106 size_t xMaxMessageSize)
4108 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4111 const size_t count =
MsgBufSlotCount(xBufferSizeBytes, xMaxMessageSize);
4131 size_t xMaxMessageSize,
4132 size_t xMessageCount,
4133 uint8_t *pucMessageBufferStorageArea,
4136 if ((pucMessageBufferStorageArea ==
nullptr) ||
4137 (pxStaticMessageBuffer ==
nullptr) ||
4138 (xMaxMessageSize == 0U) ||
4139 (xMessageCount == 0U))
4147 pucMessageBufferStorageArea, storage_size);
4164 size_t xBufferSizeBytes,
4165 size_t xMaxMessageSize,
4169 if ((xBufferSizeBytes == 0U) || (xMaxMessageSize == 0U))
4174 const size_t count = xBufferSizeBytes / slot_cost;
4180 xMaxMessageSize, count,
4181 pxSendCompletedCallback, pxReceiveCompletedCallback);
4198 size_t xMaxMessageSize,
4199 size_t xMessageCount,
4200 uint8_t *pucMessageBufferStorageArea,
4205 if ((pucMessageBufferStorageArea ==
nullptr) ||
4206 (pxStaticMessageBuffer ==
nullptr) ||
4207 (xMaxMessageSize == 0U) ||
4208 (xMessageCount == 0U))
4212 "Increase STATIC_MESSAGE_BUFFER_TCB_SIZE_WORDS in FreeRTOS.h.");
4219 pucMessageBufferStorageArea, storage_size,
4220 pxSendCompletedCallback, pxReceiveCompletedCallback);
4227 if (xMessageBuffer ==
nullptr)
4236 const void *pvTxData,
4237 size_t xDataLengthBytes,
4240 if ((xMessageBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
4280 return xDataLengthBytes;
4285 size_t xBufferLengthBytes,
4288 if ((xMessageBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4303 if (xBufferLengthBytes < env.
len)
4328 if (xMessageBuffer ==
nullptr)
4337 if (xMessageBuffer ==
nullptr)
4346 if (xMessageBuffer ==
nullptr)
4355 if (xMessageBuffer ==
nullptr)
4365 if (env.
blk !=
nullptr)
4422 const void *pvTxData,
4423 size_t xDataLengthBytes,
4426 if (pxHigherPriorityTaskWoken !=
nullptr)
4427 *pxHigherPriorityTaskWoken =
pdFALSE;
4429 if ((xMessageBuffer ==
nullptr) || (pvTxData ==
nullptr) || (xDataLengthBytes == 0U))
4467 return xDataLengthBytes;
4472 size_t xBufferLengthBytes,
4475 if (pxHigherPriorityTaskWoken !=
nullptr)
4476 *pxHigherPriorityTaskWoken =
pdFALSE;
4478 if ((xMessageBuffer ==
nullptr) || (pvRxData ==
nullptr) || (xBufferLengthBytes == 0U))
4489 if (xBufferLengthBytes < env.
len)
4517 if (pxHigherPriorityTaskWoken !=
nullptr)
4518 *pxHigherPriorityTaskWoken =
pdFALSE;
4520 if (xMessageBuffer ==
nullptr)
4531 if (env.
blk !=
nullptr)
4543 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 mode by the user 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 ...
size_t GetStackSizeBytes() const override
Get size of the memory in bytes.
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