Просмотр исходного кода

1.预加热UI页面获取的值改为直接从EEPROM中获取
2.重构各个任务的架构

zhanghongyi 2 месяцев назад
Родитель
Сommit
4db2b52982

+ 22 - 0
App/Inc/App_cpld.h

@@ -0,0 +1,22 @@
+/**
+  ******************************************************************************
+  * @file    App_cpld.h
+  * @brief   CPLD 通信任务 (App 应用层)
+  ******************************************************************************
+  */
+#ifndef __APP_CPLD_H
+#define __APP_CPLD_H
+
+#include "FreeRTOS.h"
+#include "task.h"
+
+extern TaskHandle_t xCPLDProcessTaskHandle;
+
+/**
+ * @brief  创建 CPLD 通信任务
+ * @param  无
+ * @return 无
+ */
+void App_cpld_task_create(void);
+
+#endif /* __APP_CPLD_H */

+ 22 - 0
App/Inc/App_display.h

@@ -0,0 +1,22 @@
+/**
+  ******************************************************************************
+  * @file    App_display.h
+  * @brief   LVGL 显示任务 (App 应用层)
+  ******************************************************************************
+  */
+#ifndef __APP_DISPLAY_H
+#define __APP_DISPLAY_H
+
+#include "FreeRTOS.h"
+#include "task.h"
+
+extern TaskHandle_t xLVGLDisplayTaskHandle;
+
+/**
+ * @brief  创建 LVGL 显示任务
+ * @param  无
+ * @return 无
+ */
+void App_display_task_create(void);
+
+#endif /* __APP_DISPLAY_H */

+ 0 - 16
App/Inc/App_freertosTask.h

@@ -1,16 +0,0 @@
-#ifndef __APP_FREERTOS_TASK_H
-#define __APP_FREERTOS_TASK_H
-
-#include "FreeRTOS.h"
-#include "task.h"
-
-extern TaskHandle_t xCPLDProcessTaskHandle;
-extern TaskHandle_t xLVGLDisplayTaskHandle;
-extern TaskHandle_t xTestTaskHandle;
-
-void App_Task_Create(void);
-void Task_CPLD_Process(void *argument);
-void Task_LVGL_Display(void *argument);
-void Task_Test(void *argument);
-
-#endif

+ 24 - 0
App/Inc/App_main.h

@@ -0,0 +1,24 @@
+/**
+  ******************************************************************************
+  * @file    App_main.h
+  * @brief   App 应用层任务编排接口
+  *
+  * @note    任务总览 (FreeRTOS 数字越大优先级越高):
+  *          | 任务名           | 模块         | prio | 栈(words) | 周期       |
+  *          | cpldProcessTask  | App_cpld     | 4    | 512       | 1s         |
+  *          | lvglDisplayTask  | App_display  | 3    | 2048      | 5ms 循环   |
+  *          | preheatTask      | App_preheat  | 2    | 512       | 200ms      |
+  ******************************************************************************
+  */
+#ifndef __APP_MAIN_H
+#define __APP_MAIN_H
+
+/**
+ * @brief  创建全部应用任务
+ * @note   在 vTaskStartScheduler() 之前调用一次
+ * @param  无
+ * @return 无
+ */
+void App_Task_Create(void);
+
+#endif /* __APP_MAIN_H */

+ 55 - 0
App/Inc/App_preheat.h

