/*
    Init Task
    任务初始化，创建各个线程任务和消息队列
*/

/* Includes ----------------------------------------------------------------- */
#include "task/user_task.h"

/* USER INCLUDE BEGIN */
#include "bsp/can.h"
/* USER INCLUDE END */

/* Private typedef ---------------------------------------------------------- */
/* Private define ----------------------------------------------------------- */
/* Private macro ------------------------------------------------------------ */
/* Private variables -------------------------------------------------------- */
/* Private function --------------------------------------------------------- */
/* Exported functions ------------------------------------------------------- */

/**
 * \brief 初始化
 *
 * \param argument 未使用
 */
void Task_Init(void *argument) {
  (void)argument; /* 未使用argument，消除警告 */
    /* USER CODE INIT BEGIN */
    BSP_CAN_Init();
    /* USER CODE INIT END */
  osKernelLock(); /* 锁定内核，防止任务切换 */
  
  /* 创建任务线程 */
  task_runtime.thread.atti_esit = osThreadNew(Task_atti_esit, NULL, &attr_atti_esit);
  task_runtime.thread.ctrl_chassis = osThreadNew(Task_ctrl_chassis, NULL, &attr_ctrl_chassis);
  task_runtime.thread.blink = osThreadNew(Task_blink, NULL, &attr_blink);
  task_runtime.thread.monitor = osThreadNew(Task_monitor, NULL, &attr_monitor);
  task_runtime.thread.ctrl_arm = osThreadNew(Task_ctrl_arm, NULL, &attr_ctrl_arm);
  task_runtime.thread.rc = osThreadNew(Task_rc, NULL, &attr_rc);

  // 创建消息队列
  /* USER MESSAGE BEGIN */
  task_runtime.msgq.user_msg= osMessageQueueNew(2u, 10, NULL);
  /* USER MESSAGE END */

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