#pragma once

#ifdef __cplusplus
extern "C"
{
#endif
/* Includes ----------------------------------------------------------------- */
#include <cmsis_os2.h>
#include "FreeRTOS.h"
#include "task.h"

/* USER INCLUDE BEGIN */
#include "module/config.h"
#define DEBUG
/* USER INCLUDE END */
/* Exported constants ------------------------------------------------------- */
/* 任务运行频率 */
#define TASK1_FREQ (500.0)
#define TASK2_FREQ (500.0)
#define TASK3_FREQ (500.0)
#define TASK4_FREQ (500.0)
#define TASK5_FREQ (500.0)

/* 任务初始化延时ms */
#define TASK_INIT_DELAY (100u)
#define TASK1_INIT_DELAY (0)
#define TASK2_INIT_DELAY (0)
#define TASK3_INIT_DELAY (0)
#define TASK4_INIT_DELAY (0)
#define TASK5_INIT_DELAY (0)

    /* Exported defines --------------------------------------------------------- */
    /* Exported macro ----------------------------------------------------------- */
    /* Exported types ----------------------------------------------------------- */

    /* 任务运行时结构体 */
    typedef struct
    {
        /* 各任务，也可以叫做线程 */
        struct
        {
            osThreadId_t Task1;
            osThreadId_t Task2;
            osThreadId_t Task3;
            osThreadId_t Task4;
            osThreadId_t Task5;
        } thread;

        /* USER MESSAGE BEGIN */
        struct
        {
            osMessageQueueId_t user_msg;    /* 用户自定义任务消息队列 */
            osMessageQueueId_t dr16_data;   /* dr16遥控器数据 */
            osMessageQueueId_t cmd_chassis; /*发送给底盘遥控器数据*/

            struct
            {
                osMessageQueueId_t accl; /* IMU读取 */
                osMessageQueueId_t gyro; /* IMU读取 */
                osMessageQueueId_t eulr; /* 姿态解算得到的欧拉规1�7 */
            } imu;
            struct
            {
                osMessageQueueId_t chassis6020;
                osMessageQueueId_t chassis5065;
                osMessageQueueId_t chassis3508;
                osMessageQueueId_t pitch6020;
            } output;
            struct
            {
                osMessageQueueId_t chassisfed6020;
                osMessageQueueId_t chassisfed3508;
                osMessageQueueId_t pitchfed6020;
            } feedback;

        } msgq;
        /* USER MESSAGE END */

        /* 机器人状态 */
        struct
        {
            float battery;  /* 电池电量百分比 */
            float vbat;     /* 电池电压 */
            float cpu_temp; /* CPU温度 */
        } status;

        /* USER CONFIG BEGIN */

        Config_t config;
        /* USER CONFIG END */

        /* 各任务的stack使用 */
        struct
        {
            UBaseType_t Task1;
            UBaseType_t Task2;
            UBaseType_t Task3;
            UBaseType_t Task4;
            UBaseType_t Task5;
        } stack_water_mark;

        /* 各任务运行频率 */
        struct
        {
            float Task1;
            float Task2;
            float Task3;
            float Task4;
            float Task5;
        } freq;

        /* 任务最近运行时间 */
        struct
        {
            float Task1;
            float Task2;
            float Task3;
            float Task4;
            float Task5;
        } last_up_time;

    } Task_Runtime_t;

    /* 任务运行时结构体 */
    extern Task_Runtime_t task_runtime;

    /* 初始化任务句柄 */
    extern const osThreadAttr_t attr_init;
    extern const osThreadAttr_t attr_Task1;
    extern const osThreadAttr_t attr_Task2;
    extern const osThreadAttr_t attr_Task3;
    extern const osThreadAttr_t attr_Task4;
    extern const osThreadAttr_t attr_Task5;

    /* 任务函数声明 */
    void Task_Init(void *argument);
    void Task_Task1(void *argument);
    void Task_Task2(void *argument);
    void Task_Task3(void *argument);
    void Task_Task4(void *argument);
    void Task_Task5(void *argument);

#ifdef __cplusplus
}
#endif