/*
  初始化

  线程都需要在此处配置任务句柄 队列ID等等 
  要在user_task.h中定义一系列参数 其中各个线程的属性在user_task.c中定

*/

/* Includes ----------------------------------------------------------------- */
#include "Device\bmi088.h"
#include "task\user_task.h"
#include "can_use.h"
#include "cmd.h"

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

/**
 * \brief 初始 在此函数中可以初始化任务，队列，信号量等，初始化完成后，自己删除自己
 *
 * \param argument 未使用参数传递
 */
void Task_Init(void *argument) {
  (void)argument; 
////  
  Config_Get(&task_runtime.config);
	
  osKernelLock();
  /* 任务*/
  task_runtime.thread.atti_esti =
      osThreadNew(Task_AttiEsti, NULL, &attr_atti_esti);
	task_runtime.thread.chassis =
      osThreadNew(Task_Chassis, NULL, &attr_chassis);
	task_runtime.thread.rc =
      osThreadNew(Task_rc,NULL,&attr_rc);

  task_runtime.thread.can =
      osThreadNew(Task_can,NULL,&attr_can);
  task_runtime.thread.cmd =
      osThreadNew(Task_cmd,NULL,&attr_cmd);
  task_runtime.thread.nuc =
      osThreadNew(Task_nuc,NULL,&attr_nuc);
	task_runtime.thread.up=
      osThreadNew(Task_up,NULL,&attr_up);
		
	task_runtime.thread.error_detect =
	    osThreadNew(Task_error_detect,NULL,&attr_error_detect);

  /* 消息队列 */
    /* can */			

	task_runtime.msgq.can.feedback.UP_CAN_feedback  = 
	    osMessageQueueNew(2u, sizeof(CAN_t), NULL);   
	task_runtime.msgq.can.feedback.CHASSIS_CAN_feedback  = 
	    osMessageQueueNew(2u, sizeof(CAN_t), NULL); 			
	task_runtime.msgq.can.output.chassis3508 = 
	    osMessageQueueNew(2u, sizeof(CAN_DJIOutput_t), NULL);
	task_runtime.msgq.can.output.up_shoot_3508 = 
	    osMessageQueueNew(2u, sizeof(CAN_DJIOutput_t), NULL);
	task_runtime.msgq.can.output.up_dribble_3508 = 
	    osMessageQueueNew(2u, sizeof(CAN_DJIOutput_t), NULL);



	/* imu */
   task_runtime.msgq.imu.accl =
      osMessageQueueNew(2u, sizeof(AHRS_Accl_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);
	
		/*cmd */
   task_runtime.msgq.cmd.raw.rc =
      osMessageQueueNew(3u, sizeof(CMD_RC_t), NULL);
			
	 task_runtime.msgq.cmd.UP_cmd_ctrl_t =
	    osMessageQueueNew(3u, sizeof(CMD_t), NULL);
	 task_runtime.msgq.cmd.CHASSIS_cmd_ctrl_t =
	    osMessageQueueNew(3u, sizeof(CMD_t), NULL);	
	
   task_runtime.msgq.cmd.raw.nuc =
      osMessageQueueNew(3u,sizeof(CMD_NUC_t), NULL);	 
   task_runtime.msgq.cmd.raw.nuc_send =
	    osMessageQueueNew(3u,sizeof(NUC_send_t), NULL);	
			
  osKernelUnlock();
  osThreadTerminate(osThreadGetId()); /* 结束自身 */
}