@@ -0,0 +1,55 @@
+/**
+  ******************************************************************************
+  * @file    App_preheat.h
+  * @brief   预加热控制任务接口 (App 应用层)
+  *
+  * @note    屏端 (UI) 与上位机 (预留) 是统一命令的"生产者", 经队列集汇聚后
+  *          由 Task_Preheat 统一按状态机处理, 控制逻辑相同, 仅来源实现不同。
+  ******************************************************************************
+  */
+#ifndef __APP_PREHEAT_H
+#define __APP_PREHEAT_H
+
+#include <stdint.h>
+#include "FreeRTOS.h"
+#include "task.h"
+
+extern TaskHandle_t xPreheatTaskHandle;
+
+/* 预加热控制命令 */
+typedef enum
+{
+    APP_PREHEAT_CMD_START = 0,   /* 开始预加热 (携带目标温度) */
+    APP_PREHEAT_CMD_STOP         /* 停止/取消预加热 */
+} app_preheat_cmd_e;
+
+/* 命令来源 */
+typedef enum
+{
+    APP_PREHEAT_SRC_UI = 0,      /* 屏幕 (UI 页面) */
+    APP_PREHEAT_SRC_UPPER        /* 上位机 (预留) */
+} app_preheat_src_e;
+
+/* 统一命令结构 */
+typedef struct
+{
+    app_preheat_cmd_e type;      /* 命令类型 */
+    app_preheat_src_e src;       /* 命令来源 */
+    int16_t           target;    /* START 时携带的目标温度 (°C) */
+} app_preheat_cmd_t;
+
+/**
+ * @brief  创建预加热任务 (含队列集初始化)
+ * @param  无
+ * @return 无
+ */
+void App_preheat_task_create(void);
+
+/**
+ * @brief  发送控制命令 (生产者接口: 屏端/上位机共用)
+ * @param  cmd : 命令结构体指针
+ * @return pdPASS 成功, pdFAIL 失败 (队列满或参数非法)
+ */
+BaseType_t App_preheat_send_cmd(app_preheat_cmd_t *cmd);
+
+#endif /* __APP_PREHEAT_H */

+ 72 - 0
App/Src/App_cpld.c

@@ -0,0 +1,72 @@
+/**
+  ******************************************************************************
+  * @file    App_cpld.c
+  * @brief   CPLD 通信任务 (App 应用层)
+  *
+  * 主机角色: 周期组装 SET_ALL(0x01) 帧并经 USART3(921600) 下发,
+  *           payload 取 Mid 层共享输出缓冲 (24 PTC + 8 FAN)。
+  * 注: SET_ALL 同时作为 30s 看门狗喂狗报文。
+  ******************************************************************************
+  */
+#include <stdio.h>
+#include "App_cpld.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "Com_protocol.h"
+#include "Com_usart3.h"
+#include "Mid_pid.h"
+
+/* 任务参数 (数字越大优先级越高) */
+#define TASK_CPLD_PRIORITY      4
+#define TASK_CPLD_STACK_SIZE    512
+
+/* CPLD 控制周期: 1s 定期下发; 远小于 CPLD 30s 无通讯超时 */
+#define CPLD_SEND_PERIOD_MS     1000
+
+TaskHandle_t xCPLDProcessTaskHandle = NULL;
+
+/**
+ * @brief  CPLD 通信任务体: 周期组装并下发 SET_ALL 帧
+ * @note   在任务上下文完成 Mid_PID_Init() (软复位后依赖 PID 数据表初始化);
+ *         SET_ALL 兼作 CPLD 看门狗喂狗报文 (30s 超时)。
+ * @param  argument : 任务入参 (未使用)
+ * @return 无 (任务不可返回)
+ */
+static void Task_CPLD_Process(void *argument)
+{
+    (void)argument;
+    uint8_t frame[COM_PROTOCOL_FRAME_MAX_LEN];
+    uint16_t flen;
+
+    printf("CPLD process task running...\r\n");
+
+    Mid_PID_Init();
+
+    while (1)
+    {
+        flen = Com_protocol_set_all(Mid_PID_GetOutputDuty(), frame);
+        if (flen > 0)
+        {
+            Com_usart3_send(frame, flen);
+        }
+        vTaskDelay(pdMS_TO_TICKS(CPLD_SEND_PERIOD_MS));
+    }
+}
+
+/**
+ * @brief  创建 CPLD 通信任务
+ * @note   在 vTaskStartScheduler() 之前调用一次; 句柄存于 xCPLDProcessTaskHandle。
+ * @param  无
+ * @return 无
+ */
+void App_cpld_task_create(void)
+{
+    BaseType_t ret;
+
+    ret = xTaskCreate(Task_CPLD_Process, "cpldProcessTask", TASK_CPLD_STACK_SIZE,
+                      NULL, TASK_CPLD_PRIORITY, &xCPLDProcessTaskHandle);
+    if (ret != pdPASS)
+    {
+        printf("[ERR] CPLD process task create failed\r\n");
+    }
+}

