70#include <furi/core/base.h>
71#include <furi/core/common_defines.h>
73#include <furi/core/thread.h>
74#include <furi/core/event_loop.h>
75#include <furi/core/semaphore.h>
76#include <furi/core/mutex.h>
77#include <furi/core/event_flag.h>
78#include <furi/core/kernel.h>
79#include <furi/core/message_queue.h>
80#include <furi/core/timer.h>
81#include <furi/core/event_flag.h>
101 osKernelSuspended = 4,
103 osKernelReserved = 0x7FFFFFFF
120 osPriorityIdle = FuriThreadPriorityIdle,
122 osPriorityLow1 = 1 + 1,
123 osPriorityLow2 = 1 + 2,
124 osPriorityLow3 = 1 + 3,
125 osPriorityLow4 = 1 + 4,
126 osPriorityLow5 = 1 + 4,
127 osPriorityLow6 = 1 + 4,
128 osPriorityLow7 = 1 + 4,
129 osPriorityBelowNormal = 6,
130 osPriorityBelowNormal1 = 6 + 1,
131 osPriorityBelowNormal2 = 6 + 2,
132 osPriorityBelowNormal3 = 6 + 3,
133 osPriorityBelowNormal4 = 6 + 4,
134 osPriorityBelowNormal5 = 6 + 4,
135 osPriorityBelowNormal6 = 6 + 4,
136 osPriorityBelowNormal7 = 6 + 4,
137 osPriorityNormal = 11,
138 osPriorityNormal1 = 11 + 1,
139 osPriorityNormal2 = 11 + 2,
140 osPriorityNormal3 = 11 + 3,
141 osPriorityNormal4 = 11 + 4,
142 osPriorityNormal5 = 11 + 4,
143 osPriorityNormal6 = 11 + 4,
144 osPriorityNormal7 = 11 + 4,
145 osPriorityAboveNormal = 16,
146 osPriorityAboveNormal1 = 16 + 1,
147 osPriorityAboveNormal2 = 16 + 2,
148 osPriorityAboveNormal3 = 16 + 3,
149 osPriorityAboveNormal4 = 16 + 4,
150 osPriorityAboveNormal5 = 16 + 4,
151 osPriorityAboveNormal6 = 16 + 4,
152 osPriorityAboveNormal7 = 16 + 4,
154 osPriorityHigh1 = 21 + 1,
155 osPriorityHigh2 = 21 + 2,
156 osPriorityHigh3 = 21 + 3,
157 osPriorityHigh4 = 21 + 4,
158 osPriorityHigh5 = 21 + 4,
159 osPriorityHigh6 = 21 + 4,
160 osPriorityHigh7 = 21 + 4,
161 osPriorityRealtime = 26,
162 osPriorityRealtime1 = 26 + 1,
163 osPriorityRealtime2 = 26 + 2,
164 osPriorityRealtime3 = 26 + 3,
165 osPriorityRealtime4 = 26 + 3,
166 osPriorityRealtime5 = 26 + 3,
167 osPriorityRealtime6 = 26 + 3,
168 osPriorityRealtime7 = 26 + 3,
169 osPriorityISR = FuriThreadPriorityIsr,
170 osPriorityError = -1,
171 osPriorityReserved = 0x7FFFFFFF
178typedef void (*osThreadFunc_t)(
void* argument);
181typedef void (*osTimerFunc_t)(
void* argument);
191#define osWaitForever ((uint32_t)FuriWaitForever)
195#define osFlagsWaitAny ((uint32_t)FuriFlagWaitAny)
197#define osFlagsWaitAll ((uint32_t)FuriFlagWaitAll)
199#define osFlagsNoClear ((uint32_t)FuriFlagNoClear)
203#define osFlagsError ((uint32_t)FuriFlagError)
205#define osFlagsErrorUnknown ((uint32_t)FuriFlagErrorUnknown)
207#define osFlagsErrorTimeout ((uint32_t)FuriFlagErrorTimeout)
209#define osFlagsErrorResource ((uint32_t)FuriFlagErrorResource)
211#define osFlagsErrorParameter ((uint32_t)FuriFlagErrorParameter)
213#define osFlagsErrorISR ((uint32_t)FuriFlagErrorISR)
216#define osThreadDetached 0x00000000U
217#define osThreadJoinable 0x00000001U
220#define osMutexRecursive 0x00000001U
221#define osMutexPrioInherit 0x00000002U
222#define osMutexRobust 0x00000008U
230 FuriStatusErrorTimeout,
231 osErrorResource = FuriStatusErrorResource,
232 osErrorParameter = FuriStatusErrorParameter,
234 FuriStatusErrorNoMemory,
237 osStatusReserved = FuriStatusReserved
241typedef void* osThreadId_t;
244typedef void* osTimerId_t;
247typedef void* osEventFlagsId_t;
250typedef void* osMutexId_t;
253typedef void* osSemaphoreId_t;
259typedef void* osMessageQueueId_t;
264typedef uint32_t TZ_ModuleId_t;
282 osThreadFunc_t callback;
286static FURI_ALWAYS_INLINE int32_t furi_cmsis_thread_callback(
void* context) {
288 adapter->callback(adapter->context);
349static FURI_ALWAYS_INLINE osStatus_t osKernelInitialize(
void) {
363static FURI_ALWAYS_INLINE osKernelState_t osKernelGetState(
void) {
364 osKernelState_t state;
365 uint32_t KernelState = furi_kernel_is_running();
367 switch(KernelState) {
369 state = osKernelRunning;
372 state = osKernelLocked;
375 state = osKernelError;
388static FURI_ALWAYS_INLINE int32_t osKernelLock(
void) {
389 return furi_kernel_lock();
395static FURI_ALWAYS_INLINE int32_t osKernelUnlock(
void) {
396 return furi_kernel_unlock();
403static FURI_ALWAYS_INLINE int32_t osKernelRestoreLock(int32_t lock) {
404 return furi_kernel_restore_lock(lock);
418static FURI_ALWAYS_INLINE uint32_t osKernelGetTickCount(
void) {
419 return furi_get_tick();
424static FURI_ALWAYS_INLINE uint32_t osKernelGetTickFreq (
void) {
425 return furi_kernel_get_tick_frequency();
444static FURI_ALWAYS_INLINE osThreadId_t
445 osThreadNew(osThreadFunc_t func,
void* argument,
const osThreadAttr_t* attr) {
448 adapter->callback = func;
449 adapter->context = argument;
452 furi_thread_alloc_ex(attr->
name, attr->
stack_size, furi_cmsis_thread_callback, adapter);
454 furi_thread_set_priority(adapter->thread, (FuriThreadPriority)attr->
priority);
458 furi_thread_start(adapter->thread);
461 return (osThreadId_t)adapter;
468static FURI_ALWAYS_INLINE
const char* osThreadGetName(osThreadId_t thread_id) {
470 return furi_thread_get_name((FuriThreadId)adapter->thread);
476static FURI_ALWAYS_INLINE osThreadId_t osThreadGetId(
void) {
477 return (osThreadId_t)furi_thread_get_current_id();
509static FURI_ALWAYS_INLINE osStatus_t osThreadYield(
void) {
517static FURI_ALWAYS_INLINE osStatus_t osThreadSuspend (osThreadId_t thread_id) {
519 furi_thread_suspend(adapter->thread);
537static FURI_ALWAYS_INLINE osStatus_t osThreadJoin(osThreadId_t thread_id) {
539 furi_thread_join(adapter->thread);
552static FURI_ALWAYS_INLINE osStatus_t osThreadTerminate(osThreadId_t thread_id) {
554 furi_thread_join(adapter->thread);
555 furi_thread_free(adapter->thread);
577static FURI_ALWAYS_INLINE uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags) {
579 return furi_thread_flags_set(adapter->thread, flags);
597static FURI_ALWAYS_INLINE uint32_t
598 osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout) {
599 return furi_thread_flags_wait(flags, options, timeout);
608static FURI_ALWAYS_INLINE osStatus_t osDelay(uint32_t ticks) {
609 furi_delay_tick(ticks);
617static FURI_ALWAYS_INLINE osStatus_t osDelayUntil(uint32_t ticks) {
618 return (osStatus_t)furi_delay_until_tick(ticks);
630static FURI_ALWAYS_INLINE osTimerId_t
631 osTimerNew(osTimerFunc_t func, osTimerType_t type,
void* argument,
const osTimerAttr_t* attr) {
634 return (osTimerId_t)furi_timer_alloc((FuriTimerCallback)func, (FuriTimerType)type, argument);
647static FURI_ALWAYS_INLINE osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks) {
648 FuriStatus status = furi_timer_start((FuriTimer*)timer_id, ticks);
649 return (osStatus_t)status;
656static FURI_ALWAYS_INLINE osStatus_t osTimerStop(osTimerId_t timer_id) {
657 FuriStatus status = furi_timer_stop((FuriTimer*)timer_id);
658 return (osStatus_t)status;
665static FURI_ALWAYS_INLINE uint32_t osTimerIsRunning(osTimerId_t timer_id) {
666 return furi_timer_is_running((FuriTimer*)timer_id);
673static FURI_ALWAYS_INLINE osStatus_t osTimerDelete(osTimerId_t timer_id) {
674 furi_timer_free((FuriTimer*)timer_id);
684static FURI_ALWAYS_INLINE osEventFlagsId_t osEventFlagsNew(
const osEventFlagsAttr_t* attr) {
687 return (osEventFlagsId_t)furi_event_flag_alloc();
700static FURI_ALWAYS_INLINE uint32_t osEventFlagsSet(osEventFlagsId_t ef_id, uint32_t flags) {
701 return furi_event_flag_set((FuriEventFlag*)ef_id, flags);
709static FURI_ALWAYS_INLINE uint32_t osEventFlagsClear(osEventFlagsId_t ef_id, uint32_t flags) {
710 return furi_event_flag_clear((FuriEventFlag*)ef_id, flags);
717static FURI_ALWAYS_INLINE uint32_t osEventFlagsGet(osEventFlagsId_t ef_id) {
718 return furi_event_flag_get((FuriEventFlag*)ef_id);
730static inline uint32_t
731 osEventFlagsWait(osEventFlagsId_t ef_id, uint32_t flags, uint32_t options, uint32_t timeout) {
732 return furi_event_flag_wait((FuriEventFlag*)ef_id, flags, options, timeout);
739static FURI_ALWAYS_INLINE osStatus_t osEventFlagsDelete(osEventFlagsId_t ef_id) {
740 furi_event_flag_free((FuriEventFlag*)ef_id);
749static FURI_ALWAYS_INLINE osMutexId_t osMutexNew(
const osMutexAttr_t* attr) {
750 const uint32_t attr_bits = attr ? attr->
attr_bits : 0;
751 const FuriMutexType type = attr_bits & osMutexRecursive ? FuriMutexTypeRecursive : FuriMutexTypeNormal;
752 return (osMutexId_t)furi_mutex_alloc(type);
765static FURI_ALWAYS_INLINE osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout) {
766 return (osStatus_t)furi_mutex_acquire((FuriMutex*)mutex_id, timeout);
773static FURI_ALWAYS_INLINE osStatus_t osMutexRelease(osMutexId_t mutex_id) {
774 return (osStatus_t)furi_mutex_release((FuriMutex*)mutex_id);
781static FURI_ALWAYS_INLINE osThreadId_t osMutexGetOwner(osMutexId_t mutex_id) {
782 return (osThreadId_t)furi_mutex_get_owner((FuriMutex*)mutex_id);
789static FURI_ALWAYS_INLINE osStatus_t osMutexDelete(osMutexId_t mutex_id) {
790 furi_mutex_free((FuriMutex*)mutex_id);
802static FURI_ALWAYS_INLINE osSemaphoreId_t
803 osSemaphoreNew(uint32_t max_count, uint32_t initial_count,
const osSemaphoreAttr_t* attr) {
805 return (osSemaphoreId_t)furi_semaphore_alloc(max_count, initial_count);
818static FURI_ALWAYS_INLINE osStatus_t
819 osSemaphoreAcquire(osSemaphoreId_t semaphore_id, uint32_t timeout) {
820 return (osStatus_t)furi_semaphore_acquire((FuriSemaphore*)semaphore_id, timeout);
827static FURI_ALWAYS_INLINE osStatus_t osSemaphoreRelease(osSemaphoreId_t semaphore_id) {
828 return (osStatus_t)furi_semaphore_release((FuriSemaphore*)semaphore_id);
840static FURI_ALWAYS_INLINE osStatus_t osSemaphoreDelete(osSemaphoreId_t semaphore_id) {
841 furi_semaphore_free((FuriSemaphore*)semaphore_id);
904static FURI_ALWAYS_INLINE osMessageQueueId_t
907 return (osMessageQueueId_t)furi_message_queue_alloc(msg_count, msg_size);
922static FURI_ALWAYS_INLINE osStatus_t osMessageQueuePut(
923 osMessageQueueId_t mq_id,
928 return (osStatus_t)furi_message_queue_put((FuriMessageQueue*)mq_id, msg_ptr, timeout);
938static FURI_ALWAYS_INLINE osStatus_t osMessageQueueGet(
939 osMessageQueueId_t mq_id,
944 return (osStatus_t)furi_message_queue_get((FuriMessageQueue*)mq_id, msg_ptr, timeout);
976static FURI_ALWAYS_INLINE osStatus_t osMessageQueueDelete(osMessageQueueId_t mq_id) {
977 furi_message_queue_free((FuriMessageQueue*)mq_id);
Definition cmsis_os2.h:280
Attributes structure for event flags.
Definition cmsis_os2.h:301
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:303
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:305
const char * name
name of the event flags
Definition cmsis_os2.h:302
void * cb_mem
memory for control block
Definition cmsis_os2.h:304
Attributes structure for message queue.
Definition cmsis_os2.h:335
const char * name
name of the message queue
Definition cmsis_os2.h:336
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:337
void * cb_mem
memory for control block
Definition cmsis_os2.h:338
uint32_t mq_size
size of provided memory for data storage
Definition cmsis_os2.h:341
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:339
void * mq_mem
memory for data storage
Definition cmsis_os2.h:340
Attributes structure for mutex.
Definition cmsis_os2.h:309
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:313
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:311
const char * name
name of the mutex
Definition cmsis_os2.h:310
void * cb_mem
memory for control block
Definition cmsis_os2.h:312
Attributes structure for semaphore.
Definition cmsis_os2.h:317
const char * name
name of the semaphore
Definition cmsis_os2.h:318
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:319
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:321
void * cb_mem
memory for control block
Definition cmsis_os2.h:320
Attributes structure for thread.
Definition cmsis_os2.h:268
void * cb_mem
memory for control block
Definition cmsis_os2.h:271
uint32_t reserved
reserved (must be 0)
Definition cmsis_os2.h:277
TZ_ModuleId_t tz_module
TrustZone module identifier.
Definition cmsis_os2.h:276
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:270
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:272
void * stack_mem
memory for stack
Definition cmsis_os2.h:273
osPriority_t priority
initial thread priority (default: osPriorityNormal)
Definition cmsis_os2.h:275
uint32_t stack_size
size of stack
Definition cmsis_os2.h:274
const char * name
name of the thread
Definition cmsis_os2.h:269
Attributes structure for timer.
Definition cmsis_os2.h:293
void * cb_mem
memory for control block
Definition cmsis_os2.h:296
const char * name
name of the timer
Definition cmsis_os2.h:294
uint32_t attr_bits
attribute bits
Definition cmsis_os2.h:295
uint32_t cb_size
size of provided memory for control block
Definition cmsis_os2.h:297