Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ClusterM/flipperzero-firmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorあく <alleteam@gmail.com>2022-06-20 17:54:48 +0300
committerGitHub <noreply@github.com>2022-06-20 17:54:48 +0300
commit839e52ac32ada5eaa08796a2022c7aa6187845a1 (patch)
treead279ff4f377b6d54839a6746a99edb1ae6f3ded /lib
parent7618c8ba6ffe3026858373f8346b052dd45193ef (diff)
[FL-2591] Furi: remove CMSIS thread api, migrate to FuriThread, remove unused CMSIS APIs (#1333)
* Furi: remove CMSIS thread api, migrate to FuriThread, remove unused CMSIS APIs * Furi: magic thread catcher validating thread completion; backtrace improver * Furi: allow furi_thread_get_current_id outside of thread context * Furi: use IRQ instead of ISR for core primitives
Diffstat (limited to 'lib')
-rw-r--r--lib/FreeRTOS-glue/cmsis_os2.c1756
-rw-r--r--lib/FreeRTOS-glue/cmsis_os2.h572
-rw-r--r--lib/FreeRTOS-glue/freertos_mpool.h63
-rw-r--r--lib/FreeRTOS-glue/freertos_os2.h31
-rw-r--r--lib/FreeRTOS-glue/os_tick.h80
-rw-r--r--lib/ST25RFAL002/platform.c51
-rw-r--r--lib/infrared/worker/infrared_worker.c28
-rw-r--r--lib/subghz/subghz_file_encoder_worker.c5
8 files changed, 114 insertions, 2472 deletions
diff --git a/lib/FreeRTOS-glue/cmsis_os2.c b/lib/FreeRTOS-glue/cmsis_os2.c
index 4e59fb54..bee37572 100644
--- a/lib/FreeRTOS-glue/cmsis_os2.c
+++ b/lib/FreeRTOS-glue/cmsis_os2.c
@@ -26,15 +26,11 @@
#include "cmsis_os2.h" // ::CMSIS:RTOS2
#include "cmsis_compiler.h" // Compiler agnostic definitions
-#include "os_tick.h" // OS Tick API
#include "FreeRTOS.h" // ARM.FreeRTOS::RTOS:Core
-#include "task.h" // ARM.FreeRTOS::RTOS:Core
-#include "event_groups.h" // ARM.FreeRTOS::RTOS:Event Groups
-#include "semphr.h" // ARM.FreeRTOS::RTOS:Core
#include "timers.h" // ARM.FreeRTOS::RTOS:Timers
+#include "queue.h"
-#include "freertos_mpool.h" // osMemoryPool definitions
#include "freertos_os2.h" // Configuration check and setup
#include CMSIS_device_header
@@ -87,10 +83,8 @@
/* Limits */
#define MAX_BITS_TASK_NOTIFY 31U
-#define MAX_BITS_EVENT_GROUPS 24U
#define THREAD_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_TASK_NOTIFY) - 1U))
-#define EVENT_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_EVENT_GROUPS) - 1U))
/* Kernel version and identification string definition (major.minor.rev: mmnnnrrrr dec) */
#define KERNEL_VERSION (((uint32_t)tskKERNEL_VERSION_MAJOR * 10000000UL) | \
@@ -454,31 +448,6 @@ uint32_t osKernelGetTickFreq (void) {
}
/*
- Get the RTOS kernel system timer count.
-*/
-uint32_t osKernelGetSysTimerCount (void) {
- TickType_t ticks;
- uint32_t val;
-
- FURI_CRITICAL_ENTER();
-
- ticks = xTaskGetTickCount();
- val = OS_Tick_GetCount();
-
- /* Update tick count and timer value when timer overflows */
- if (OS_Tick_GetOverflow() != 0U) {
- val = OS_Tick_GetCount();
- ticks++;
- }
- val += ticks * OS_Tick_GetInterval();
-
- FURI_CRITICAL_EXIT();
-
- /* Return system timer count */
- return (val);
-}
-
-/*
Get the RTOS kernel system timer frequency.
*/
uint32_t osKernelGetSysTimerFreq (void) {
@@ -486,531 +455,6 @@ uint32_t osKernelGetSysTimerFreq (void) {
return (configCPU_CLOCK_HZ);
}
-
-/* ==== Thread Management Functions ==== */
-
-/*
- Create a thread and add it to Active Threads.
-
- Limitations:
- - The memory for control block and stack must be provided in the osThreadAttr_t
- structure in order to allocate object statically.
- - Attribute osThreadJoinable is not supported, NULL is returned if used.
-*/
-osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr) {
- const char *name;
- uint32_t stack;
- TaskHandle_t hTask;
- UBaseType_t prio;
- int32_t mem;
-
- hTask = NULL;
-
- if ((IRQ_Context() == 0U) && (func != NULL)) {
- stack = configMINIMAL_STACK_SIZE;
- prio = (UBaseType_t)osPriorityNormal;
-
- name = NULL;
- mem = -1;
-
- if (attr != NULL) {
- if (attr->name != NULL) {
- name = attr->name;
- }
- if (attr->priority != osPriorityNone) {
- prio = (UBaseType_t)attr->priority;
- }
-
- if ((prio < osPriorityIdle) || (prio > osPriorityISR) || ((attr->attr_bits & osThreadJoinable) == osThreadJoinable)) {
- /* Invalid priority or unsupported osThreadJoinable attribute used */
- return (NULL);
- }
-
- if (attr->stack_size > 0U) {
- /* In FreeRTOS stack is not in bytes, but in sizeof(StackType_t) which is 4 on ARM ports. */
- /* Stack size should be therefore 4 byte aligned in order to avoid division caused side effects */
- stack = attr->stack_size / sizeof(StackType_t);
- }
-
- if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticTask_t)) &&
- (attr->stack_mem != NULL) && (attr->stack_size > 0U)) {
- /* The memory for control block and stack is provided, use static object */
- mem = 1;
- }
- else {
- if ((attr->cb_mem == NULL) && (attr->cb_size == 0U) && (attr->stack_mem == NULL)) {
- /* Control block and stack memory will be allocated from the dynamic pool */
- mem = 0;
- }
- }
- }
- else {
- mem = 0;
- }
-
- if (mem == 1) {
- #if (configSUPPORT_STATIC_ALLOCATION == 1)
- hTask = xTaskCreateStatic ((TaskFunction_t)func, name, stack, argument, prio, (StackType_t *)attr->stack_mem,
- (StaticTask_t *)attr->cb_mem);
- #endif
- }
- else {
- if (mem == 0) {
- #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
- if (xTaskCreate ((TaskFunction_t)func, name, (configSTACK_DEPTH_TYPE)stack, argument, prio, &hTask) != pdPASS) {
- hTask = NULL;
- }
- #endif
- }
- }
- }
-
- /* Return thread ID */
- return ((osThreadId_t)hTask);
-}
-
-/*
- Get name of a thread.
-*/
-const char *osThreadGetName (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- const char *name;
-
- if ((IRQ_Context() != 0U) || (hTask == NULL)) {
- name = NULL;
- } else if(osKernelGetState() == osKernelRunning) {
- name = pcTaskGetName (hTask);
- } else {
- name = NULL;
- }
-
- /* Return name as null-terminated string */
- return (name);
-}
-
-/*
- Return the thread ID of the current running thread.
-*/
-osThreadId_t osThreadGetId (void) {
- osThreadId_t id;
-
- id = (osThreadId_t)xTaskGetCurrentTaskHandle();
-
- /* Return thread ID */
- return (id);
-}
-
-/*
- Get current thread state of a thread.
-*/
-osThreadState_t osThreadGetState (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- osThreadState_t state;
-
- if ((IRQ_Context() != 0U) || (hTask == NULL)) {
- state = osThreadError;
- }
- else {
- switch (eTaskGetState (hTask)) {
- case eRunning: state = osThreadRunning; break;
- case eReady: state = osThreadReady; break;
- case eBlocked:
- case eSuspended: state = osThreadBlocked; break;
- case eDeleted: state = osThreadTerminated; break;
- case eInvalid:
- default: state = osThreadError; break;
- }
- }
-
- /* Return current thread state */
- return (state);
-}
-
-/*
- Get available stack space of a thread based on stack watermark recording during execution.
-*/
-uint32_t osThreadGetStackSpace (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- uint32_t sz;
-
- if ((IRQ_Context() != 0U) || (hTask == NULL)) {
- sz = 0U;
- } else {
- sz = (uint32_t)(uxTaskGetStackHighWaterMark(hTask) * sizeof(StackType_t));
- }
-
- /* Return remaining stack space in bytes */
- return (sz);
-}
-
-/*
- Change priority of a thread.
-*/
-osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- osStatus_t stat;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if ((hTask == NULL) || (priority < osPriorityIdle) || (priority > osPriorityISR)) {
- stat = osErrorParameter;
- }
- else {
- stat = osOK;
- vTaskPrioritySet (hTask, (UBaseType_t)priority);
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Get current priority of a thread.
-*/
-osPriority_t osThreadGetPriority (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- osPriority_t prio;
-
- if ((IRQ_Context() != 0U) || (hTask == NULL)) {
- prio = osPriorityError;
- } else {
- prio = (osPriority_t)((int32_t)uxTaskPriorityGet (hTask));
- }
-
- /* Return current thread priority */
- return (prio);
-}
-
-/*
- Pass control to next thread that is in state READY.
-*/
-osStatus_t osThreadYield (void) {
- osStatus_t stat;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- } else {
- stat = osOK;
- taskYIELD();
- }
-
- /* Return execution status */
- return (stat);
-}
-
-#if (configUSE_OS2_THREAD_SUSPEND_RESUME == 1)
-/*
- Suspend execution of a thread.
-*/
-osStatus_t osThreadSuspend (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- osStatus_t stat;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hTask == NULL) {
- stat = osErrorParameter;
- }
- else {
- stat = osOK;
- vTaskSuspend (hTask);
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Resume execution of a thread.
-*/
-osStatus_t osThreadResume (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- osStatus_t stat;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hTask == NULL) {
- stat = osErrorParameter;
- }
- else {
- stat = osOK;
- vTaskResume (hTask);
- }
-
- /* Return execution status */
- return (stat);
-}
-#endif /* (configUSE_OS2_THREAD_SUSPEND_RESUME == 1) */
-
-/*
- Terminate execution of current running thread.
-*/
-__NO_RETURN void osThreadExit (void) {
-#ifndef USE_FreeRTOS_HEAP_1
- vTaskDelete (NULL);
-#endif
- for (;;);
-}
-
-/*
- Terminate execution of a thread.
-*/
-osStatus_t osThreadTerminate (osThreadId_t thread_id) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- osStatus_t stat;
-#ifndef USE_FreeRTOS_HEAP_1
- eTaskState tstate;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hTask == NULL) {
- stat = osErrorParameter;
- }
- else {
- tstate = eTaskGetState (hTask);
-
- if (tstate != eDeleted) {
- stat = osOK;
- vTaskDelete (hTask);
- } else {
- stat = osErrorResource;
- }
- }
-#else
- stat = osError;
-#endif
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Get number of active threads.
-*/
-uint32_t osThreadGetCount (void) {
- uint32_t count;
-
- if (IRQ_Context() != 0U) {
- count = 0U;
- } else {
- count = uxTaskGetNumberOfTasks();
- }
-
- /* Return number of active threads */
- return (count);
-}
-
-#if (configUSE_OS2_THREAD_ENUMERATE == 1)
-/*
- Enumerate active threads.
-*/
-uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items) {
- uint32_t i, count;
- TaskStatus_t *task;
-
- if ((IRQ_Context() != 0U) || (thread_array == NULL) || (array_items == 0U)) {
- count = 0U;
- } else {
- vTaskSuspendAll();
-
- /* Allocate memory on heap to temporarily store TaskStatus_t information */
- count = uxTaskGetNumberOfTasks();
- task = pvPortMalloc (count * sizeof(TaskStatus_t));
-
- if (task != NULL) {
- /* Retrieve task status information */
- count = uxTaskGetSystemState (task, count, NULL);
-
- /* Copy handles from task status array into provided thread array */
- for (i = 0U; (i < count) && (i < array_items); i++) {
- thread_array[i] = (osThreadId_t)task[i].xHandle;
- }
- count = i;
- }
- (void)xTaskResumeAll();
-
- vPortFree (task);
- }
-
- /* Return number of enumerated threads */
- return (count);
-}
-#endif /* (configUSE_OS2_THREAD_ENUMERATE == 1) */
-
-
-/* ==== Thread Flags Functions ==== */
-
-#if (configUSE_OS2_THREAD_FLAGS == 1)
-/*
- Set the specified Thread Flags of a thread.
-*/
-uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags) {
- TaskHandle_t hTask = (TaskHandle_t)thread_id;
- uint32_t rflags;
- BaseType_t yield;
-
- if ((hTask == NULL) || ((flags & THREAD_FLAGS_INVALID_BITS) != 0U)) {
- rflags = (uint32_t)osErrorParameter;
- }
- else {
- rflags = (uint32_t)osError;
-
- if (IRQ_Context() != 0U) {
- yield = pdFALSE;
-
- (void)xTaskNotifyIndexedFromISR (hTask, CMSIS_TASK_NOTIFY_INDEX, flags, eSetBits, &yield);
- (void)xTaskNotifyAndQueryIndexedFromISR (hTask, CMSIS_TASK_NOTIFY_INDEX, 0, eNoAction, &rflags, NULL);
-
- portYIELD_FROM_ISR (yield);
- }
- else {
- (void)xTaskNotifyIndexed (hTask, CMSIS_TASK_NOTIFY_INDEX, flags, eSetBits);
- (void)xTaskNotifyAndQueryIndexed (hTask, CMSIS_TASK_NOTIFY_INDEX, 0, eNoAction, &rflags);
- }
- }
- /* Return flags after setting */
- return (rflags);
-}
-
-/*
- Clear the specified Thread Flags of current running thread.
-*/
-uint32_t osThreadFlagsClear (uint32_t flags) {
- TaskHandle_t hTask;
- uint32_t rflags, cflags;
-
- if (IRQ_Context() != 0U) {
- rflags = (uint32_t)osErrorISR;
- }
- else if ((flags & THREAD_FLAGS_INVALID_BITS) != 0U) {
- rflags = (uint32_t)osErrorParameter;
- }
- else {
- hTask = xTaskGetCurrentTaskHandle();
-
- if (xTaskNotifyAndQueryIndexed (hTask, CMSIS_TASK_NOTIFY_INDEX, 0, eNoAction, &cflags) == pdPASS) {
- rflags = cflags;
- cflags &= ~flags;
-
- if (xTaskNotifyIndexed (hTask, CMSIS_TASK_NOTIFY_INDEX, cflags, eSetValueWithOverwrite) != pdPASS) {
- rflags = (uint32_t)osError;
- }
- }
- else {
- rflags = (uint32_t)osError;
- }
- }
-
- /* Return flags before clearing */
- return (rflags);
-}
-
-/*
- Get the current Thread Flags of current running thread.
-*/
-uint32_t osThreadFlagsGet (void) {
- TaskHandle_t hTask;
- uint32_t rflags;
-
- if (IRQ_Context() != 0U) {
- rflags = (uint32_t)osErrorISR;
- }
- else {
- hTask = xTaskGetCurrentTaskHandle();
-
- if (xTaskNotifyAndQueryIndexed (hTask, CMSIS_TASK_NOTIFY_INDEX, 0, eNoAction, &rflags) != pdPASS) {
- rflags = (uint32_t)osError;
- }
- }
-
- /* Return current flags */
- return (rflags);
-}
-
-/*
- Wait for one or more Thread Flags of the current running thread to become signaled.
-*/
-uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout) {
- uint32_t rflags, nval;
- uint32_t clear;
- TickType_t t0, td, tout;
- BaseType_t rval;
-
- if (IRQ_Context() != 0U) {
- rflags = (uint32_t)osErrorISR;
- }
- else if ((flags & THREAD_FLAGS_INVALID_BITS) != 0U) {
- rflags = (uint32_t)osErrorParameter;
- }
- else {
- if ((options & osFlagsNoClear) == osFlagsNoClear) {
- clear = 0U;
- } else {
- clear = flags;
- }
-
- rflags = 0U;
- tout = timeout;
-
- t0 = xTaskGetTickCount();
- do {
- rval = xTaskNotifyWaitIndexed (CMSIS_TASK_NOTIFY_INDEX, 0, clear, &nval, tout);
-
- if (rval == pdPASS) {
- rflags &= flags;
- rflags |= nval;
-
- if ((options & osFlagsWaitAll) == osFlagsWaitAll) {
- if ((flags & rflags) == flags) {
- break;
- } else {
- if (timeout == 0U) {
- rflags = (uint32_t)osErrorResource;
- break;
- }
- }
- }
- else {
- if ((flags & rflags) != 0) {
- break;
- } else {
- if (timeout == 0U) {
- rflags = (uint32_t)osErrorResource;
- break;
- }
- }
- }
-
- /* Update timeout */
- td = xTaskGetTickCount() - t0;
-
- if (td > timeout) {
- tout = 0;
- } else {
- tout = timeout - td;
- }
- }
- else {
- if (timeout == 0) {
- rflags = (uint32_t)osErrorResource;
- } else {
- rflags = (uint32_t)osErrorTimeout;
- }
- }
- }
- while (rval != pdFAIL);
- }
-
- /* Return flags before clearing */
- return (rflags);
-}
-#endif /* (configUSE_OS2_THREAD_FLAGS == 1) */
-
-
/* ==== Generic Wait Functions ==== */
/*
@@ -1330,681 +774,6 @@ osStatus_t osTimerDelete (osTimerId_t timer_id) {
#endif /* (configUSE_OS2_TIMER == 1) */
-/* ==== Event Flags Management Functions ==== */
-
-/*
- Create and Initialize an Event Flags object.
-
- Limitations:
- - Event flags are limited to 24 bits.
-*/
-osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr) {
- EventGroupHandle_t hEventGroup;
- int32_t mem;
-
- hEventGroup = NULL;
-
- if (IRQ_Context() == 0U) {
- mem = -1;
-
- if (attr != NULL) {
- if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticEventGroup_t))) {
- /* The memory for control block is provided, use static object */
- mem = 1;
- }
- else {
- if ((attr->cb_mem == NULL) && (attr->cb_size == 0U)) {
- /* Control block will be allocated from the dynamic pool */
- mem = 0;
- }
- }
- }
- else {
- mem = 0;
- }
-
- if (mem == 1) {
- #if (configSUPPORT_STATIC_ALLOCATION == 1)
- hEventGroup = xEventGroupCreateStatic (attr->cb_mem);
- #endif
- }
- else {
- if (mem == 0) {
- #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
- hEventGroup = xEventGroupCreate();
- #endif
- }
- }
- }
-
- /* Return event flags ID */
- return ((osEventFlagsId_t)hEventGroup);
-}
-
-/*
- Set the specified Event Flags.
-
- Limitations:
- - Event flags are limited to 24 bits.
-*/
-uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags) {
- EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id;
- uint32_t rflags;
- BaseType_t yield;
-
- if ((hEventGroup == NULL) || ((flags & EVENT_FLAGS_INVALID_BITS) != 0U)) {
- rflags = (uint32_t)osErrorParameter;
- }
- else if (IRQ_Context() != 0U) {
- #if (configUSE_OS2_EVENTFLAGS_FROM_ISR == 0)
- (void)yield;
- /* Enable timers and xTimerPendFunctionCall function to support osEventFlagsSet from ISR */
- rflags = (uint32_t)osErrorResource;
- #else
- yield = pdFALSE;
-
- if (xEventGroupSetBitsFromISR (hEventGroup, (EventBits_t)flags, &yield) == pdFAIL) {
- rflags = (uint32_t)osErrorResource;
- } else {
- rflags = flags;
- portYIELD_FROM_ISR (yield);
- }
- #endif
- }
- else {
- rflags = xEventGroupSetBits (hEventGroup, (EventBits_t)flags);
- }
-
- /* Return event flags after setting */
- return (rflags);
-}
-
-/*
- Clear the specified Event Flags.
-
- Limitations:
- - Event flags are limited to 24 bits.
-*/
-uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags) {
- EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id;
- uint32_t rflags;
-
- if ((hEventGroup == NULL) || ((flags & EVENT_FLAGS_INVALID_BITS) != 0U)) {
- rflags = (uint32_t)osErrorParameter;
- }
- else if (IRQ_Context() != 0U) {
- #if (configUSE_OS2_EVENTFLAGS_FROM_ISR == 0)
- /* Enable timers and xTimerPendFunctionCall function to support osEventFlagsSet from ISR */
- rflags = (uint32_t)osErrorResource;
- #else
- rflags = xEventGroupGetBitsFromISR (hEventGroup);
-
- if (xEventGroupClearBitsFromISR (hEventGroup, (EventBits_t)flags) == pdFAIL) {
- rflags = (uint32_t)osErrorResource;
- }
- else {
- /* xEventGroupClearBitsFromISR only registers clear operation in the timer command queue. */
- /* Yield is required here otherwise clear operation might not execute in the right order. */
- /* See https://github.com/FreeRTOS/FreeRTOS-Kernel/issues/93 for more info. */
- portYIELD_FROM_ISR (pdTRUE);
- }
- #endif
- }
- else {
- rflags = xEventGroupClearBits (hEventGroup, (EventBits_t)flags);
- }
-
- /* Return event flags before clearing */
- return (rflags);
-}
-
-/*
- Get the current Event Flags.
-
- Limitations:
- - Event flags are limited to 24 bits.
-*/
-uint32_t osEventFlagsGet (osEventFlagsId_t ef_id) {
- EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id;
- uint32_t rflags;
-
- if (ef_id == NULL) {
- rflags = 0U;
- }
- else if (IRQ_Context() != 0U) {
- rflags = xEventGroupGetBitsFromISR (hEventGroup);
- }
- else {
- rflags = xEventGroupGetBits (hEventGroup);
- }
-
- /* Return current event flags */
- return (rflags);
-}
-
-/*
- Wait for one or more Event Flags to become signaled.
-
- Limitations:
- - Event flags are limited to 24 bits.
- - osEventFlagsWait cannot be called from an ISR.
-*/
-uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
- EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id;
- BaseType_t wait_all;
- BaseType_t exit_clr;
- uint32_t rflags;
-
- if ((hEventGroup == NULL) || ((flags & EVENT_FLAGS_INVALID_BITS) != 0U)) {
- rflags = (uint32_t)osErrorParameter;
- }
- else if (IRQ_Context() != 0U) {
- rflags = (uint32_t)osErrorISR;
- }
- else {
- if (options & osFlagsWaitAll) {
- wait_all = pdTRUE;
- } else {
- wait_all = pdFAIL;
- }
-
- if (options & osFlagsNoClear) {
- exit_clr = pdFAIL;
- } else {
- exit_clr = pdTRUE;
- }
-
- rflags = xEventGroupWaitBits (hEventGroup, (EventBits_t)flags, exit_clr, wait_all, (TickType_t)timeout);
-
- if (options & osFlagsWaitAll) {
- if ((flags & rflags) != flags) {
- if (timeout > 0U) {
- rflags = (uint32_t)osErrorTimeout;
- } else {
- rflags = (uint32_t)osErrorResource;
- }
- }
- }
- else {
- if ((flags & rflags) == 0U) {
- if (timeout > 0U) {
- rflags = (uint32_t)osErrorTimeout;
- } else {
- rflags = (uint32_t)osErrorResource;
- }
- }
- }
- }
-
- /* Return event flags before clearing */
- return (rflags);
-}
-
-/*
- Delete an Event Flags object.
-*/
-osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id) {
- EventGroupHandle_t hEventGroup = (EventGroupHandle_t)ef_id;
- osStatus_t stat;
-
-#ifndef USE_FreeRTOS_HEAP_1
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hEventGroup == NULL) {
- stat = osErrorParameter;
- }
- else {
- stat = osOK;
- vEventGroupDelete (hEventGroup);
- }
-#else
- stat = osError;
-#endif
-
- /* Return execution status */
- return (stat);
-}
-
-
-/* ==== Mutex Management Functions ==== */
-
-#if (configUSE_OS2_MUTEX == 1)
-/*
- Create and Initialize a Mutex object.
-
- Limitations:
- - Priority inherit protocol is used by default, osMutexPrioInherit attribute is ignored.
- - Robust mutex is not supported, NULL is returned if used.
-*/
-osMutexId_t osMutexNew (const osMutexAttr_t *attr) {
- SemaphoreHandle_t hMutex;
- uint32_t type;
- uint32_t rmtx;
- int32_t mem;
-
- hMutex = NULL;
-
- if (IRQ_Context() == 0U) {
- if (attr != NULL) {
- type = attr->attr_bits;
- } else {
- type = 0U;
- }
-
- if ((type & osMutexRecursive) == osMutexRecursive) {
- rmtx = 1U;
- } else {
- rmtx = 0U;
- }
-
- if ((type & osMutexRobust) != osMutexRobust) {
- mem = -1;
-
- if (attr != NULL) {
- if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticSemaphore_t))) {
- /* The memory for control block is provided, use static object */
- mem = 1;
- }
- else {
- if ((attr->cb_mem == NULL) && (attr->cb_size == 0U)) {
- /* Control block will be allocated from the dynamic pool */
- mem = 0;
- }
- }
- }
- else {
- mem = 0;
- }
-
- if (mem == 1) {
- #if (configSUPPORT_STATIC_ALLOCATION == 1)
- if (rmtx != 0U) {
- #if (configUSE_RECURSIVE_MUTEXES == 1)
- hMutex = xSemaphoreCreateRecursiveMutexStatic (attr->cb_mem);
- #endif
- }
- else {
- hMutex = xSemaphoreCreateMutexStatic (attr->cb_mem);
- }
- #endif
- }
- else {
- if (mem == 0) {
- #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
- if (rmtx != 0U) {
- #if (configUSE_RECURSIVE_MUTEXES == 1)
- hMutex = xSemaphoreCreateRecursiveMutex ();
- #endif
- } else {
- hMutex = xSemaphoreCreateMutex ();
- }
- #endif
- }
- }
-
- #if (configQUEUE_REGISTRY_SIZE > 0)
- if (hMutex != NULL) {
- if ((attr != NULL) && (attr->name != NULL)) {
- /* Only non-NULL name objects are added to the Queue Registry */
- vQueueAddToRegistry (hMutex, attr->name);
- }
- }
- #endif
-
- if ((hMutex != NULL) && (rmtx != 0U)) {
- /* Set LSB as 'recursive mutex flag' */
- hMutex = (SemaphoreHandle_t)((uint32_t)hMutex | 1U);
- }
- }
- }
-
- /* Return mutex ID */
- return ((osMutexId_t)hMutex);
-}
-
-/*
- Acquire a Mutex or timeout if it is locked.
-*/
-osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout) {
- SemaphoreHandle_t hMutex;
- osStatus_t stat;
- uint32_t rmtx;
-
- hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U);
-
- /* Extract recursive mutex flag */
- rmtx = (uint32_t)mutex_id & 1U;
-
- stat = osOK;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hMutex == NULL) {
- stat = osErrorParameter;
- }
- else {
- if (rmtx != 0U) {
- #if (configUSE_RECURSIVE_MUTEXES == 1)
- if (xSemaphoreTakeRecursive (hMutex, timeout) != pdPASS) {
- if (timeout != 0U) {
- stat = osErrorTimeout;
- } else {
- stat = osErrorResource;
- }
- }
- #endif
- }
- else {
- if (xSemaphoreTake (hMutex, timeout) != pdPASS) {
- if (timeout != 0U) {
- stat = osErrorTimeout;
- } else {
- stat = osErrorResource;
- }
- }
- }
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Release a Mutex that was acquired by osMutexAcquire.
-*/
-osStatus_t osMutexRelease (osMutexId_t mutex_id) {
- SemaphoreHandle_t hMutex;
- osStatus_t stat;
- uint32_t rmtx;
-
- hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U);
-
- /* Extract recursive mutex flag */
- rmtx = (uint32_t)mutex_id & 1U;
-
- stat = osOK;
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hMutex == NULL) {
- stat = osErrorParameter;
- }
- else {
- if (rmtx != 0U) {
- #if (configUSE_RECURSIVE_MUTEXES == 1)
- if (xSemaphoreGiveRecursive (hMutex) != pdPASS) {
- stat = osErrorResource;
- }
- #endif
- }
- else {
- if (xSemaphoreGive (hMutex) != pdPASS) {
- stat = osErrorResource;
- }
- }
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Get Thread which owns a Mutex object.
-*/
-osThreadId_t osMutexGetOwner (osMutexId_t mutex_id) {
- SemaphoreHandle_t hMutex;
- osThreadId_t owner;
-
- hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U);
-
- if ((IRQ_Context() != 0U) || (hMutex == NULL)) {
- owner = NULL;
- } else {
- owner = (osThreadId_t)xSemaphoreGetMutexHolder (hMutex);
- }
-
- /* Return owner thread ID */
- return (owner);
-}
-
-/*
- Delete a Mutex object.
-*/
-osStatus_t osMutexDelete (osMutexId_t mutex_id) {
- osStatus_t stat;
-#ifndef USE_FreeRTOS_HEAP_1
- SemaphoreHandle_t hMutex;
-
- hMutex = (SemaphoreHandle_t)((uint32_t)mutex_id & ~1U);
-
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hMutex == NULL) {
- stat = osErrorParameter;
- }
- else {
- #if (configQUEUE_REGISTRY_SIZE > 0)
- vQueueUnregisterQueue (hMutex);
- #endif
- stat = osOK;
- vSemaphoreDelete (hMutex);
- }
-#else
- stat = osError;
-#endif
-
- /* Return execution status */
- return (stat);
-}
-#endif /* (configUSE_OS2_MUTEX == 1) */
-
-
-/* ==== Semaphore Management Functions ==== */
-
-/*
- Create and Initialize a Semaphore object.
-*/
-osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr) {
- SemaphoreHandle_t hSemaphore;
- int32_t mem;
-
- hSemaphore = NULL;
-
- if ((IRQ_Context() == 0U) && (max_count > 0U) && (initial_count <= max_count)) {
- mem = -1;
-
- if (attr != NULL) {
- if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticSemaphore_t))) {
- /* The memory for control block is provided, use static object */
- mem = 1;
- }
- else {
- if ((attr->cb_mem == NULL) && (attr->cb_size == 0U)) {
- /* Control block will be allocated from the dynamic pool */
- mem = 0;
- }
- }
- }
- else {
- mem = 0;
- }
-
- if (mem != -1) {
- if (max_count == 1U) {
- if (mem == 1) {
- #if (configSUPPORT_STATIC_ALLOCATION == 1)
- hSemaphore = xSemaphoreCreateBinaryStatic ((StaticSemaphore_t *)attr->cb_mem);
- #endif
- }
- else {
- #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
- hSemaphore = xSemaphoreCreateBinary();
- #endif
- }
-
- if ((hSemaphore != NULL) && (initial_count != 0U)) {
- if (xSemaphoreGive (hSemaphore) != pdPASS) {
- vSemaphoreDelete (hSemaphore);
- hSemaphore = NULL;
- }
- }
- }
- else {
- if (mem == 1) {
- #if (configSUPPORT_STATIC_ALLOCATION == 1)
- hSemaphore = xSemaphoreCreateCountingStatic (max_count, initial_count, (StaticSemaphore_t *)attr->cb_mem);
- #endif
- }
- else {
- #if (configSUPPORT_DYNAMIC_ALLOCATION == 1)
- hSemaphore = xSemaphoreCreateCounting (max_count, initial_count);
- #endif
- }
- }
-
- #if (configQUEUE_REGISTRY_SIZE > 0)
- if (hSemaphore != NULL) {
- if ((attr != NULL) && (attr->name != NULL)) {
- /* Only non-NULL name objects are added to the Queue Registry */
- vQueueAddToRegistry (hSemaphore, attr->name);
- }
- }
- #endif
- }
- }
-
- /* Return semaphore ID */
- return ((osSemaphoreId_t)hSemaphore);
-}
-
-/*
- Acquire a Semaphore token or timeout if no tokens are available.
-*/
-osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout) {
- SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id;
- osStatus_t stat;
- BaseType_t yield;
-
- stat = osOK;
-
- if (hSemaphore == NULL) {
- stat = osErrorParameter;
- }
- else if (IRQ_Context() != 0U) {
- if (timeout != 0U) {
- stat = osErrorParameter;
- }
- else {
- yield = pdFALSE;
-
- if (xSemaphoreTakeFromISR (hSemaphore, &yield) != pdPASS) {
- stat = osErrorResource;
- } else {
- portYIELD_FROM_ISR (yield);
- }
- }
- }
- else {
- if (xSemaphoreTake (hSemaphore, (TickType_t)timeout) != pdPASS) {
- if (timeout != 0U) {
- stat = osErrorTimeout;
- } else {
- stat = osErrorResource;
- }
- }
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Release a Semaphore token up to the initial maximum count.
-*/
-osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id) {
- SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id;
- osStatus_t stat;
- BaseType_t yield;
-
- stat = osOK;
-
- if (hSemaphore == NULL) {
- stat = osErrorParameter;
- }
- else if (IRQ_Context() != 0U) {
- yield = pdFALSE;
-
- if (xSemaphoreGiveFromISR (hSemaphore, &yield) != pdTRUE) {
- stat = osErrorResource;
- } else {
- portYIELD_FROM_ISR (yield);
- }
- }
- else {
- if (xSemaphoreGive (hSemaphore) != pdPASS) {
- stat = osErrorResource;
- }
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Get current Semaphore token count.
-*/
-uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id) {
- SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id;
- uint32_t count;
-
- if (hSemaphore == NULL) {
- count = 0U;
- }
- else if (IRQ_Context() != 0U) {
- count = (uint32_t)uxSemaphoreGetCountFromISR (hSemaphore);
- } else {
- count = (uint32_t)uxSemaphoreGetCount (hSemaphore);
- }
-
- /* Return number of tokens */
- return (count);
-}
-
-/*
- Delete a Semaphore object.
-*/
-osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id) {
- SemaphoreHandle_t hSemaphore = (SemaphoreHandle_t)semaphore_id;
- osStatus_t stat;
-
-#ifndef USE_FreeRTOS_HEAP_1
- if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else if (hSemaphore == NULL) {
- stat = osErrorParameter;
- }
- else {
- #if (configQUEUE_REGISTRY_SIZE > 0)
- vQueueUnregisterQueue (hSemaphore);
- #endif
-
- stat = osOK;
- vSemaphoreDelete (hSemaphore);
- }
-#else
- stat = osError;
-#endif
-
- /* Return execution status */
- return (stat);
-}
-
-
/* ==== Message Queue Management Functions ==== */
/*
@@ -2301,498 +1070,6 @@ osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id) {
return (stat);
}
-
-/* ==== Memory Pool Management Functions ==== */
-
-#ifdef FREERTOS_MPOOL_H_
-/* Static memory pool functions */
-static void FreeBlock (MemPool_t *mp, void *block);
-static void *AllocBlock (MemPool_t *mp);
-static void *CreateBlock (MemPool_t *mp);
-
-/*
- Create and Initialize a Memory Pool object.
-*/
-osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr) {
- MemPool_t *mp;
- const char *name;
- int32_t mem_cb, mem_mp;
- uint32_t sz;
-
- if (IRQ_Context() != 0U) {
- mp = NULL;
- }
- else if ((block_count == 0U) || (block_size == 0U)) {
- mp = NULL;
- }
- else {
- mp = NULL;
- sz = MEMPOOL_ARR_SIZE (block_count, block_size);
-
- name = NULL;
- mem_cb = -1;
- mem_mp = -1;
-
- if (attr != NULL) {
- if (attr->name != NULL) {
- name = attr->name;
- }
-
- if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(MemPool_t))) {
- /* Static control block is provided */
- mem_cb = 1;
- }
- else if ((attr->cb_mem == NULL) && (attr->cb_size == 0U)) {
- /* Allocate control block memory on heap */
- mem_cb = 0;
- }
-
- if ((attr->mp_mem == NULL) && (attr->mp_size == 0U)) {
- /* Allocate memory array on heap */
- mem_mp = 0;
- }
- else {
- if (attr->mp_mem != NULL) {
- /* Check if array is 4-byte aligned */
- if (((uint32_t)attr->mp_mem & 3U) == 0U) {
- /* Check if array big enough */
- if (attr->mp_size >= sz) {
- /* Static memory pool array is provided */
- mem_mp = 1;
- }
- }
- }
- }
- }
- else {
- /* Attributes not provided, allocate memory on heap */
- mem_cb = 0;
- mem_mp = 0;
- }
-
- if (mem_cb == 0) {
- mp = pvPortMalloc (sizeof(MemPool_t));
- } else {
- mp = attr->cb_mem;
- }
-
- if (mp != NULL) {
- /* Create a semaphore (max count == initial count == block_count) */
- #if (configSUPPORT_STATIC_ALLOCATION == 1)
- mp->sem = xSemaphoreCreateCountingStatic (block_count, block_count, &mp->mem_sem);
- #elif (configSUPPORT_DYNAMIC_ALLOCATION == 1)
- mp->sem = xSemaphoreCreateCounting (block_count, block_count);
- #else
- mp->sem = NULL;
- #endif
-
- if (mp->sem != NULL) {
- /* Setup memory array */
- if (mem_mp == 0) {
- mp->mem_arr = pvPortMalloc (sz);
- } else {
- mp->mem_arr = attr->mp_mem;
- }
- }
- }
-
- if ((mp != NULL) && (mp->mem_arr != NULL)) {
- /* Memory pool can be created */
- mp->head = NULL;
- mp->mem_sz = sz;
- mp->name = name;
- mp->bl_sz = block_size;
- mp->bl_cnt = block_count;
- mp->n = 0U;
-
- /* Set heap allocated memory flags */
- mp->status = MPOOL_STATUS;
-
- if (mem_cb == 0) {
- /* Control block on heap */
- mp->status |= 1U;
- }
- if (mem_mp == 0) {
- /* Memory array on heap */
- mp->status |= 2U;
- }
- }
- else {
- /* Memory pool cannot be created, release allocated resources */
- if ((mem_cb == 0) && (mp != NULL)) {
- /* Free control block memory */
- vPortFree (mp);
- }
- mp = NULL;
- }
- }
-
- /* Return memory pool ID */
- return (mp);
-}
-
-/*
- Get name of a Memory Pool object.
-*/
-const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id) {
- MemPool_t *mp = (osMemoryPoolId_t)mp_id;
- const char *p;
-
- if (IRQ_Context() != 0U) {
- p = NULL;
- }
- else if (mp_id == NULL) {
- p = NULL;
- }
- else {
- p = mp->name;
- }
-
- /* Return name as null-terminated string */
- return (p);
-}
-
-/*
- Allocate a memory block from a Memory Pool.
-*/
-void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout) {
- MemPool_t *mp;
- void *block;
- uint32_t isrm;
-
- if (mp_id == NULL) {
- /* Invalid input parameters */
- block = NULL;
- }
- else {
- block = NULL;
-
- mp = (MemPool_t *)mp_id;
-
- if ((mp->status & MPOOL_STATUS) == MPOOL_STATUS) {
- if (IRQ_Context() != 0U) {
- if (timeout == 0U) {
- if (xSemaphoreTakeFromISR (mp->sem, NULL) == pdTRUE) {
- if ((mp->status & MPOOL_STATUS) == MPOOL_STATUS) {
- isrm = taskENTER_CRITICAL_FROM_ISR();
-
- /* Get a block from the free-list */
- block = AllocBlock(mp);
-
- if (block == NULL) {
- /* List of free blocks is empty, 'create' new block */
- block = CreateBlock(mp);
- }
-
- taskEXIT_CRITICAL_FROM_ISR(isrm);
- }
- }
- }
- }
- else {
- if (xSemaphoreTake (mp->sem, (TickType_t)timeout) == pdTRUE) {
- if ((mp->status & MPOOL_STATUS) == MPOOL_STATUS) {
- taskENTER_CRITICAL();
-
- /* Get a block from the free-list */
- block = AllocBlock(mp);
-
- if (block == NULL) {
- /* List of free blocks is empty, 'create' new block */
- block = CreateBlock(mp);
- }
-
- taskEXIT_CRITICAL();
- }
- }
- }
- }
- }
-
- /* Return memory block address */
- return (block);
-}
-
-/*
- Return an allocated memory block back to a Memory Pool.
-*/
-osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block) {
- MemPool_t *mp;
- osStatus_t stat;
- uint32_t isrm;
- BaseType_t yield;
-
- if ((mp_id == NULL) || (block == NULL)) {
- /* Invalid input parameters */
- stat = osErrorParameter;
- }
- else {
- mp = (MemPool_t *)mp_id;
-
- if ((mp->status & MPOOL_STATUS) != MPOOL_STATUS) {
- /* Invalid object status */
- stat = osErrorResource;
- }
- else if ((block < (void *)&mp->mem_arr[0]) || (block > (void*)&mp->mem_arr[mp->mem_sz-1])) {
- /* Block pointer outside of memory array area */
- stat = osErrorParameter;
- }
- else {
- stat = osOK;
-
- if (IRQ_Context() != 0U) {
- if (uxSemaphoreGetCountFromISR (mp->sem) == mp->bl_cnt) {
- stat = osErrorResource;
- }
- else {
- isrm = taskENTER_CRITICAL_FROM_ISR();
-
- /* Add block to the list of free blocks */
- FreeBlock(mp, block);
-
- taskEXIT_CRITICAL_FROM_ISR(isrm);
-
- yield = pdFALSE;
- xSemaphoreGiveFromISR (mp->sem, &yield);
- portYIELD_FROM_ISR (yield);
- }
- }
- else {
- if (uxSemaphoreGetCount (mp->sem) == mp->bl_cnt) {
- stat = osErrorResource;
- }
- else {
- taskENTER_CRITICAL();
-
- /* Add block to the list of free blocks */
- FreeBlock(mp, block);
-
- taskEXIT_CRITICAL();
-
- xSemaphoreGive (mp->sem);
- }
- }
- }
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Get maximum number of memory blocks in a Memory Pool.
-*/
-uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id) {
- MemPool_t *mp;
- uint32_t n;
-
- if (mp_id == NULL) {
- /* Invalid input parameters */
- n = 0U;
- }
- else {
- mp = (MemPool_t *)mp_id;
-
- if ((mp->status & MPOOL_STATUS) != MPOOL_STATUS) {
- /* Invalid object status */
- n = 0U;
- }
- else {
- n = mp->bl_cnt;
- }
- }
-
- /* Return maximum number of memory blocks */
- return (n);
-}
-
-/*
- Get memory block size in a Memory Pool.
-*/
-uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id) {
- MemPool_t *mp;
- uint32_t sz;
-
- if (mp_id == NULL) {
- /* Invalid input parameters */
- sz = 0U;
- }
- else {
- mp = (MemPool_t *)mp_id;
-
- if ((mp->status & MPOOL_STATUS) != MPOOL_STATUS) {
- /* Invalid object status */
- sz = 0U;
- }
- else {
- sz = mp->bl_sz;
- }
- }
-
- /* Return memory block size in bytes */
- return (sz);
-}
-
-/*
- Get number of memory blocks used in a Memory Pool.
-*/
-uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id) {
- MemPool_t *mp;
- uint32_t n;
-
- if (mp_id == NULL) {
- /* Invalid input parameters */
- n = 0U;
- }
- else {
- mp = (MemPool_t *)mp_id;
-
- if ((mp->status & MPOOL_STATUS) != MPOOL_STATUS) {
- /* Invalid object status */
- n = 0U;
- }
- else {
- if (IRQ_Context() != 0U) {
- n = uxSemaphoreGetCountFromISR (mp->sem);
- } else {
- n = uxSemaphoreGetCount (mp->sem);
- }
-
- n = mp->bl_cnt - n;
- }
- }
-
- /* Return number of memory blocks used */
- return (n);
-}
-
-/*
- Get number of memory blocks available in a Memory Pool.
-*/
-uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id) {
- MemPool_t *mp;
- uint32_t n;
-
- if (mp_id == NULL) {
- /* Invalid input parameters */
- n = 0U;
- }
- else {
- mp = (MemPool_t *)mp_id;
-
- if ((mp->status & MPOOL_STATUS) != MPOOL_STATUS) {
- /* Invalid object status */
- n = 0U;
- }
- else {
- if (IRQ_Context() != 0U) {
- n = uxSemaphoreGetCountFromISR (mp->sem);
- } else {
- n = uxSemaphoreGetCount (mp->sem);
- }
- }
- }
-
- /* Return number of memory blocks available */
- return (n);
-}
-
-/*
- Delete a Memory Pool object.
-*/
-osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id) {
- MemPool_t *mp;
- osStatus_t stat;
-
- if (mp_id == NULL) {
- /* Invalid input parameters */
- stat = osErrorParameter;
- }
- else if (IRQ_Context() != 0U) {
- stat = osErrorISR;
- }
- else {
- mp = (MemPool_t *)mp_id;
-
- taskENTER_CRITICAL();
-
- /* Invalidate control block status */
- mp->status = mp->status & 3U;
-
- /* Wake-up tasks waiting for pool semaphore */
- while (xSemaphoreGive (mp->sem) == pdTRUE);
-
- mp->head = NULL;
- mp->bl_sz = 0U;
- mp->bl_cnt = 0U;
-
- if ((mp->status & 2U) != 0U) {
- /* Memory pool array allocated on heap */
- vPortFree (mp->mem_arr);
- }
- if ((mp->status & 1U) != 0U) {
- /* Memory pool control block allocated on heap */
- vPortFree (mp);
- }
-
- taskEXIT_CRITICAL();
-
- stat = osOK;
- }
-
- /* Return execution status */
- return (stat);
-}
-
-/*
- Create new block given according to the current block index.
-*/
-static void *CreateBlock (MemPool_t *mp) {
- MemPoolBlock_t *p = NULL;
-
- if (mp->n < mp->bl_cnt) {
- /* Unallocated blocks exist, set pointer to new block */
- p = (void *)(mp->mem_arr + (mp->bl_sz * mp->n));
-
- /* Increment block index */
- mp->n += 1U;
- }
-
- return (p);
-}
-
-/*
- Allocate a block by reading the list of free blocks.
-*/
-static void *AllocBlock (MemPool_t *mp) {
- MemPoolBlock_t *p = NULL;
-
- if (mp->head != NULL) {
- /* List of free block exists, get head block */
- p = mp->head;
-
- /* Head block is now next on the list */
- mp->head = p->next;
- }
-
- return (p);
-}
-
-/*
- Free block by putting it to the list of free blocks.
-*/
-static void FreeBlock (MemPool_t *mp, void *block) {
- MemPoolBlock_t *p = block;
-
- /* Store current head into block memory space */
- p->next = mp->head;
-
- /* Store current block as new head */
- mp->head = p;
-}
-#endif /* FREERTOS_MPOOL_H_ */
-/*---------------------------------------------------------------------------*/
-
/* Callback function prototypes */
extern void vApplicationIdleHook (void);
extern void vApplicationMallocFailedHook (void);
@@ -2841,34 +1118,3 @@ __WEAK void vApplicationStackOverflowHook (TaskHandle_t xTask, char *pcTaskName)
configASSERT(0);
}
#endif
-
-/*---------------------------------------------------------------------------*/
-#if (configSUPPORT_STATIC_ALLOCATION == 1)
-/*
- vApplicationGetIdleTaskMemory gets called when configSUPPORT_STATIC_ALLOCATION
- equals to 1 and is required for static memory allocation support.
-*/
-__WEAK void vApplicationGetIdleTaskMemory (StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
- /* Idle task control block and stack */
- static StaticTask_t Idle_TCB;
- static StackType_t Idle_Stack[configMINIMAL_STACK_SIZE];
-
- *ppxIdleTaskTCBBuffer = &Idle_TCB;
- *ppxIdleTaskStackBuffer = &Idle_Stack[0];
- *pulIdleTaskStackSize = (uint32_t)configMINIMAL_STACK_SIZE;
-}
-
-/*
- vApplicationGetTimerTaskMemory gets called when configSUPPORT_STATIC_ALLOCATION
- equals to 1 and is required for static memory allocation support.
-*/
-__WEAK void vApplicationGetTimerTaskMemory (StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize) {
- /* Timer task control block and stack */
- static StaticTask_t Timer_TCB;
- static StackType_t Timer_Stack[configTIMER_TASK_STACK_DEPTH];
-
- *ppxTimerTaskTCBBuffer = &Timer_TCB;
- *ppxTimerTaskStackBuffer = &Timer_Stack[0];
- *pulTimerTaskStackSize = (uint32_t)configTIMER_TASK_STACK_DEPTH;
-}
-#endif
diff --git a/lib/FreeRTOS-glue/cmsis_os2.h b/lib/FreeRTOS-glue/cmsis_os2.h
index 76612e29..044c9851 100644
--- a/lib/FreeRTOS-glue/cmsis_os2.h
+++ b/lib/FreeRTOS-glue/cmsis_os2.h
@@ -43,10 +43,10 @@
* Version 2.0.0
* Initial Release
*---------------------------------------------------------------------------*/
-
+
#ifndef CMSIS_OS2_H_
#define CMSIS_OS2_H_
-
+
#ifndef __NO_RETURN
#if defined(__CC_ARM)
#define __NO_RETURN __declspec(noreturn)
@@ -60,24 +60,23 @@
#define __NO_RETURN
#endif
#endif
-
-#include <stdint.h>
-#include <stddef.h>
-
+
+#include <furi/base.h>
+
#ifdef __cplusplus
extern "C"
{
#endif
-
-
+
+
// ==== Enumerations, structures, defines ====
-
+
/// Version information.
typedef struct {
uint32_t api; ///< API version (major.minor.rev: mmnnnrrrr dec).
uint32_t kernel; ///< Kernel version (major.minor.rev: mmnnnrrrr dec).
} osVersion_t;
-
+
/// Kernel state.
typedef enum {
osKernelInactive = 0, ///< Inactive.
@@ -88,167 +87,31 @@ typedef enum {
osKernelError = -1, ///< Error.
osKernelReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
} osKernelState_t;
-
-/// Thread state.
-typedef enum {
- osThreadInactive = 0, ///< Inactive.
- osThreadReady = 1, ///< Ready.
- osThreadRunning = 2, ///< Running.
- osThreadBlocked = 3, ///< Blocked.
- osThreadTerminated = 4, ///< Terminated.
- osThreadError = -1, ///< Error.
- osThreadReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
-} osThreadState_t;
-
-/// Priority values.
-typedef enum {
- osPriorityNone = 0, ///< No priority (not initialized).
- osPriorityIdle = 1, ///< Reserved for Idle thread.
- osPriorityLow = 8, ///< Priority: low
- osPriorityLow1 = 8+1, ///< Priority: low + 1
- osPriorityLow2 = 8+2, ///< Priority: low + 2
- osPriorityLow3 = 8+3, ///< Priority: low + 3
- osPriorityLow4 = 8+4, ///< Priority: low + 4
- osPriorityLow5 = 8+5, ///< Priority: low + 5
- osPriorityLow6 = 8+6, ///< Priority: low + 6
- osPriorityLow7 = 8+7, ///< Priority: low + 7
- osPriorityBelowNormal = 16, ///< Priority: below normal
- osPriorityBelowNormal1 = 16+1, ///< Priority: below normal + 1
- osPriorityBelowNormal2 = 16+2, ///< Priority: below normal + 2
- osPriorityBelowNormal3 = 16+3, ///< Priority: below normal + 3
- osPriorityBelowNormal4 = 16+4, ///< Priority: below normal + 4
- osPriorityBelowNormal5 = 16+5, ///< Priority: below normal + 5
- osPriorityBelowNormal6 = 16+6, ///< Priority: below normal + 6
- osPriorityBelowNormal7 = 16+7, ///< Priority: below normal + 7
- osPriorityNormal = 24, ///< Priority: normal
- osPriorityNormal1 = 24+1, ///< Priority: normal + 1
- osPriorityNormal2 = 24+2, ///< Priority: normal + 2
- osPriorityNormal3 = 24+3, ///< Priority: normal + 3
- osPriorityNormal4 = 24+4, ///< Priority: normal + 4
- osPriorityNormal5 = 24+5, ///< Priority: normal + 5
- osPriorityNormal6 = 24+6, ///< Priority: normal + 6
- osPriorityNormal7 = 24+7, ///< Priority: normal + 7
- osPriorityAboveNormal = 32, ///< Priority: above normal
- osPriorityAboveNormal1 = 32+1, ///< Priority: above normal + 1
- osPriorityAboveNormal2 = 32+2, ///< Priority: above normal + 2
- osPriorityAboveNormal3 = 32+3, ///< Priority: above normal + 3
- osPriorityAboveNormal4 = 32+4, ///< Priority: above normal + 4
- osPriorityAboveNormal5 = 32+5, ///< Priority: above normal + 5
- osPriorityAboveNormal6 = 32+6, ///< Priority: above normal + 6
- osPriorityAboveNormal7 = 32+7, ///< Priority: above normal + 7
- osPriorityHigh = 40, ///< Priority: high
- osPriorityHigh1 = 40+1, ///< Priority: high + 1
- osPriorityHigh2 = 40+2, ///< Priority: high + 2
- osPriorityHigh3 = 40+3, ///< Priority: high + 3
- osPriorityHigh4 = 40+4, ///< Priority: high + 4
- osPriorityHigh5 = 40+5, ///< Priority: high + 5
- osPriorityHigh6 = 40+6, ///< Priority: high + 6
- osPriorityHigh7 = 40+7, ///< Priority: high + 7
- osPriorityRealtime = 48, ///< Priority: realtime
- osPriorityRealtime1 = 48+1, ///< Priority: realtime + 1
- osPriorityRealtime2 = 48+2, ///< Priority: realtime + 2
- osPriorityRealtime3 = 48+3, ///< Priority: realtime + 3
- osPriorityRealtime4 = 48+4, ///< Priority: realtime + 4
- osPriorityRealtime5 = 48+5, ///< Priority: realtime + 5
- osPriorityRealtime6 = 48+6, ///< Priority: realtime + 6
- osPriorityRealtime7 = 48+7, ///< Priority: realtime + 7
- osPriorityISR = 56, ///< Reserved for ISR deferred thread.
- osPriorityError = -1, ///< System cannot determine priority or illegal priority.
- osPriorityReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
-} osPriority_t;
-
-/// Entry point of a thread.
-typedef void (*osThreadFunc_t) (void *argument);
-
+
/// Timer callback function.
typedef void (*osTimerFunc_t) (void *argument);
-
+
/// Timer type.
typedef enum {
osTimerOnce = 0, ///< One-shot timer.
osTimerPeriodic = 1 ///< Repeating timer.
} osTimerType_t;
-
-// Timeout value.
-#define osWaitForever 0xFFFFFFFFU ///< Wait forever timeout value.
-
-// Flags options (\ref osThreadFlagsWait and \ref osEventFlagsWait).
-#define osFlagsWaitAny 0x00000000U ///< Wait for any flag (default).
-#define osFlagsWaitAll 0x00000001U ///< Wait for all flags.
-#define osFlagsNoClear 0x00000002U ///< Do not clear flags which have been specified to wait for.
-
-// Flags errors (returned by osThreadFlagsXxxx and osEventFlagsXxxx).
-#define osFlagsError 0x80000000U ///< Error indicator.
-#define osFlagsErrorUnknown 0xFFFFFFFFU ///< osError (-1).
-#define osFlagsErrorTimeout 0xFFFFFFFEU ///< osErrorTimeout (-2).
-#define osFlagsErrorResource 0xFFFFFFFDU ///< osErrorResource (-3).
-#define osFlagsErrorParameter 0xFFFFFFFCU ///< osErrorParameter (-4).
-#define osFlagsErrorISR 0xFFFFFFFAU ///< osErrorISR (-6).
-
-// Thread attributes (attr_bits in \ref osThreadAttr_t).
-#define osThreadDetached 0x00000000U ///< Thread created in detached mode (default)
-#define osThreadJoinable 0x00000001U ///< Thread created in joinable mode
-
-// Mutex attributes (attr_bits in \ref osMutexAttr_t).
-#define osMutexRecursive 0x00000001U ///< Recursive mutex.
-#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
-#define osMutexRobust 0x00000008U ///< Robust mutex.
-
-/// Status code values returned by CMSIS-RTOS functions.
-typedef enum {
- osOK = 0, ///< Operation completed successfully.
- osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
- osErrorTimeout = -2, ///< Operation not completed within the timeout period.
- osErrorResource = -3, ///< Resource not available.
- osErrorParameter = -4, ///< Parameter error.
- osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
- osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
- osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
-} osStatus_t;
-
-
-/// \details Thread ID identifies the thread.
-typedef void *osThreadId_t;
-
+
+
/// \details Timer ID identifies the timer.
typedef void *osTimerId_t;
-
-/// \details Event Flags ID identifies the event flags.
-typedef void *osEventFlagsId_t;
-
-/// \details Mutex ID identifies the mutex.
-typedef void *osMutexId_t;
-
-/// \details Semaphore ID identifies the semaphore.
-typedef void *osSemaphoreId_t;
-
-/// \details Memory Pool ID identifies the memory pool.
-typedef void *osMemoryPoolId_t;
-
+
/// \details Message Queue ID identifies the message queue.
typedef void *osMessageQueueId_t;
-
-
+
+
#ifndef TZ_MODULEID_T
#define TZ_MODULEID_T
/// \details Data type that identifies secure software modules called by a process.
typedef uint32_t TZ_ModuleId_t;
#endif
-
-
-/// Attributes structure for thread.
-typedef struct {
- const char *name; ///< name of the thread
- uint32_t attr_bits; ///< attribute bits
- void *cb_mem; ///< memory for control block
- uint32_t cb_size; ///< size of provided memory for control block
- void *stack_mem; ///< memory for stack
- uint32_t stack_size; ///< size of stack
- osPriority_t priority; ///< initial thread priority (default: osPriorityNormal)
- TZ_ModuleId_t tz_module; ///< TrustZone module identifier
- uint32_t reserved; ///< reserved (must be 0)
-} osThreadAttr_t;
-
+
+
/// Attributes structure for timer.
typedef struct {
const char *name; ///< name of the timer
@@ -256,41 +119,7 @@ typedef struct {
void *cb_mem; ///< memory for control block
uint32_t cb_size; ///< size of provided memory for control block
} osTimerAttr_t;
-
-/// Attributes structure for event flags.
-typedef struct {
- const char *name; ///< name of the event flags
- uint32_t attr_bits; ///< attribute bits
- void *cb_mem; ///< memory for control block
- uint32_t cb_size; ///< size of provided memory for control block
-} osEventFlagsAttr_t;
-
-/// Attributes structure for mutex.
-typedef struct {
- const char *name; ///< name of the mutex
- uint32_t attr_bits; ///< attribute bits
- void *cb_mem; ///< memory for control block
- uint32_t cb_size; ///< size of provided memory for control block
-} osMutexAttr_t;
-
-/// Attributes structure for semaphore.
-typedef struct {
- const char *name; ///< name of the semaphore
- uint32_t attr_bits; ///< attribute bits
- void *cb_mem; ///< memory for control block
- uint32_t cb_size; ///< size of provided memory for control block
-} osSemaphoreAttr_t;
-
-/// Attributes structure for memory pool.
-typedef struct {
- const char *name; ///< name of the memory pool
- uint32_t attr_bits; ///< attribute bits
- void *cb_mem; ///< memory for control block
- uint32_t cb_size; ///< size of provided memory for control block
- void *mp_mem; ///< memory for data storage
- uint32_t mp_size; ///< size of provided memory for data storage
-} osMemoryPoolAttr_t;
-
+
/// Attributes structure for message queue.
typedef struct {
const char *name; ///< name of the message queue
@@ -298,196 +127,79 @@ typedef struct {
void *cb_mem; ///< memory for control block
uint32_t cb_size; ///< size of provided memory for control block
void *mq_mem; ///< memory for data storage
- uint32_t mq_size; ///< size of provided memory for data storage
+ uint32_t mq_size; ///< size of provided memory for data storage
} osMessageQueueAttr_t;
-
-
+
+
// ==== Kernel Management Functions ====
-
+
/// Initialize the RTOS Kernel.
/// \return status code that indicates the execution status of the function.
osStatus_t osKernelInitialize (void);
-
+
/// Get RTOS Kernel Information.
/// \param[out] version pointer to buffer for retrieving version information.
/// \param[out] id_buf pointer to buffer for retrieving kernel identification string.
/// \param[in] id_size size of buffer for kernel identification string.
/// \return status code that indicates the execution status of the function.
osStatus_t osKernelGetInfo (osVersion_t *version, char *id_buf, uint32_t id_size);
-
+
/// Get the current RTOS Kernel state.
/// \return current RTOS Kernel state.
osKernelState_t osKernelGetState (void);
-
+
/// Start the RTOS Kernel scheduler.
/// \return status code that indicates the execution status of the function.
osStatus_t osKernelStart (void);
-
+
/// Lock the RTOS Kernel scheduler.
/// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
int32_t osKernelLock (void);
-
+
/// Unlock the RTOS Kernel scheduler.
/// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
int32_t osKernelUnlock (void);
-
+
/// Restore the RTOS Kernel scheduler lock state.
/// \param[in] lock lock state obtained by \ref osKernelLock or \ref osKernelUnlock.
/// \return new lock state (1 - locked, 0 - not locked, error code if negative).
int32_t osKernelRestoreLock (int32_t lock);
-
+
/// Suspend the RTOS Kernel scheduler.
/// \return time in ticks, for how long the system can sleep or power-down.
uint32_t osKernelSuspend (void);
-
+
/// Resume the RTOS Kernel scheduler.
/// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode.
void osKernelResume (uint32_t sleep_ticks);
-
+
/// Get the RTOS kernel tick count.
/// \return RTOS kernel current tick count.
uint32_t osKernelGetTickCount (void);
-
+
/// Get the RTOS kernel tick frequency.
/// \return frequency of the kernel tick in hertz, i.e. kernel ticks per second.
uint32_t osKernelGetTickFreq (void);
-
-/// Get the RTOS kernel system timer count.
-/// \return RTOS kernel current system timer count as 32-bit value.
-uint32_t osKernelGetSysTimerCount (void);
-
+
/// Get the RTOS kernel system timer frequency.
/// \return frequency of the system timer in hertz, i.e. timer ticks per second.
uint32_t osKernelGetSysTimerFreq (void);
-
-
-// ==== Thread Management Functions ====
-
-/// Create a thread and add it to Active Threads.
-/// \param[in] func thread function.
-/// \param[in] argument pointer that is passed to the thread function as start argument.
-/// \param[in] attr thread attributes; NULL: default values.
-/// \return thread ID for reference by other functions or NULL in case of error.
-osThreadId_t osThreadNew (osThreadFunc_t func, void *argument, const osThreadAttr_t *attr);
-
-/// Get name of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return name as null-terminated string.
-const char *osThreadGetName (osThreadId_t thread_id);
-
-/// Return the thread ID of the current running thread.
-/// \return thread ID for reference by other functions or NULL in case of error.
-osThreadId_t osThreadGetId (void);
-
-/// Get current thread state of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return current thread state of the specified thread.
-osThreadState_t osThreadGetState (osThreadId_t thread_id);
-
-/// Get stack size of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return stack size in bytes.
-uint32_t osThreadGetStackSize (osThreadId_t thread_id);
-
-/// Get available stack space of a thread based on stack watermark recording during execution.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return remaining stack space in bytes.
-uint32_t osThreadGetStackSpace (osThreadId_t thread_id);
-
-/// Change priority of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \param[in] priority new priority value for the thread function.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadSetPriority (osThreadId_t thread_id, osPriority_t priority);
-
-/// Get current priority of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return current priority value of the specified thread.
-osPriority_t osThreadGetPriority (osThreadId_t thread_id);
-
-/// Pass control to next thread that is in state \b READY.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadYield (void);
-
-/// Suspend execution of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadSuspend (osThreadId_t thread_id);
-
-/// Resume execution of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadResume (osThreadId_t thread_id);
-
-/// Detach a thread (thread storage can be reclaimed when thread terminates).
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadDetach (osThreadId_t thread_id);
-
-/// Wait for specified thread to terminate.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadJoin (osThreadId_t thread_id);
-
-/// Terminate execution of current running thread.
-__NO_RETURN void osThreadExit (void);
-
-/// Terminate execution of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osThreadTerminate (osThreadId_t thread_id);
-
-/// Get number of active threads.
-/// \return number of active threads.
-uint32_t osThreadGetCount (void);
-
-/// Enumerate active threads.
-/// \param[out] thread_array pointer to array for retrieving thread IDs.
-/// \param[in] array_items maximum number of items in array for retrieving thread IDs.
-/// \return number of enumerated threads.
-uint32_t osThreadEnumerate (osThreadId_t *thread_array, uint32_t array_items);
-
-
-// ==== Thread Flags Functions ====
-
-/// Set the specified Thread Flags of a thread.
-/// \param[in] thread_id thread ID obtained by \ref osThreadNew or \ref osThreadGetId.
-/// \param[in] flags specifies the flags of the thread that shall be set.
-/// \return thread flags after setting or error code if highest bit set.
-uint32_t osThreadFlagsSet (osThreadId_t thread_id, uint32_t flags);
-
-/// Clear the specified Thread Flags of current running thread.
-/// \param[in] flags specifies the flags of the thread that shall be cleared.
-/// \return thread flags before clearing or error code if highest bit set.
-uint32_t osThreadFlagsClear (uint32_t flags);
-
-/// Get the current Thread Flags of current running thread.
-/// \return current thread flags.
-uint32_t osThreadFlagsGet (void);
-
-/// Wait for one or more Thread Flags of the current running thread to become signaled.
-/// \param[in] flags specifies the flags to wait for.
-/// \param[in] options specifies flags options (osFlagsXxxx).
-/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
-/// \return thread flags before clearing or error code if highest bit set.
-uint32_t osThreadFlagsWait (uint32_t flags, uint32_t options, uint32_t timeout);
-
-
+
// ==== Generic Wait Functions ====
-
+
/// Wait for Timeout (Time Delay).
/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value
/// \return status code that indicates the execution status of the function.
osStatus_t osDelay (uint32_t ticks);
-
+
/// Wait until specified time.
/// \param[in] ticks absolute time in ticks
/// \return status code that indicates the execution status of the function.
osStatus_t osDelayUntil (uint32_t ticks);
-
-
+
+
// ==== Timer Management Functions ====
-
+
/// Create and Initialize a timer.
/// \param[in] func function pointer to callback function.
/// \param[in] type \ref osTimerOnce for one-shot or \ref osTimerPeriodic for periodic behavior.
@@ -495,213 +207,47 @@ osStatus_t osDelayUntil (uint32_t ticks);
/// \param[in] attr timer attributes; NULL: default values.
/// \return timer ID for reference by other functions or NULL in case of error.
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr);
-
+
/// Get name of a timer.
/// \param[in] timer_id timer ID obtained by \ref osTimerNew.
/// \return name as null-terminated string.
const char *osTimerGetName (osTimerId_t timer_id);
-
+
/// Start or restart a timer.
/// \param[in] timer_id timer ID obtained by \ref osTimerNew.
/// \param[in] ticks \ref CMSIS_RTOS_TimeOutValue "time ticks" value of the timer.
/// \return status code that indicates the execution status of the function.
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks);
-
+
/// Stop a timer.
/// \param[in] timer_id timer ID obtained by \ref osTimerNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osTimerStop (osTimerId_t timer_id);
-
+
/// Check if a timer is running.
/// \param[in] timer_id timer ID obtained by \ref osTimerNew.
/// \return 0 not running, 1 running.
uint32_t osTimerIsRunning (osTimerId_t timer_id);
-
+
/// Delete a timer.
/// \param[in] timer_id timer ID obtained by \ref osTimerNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osTimerDelete (osTimerId_t timer_id);
-
-
-// ==== Event Flags Management Functions ====
-
-/// Create and Initialize an Event Flags object.
-/// \param[in] attr event flags attributes; NULL: default values.
-/// \return event flags ID for reference by other functions or NULL in case of error.
-osEventFlagsId_t osEventFlagsNew (const osEventFlagsAttr_t *attr);
-
-/// Get name of an Event Flags object.
-/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
-/// \return name as null-terminated string.
-const char *osEventFlagsGetName (osEventFlagsId_t ef_id);
-
-/// Set the specified Event Flags.
-/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
-/// \param[in] flags specifies the flags that shall be set.
-/// \return event flags after setting or error code if highest bit set.
-uint32_t osEventFlagsSet (osEventFlagsId_t ef_id, uint32_t flags);
-
-/// Clear the specified Event Flags.
-/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
-/// \param[in] flags specifies the flags that shall be cleared.
-/// \return event flags before clearing or error code if highest bit set.
-uint32_t osEventFlagsClear (osEventFlagsId_t ef_id, uint32_t flags);
-
-/// Get the current Event Flags.
-/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
-/// \return current event flags.
-uint32_t osEventFlagsGet (osEventFlagsId_t ef_id);
-
-/// Wait for one or more Event Flags to become signaled.
-/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
-/// \param[in] flags specifies the flags to wait for.
-/// \param[in] options specifies flags options (osFlagsXxxx).
-/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
-/// \return event flags before clearing or error code if highest bit set.
-uint32_t osEventFlagsWait (osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout);
-
-/// Delete an Event Flags object.
-/// \param[in] ef_id event flags ID obtained by \ref osEventFlagsNew.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osEventFlagsDelete (osEventFlagsId_t ef_id);
-
-
-// ==== Mutex Management Functions ====
-
-/// Create and Initialize a Mutex object.
-/// \param[in] attr mutex attributes; NULL: default values.
-/// \return mutex ID for reference by other functions or NULL in case of error.
-osMutexId_t osMutexNew (const osMutexAttr_t *attr);
-
-/// Get name of a Mutex object.
-/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
-/// \return name as null-terminated string.
-const char *osMutexGetName (osMutexId_t mutex_id);
-
-/// Acquire a Mutex or timeout if it is locked.
-/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
-/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osMutexAcquire (osMutexId_t mutex_id, uint32_t timeout);
-
-/// Release a Mutex that was acquired by \ref osMutexAcquire.
-/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osMutexRelease (osMutexId_t mutex_id);
-
-/// Get Thread which owns a Mutex object.
-/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
-/// \return thread ID of owner thread or NULL when mutex was not acquired.
-osThreadId_t osMutexGetOwner (osMutexId_t mutex_id);
-
-/// Delete a Mutex object.
-/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osMutexDelete (osMutexId_t mutex_id);
-
-
-// ==== Semaphore Management Functions ====
-
-/// Create and Initialize a Semaphore object.
-/// \param[in] max_count maximum number of available tokens.
-/// \param[in] initial_count initial number of available tokens.
-/// \param[in] attr semaphore attributes; NULL: default values.
-/// \return semaphore ID for reference by other functions or NULL in case of error.
-osSemaphoreId_t osSemaphoreNew (uint32_t max_count, uint32_t initial_count, const osSemaphoreAttr_t *attr);
-
-/// Get name of a Semaphore object.
-/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
-/// \return name as null-terminated string.
-const char *osSemaphoreGetName (osSemaphoreId_t semaphore_id);
-
-/// Acquire a Semaphore token or timeout if no tokens are available.
-/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
-/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osSemaphoreAcquire (osSemaphoreId_t semaphore_id, uint32_t timeout);
-
-/// Release a Semaphore token up to the initial maximum count.
-/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osSemaphoreRelease (osSemaphoreId_t semaphore_id);
-
-/// Get current Semaphore token count.
-/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
-/// \return number of tokens available.
-uint32_t osSemaphoreGetCount (osSemaphoreId_t semaphore_id);
-
-/// Delete a Semaphore object.
-/// \param[in] semaphore_id semaphore ID obtained by \ref osSemaphoreNew.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osSemaphoreDelete (osSemaphoreId_t semaphore_id);
-
-
-// ==== Memory Pool Management Functions ====
-
-/// Create and Initialize a Memory Pool object.
-/// \param[in] block_count maximum number of memory blocks in memory pool.
-/// \param[in] block_size memory block size in bytes.
-/// \param[in] attr memory pool attributes; NULL: default values.
-/// \return memory pool ID for reference by other functions or NULL in case of error.
-osMemoryPoolId_t osMemoryPoolNew (uint32_t block_count, uint32_t block_size, const osMemoryPoolAttr_t *attr);
-
-/// Get name of a Memory Pool object.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \return name as null-terminated string.
-const char *osMemoryPoolGetName (osMemoryPoolId_t mp_id);
-
-/// Allocate a memory block from a Memory Pool.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
-/// \return address of the allocated memory block or NULL in case of no memory is available.
-void *osMemoryPoolAlloc (osMemoryPoolId_t mp_id, uint32_t timeout);
-
-/// Return an allocated memory block back to a Memory Pool.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \param[in] block address of the allocated memory block to be returned to the memory pool.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osMemoryPoolFree (osMemoryPoolId_t mp_id, void *block);
-
-/// Get maximum number of memory blocks in a Memory Pool.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \return maximum number of memory blocks.
-uint32_t osMemoryPoolGetCapacity (osMemoryPoolId_t mp_id);
-
-/// Get memory block size in a Memory Pool.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \return memory block size in bytes.
-uint32_t osMemoryPoolGetBlockSize (osMemoryPoolId_t mp_id);
-
-/// Get number of memory blocks used in a Memory Pool.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \return number of memory blocks used.
-uint32_t osMemoryPoolGetCount (osMemoryPoolId_t mp_id);
-
-/// Get number of memory blocks available in a Memory Pool.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \return number of memory blocks available.
-uint32_t osMemoryPoolGetSpace (osMemoryPoolId_t mp_id);
-
-/// Delete a Memory Pool object.
-/// \param[in] mp_id memory pool ID obtained by \ref osMemoryPoolNew.
-/// \return status code that indicates the execution status of the function.
-osStatus_t osMemoryPoolDelete (osMemoryPoolId_t mp_id);
-
-
+
// ==== Message Queue Management Functions ====
-
+
/// Create and Initialize a Message Queue object.
/// \param[in] msg_count maximum number of messages in queue.
/// \param[in] msg_size maximum message size in bytes.
/// \param[in] attr message queue attributes; NULL: default values.
/// \return message queue ID for reference by other functions or NULL in case of error.
osMessageQueueId_t osMessageQueueNew (uint32_t msg_count, uint32_t msg_size, const osMessageQueueAttr_t *attr);
-
+
/// Get name of a Message Queue object.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return name as null-terminated string.
const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
-
+
/// Put a Message into a Queue or timeout if Queue is full.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \param[in] msg_ptr pointer to buffer with message to put into a queue.
@@ -709,7 +255,7 @@ const char *osMessageQueueGetName (osMessageQueueId_t mq_id);
/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
/// \return status code that indicates the execution status of the function.
osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uint8_t msg_prio, uint32_t timeout);
-
+
/// Get a Message from a Queue or timeout if Queue is empty.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \param[out] msg_ptr pointer to buffer for message to get from a queue.
@@ -717,40 +263,40 @@ osStatus_t osMessageQueuePut (osMessageQueueId_t mq_id, const void *msg_ptr, uin
/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
/// \return status code that indicates the execution status of the function.
osStatus_t osMessageQueueGet (osMessageQueueId_t mq_id, void *msg_ptr, uint8_t *msg_prio, uint32_t timeout);
-
+
/// Get maximum number of messages in a Message Queue.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return maximum number of messages.
uint32_t osMessageQueueGetCapacity (osMessageQueueId_t mq_id);
-
+
/// Get maximum message size in a Message Queue.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return maximum message size in bytes.
uint32_t osMessageQueueGetMsgSize (osMessageQueueId_t mq_id);
-
+
/// Get number of queued messages in a Message Queue.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return number of queued messages.
uint32_t osMessageQueueGetCount (osMessageQueueId_t mq_id);
-
+
/// Get number of available slots for messages in a Message Queue.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return number of available slots for messages.
uint32_t osMessageQueueGetSpace (osMessageQueueId_t mq_id);
-
+
/// Reset a Message Queue to initial empty state.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osMessageQueueReset (osMessageQueueId_t mq_id);
-
+
/// Delete a Message Queue object.
/// \param[in] mq_id message queue ID obtained by \ref osMessageQueueNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osMessageQueueDelete (osMessageQueueId_t mq_id);
-
-
+
+
#ifdef __cplusplus
}
#endif
-
+
#endif // CMSIS_OS2_H_
diff --git a/lib/FreeRTOS-glue/freertos_mpool.h b/lib/FreeRTOS-glue/freertos_mpool.h
deleted file mode 100644
index cea5017e..00000000
--- a/lib/FreeRTOS-glue/freertos_mpool.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* --------------------------------------------------------------------------
- * Copyright (c) 2013-2020 Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * Name: freertos_mpool.h
- * Purpose: CMSIS RTOS2 wrapper for FreeRTOS
- *
- *---------------------------------------------------------------------------*/
-
-#ifndef FREERTOS_MPOOL_H_
-#define FREERTOS_MPOOL_H_
-
-#include <stdint.h>
-#include "FreeRTOS.h"
-#include "semphr.h"
-
-/* Memory Pool implementation definitions */
-#define MPOOL_STATUS 0x5EED0000U
-
-/* Memory Block header */
-typedef struct {
- void *next; /* Pointer to next block */
-} MemPoolBlock_t;
-
-/* Memory Pool control block */
-typedef struct MemPoolDef_t {
- MemPoolBlock_t *head; /* Pointer to head block */
- SemaphoreHandle_t sem; /* Pool semaphore handle */
- uint8_t *mem_arr; /* Pool memory array */
- uint32_t mem_sz; /* Pool memory array size */
- const char *name; /* Pointer to name string */
- uint32_t bl_sz; /* Size of a single block */
- uint32_t bl_cnt; /* Number of blocks */
- uint32_t n; /* Block allocation index */
- volatile uint32_t status; /* Object status flags */
-#if (configSUPPORT_STATIC_ALLOCATION == 1)
- StaticSemaphore_t mem_sem; /* Semaphore object memory */
-#endif
-} MemPool_t;
-
-/* No need to hide static object type, just align to coding style */
-#define StaticMemPool_t MemPool_t
-
-/* Define memory pool control block size */
-#define MEMPOOL_CB_SIZE (sizeof(StaticMemPool_t))
-
-/* Define size of the byte array required to create count of blocks of given size */
-#define MEMPOOL_ARR_SIZE(bl_count, bl_size) (((((bl_size) + (4 - 1)) / 4) * 4)*(bl_count))
-
-#endif /* FREERTOS_MPOOL_H_ */
diff --git a/lib/FreeRTOS-glue/freertos_os2.h b/lib/FreeRTOS-glue/freertos_os2.h
index f67d2ae9..1e70b3fc 100644
--- a/lib/FreeRTOS-glue/freertos_os2.h
+++ b/lib/FreeRTOS-glue/freertos_os2.h
@@ -75,7 +75,7 @@
#endif
/*
- Option to exclude CMSIS-RTOS2 function osThreadEnumerate from the application image.
+ Option to exclude CMSIS-RTOS2 function furi_thread_enumerate from the application image.
*/
#ifndef configUSE_OS2_THREAD_ENUMERATE
#define configUSE_OS2_THREAD_ENUMERATE 1
@@ -153,7 +153,7 @@
#if (INCLUDE_xTaskGetCurrentTaskHandle == 0)
/*
CMSIS-RTOS2 API uses FreeRTOS function xTaskGetCurrentTaskHandle to implement
- functions osThreadGetId, osThreadFlagsClear and osThreadFlagsGet. In case if these
+ functions osThreadGetId, furi_thread_flags_clear and furi_thread_flags_get. In case if these
functions are not used in the application image, compiler will optimize them away.
Set #define INCLUDE_xTaskGetCurrentTaskHandle 1 to fix this error.
*/
@@ -170,8 +170,8 @@
#endif
#if (INCLUDE_uxTaskGetStackHighWaterMark == 0)
/*
- CMSIS-RTOS2 function osThreadGetStackSpace uses FreeRTOS function uxTaskGetStackHighWaterMark.
- In case if osThreadGetStackSpace is not used in the application image, compiler will
+ CMSIS-RTOS2 function furi_thread_get_stack_space uses FreeRTOS function uxTaskGetStackHighWaterMark.
+ In case if furi_thread_get_stack_space is not used in the application image, compiler will
optimize it away.
Set #define INCLUDE_uxTaskGetStackHighWaterMark 1 to fix this error.
*/
@@ -294,16 +294,16 @@
#if (configUSE_TRACE_FACILITY == 0)
/*
- CMSIS-RTOS2 function osThreadEnumerate requires FreeRTOS function uxTaskGetSystemState
+ CMSIS-RTOS2 function furi_thread_enumerate requires FreeRTOS function uxTaskGetSystemState
which is only enabled if configUSE_TRACE_FACILITY == 1.
Set #define configUSE_TRACE_FACILITY 1 to fix this error.
- Alternatively, if the application does not use osThreadEnumerate it can be
+ Alternatively, if the application does not use furi_thread_enumerate it can be
excluded from the image code by setting:
#define configUSE_OS2_THREAD_ENUMERATE 0 (in FreeRTOSConfig.h)
*/
#if (configUSE_OS2_THREAD_ENUMERATE == 1)
- #error "Definition configUSE_TRACE_FACILITY must equal 1 to implement osThreadEnumerate."
+ #error "Definition configUSE_TRACE_FACILITY must equal 1 to implement furi_thread_enumerate."
#endif
#endif
@@ -316,21 +316,4 @@
#error "Definition configUSE_16_BIT_TICKS must be zero to implement CMSIS-RTOS2 API."
#endif
-#if (configMAX_PRIORITIES != 56)
- /*
- CMSIS-RTOS2 defines 56 different priorities (see osPriority_t) and portable CMSIS-RTOS2
- implementation should implement the same number of priorities.
- Set #define configMAX_PRIORITIES 56 to fix this error.
- */
- #error "Definition configMAX_PRIORITIES must equal 56 to implement Thread Management API."
-#endif
-#if (configUSE_PORT_OPTIMISED_TASK_SELECTION != 0)
- /*
- CMSIS-RTOS2 requires handling of 56 different priorities (see osPriority_t) while FreeRTOS port
- optimised selection for Cortex core only handles 32 different priorities.
- Set #define configUSE_PORT_OPTIMISED_TASK_SELECTION 0 to fix this error.
- */
- #error "Definition configUSE_PORT_OPTIMISED_TASK_SELECTION must be zero to implement Thread Management API."
-#endif
-
#endif /* FREERTOS_OS2_H_ */
diff --git a/lib/FreeRTOS-glue/os_tick.h b/lib/FreeRTOS-glue/os_tick.h
deleted file mode 100644
index 3cfd8954..00000000
--- a/lib/FreeRTOS-glue/os_tick.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/**************************************************************************//**
- * @file os_tick.h
- * @brief CMSIS OS Tick header file
- * @version V1.0.2
- * @date 19. March 2021
- ******************************************************************************/
-/*
- * Copyright (c) 2017-2021 ARM Limited. All rights reserved.
- *
- * SPDX-License-Identifier: Apache-2.0
- *
- * Licensed under the Apache License, Version 2.0 (the License); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef OS_TICK_H
-#define OS_TICK_H
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-/// IRQ Handler.
-#ifndef IRQHANDLER_T
-#define IRQHANDLER_T
-typedef void (*IRQHandler_t) (void);
-#endif
-
-/// Setup OS Tick timer to generate periodic RTOS Kernel Ticks
-/// \param[in] freq tick frequency in Hz
-/// \param[in] handler tick IRQ handler
-/// \return 0 on success, -1 on error.
-int32_t OS_Tick_Setup (uint32_t freq, IRQHandler_t handler);
-
-/// Enable OS Tick timer interrupt
-void OS_Tick_Enable (void);
-
-/// Disable OS Tick timer interrupt
-void OS_Tick_Disable (void);
-
-/// Acknowledge execution of OS Tick timer interrupt
-void OS_Tick_AcknowledgeIRQ (void);
-
-/// Get OS Tick timer IRQ number
-/// \return OS Tick IRQ number
-int32_t OS_Tick_GetIRQn (void);
-
-/// Get OS Tick timer clock frequency
-/// \return OS Tick timer clock frequency in Hz
-uint32_t OS_Tick_GetClock (void);
-
-/// Get OS Tick timer interval reload value
-/// \return OS Tick timer interval reload value
-uint32_t OS_Tick_GetInterval (void);
-
-/// Get OS Tick timer counter value
-/// \return OS Tick timer counter value
-uint32_t OS_Tick_GetCount (void);
-
-/// Get OS Tick timer overflow status
-/// \return OS Tick overflow status (1 - overflow, 0 - no overflow).
-uint32_t OS_Tick_GetOverflow (void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* OS_TICK_H */
diff --git a/lib/ST25RFAL002/platform.c b/lib/ST25RFAL002/platform.c
index 52ac843e..c688bd59 100644
--- a/lib/ST25RFAL002/platform.c
+++ b/lib/ST25RFAL002/platform.c
@@ -3,49 +3,58 @@
#include <furi.h>
#include <furi_hal_spi.h>
-static const osThreadAttr_t platform_irq_thread_attr = {
- .name = "RfalIrqDriver",
- .stack_size = 1024,
- .priority = osPriorityRealtime,
-};
+typedef struct {
+ FuriThread* thread;
+ volatile PlatformIrqCallback callback;
+} RfalPlatform;
-static volatile osThreadId_t platform_irq_thread_id = NULL;
-static volatile PlatformIrqCallback platform_irq_callback = NULL;
-static const GpioPin pin = {ST25R_INT_PORT, ST25R_INT_PIN};
+static volatile RfalPlatform rfal_platform = {
+ .thread = NULL,
+ .callback = NULL,
+};
void nfc_isr(void* _ctx) {
UNUSED(_ctx);
- if(platform_irq_callback && platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
- osThreadFlagsSet(platform_irq_thread_id, 0x1);
+ if(rfal_platform.callback && platformGpioIsHigh(ST25R_INT_PORT, ST25R_INT_PIN)) {
+ furi_thread_flags_set(furi_thread_get_id(rfal_platform.thread), 0x1);
}
}
-void platformIrqThread() {
+int32_t rfal_platform_irq_thread(void* context) {
+ UNUSED(context);
+
while(1) {
- uint32_t flags = osThreadFlagsWait(0x1, osFlagsWaitAny, osWaitForever);
+ uint32_t flags = furi_thread_flags_wait(0x1, osFlagsWaitAny, osWaitForever);
if(flags & 0x1) {
- platform_irq_callback();
+ rfal_platform.callback();
}
}
}
void platformEnableIrqCallback() {
- furi_hal_gpio_init(&pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
- furi_hal_gpio_enable_int_callback(&pin);
+ furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
+ furi_hal_gpio_enable_int_callback(&gpio_nfc_irq_rfid_pull);
}
void platformDisableIrqCallback() {
- furi_hal_gpio_init(&pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
- furi_hal_gpio_disable_int_callback(&pin);
+ furi_hal_gpio_init(&gpio_nfc_irq_rfid_pull, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
+ furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
}
void platformSetIrqCallback(PlatformIrqCallback callback) {
- platform_irq_callback = callback;
- platform_irq_thread_id = osThreadNew(platformIrqThread, NULL, &platform_irq_thread_attr);
- furi_hal_gpio_add_int_callback(&pin, nfc_isr, NULL);
+ rfal_platform.callback = callback;
+ rfal_platform.thread = furi_thread_alloc();
+
+ furi_thread_set_name(rfal_platform.thread, "RfalIrqDriver");
+ furi_thread_set_callback(rfal_platform.thread, rfal_platform_irq_thread);
+ furi_thread_set_stack_size(rfal_platform.thread, 1024);
+ furi_thread_set_priority(rfal_platform.thread, FuriThreadPriorityIsr);
+ furi_thread_start(rfal_platform.thread);
+
+ furi_hal_gpio_add_int_callback(&gpio_nfc_irq_rfid_pull, nfc_isr, NULL);
// Disable interrupt callback as the pin is shared between 2 apps
// It is enabled in rfalLowPowerModeStop()
- furi_hal_gpio_disable_int_callback(&pin);
+ furi_hal_gpio_disable_int_callback(&gpio_nfc_irq_rfid_pull);
}
bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {
diff --git a/lib/infrared/worker/infrared_worker.c b/lib/infrared/worker/infrared_worker.c
index 71126c86..b24b7480 100644
--- a/lib/infrared/worker/infrared_worker.c
+++ b/lib/infrared/worker/infrared_worker.c
@@ -92,8 +92,8 @@ static void infrared_worker_furi_hal_message_sent_isr_callback(void* context);
static void infrared_worker_rx_timeout_callback(void* context) {
InfraredWorker* instance = context;
- uint32_t flags_set = osThreadFlagsSet(
- furi_thread_get_thread_id(instance->thread), INFRARED_WORKER_RX_TIMEOUT_RECEIVED);
+ uint32_t flags_set = furi_thread_flags_set(
+ furi_thread_get_id(instance->thread), INFRARED_WORKER_RX_TIMEOUT_RECEIVED);
furi_check(flags_set & INFRARED_WORKER_RX_TIMEOUT_RECEIVED);
}
@@ -110,7 +110,7 @@ static void infrared_worker_rx_callback(void* context, bool level, uint32_t dura
INFRARED_WORKER_OVERRUN;
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
- uint32_t flags_set = osThreadFlagsSet(furi_thread_get_thread_id(instance->thread), events);
+ uint32_t flags_set = furi_thread_flags_set(furi_thread_get_id(instance->thread), events);
furi_check(flags_set & events);
}
@@ -152,8 +152,8 @@ static void
instance->signal.timings[instance->signal.timings_cnt] = duration;
++instance->signal.timings_cnt;
} else {
- uint32_t flags_set = osThreadFlagsSet(
- furi_thread_get_thread_id(instance->thread), INFRARED_WORKER_OVERRUN);
+ uint32_t flags_set = furi_thread_flags_set(
+ furi_thread_get_id(instance->thread), INFRARED_WORKER_OVERRUN);
furi_check(flags_set & INFRARED_WORKER_OVERRUN);
instance->rx.overrun = true;
}
@@ -167,7 +167,7 @@ static int32_t infrared_worker_rx_thread(void* thread_context) {
TickType_t last_blink_time = 0;
while(1) {
- events = osThreadFlagsWait(INFRARED_WORKER_ALL_RX_EVENTS, 0, osWaitForever);
+ events = furi_thread_flags_wait(INFRARED_WORKER_ALL_RX_EVENTS, 0, osWaitForever);
furi_check(events & INFRARED_WORKER_ALL_RX_EVENTS); /* at least one caught */
if(events & INFRARED_WORKER_RX_RECEIVED) {
@@ -282,7 +282,7 @@ void infrared_worker_rx_stop(InfraredWorker* instance) {
furi_hal_infrared_async_rx_set_capture_isr_callback(NULL, NULL);
furi_hal_infrared_async_rx_stop();
- osThreadFlagsSet(furi_thread_get_thread_id(instance->thread), INFRARED_WORKER_EXIT);
+ furi_thread_flags_set(furi_thread_get_id(instance->thread), INFRARED_WORKER_EXIT);
furi_thread_join(instance->thread);
BaseType_t xReturn = xStreamBufferReset(instance->stream);
@@ -342,8 +342,8 @@ void infrared_worker_tx_start(InfraredWorker* instance) {
static void infrared_worker_furi_hal_message_sent_isr_callback(void* context) {
InfraredWorker* instance = context;
- uint32_t flags_set = osThreadFlagsSet(
- furi_thread_get_thread_id(instance->thread), INFRARED_WORKER_TX_MESSAGE_SENT);
+ uint32_t flags_set = furi_thread_flags_set(
+ furi_thread_get_id(instance->thread), INFRARED_WORKER_TX_MESSAGE_SENT);
furi_check(flags_set & INFRARED_WORKER_TX_MESSAGE_SENT);
}
@@ -369,8 +369,8 @@ static FuriHalInfraredTxGetDataState
state = FuriHalInfraredTxGetDataStateDone;
}
- uint32_t flags_set = osThreadFlagsSet(
- furi_thread_get_thread_id(instance->thread), INFRARED_WORKER_TX_FILL_BUFFER);
+ uint32_t flags_set = furi_thread_flags_set(
+ furi_thread_get_id(instance->thread), INFRARED_WORKER_TX_FILL_BUFFER);
furi_check(flags_set & INFRARED_WORKER_TX_FILL_BUFFER);
return state;
@@ -498,7 +498,7 @@ static int32_t infrared_worker_tx_thread(void* thread_context) {
furi_hal_infrared_async_tx_wait_termination();
instance->state = InfraredWorkerStateStartTx;
- events = osThreadFlagsGet();
+ events = furi_thread_flags_get();
if(events & INFRARED_WORKER_EXIT) {
exit = true;
break;
@@ -506,7 +506,7 @@ static int32_t infrared_worker_tx_thread(void* thread_context) {
break;
case InfraredWorkerStateRunTx:
- events = osThreadFlagsWait(INFRARED_WORKER_ALL_TX_EVENTS, 0, osWaitForever);
+ events = furi_thread_flags_wait(INFRARED_WORKER_ALL_TX_EVENTS, 0, osWaitForever);
furi_check(events & INFRARED_WORKER_ALL_TX_EVENTS); /* at least one caught */
if(events & INFRARED_WORKER_EXIT) {
@@ -558,7 +558,7 @@ void infrared_worker_tx_stop(InfraredWorker* instance) {
furi_assert(instance);
furi_assert(instance->state != InfraredWorkerStateRunRx);
- osThreadFlagsSet(furi_thread_get_thread_id(instance->thread), INFRARED_WORKER_EXIT);
+ furi_thread_flags_set(furi_thread_get_id(instance->thread), INFRARED_WORKER_EXIT);
furi_thread_join(instance->thread);
furi_hal_infrared_async_tx_set_data_isr_callback(NULL, NULL);
furi_hal_infrared_async_tx_set_signal_sent_isr_callback(NULL, NULL);
diff --git a/lib/subghz/subghz_file_encoder_worker.c b/lib/subghz/subghz_file_encoder_worker.c
index 83cf90b7..0ec4c861 100644
--- a/lib/subghz/subghz_file_encoder_worker.c
+++ b/lib/subghz/subghz_file_encoder_worker.c
@@ -216,8 +216,9 @@ bool subghz_file_encoder_worker_start(SubGhzFileEncoderWorker* instance, const c
xStreamBufferReset(instance->stream);
string_set(instance->file_path, file_path);
instance->worker_running = true;
- bool res = furi_thread_start(instance->thread);
- return res;
+ furi_thread_start(instance->thread);
+
+ return true;
}
void subghz_file_encoder_worker_stop(SubGhzFileEncoderWorker* instance) {