+ 85 - 0
App/Src/App_display.c

@@ -0,0 +1,85 @@
+/**
+  ******************************************************************************
+  * @file    App_display.c
+  * @brief   LVGL 显示任务 (App 应用层)
+  *
+  * 初始化 LVGL 内核/显示驱动/触摸, 创建主界面, 并周期驱动渲染。
+  ******************************************************************************
+  */
+#include <stdio.h>
+#include "App_display.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "lvgl.h"
+#include "lv_port_disp.h"
+#include "lv_port_indev.h"
+#include "Int_gt1151.h"
+#include "Ui.h"
+
+/* 任务参数 (数字越大优先级越高); LVGL 渲染/动画/触摸处理较重, 栈需较大 */
+#define TASK_LVGL_PRIORITY      3
+#define TASK_LVGL_STACK_SIZE    2048
+
+TaskHandle_t xLVGLDisplayTaskHandle = NULL;
+
+/**
+ * @brief  LVGL 显示任务体: 初始化渲染链并周期驱动 LVGL
+ * @note   初始化顺序有依赖: lv_init → 显示驱动 → 触摸 → indev → 主界面;
+ *         循环内 5ms 步进配合 LV_DISP_DEF_REFR_PERIOD(30ms) 完成刷新/动画/输入。
+ * @param  argument : 任务入参 (未使用)
+ * @return 无 (任务不可返回)
+ */
+static void Task_LVGL_Display(void *argument)
+{
+    (void)argument;
+    printf("LVGL display task running...\r\n");
+
+    /* LVGL 内核初始化 */
+    lv_init();
+
+    /* 注册显示驱动:LTDC + SDRAM 静态显存 + 双全屏缓冲 */
+    lv_port_disp_init();
+
+    /* 初始化 GT1151Q 电容触摸芯片 */
+    if (Int_gt1151_init() == 0)
+    {
+        printf("GT1151 Init OK\r\n");
+        /* 注册触摸输入设备 (注意: 需在 lv_init 之后、主循环 lv_timer_handler 之前) */
+        lv_port_indev_init();
+    }
+    else
+    {
+        printf("[ERR] GT1151 Init failed\r\n");
+    }
+
+    /* 创建工业设备主页 (UI 页面层) */
+    Ui_init();
+
+    /* 假数据: 设备就绪 */
+    Ui_set_ready(true);
+
+    while (1)
+    {
+        /* 周期驱动 LVGL(渲染/动画/输入),配合 LV_DISP_DEF_REFR_PERIOD 30ms */
+        lv_timer_handler();
+        vTaskDelay(pdMS_TO_TICKS(5));
+    }
+}
+
+/**
+ * @brief  创建 LVGL 显示任务
+ * @note   在 vTaskStartScheduler() 之前调用一次; 句柄存于 xLVGLDisplayTaskHandle。
+ * @param  无
+ * @return 无
+ */
+void App_display_task_create(void)
+{
+    BaseType_t ret;
+
+    ret = xTaskCreate(Task_LVGL_Display, "lvglDisplayTask", TASK_LVGL_STACK_SIZE,
+                      NULL, TASK_LVGL_PRIORITY, &xLVGLDisplayTaskHandle);
+    if (ret != pdPASS)
+    {
+        printf("[ERR] LVGL display task create failed\r\n");
+    }
+}

+ 0 - 144
App/Src/App_freertosTask.c

