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

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

/* USER INCLUDE BEGIN */
#include "device/dr16.h"
 #include "device/ledi.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 */

    /* USER CODE INIT END */
  osKernelLock(); /* 锁定内核，防止任务切换 */
  
  /* 创建任务线程 */
 task_runtime.thread.Task1 = osThreadNew(Task_Task1, NULL, &attr_Task1);
  task_runtime.thread.Task2 = osThreadNew(Task_Task2, NULL, &attr_Task2);
 task_runtime.thread.Task3 = osThreadNew(Task_Task3, NULL, &attr_Task3);
 task_runtime.thread.Task4 = osThreadNew(Task_Task4, NULL, &attr_Task4);
 task_runtime.thread.Task5 = osThreadNew(Task_Task5, NULL, &attr_Task5);

  // 创建消息队列
  /* USER MESSAGE BEGIN */
  task_runtime.msgq.user_msg= osMessageQueueNew(2u, 10, NULL);
  task_runtime.msgq.dr16_data = osMessageQueueNew(2u, sizeof(LD_t), NULL);
  task_runtime.msgq.imu.eulr = osMessageQueueNew(2u, sizeof(AHRS_Eulr_t), NULL);
  task_runtime.msgq.imu.gyro = osMessageQueueNew(2u, sizeof(AHRS_Gyro_t), NULL); 
   task_runtime.msgq.cmd_chassis= osMessageQueueNew(2u,sizeof(Chassis_CMD_t),NULL);
  
  /* USER MESSAGE END */

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