/*
  初始化任务

  根据机器人的FLASH配置，决定生成哪些任务。
*/

/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"
#include "device/ads8864.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(); // 锁定内核，防止任务切换

  // 创建任务，确保任务创建成功
  task_runtime.thread.adc = osThreadNew(Task_Adc, NULL, &attr_adc);
  task_runtime.thread.can = osThreadNew(Task_Can, NULL, &attr_can);
  task_runtime.thread.monitor = osThreadNew(Task_Monitor, NULL, &attr_monitor);
  task_runtime.thread.pc = osThreadNew(Task_PC, NULL, &attr_pc);

  //创建消息队列
  task_runtime.msgq.adc =osMessageQueueNew(2u, sizeof(Ads8864_Filtered_t), NULL);
  task_runtime.msgq.can = osMessageQueueNew(2u, sizeof(Ads8864_Filtered_t), NULL);
  task_runtime.msgq.pc = osMessageQueueNew(2u, sizeof(float), NULL);

  osKernelUnlock(); // 解锁内核
  osThreadTerminate(osThreadGetId()); // 任务完成后结束自身
}