@@ -1,144 +0,0 @@
-#include "App_freertosTask.h"
-#include <stdio.h>
-
-#include "lvgl.h"
-#include "lv_port_disp.h"
-#include "lv_port_indev.h"
-#include "Int_gt1151.h"
-#include "Ui.h"
-#include "Com_usb_cdc.h"
-#include "Com_usart3.h"
-#include "Com_protocol.h"
-#include "Mid_pid.h"
-
-#define TASK_CPLD_PRIORITY          4
-#define TASK_CPLD_STACK_SIZE        512
-
-#define TASK_LVGL_PRIORITY          3
-#define TASK_LVGL_STACK_SIZE        2048
-
-#define TASK_TEST_PRIORITY          1
-#define TASK_TEST_STACK_SIZE        512
-
-/* CPLD 控制周期 ( 30s 超时; 1s 周期远小于它) */
-#define CPLD_SEND_PERIOD_MS         1000
-
-
-TaskHandle_t xCPLDProcessTaskHandle = NULL;
-TaskHandle_t xLVGLDisplayTaskHandle = NULL;
-TaskHandle_t xTestTaskHandle = NULL;
-
-/**
- * @brief 创建各个任务
- * 
- */
-void App_Task_Create(void)
-{
-    BaseType_t ret;
-
-    ret = xTaskCreate(Task_CPLD_Process, "cpldProcessTask", TASK_CPLD_STACK_SIZE, NULL, TASK_CPLD_PRIORITY, &xCPLDProcessTaskHandle);
-    if (ret != pdPASS)
-    {
-        printf("[ERR] CPLD process task create failed\r\n");
-    }
-
-    ret = xTaskCreate(Task_LVGL_Display, "lvglDisplayTask", TASK_LVGL_STACK_SIZE, NULL, TASK_LVGL_PRIORITY, &xLVGLDisplayTaskHandle);
-    if (ret != pdPASS)
-    {
-        printf("[ERR] LVGL display task create failed\r\n");
-    }
-
-    ret = xTaskCreate(Task_Test, "testTask", TASK_TEST_STACK_SIZE, NULL, TASK_TEST_PRIORITY, &xTestTaskHandle);
-    if (ret != pdPASS)
-    {
-        printf("[ERR] Test task create failed\r\n");
-    }
-}
-
-/**
- * @brief 处理 CPLD 通信的任务
- *
- * 主机角色: 周期组装 SET_ALL(0x01) 帧并经 USART3(921600) 下发,
- *           payload 取 Mid 层共享输出缓冲 (24 PTC + 8 FAN)。
- * 注: SET_ALL 同时作为 30s 看门狗喂狗报文。
- *
- * @param argument
- */
-void Task_CPLD_Process(void *argument)
-{
-    (void)argument;
-    uint8_t frame[COM_PROTOCOL_FRAME_MAX_LEN];
-    uint16_t flen;
-
-    printf("CPLD process task running...\r\n");
-
-    Mid_PID_Init();
-
-    while (1)
-    {
-        flen = Com_protocol_set_all(Mid_PID_GetOutputDuty(), frame);
-        if (flen > 0)
-        {
-            Com_usart3_send(frame, flen);
-        }
-        vTaskDelay(pdMS_TO_TICKS(CPLD_SEND_PERIOD_MS));
-    }
-}
-
-/**
- * @brief 处理 LVGL 显示的任务
- * 
- * @param argument 
- */
-void Task_LVGL_Display(void *argument)
-{
-    (void)argument;
-    printf("LVGL display task running...\r\n");
-
-    /* LVGL 内核初始化 */
-    lv_init();
-
-    /* 注册显示驱动:LTDC + SDRAM 静态显存 + 双全屏缓冲 */
-    lv_port_disp_init();
-
-    /* 初始化 GT1151Q 电容触摸芯片 */
-    if (Int_gt1151_init() == 0)
-    {
-        printf("GT1151 Init OK\r\n");
-        /* 注册触摸输入设备 (注意: 需在 lv_init 之后、主循环 lv_timer_handler 之前) */
-        lv_port_indev_init();
-    }
-    else
-    {
-        printf("[ERR] GT1151 Init failed\r\n");
-    }
-
-    /* 创建工业设备主页 (UI 页面层) */
-    Ui_init();
-
-    /* 假数据: 设备就绪 */
-    Ui_set_ready(true);
-
-    while (1)
-    {
-        /* 周期驱动 LVGL(渲染/动画/输入),配合 LV_DISP_DEF_REFR_PERIOD 30ms */
-        lv_timer_handler();
-        vTaskDelay(pdMS_TO_TICKS(5));
-    }
-}
-
-/**
- * @brief 处理测试的任务 (内容已清空, 预留)
- * 
- * @param argument 
- */
-void Task_Test(void *argument)
-{
-    (void)argument;
-    printf("Test task running...\r\n");
-
-    while (1)
-    {
-        vTaskDelay(pdMS_TO_TICKS(1000));
-    }
-}

