diff --git a/User/task/init.c b/User/task/init.c deleted file mode 100644 index 2b3a65c..0000000 --- a/User/task/init.c +++ /dev/null @@ -1,33 +0,0 @@ -/* - 初始化任务 -*/ - -/* Includes ----------------------------------------------------------------- */ -#include "task\user_task.h" -/* Private typedef ---------------------------------------------------------- */ -/* Private define ----------------------------------------------------------- */ -/* Private macro ------------------------------------------------------------ */ -/* Private variables -------------------------------------------------------- */ -/* Private function --------------------------------------------------------- */ -/* Exported functions ------------------------------------------------------- */ - -/** - * \brief 初始化 - * - * \param argument 未使用 - */ -void Task_Init(void *argument) { - (void)argument; /* 未使用argument,消除警告 */ - - osKernelLock(); // 锁定内核,防止任务切换 - - // 创建线程 -{{thread_creation_code}} - - // 创建消息队列 - task_runtime.msgq.user_msg= osMessageQueueNew(2u, 10, NULL); - - osKernelUnlock(); // 解锁内核 - osThreadTerminate(osThreadGetId()); // 任务完成后结束自身 -} - diff --git a/User/task/init.c.template b/User/task/init.c.template index 425314a..2b3a65c 100644 --- a/User/task/init.c.template +++ b/User/task/init.c.template @@ -3,7 +3,7 @@ */ /* Includes ----------------------------------------------------------------- */ -#include "task\\user_task.h" +#include "task\user_task.h" /* Private typedef ---------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */ /* Private macro ------------------------------------------------------------ */ diff --git a/User/task/task.c b/User/task/task.c deleted file mode 100644 index 71af011..0000000 --- a/User/task/task.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - {{task_name}} Task -*/ - -/* Includes ----------------------------------------------------------------- */ -#include "task\user_task.h" - -/* Private typedef ---------------------------------------------------------- */ -/* Private define ----------------------------------------------------------- */ -/* Private macro ------------------------------------------------------------ */ -/* Private variables -------------------------------------------------------- */ -/* Private function --------------------------------------------------------- */ -/* Exported functions ------------------------------------------------------- */ - -/** - * \brief {{task_name}} Task - * - * \param argument 未使用 - */ -void {{task_function}}(void *argument) { - (void)argument; /* 未使用argument,消除警告 */ - - /* 计算任务运行到指定频率需要等待的tick数 */ - const uint32_t delay_tick = osKernelGetTickFreq() / {{task_frequency}}; - - osDelay({{task_delay}}); /* 延时一段时间再开启任务 */ - - uint32_t tick = osKernelGetTickCount(); /* 控制任务运行频率的计时 */ - while (1) { - /* 记录任务所使用的的栈空间 */ - task_runtime.stack_water_mark.{{task_variable}} = osThreadGetStackSpace(osThreadGetId()); - - tick += delay_tick; /* 计算下一个唤醒时刻 */ - - /*User code begin*/ - - /*User code end*/ - - osDelayUntil(tick); /* 运行结束,等待下一次唤醒 */ - } -} \ No newline at end of file diff --git a/User/task/user_task.c b/User/task/user_task.c deleted file mode 100644 index 7eac562..0000000 --- a/User/task/user_task.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "task/user_task.h" - -Task_Runtime_t task_runtime; - -const osThreadAttr_t attr_init = { - .name = "Task_Init", - .priority = osPriorityRealtime, - .stack_size = 256 * 4, -}; - -//用户自定义任务 - -const osThreadAttr_t attr_user_task = { - .name = "Task_User", - .priority = osPriorityRealtime, - .stack_size = 128 * 4, -}; diff --git a/User/task/user_task.c.template b/User/task/user_task.c.template index d71b245..0e4ee69 100644 --- a/User/task/user_task.c.template +++ b/User/task/user_task.c.template @@ -1,4 +1,4 @@ -#include "task/user_task.h" +#include "task\user_task.h" Task_Runtime_t task_runtime; diff --git a/User/task/user_task.h b/User/task/user_task.h deleted file mode 100644 index 06e0712..0000000 --- a/User/task/user_task.h +++ /dev/null @@ -1,67 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "FreeRTOS.h" -#include "task.h" - -// 定义任务运行时结构体 -typedef struct { - /* 各任务,也可以叫做线程 */ - struct { - osThreadId_t user_task; - } thread; - - struct { - osMessageQueueId_t pc; - } msgq; - - - struct { - uint32_t user_task; - } heap_water_mark; /* heap使用 */ - - struct { - float user_task; /* 用户自定义任务运行频率 */ - } freq; /* 任务运行频率 */ - - struct { - uint32_t user_task; - } last_up_time; /* 任务最近运行时间 */ - } Task_Runtime_t; - - - -// 任务频率和初始化延时 -#define TASK_FREQ_USER_TASK (100u) // 用户自定义任务频率 - - -#define TASK_INIT_DELAY_INFO (100u) - -// 任务句柄 -typedef struct { - osThreadId_t user_task; /* 用户自定义任务 */ -} Task_Handles_t; - -// 任务运行时结构体 -extern Task_Runtime_t task_runtime; - -// 初始化任务句柄 -extern const osThreadAttr_t attr_init; - -// 用户自定义任务句柄 -extern const osThreadAttr_t attr_user_task - -// 任务函数声明 -//初始化任务 -void Task_Init(void *argument); -//用户自定义任务 -void Task_UserTask(void *argument); - - -#ifdef __cplusplus -} -#endif