13 #include "cmsis_os2.h"
21 osThreadAttr_t task_attribs = {.tz_module = 1};
25 task_attribs.stack_size = stack_size;
27 task_attribs.name = name;
28 task_attribs.priority = (osPriority_t) priority;
30 return (
void *)osThreadNew(func, arg, &task_attribs);
36 osSemaphoreAttr_t sema_attrib = {0};
38 sema_attrib.name = name;
40 return (
void *)osSemaphoreNew(max_count, initial_count, &sema_attrib);
47 status = osSemaphoreAcquire((osSemaphoreId_t)handle,
49 osWaitForever : timeout);
61 status = osSemaphoreRelease((osSemaphoreId_t)handle);
73 status = osSemaphoreDelete((osSemaphoreId_t)handle);
83 const osMutexAttr_t attr = {
85 .attr_bits = osMutexPrioInherit,
95 return (
void *)osMutexNew(&attr);
100 osStatus_t status = osOK;
106 status = osMutexAcquire((osMutexId_t)handle,
108 osWaitForever : timeout);
109 if (status != osOK) {
118 osStatus_t status = osOK;
124 status = osMutexRelease((osMutexId_t)handle);
125 if (status != osOK) {
134 osStatus_t status = osOK;
140 status = osMutexDelete((osMutexId_t)handle);
141 if (status != osOK) {
150 return (
void *)osThreadGetId();
157 prio = osThreadGetPriority((osThreadId_t)handle);
158 if (prio == osPriorityError) {
162 *priority = (uint32_t)prio;
176 ret = osThreadFlagsSet((osThreadId_t)handle, flags);
177 if (ret & osFlagsError) {
192 ret = osThreadFlagsSet((osThreadId_t)handle, flags);
193 if (ret & osFlagsError) {
204 ret = osThreadFlagsWait(flags, osFlagsWaitAll,
206 osWaitForever : timeout);
207 if (ret & osFlagsError) {
216 return osKernelGetTickCount();
uint32_t os_wrapper_mutex_delete(void *handle)
Deletes a mutex that is created by os_wrapper_mutex_create()
uint32_t os_wrapper_semaphore_delete(void *handle)
Deletes the semaphore.
void * os_wrapper_thread_get_handle(void)
Gets current thread handle.
uint32_t os_wrapper_semaphore_acquire(void *handle, uint32_t timeout)
Acquires the semaphore.
void(* os_wrapper_thread_func)(void *argument)
#define OS_WRAPPER_DEFAULT_STACK_SIZE
uint32_t os_wrapper_thread_set_flag_isr(void *handle, uint32_t flags)
Set the event flags in an interrupt handler for synchronizing a thread specified by handle...
void os_wrapper_thread_exit(void)
Exits the calling thread.
uint32_t os_wrapper_thread_wait_flag(uint32_t flags, uint32_t timeout)
Wait for the event flags for synchronizing threads.
uint32_t os_wrapper_semaphore_release(void *handle)
Releases the semaphore.
#define OS_WRAPPER_WAIT_FOREVER
uint32_t os_wrapper_mutex_acquire(void *handle, uint32_t timeout)
Acquires a mutex that is created by os_wrapper_mutex_create()
uint32_t os_wrapper_thread_get_priority(void *handle, uint32_t *priority)
Gets thread priority.
void * os_wrapper_semaphore_create(uint32_t max_count, uint32_t initial_count, const char *name)
Creates a new semaphore.
void * os_wrapper_mutex_create(void)
Creates a mutex for mutual exclusion of resources.
#define OS_WRAPPER_SUCCESS
uint32_t os_wrapper_thread_set_flag(void *handle, uint32_t flags)
Set the event flags for synchronizing a thread specified by handle.
uint32_t os_wrapper_mutex_release(void *handle)
Releases the mutex acquired previously.
void * os_wrapper_thread_new(const char *name, int32_t stack_size, os_wrapper_thread_func func, void *arg, uint32_t priority)
Creates a new thread.
uint32_t os_wrapper_get_tick(void)
Return RTOS current tick count.