+ 19 - 0
App/Src/App_main.c

@@ -0,0 +1,19 @@
+/**
+  ******************************************************************************
+  * @file    App_main.c
+  * @brief   App 应用层任务编排
+  *
+  * @note    仅负责依次创建各业务模块任务; 各任务实现与配置在其模块内自持。
+  ******************************************************************************
+  */
+#include "App_main.h"
+#include "App_cpld.h"
+#include "App_display.h"
+#include "App_preheat.h"
+
+void App_Task_Create(void)
+{
+    App_cpld_task_create();      /* prio4 周期下发 SET_ALL (兼 30s 喂狗) */
+    App_display_task_create();   /* prio3 LVGL 渲染/输入 */
+    App_preheat_task_create();   /* prio2 预加热状态机 */
+}

+ 196 - 0
App/Src/App_preheat.c

@@ -0,0 +1,196 @@
+/**
+  ******************************************************************************
+  * @file    App_preheat.c
+  * @brief   预加热控制任务 (App 应用层)
+  *
+  * @note    屏端 (UI) 与上位机命令经队列集 (UI 队列 / 上位机队列) 汇聚,
+  *          Task_Preheat 统一按命令驱动状态机:
+  *            IDLE    = 未预热
+  *            RUNNING = 预热中 (控制段为骨架占位, 后续接入
+  *                      设定加热块/风扇 → 读反馈温度 → 达标进入下一阶段)
+  ******************************************************************************
+  */
+#include <stdio.h>
+#include "App_preheat.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+
+/* 队列长度 */
+#define APP_PREHEAT_UI_QUEUE_LEN    4      /* 屏端命令队列 */
+#define APP_PREHEAT_UPPER_QUEUE_LEN 8      /* 上位机命令队列 (预留) */
+
+/* 队列集超时: 作为状态"控制周期步进"间隔 (ms) */
+#define APP_PREHEAT_PERIOD_MS       200
+
+/* 任务参数 */
+#define APP_PREHEAT_TASK_PRIORITY   2
+#define APP_PREHEAT_TASK_STACK      512
+
+/* 状态机 */
+#define PREHEAT_STATE_IDLE          0
+#define PREHEAT_STATE_RUNNING       1
+
+/* 队列集成员 */
+static QueueHandle_t     s_ui_q    = NULL;
+static QueueHandle_t     s_upper_q = NULL;
+static QueueSetHandle_t  s_qset    = NULL;
+
+TaskHandle_t xPreheatTaskHandle = NULL;
+
+/* 当前状态 */
+static uint8_t  s_state  = PREHEAT_STATE_IDLE;
+static int16_t  s_target = 0;
+
+/**
+ * @brief  START 命令处理
+ * @param  cmd : 来源命令
+ * @return 无
+ */
+static void preheat_handle_start(const app_preheat_cmd_t *cmd)
+{
+    s_target = cmd->target;
+    printf("[Preheat] start target=%d src=%d\r\n", (int)s_target, (int)cmd->src);
+    s_state = PREHEAT_STATE_RUNNING;
+}
+
+/**
+ * @brief  STOP 命令处理
+ * @param  cmd : 来源命令
+ * @return 无
+ */
+static void preheat_handle_stop(const app_preheat_cmd_t *cmd)
+{
+    printf("[Preheat] stop src=%d\r\n", (int)cmd->src);
+    s_state = PREHEAT_STATE_IDLE;
+}
+
+/**
+ * @brief  控制周期步进 (骨架占位)
+ * @note   后续接入: 设定加热块/风扇 → 等待反馈温度 → 达标进入下一阶段
+ * @param  无
+ * @return 无
+ */
+static void preheat_ctrl_step(void)
+{
+}
+
+static void App_preheat_init(void)
+{
+    if (s_qset != NULL)
+    {
+        return;
+    }
+
+    s_ui_q    = xQueueCreate(APP_PREHEAT_UI_QUEUE_LEN, sizeof(app_preheat_cmd_t));
+    s_upper_q = xQueueCreate(APP_PREHEAT_UPPER_QUEUE_LEN, sizeof(app_preheat_cmd_t));
+
+    s_qset = xQueueCreateSet((APP_PREHEAT_UI_QUEUE_LEN + APP_PREHEAT_UPPER_QUEUE_LEN)
+                             * sizeof(app_preheat_cmd_t));
+    if (s_qset == NULL)
+    {
+        printf("[ERR] Preheat queue-set create failed\r\n");
+        return;
+    }
+
+    if (s_ui_q != NULL)
+    {
+        xQueueAddToSet(s_ui_q, s_qset);
+    }
+    if (s_upper_q != NULL)
+    {
+        xQueueAddToSet(s_upper_q, s_qset);
+    }
+    printf("[OK] Preheat queue-set init\r\n");
+}
+
+BaseType_t App_preheat_send_cmd(app_preheat_cmd_t *cmd)
+{
+    BaseType_t ret;
+
+    if (cmd == NULL)
+    {
+        return pdFAIL;
+    }
+
+    if (cmd->src == APP_PREHEAT_SRC_UPPER)
+    {
+        ret = xQueueSend(s_upper_q, cmd, 0);
+    }
+    else
+    {
+        ret = xQueueSend(s_ui_q, cmd, 0);
+    }
+    return ret;
+}
+
+/**
+ * @brief  预加热任务体: 队列集汇聚多来源命令并周期步进状态机
+ * @note   阻塞 xQueueSelectFromSet() 等待 UI/上位机命令; 200ms 超时视为
+ *         一次控制周期步进 (仅 RUNNING 状态执行); 命令处理逻辑与来源无关。
+ * @param  argument : 任务入参 (未使用)
+ * @return 无 (任务不可返回)
+ */
+void Task_Preheat(void *argument)
+{
+    (void)argument;
+    QueueSetMemberHandle_t qm;
+    app_preheat_cmd_t      cmd;
+
+    printf("Preheat task running...\r\n");
+
+    while (1)
+    {
+        /* 阻塞等待任一来源命令; 超时则执行控制周期步进 */
+        qm = xQueueSelectFromSet(s_qset, pdMS_TO_TICKS(APP_PREHEAT_PERIOD_MS));
+
+        if (qm == s_ui_q)
+        {
+            xQueueReceive(s_ui_q, &cmd, 0);
+            if (cmd.type == APP_PREHEAT_CMD_START)
+            {
+                preheat_handle_start(&cmd);
+            }
+            else
+            {
+                preheat_handle_stop(&cmd);
+            }
+        }
+        else if (qm == s_upper_q)
+        {
+            xQueueReceive(s_upper_q, &cmd, 0);
+            if (cmd.type == APP_PREHEAT_CMD_START)
+            {
+                preheat_handle_start(&cmd);
+            }
+            else
+            {
+                preheat_handle_stop(&cmd);
+            }
+        }
+        else if (s_state == PREHEAT_STATE_RUNNING)
+        {
+            preheat_ctrl_step();
+        }
+    }
+}
+
+/**
+ * @brief  创建预加热任务 (内部先初始化队列集, 再创建任务)
+ * @note   在 vTaskStartScheduler() 之前调用一次; 句柄存于 xPreheatTaskHandle。
+ * @param  无
+ * @return 无
+ */
+void App_preheat_task_create(void)
+{
+    BaseType_t ret;
+
+    App_preheat_init();
+
+    ret = xTaskCreate(Task_Preheat, "preheatTask", APP_PREHEAT_TASK_STACK,
+                      NULL, APP_PREHEAT_TASK_PRIORITY, &xPreheatTaskHandle);
+    if (ret != pdPASS)
+    {
+        printf("[ERR] Preheat task create failed\r\n");
+    }
+}

