From 9236177b20f33aa5a674dfcbbc7966768d24eeb5 Mon Sep 17 00:00:00 2001 From: RB Date: Sun, 27 Apr 2025 14:16:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- User/task/init.c | 7 ++++--- User/task/init.c.template | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 User/task/init.c.template diff --git a/User/task/init.c b/User/task/init.c index 9f8f6e8..425314a 100644 --- a/User/task/init.c +++ b/User/task/init.c @@ -3,7 +3,7 @@ */ /* Includes ----------------------------------------------------------------- */ -#include "task\user_task.h" +#include "task\\user_task.h" /* Private typedef ---------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */ /* Private macro ------------------------------------------------------------ */ @@ -21,9 +21,10 @@ void Task_Init(void *argument) { osKernelLock(); // 锁定内核,防止任务切换 - task_runtime.thread.user_task = osThreadNew(Task_UserTask, NULL, &attr_user_task); + // 创建线程 +{{thread_creation_code}} - //创建消息队列 + // 创建消息队列 task_runtime.msgq.user_msg= osMessageQueueNew(2u, 10, NULL); osKernelUnlock(); // 解锁内核 diff --git a/User/task/init.c.template b/User/task/init.c.template new file mode 100644 index 0000000..425314a --- /dev/null +++ b/User/task/init.c.template @@ -0,0 +1,33 @@ +/* + 初始化任务 +*/ + +/* 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()); // 任务完成后结束自身 +} +