CmsisRtosThreadUtils/CmsisRtosThreadUtils.c

74 lines
1.7 KiB
C

//
// Created by xemon on 23.11.22.
//
#include "CmsisRtosThreadUtils.h"
void InitThreadAtr(
osThreadAttr_t *attr,
const char *name, ///< name of the thread
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)
) {
attr->name = name;
attr->cb_mem = cb_mem;
attr->cb_size = cb_size;
attr->stack_mem = stack_mem;
attr->stack_size = stack_size;
attr->priority = priority;
attr->tz_module = 0;
attr->reserved = 0;
}
void InitQueueAtr(
osMessageQueueAttr_t *attr,
const char *name, ///< name of the thread
void *cb_mem, ///< memory for control block
uint32_t cb_size, ///< size of provided memory for control block
void *mem, ///< memory for data
uint32_t mem_size ///< size of mem
) {
attr->name = name;
attr->cb_mem = cb_mem;
attr->cb_size = cb_size;
attr->mq_mem = mem;
attr->mq_size = mem_size;
}
void utils_thread_block_start(void *env, osThreadId_t *id, osThreadAttr_t *attr, osThreadFunc_t func) {
if (!*id) {
*id = osThreadNew((osThreadFunc_t) func, (void *) (env), attr);
} else {
osThreadResume(*id);
}
}
void utils_thread_block_pause(osThreadId_t id) {
if (id) {
osThreadSuspend(id);
}
}
void utils_thread_block_stop(osThreadId_t *id) {
if (*id) {
if (osThreadTerminate(*id) == osOK) {
*id = NULL;
}
}
}