+ 7 - 0
Com/Src/Com_usb_cdc.c

@@ -83,7 +83,14 @@ static void Task_Usb_Send(void *argument)
 /**
  * @brief 初始化 USB CDC 通信层:创建流缓冲与发送任务
  * 注意!注意!要放在Com_parameter_init初始化后面,不然会出现卡死现象
+ * 调度器启动前创建 RTOS 对象(xTaskCreate/xStreamBufferCreate、printf 经
+ * fputc 写流缓冲)都会进临界区: uxCriticalNesting 初值是哨兵 0xaaaaaaaa,
+ * vPortExitCritical 要等计数减到 0 才恢复中断, 调度器启动前到不了 0,
+ * BASEPRI 会被一直压在 0x50, 屏蔽掉 TIM2(HAL tick) 等优先级>=5 的中断,
+ * 此后任何 HAL_Delay 都会死等。调度器启动时 SVC 会恢复 BASEPRI,
+ * 这里提前恢复是安全的
  */
+
 void Com_usb_cdc_init(void)
 {
     if (xUsbTxStream == NULL)

+ 2 - 1
Core/Src/main.c

@@ -37,7 +37,7 @@
 #include "Int_lcd.h"
 #include "FreeRTOS.h"
 #include "task.h"
-#include "App_freertosTask.h"
+#include "App_main.h"
 #include "Com_usart3.h"
 #include "Com_usb_cdc.h"
 #include "Com_parameter.h"
@@ -141,6 +141,7 @@ int main(void)
 
   /* Infinite loop */
   /* USER CODE BEGIN WHILE */
+  /* 创建应用任务 (vTaskStartScheduler 之前, 依次建 cpld/display/preheat 三任务) */
   App_Task_Create();
 
   vTaskStartScheduler();

+ 1 - 1
FreeRTOS/FreeRTOSConfig.h

@@ -634,7 +634,7 @@
 #define configUSE_MUTEXES                      1
 #define configUSE_RECURSIVE_MUTEXES            1
 #define configUSE_COUNTING_SEMAPHORES          1
-#define configUSE_QUEUE_SETS                   0
+#define configUSE_QUEUE_SETS                   1
 #define configUSE_APPLICATION_TASK_TAG         0
 
 /* Set the following INCLUDE_* constants to 1 to incldue the named API function,

+ 2 - 2
LVGL8v3/examples/porting/lv_port_indev.c

@@ -23,7 +23,7 @@ lv_indev_t * indev_touchpad;
 
 /**
  * @brief  注册 LVGL 触摸输入设备
- * @note   触摸芯片 Int_gt1151_init() 需在此之前调用 (见 App_freertosTask.c)
+ * @note   触摸芯片 Int_gt1151_init() 需在此之前调用 (见 App_display.c)
  * @param  无
  * @retval 无
  */
@@ -44,7 +44,7 @@ void lv_port_indev_init(void)
 /* 初始化触摸板 */
 static void touchpad_init(void)
 {
-    /* 触摸芯片初始化已在 App_freertosTask.c 中通过 Int_gt1151_init() 完成 */
+    /* 触摸芯片初始化已在 App_display.c 中通过 Int_gt1151_init() 完成 */
 }
 
 /* 由 LVGL 周期调用, 读取触摸状态与坐标 */

+ 10 - 2
LVGL8v3/ui/Ui_preheat.c

@@ -11,9 +11,10 @@
 #include <stdio.h>
 #include "Ui.h"
 #include "Ui_preheat.h"
-#include "Ui_temp_setting.h"
 #include "Ui_theme.h"
 #include "Logic_temperature.h"
+#include "Com_parameter.h"
+#include "App_preheat.h"
 
 /*-------------------------------- 布局 ---------------------------------*/
 #define UI_PRE_W               (LV_HOR_RES)                       /* 全屏宽 */
@@ -104,6 +105,13 @@ static void ui_preheat_cancel_cb(lv_event_t * e)
     }
     if (s_pre_root != NULL)
     {
+        /* cancel: 通知预加热任务停止, 再销毁页面 */
+        app_preheat_cmd_t cmd;
+        cmd.type   = APP_PREHEAT_CMD_STOP;
+        cmd.src    = APP_PREHEAT_SRC_UI;
+        cmd.target = 0;
+        App_preheat_send_cmd(&cmd);
+
         lv_obj_del(s_pre_root);
         s_pre_root = NULL;
     }
