/* 初始化任务 根据机器人的FLASH配置,决定生成哪些任务。 */ /* Includes ----------------------------------------------------------------- */ #include "task\user_task.h" /* Private typedef ---------------------------------------------------------- */ /* Private define ----------------------------------------------------------- */ /* Private macro ------------------------------------------------------------ */ /* Private variables -------------------------------------------------------- */ osMessageQueueId_t adcQueueHandle; osMessageQueueId_t pcQueueHandle; /* Private function --------------------------------------------------------- */ /* Exported functions ------------------------------------------------------- */ /** * \brief 初始化 * * \param argument 未使用 */ void Task_Init(void *argument) { (void)argument; /* 未使用argument,消除警告 */ osKernelLock(); // 锁定内核,防止任务切换 // 创建任务,确保任务创建成功 osThreadId_t monitorTaskHandle = osThreadNew(Task_Monitor, NULL, &attr_monitor); osThreadId_t adcReadTaskHandle = osThreadNew(Task_Adc, NULL, &attr_adc); osThreadId_t canTaskHandle = osThreadNew(Task_Can, NULL, &attr_can); osThreadId_t pcTaskHandle = osThreadNew(Task_PC, NULL, &attr_pc); //创建消息队列 adcQueueHandle = osMessageQueueNew(2u, sizeof(uint16_t), NULL); pcQueueHandle = osMessageQueueNew(2u, sizeof(uint16_t), NULL); osKernelUnlock(); // 解锁内核 osThreadTerminate(osThreadGetId()); // 任务完成后结束自身 }