Начало

This commit is contained in:
cfif 2025-09-23 17:12:43 +03:00
commit 80e851b00f
3 changed files with 166 additions and 0 deletions

74
CmsisRtosThreadUtils.c Normal file
View File

@ -0,0 +1,74 @@
//
// 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;
}
}
}

75
CmsisRtosThreadUtils.h Normal file
View File

@ -0,0 +1,75 @@
//
// Created by xemon on 08.09.22.
//
#ifndef CMSISRTOSTHREADSUTILS_CMSISRTOSTHREADSUTILS_H
#define CMSISRTOSTHREADSUTILS_CMSISRTOSTHREADSUTILS_H
#include "cmsis_os.h"
typedef struct {
osThreadId_t id;
StaticTask_t controlBlock;
} tThreadData;
#define tStaticThreadBlock(WORDS_LEN) struct { osThreadId_t id; osThreadAttr_t attr; StaticTask_t controlBlock; uint32_t stack[WORDS_LEN]; }
#define tStaticThreadDynBlock struct { osThreadId_t id; osThreadAttr_t attr; }
#define THREAD_ATTR_CREATE(PRIORITY, TASK_NAME) osThreadAttr_t TASK_NAME##TaskAttr ={ \
.name = #TASK_NAME, \
.cb_mem = &threads.TASK_NAME.controlBlock, \
.cb_size = sizeof(threads.TASK_NAME.controlBlock), \
\
.stack_mem = &threadsBuffers.TASK_NAME[0], \
.stack_size = sizeof(threadsBuffers.TASK_NAME), \
\
.priority = (osPriority_t) (PRIORITY) \
}
#define THREAD_ADD(THREAD_NAME, ENV, FUNC) threads.THREAD_NAME.id = osThreadNew((osThreadFunc_t)(FUNC), (void *) (ENV), &THREAD_NAME##TaskAttr)
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)
);
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
);
#define InitThreadAtrStatic(ATTR, NAME, CB, STACK, PRIOR) InitThreadAtr(ATTR,NAME,&CB,sizeof(CB),STACK,sizeof(STACK),PRIOR)
#define InitQueueAtrStatic(ATTR, NAME, CB, MEM) InitQueueAtr(ATTR,NAME,&CB,sizeof(CB),MEM,sizeof(MEM))
#define InitThreadBlock(BLOCK, NAME, PRIOR) (BLOCK).id = 0; InitThreadAtr(&(BLOCK).attr,NAME,&(BLOCK).controlBlock,sizeof((BLOCK).controlBlock),(BLOCK).stack,sizeof((BLOCK).stack),PRIOR)
#define InitThreadDynBlock(BLOCK, NAME, STACK, PRIOR) (BLOCK).id = 0; InitThreadAtr(&(BLOCK).attr,NAME,NULL,0,NULL,STACK,PRIOR)
void utils_thread_block_start(void *env, osThreadId_t *id, osThreadAttr_t *attr, osThreadFunc_t func);
void utils_thread_block_pause(osThreadId_t id);
void utils_thread_block_stop(osThreadId_t *id);
#define ThreadBlock_Start(THREAD, ENV, FUNC) utils_thread_block_start(ENV,&(THREAD).id,&(THREAD).attr, (osThreadFunc_t)(FUNC))
#define ThreadBlock_Pause(THREAD) utils_thread_block_pause((THREAD).id)
#define ThreadBlock_Stop(THREAD) utils_thread_block_stop(&(THREAD).id)
#define PinThreadToCore(BLOCK, CORE) (BLOCK).attr.pinToCore = 1; (BLOCK).attr.core = CORE
#endif //CMSISRTOSTHREADSUTILS_CMSISRTOSTHREADSUTILS_H

17
modular.json Normal file
View File

@ -0,0 +1,17 @@
{
"dep": [
{
"type": "git",
"provider": "HVAC_DEV",
"repo": "CmsisRtosInterface"
}
],
"cmake": {
"inc_dirs": [
"./"
],
"srcs": [
"./*.c"
]
}
}