@@ -204,7 +212,7 @@ void Ui_preheat_enter(void)
     Ui_theme_add_title(root, "Preheating", 10);
 
     /* 右上: 目标温度 chip */
-    int16_t target = Ui_temp_setting_get_target();
+    int16_t target = (int16_t)Com_parameter_get_target();
     lv_obj_t * target_chip = lv_obj_create(root);
     lv_obj_set_size(target_chip, UI_PRE_TARGET_W, UI_PRE_TARGET_H);
     lv_obj_align(target_chip, LV_ALIGN_TOP_RIGHT, -16, 10);

+ 8 - 1
LVGL8v3/ui/Ui_temp_setting.c

@@ -19,6 +19,7 @@
 #include "Ui_preheat.h"
 #include "Ui_theme.h"
 #include "Com_parameter.h"
+#include "App_preheat.h"
 
 /* 目标温度范围 */
 #define UI_TSET_MIN         40
@@ -299,7 +300,13 @@ static void ui_tset_msgbox_cb(lv_event_t * e)
     lv_obj_t * mbox = lv_event_get_current_target(e);
     if (lv_msgbox_get_active_btn(mbox) == 0)
     {
-        /* Yes: 进入预加热页面 */
+        /* Yes: 通知预加热任务开始, 再进入预加热页面 */
+        app_preheat_cmd_t cmd;
+        cmd.type   = APP_PREHEAT_CMD_START;
+        cmd.src    = APP_PREHEAT_SRC_UI;
+        cmd.target = (int16_t)Com_parameter_get_target();
+        App_preheat_send_cmd(&cmd);
+
         lv_msgbox_close(mbox);
         s_msgbox = NULL;
         Ui_preheat_enter();

+ 17 - 2
MDK-ARM/STMH7_temperature_control_board.uvprojx

@@ -2570,9 +2570,24 @@
           <GroupName>App</GroupName>
           <Files>
             <File>
-              <FileName>App_freertosTask.c</FileName>
+              <FileName>App_main.c</FileName>
               <FileType>1</FileType>
-              <FilePath>..\App\Src\App_freertosTask.c</FilePath>
+              <FilePath>..\App\Src\App_main.c</FilePath>
+            </File>
+            <File>
+              <FileName>App_cpld.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\App\Src\App_cpld.c</FilePath>
+            </File>
+            <File>
+              <FileName>App_display.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\App\Src\App_display.c</FilePath>
+            </File>
+            <File>
+              <FileName>App_preheat.c</FileName>
+              <FileType>1</FileType>
+              <FilePath>..\App\Src\App_preheat.c</FilePath>
             </File>
           </Files>
         </Group>