Преглед изворни кода

修改CPLD,PC通信命名和接口命名,统一命名规范

zhanghongyi пре 2 месеци
родитељ
комит
03d04e66bb

+ 1 - 1
App/Inc/App_pc.h

@@ -4,7 +4,7 @@
   * @brief   PC 上位机通信任务接口 (App 应用层)
   *
   * @note   上位机经 USART1(115200 8N1) 下发 0x01 设置目标温度 / 0x02 请求
-  *         24 路温度; 本任务解析应答帧并回 0x81 / 0x82。协议见 Com_pc.h。
+  *         24 路温度; 本任务解析应答帧并回 0x81 / 0x82。协议见 Com_pc_protocol.h。
   ******************************************************************************
   */
 #ifndef __APP_PC_H

+ 15 - 15
App/Src/App_cpld.c

@@ -16,8 +16,8 @@
 #include "App_cpld.h"
 #include "FreeRTOS.h"
 #include "task.h"
-#include "Com_protocol.h"
-#include "Com_usart3.h"
+#include "Com_cpld_protocol.h"
+#include "Com_cpld_usart.h"
 #include "Mid_pid.h"
 #include "Mid_temp.h"
 
@@ -28,8 +28,8 @@
 /* CPLD 控制周期: 1s 定期下发; 远小于 CPLD 30s 无通讯超时 */
 #define CPLD_SEND_PERIOD_MS     1000
 
-/* RX 滚动缓冲 (一帧最多 COM_PROTOCOL_FRAME_MAX_LEN 字节) */
-#define CPLD_RX_BUF_LEN         (COM_PROTOCOL_FRAME_MAX_LEN + 8)
+/* RX 滚动缓冲 (一帧最多 COM_CPLD_FRAME_MAX_LEN 字节) */
+#define CPLD_RX_BUF_LEN         (COM_CPLD_FRAME_MAX_LEN + 8)
 
 /* 通讯存活判定窗口: 超过该时长未收到任何有效帧视为失联 */
 #define APP_CPLD_COMM_TIMEOUT_MS  4000
@@ -121,20 +121,20 @@ static void App_Cpld_PollRx(void)
     uint16_t avail;
     uint16_t pos;
 
-    avail = Com_usart3_available();
+    avail = Com_cpld_usart_available();
     if (avail > 0)
     {
         if (avail > (uint16_t)(CPLD_RX_BUF_LEN - s_len))
         {
             avail = (uint16_t)(CPLD_RX_BUF_LEN - s_len);
         }
-        s_len += (uint16_t)Com_usart3_read(&s_rx[s_len], avail);
+        s_len += (uint16_t)Com_cpld_usart_read(&s_rx[s_len], avail);
     }
 
     pos = 0;
     while ((uint16_t)(pos + 6) <= s_len)
     {
-        if (s_rx[pos] == COM_PROTOCOL_HEADER_H && s_rx[pos + 1] == COM_PROTOCOL_HEADER_L)
+        if (s_rx[pos] == COM_CPLD_HEADER_H && s_rx[pos + 1] == COM_CPLD_HEADER_L)
         {
             uint16_t need = (uint16_t)(s_rx[pos + 3] + 6);   /* 3(头+type+len) + payload + 2(CRC) */
             uint8_t  type;
@@ -146,11 +146,11 @@ static void App_Cpld_PollRx(void)
                 break;                                  /* 帧未收全, 等待更多数据 */
             }
 
-            if (Com_protocol_check_frame(&s_rx[pos], need, &type, &payload, &plen))
+            if (Com_cpld_check_frame(&s_rx[pos], need, &type, &payload, &plen))
             {
                 s_last_rx_ticks = xTaskGetTickCount();
 
-                if (type == COM_PROTOCOL_TYPE_SNAPSHOT_DATA)
+                if (type == COM_CPLD_TYPE_SNAPSHOT_DATA)
                 {
                     if (Mid_Temp_UpdateSnapshot(payload, plen))
                     {
@@ -161,7 +161,7 @@ static void App_Cpld_PollRx(void)
                         printf("[ERR] snapshot len=%d\r\n", (int)plen);
                     }
                 }
-                else if (type == COM_PROTOCOL_TYPE_ACK_NACK)
+                else if (type == COM_CPLD_TYPE_ACK_NACK)
                 {
                     printf("[ACK] ok=%d req=0x%02X st=%d detail=%d\r\n",
                            (int)payload[0], (int)payload[1],
@@ -218,7 +218,7 @@ uint8_t App_cpld_comm_alive(void)
 static void Task_CPLD_Process(void *argument)
 {
     (void)argument;
-    uint8_t frame[COM_PROTOCOL_FRAME_MAX_LEN];
+    uint8_t frame[COM_CPLD_FRAME_MAX_LEN];
     uint16_t flen;
 
     printf("CPLD process task running...\r\n");
@@ -228,16 +228,16 @@ static void Task_CPLD_Process(void *argument)
 
     while (1)
     {
-        flen = Com_protocol_set_all(Mid_PID_GetOutputDuty(), frame);
+        flen = Com_cpld_set_all(Mid_PID_GetOutputDuty(), frame);
         if (flen > 0)
         {
-            Com_usart3_send(frame, flen);
+            Com_cpld_usart_send(frame, flen);
         }
 
-        flen = Com_protocol_get_snapshot(frame);
+        flen = Com_cpld_get_snapshot(frame);
         if (flen > 0)
         {
-            Com_usart3_send(frame, flen);
+            Com_cpld_usart_send(frame, flen);
         }
 
         App_Cpld_PollRx();

+ 7 - 7
App/Src/App_pc.c

@@ -6,7 +6,7 @@
   * 上位机 (Qt/串口助手) 经 USART1(115200 8N1) 按"精简版"协议交互:
   *   0x01 设置目标温度: 校验 40~90 → 写 EEPROM 参数 → 回 0x81 (01成功/00失败);
   *   0x02 请求24路温度: 取 Mid_temp BMC 24 路快照 → 回 0x82 (无效通道补 0)。
-  * 帧格式 |AA 55|CMD|LEN|Payload|CRC8|, 详见 Com_pc.h。
+  * 帧格式 |AA 55|CMD|LEN|Payload|CRC8|, 详见 Com_pc_protocol.h。
   * 注: 0x01 仅保存目标温度, 不自动启动预加热/PID (与 UI 的 Apply 行为一致)。
   ******************************************************************************
   */
@@ -15,8 +15,8 @@
 #include "App_pc.h"
 #include "FreeRTOS.h"
 #include "task.h"
-#include "Com_pc.h"
-#include "Com_usart1.h"
+#include "Com_pc_protocol.h"
+#include "Com_pc_usart.h"
 #include "Com_parameter.h"
 #include "Mid_temp.h"
 
@@ -69,7 +69,7 @@ static void App_Pc_HandleSetTarget(const uint8_t *payload, uint8_t plen)
     flen = Com_pc_set_ack(status, frame);
     if (flen > 0)
     {
-        Com_usart1_send(frame, flen);
+        Com_pc_usart_send(frame, flen);
     }
 }
 
@@ -96,7 +96,7 @@ static void App_Pc_HandleGetTemp(void)
     flen = Com_pc_temp_reply(temps, frame);
     if (flen > 0)
     {
-        Com_usart1_send(frame, flen);
+        Com_pc_usart_send(frame, flen);
     }
 }
 
@@ -113,7 +113,7 @@ static void App_Pc_PollRx(void)
     uint16_t avail;
     uint16_t pos;
 
-    avail = Com_usart1_available();
+    avail = Com_pc_usart_available();
     if (avail > 0)
     {
         uint16_t can = avail;
@@ -121,7 +121,7 @@ static void App_Pc_PollRx(void)
         {
             can = (uint16_t)(PC_RX_BUF_LEN - s_len);
         }
-        s_len += (uint16_t)Com_usart1_read(&s_rx[s_len], can);
+        s_len += (uint16_t)Com_pc_usart_read(&s_rx[s_len], can);
     }
 
     pos = 0;

+ 5 - 5
App/Src/App_pidControl.c

@@ -15,8 +15,8 @@
 #include "App_pidControl.h"
 #include "FreeRTOS.h"
 #include "task.h"
-#include "Com_protocol.h"
-#include "Com_usart3.h"
+#include "Com_cpld_protocol.h"
+#include "Com_cpld_usart.h"
 #include "Mid_pid.h"
 #include "Mid_temp.h"
 
@@ -39,13 +39,13 @@ static volatile uint8_t s_running = 0;
  */
 static void pid_send_set_all(void)
 {
-    uint8_t  frame[COM_PROTOCOL_FRAME_MAX_LEN];
+    uint8_t  frame[COM_CPLD_FRAME_MAX_LEN];
     uint16_t flen;
 
-    flen = Com_protocol_set_all(Mid_PID_GetOutputDuty(), frame);
+    flen = Com_cpld_set_all(Mid_PID_GetOutputDuty(), frame);
     if (flen > 0)
     {
-        Com_usart3_send(frame, flen);
+        Com_cpld_usart_send(frame, flen);
     }
 }
 

+ 5 - 5
App/Src/App_preheat.c

@@ -19,8 +19,8 @@
 #include "FreeRTOS.h"
 #include "task.h"
 #include "queue.h"
-#include "Com_protocol.h"
-#include "Com_usart3.h"
+#include "Com_cpld_protocol.h"
+#include "Com_cpld_usart.h"
 #include "Mid_pid.h"
 #include "Mid_temp.h"
 #include "Ui_preheat.h"
@@ -65,13 +65,13 @@ static int16_t  s_target = 0;
  */
 static void preheat_send_set_all(void)
 {
-    uint8_t  frame[COM_PROTOCOL_FRAME_MAX_LEN];
+    uint8_t  frame[COM_CPLD_FRAME_MAX_LEN];
     uint16_t flen;
 
-    flen = Com_protocol_set_all(Mid_PID_GetOutputDuty(), frame);
+    flen = Com_cpld_set_all(Mid_PID_GetOutputDuty(), frame);
     if (flen > 0)
     {
-        Com_usart3_send(frame, flen);
+        Com_cpld_usart_send(frame, flen);
     }
 }
 

+ 33 - 33
Com/Inc/Com_protocol.h

@@ -1,5 +1,5 @@
-#ifndef __COM_PROTOCOL_H
-#define __COM_PROTOCOL_H
+#ifndef __COM_CPLD_PROTOCOL_H
+#define __COM_CPLD_PROTOCOL_H
 
 #include <stdint.h>
 
@@ -12,38 +12,38 @@
  */
 
 /* 帧固定字段 */
-#define COM_PROTOCOL_HEADER_H       0xA5
-#define COM_PROTOCOL_HEADER_L       0x5A
+#define COM_CPLD_HEADER_H       0xA5
+#define COM_CPLD_HEADER_L       0x5A
 
 /* 命令字 */
-#define COM_PROTOCOL_TYPE_SET_ALL        0x01    /* 主机->CPLD, 32B: 24PTC+4进风+4出风, 兼喂狗 */
-#define COM_PROTOCOL_TYPE_GET_SNAPSHOT   0x02    /* 主机->CPLD, 0B */
-#define COM_PROTOCOL_TYPE_SET_PID_TARGET 0x05    /* 主机->CPLD, 1B: 目标温度 20..70°C */
-#define COM_PROTOCOL_TYPE_ACK_NACK       0x06    /* CPLD->主机, 4B */
-#define COM_PROTOCOL_TYPE_SNAPSHOT_DATA  0x82    /* CPLD->主机, 199B */
+#define COM_CPLD_TYPE_SET_ALL        0x01    /* 主机->CPLD, 32B: 24PTC+4进风+4出风, 兼喂狗 */
+#define COM_CPLD_TYPE_GET_SNAPSHOT   0x02    /* 主机->CPLD, 0B */
+#define COM_CPLD_TYPE_SET_PID_TARGET 0x05    /* 主机->CPLD, 1B: 目标温度 20..70°C */
+#define COM_CPLD_TYPE_ACK_NACK       0x06    /* CPLD->主机, 4B */
+#define COM_CPLD_TYPE_SNAPSHOT_DATA  0x82    /* CPLD->主机, 199B */
 
 /* 载荷长度常量 */
-#define COM_PROTOCOL_PAYLOAD_SET_ALL        32
-#define COM_PROTOCOL_PAYLOAD_SET_PID_TARGET 1
-#define COM_PROTOCOL_PAYLOAD_ACK_NACK       4
-#define COM_PROTOCOL_PAYLOAD_SNAPSHOT       199
-#define COM_PROTOCOL_PAYLOAD_MAX            255
+#define COM_CPLD_PAYLOAD_SET_ALL        32
+#define COM_CPLD_PAYLOAD_SET_PID_TARGET 1
+#define COM_CPLD_PAYLOAD_ACK_NACK       4
+#define COM_CPLD_PAYLOAD_SNAPSHOT       199
+#define COM_CPLD_PAYLOAD_MAX            255
 
 /* SET_ALL 载荷内偏移 */
-#define COM_PROTOCOL_SET_ALL_PTC_OFF    0   /* 24 路 PTC 占空比 0~100 */
-#define COM_PROTOCOL_SET_ALL_FRONT_OFF  24  /* 4 路进风风扇 */
-#define COM_PROTOCOL_SET_ALL_REAR_OFF   28  /* 4 路出风风扇 */
+#define COM_CPLD_SET_ALL_PTC_OFF    0   /* 24 路 PTC 占空比 0~100 */
+#define COM_CPLD_SET_ALL_FRONT_OFF  24  /* 4 路进风风扇 */
+#define COM_CPLD_SET_ALL_REAR_OFF   28  /* 4 路出风风扇 */
 
 /* 帧最大长度: 2(头)+1(Type)+1(Length)+255(Payload)+2(CRC) */
-#define COM_PROTOCOL_FRAME_MAX_LEN     (2 + 1 + 1 + COM_PROTOCOL_PAYLOAD_MAX + 2)
+#define COM_CPLD_FRAME_MAX_LEN     (2 + 1 + 1 + COM_CPLD_PAYLOAD_MAX + 2)
 
 /* ACK/NACK 状态码 (对应 status 字段) */
-#define COM_PROTOCOL_STATUS_OK             0
-#define COM_PROTOCOL_STATUS_UNSUPPORTED    1
-#define COM_PROTOCOL_STATUS_BAD_LENGTH     2
-#define COM_PROTOCOL_STATUS_BAD_VALUE      3
-#define COM_PROTOCOL_STATUS_SAFETY_LOCKED  4
-#define COM_PROTOCOL_STATUS_BUSY           5
+#define COM_CPLD_STATUS_OK             0
+#define COM_CPLD_STATUS_UNSUPPORTED    1
+#define COM_CPLD_STATUS_BAD_LENGTH     2
+#define COM_CPLD_STATUS_BAD_VALUE      3
+#define COM_CPLD_STATUS_SAFETY_LOCKED  4
+#define COM_CPLD_STATUS_BUSY           5
 
 /* ACK/NACK 载荷结构: [ok, request_type, status, detail] */
 typedef struct {
@@ -51,7 +51,7 @@ typedef struct {
     uint8_t request_type;   /* 引发应答的请求类型 */
     uint8_t status;         /* 状态码枚举 */
     uint8_t detail;         /* 错误上下文 */
-} com_protocol_ack_t;
+} com_cpld_ack_t;
 
 /**
  * @brief  CRC-16/CCITT-FALSE 校验计算
@@ -60,7 +60,7 @@ typedef struct {
  * @param  len  : 数据长度 (字节数)
  * @return 16 位 CRC 校验值
  */
-uint16_t Com_protocol_crc16(const uint8_t *data, uint16_t len);
+uint16_t Com_cpld_crc16(const uint8_t *data, uint16_t len);
 
 /**
  * @brief  通用帧封装: |A5 5A|Type|Length|Payload|CRC_L|CRC_H
@@ -68,10 +68,10 @@ uint16_t Com_protocol_crc16(const uint8_t *data, uint16_t len);
  * @param  type    : 命令类型 (如 0x01 SET_ALL)
  * @param  payload : 载荷数据指针
  * @param  len     : 载荷长度 (0..255)
- * @param  frame   : 输出帧缓冲区指针 (需 >= COM_PROTOCOL_FRAME_MAX_LEN)
+ * @param  frame   : 输出帧缓冲区指针 (需 >= COM_CPLD_FRAME_MAX_LEN)
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_encode(uint8_t type, const uint8_t *payload, uint8_t len, uint8_t *frame);
+uint16_t Com_cpld_encode(uint8_t type, const uint8_t *payload, uint8_t len, uint8_t *frame);
 
 /**
  * @brief  封装 SET_ALL (0x01) 帧: 32 字节载荷
@@ -80,14 +80,14 @@ uint16_t Com_protocol_encode(uint8_t type, const uint8_t *payload, uint8_t len,
  * @param  frame : 输出帧缓冲区指针
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_set_all(const uint8_t *duty, uint8_t *frame);
+uint16_t Com_cpld_set_all(const uint8_t *duty, uint8_t *frame);
 
 /**
  * @brief  封装 GET_SNAPSHOT (0x02) 查询帧: 0 字节载荷
  * @param  frame : 输出帧缓冲区指针
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_get_snapshot(uint8_t *frame);
+uint16_t Com_cpld_get_snapshot(uint8_t *frame);
 
 /**
  * @brief  封装 SET_PID_TARGET (0x05) 帧: 1 字节目标温度
@@ -95,7 +95,7 @@ uint16_t Com_protocol_get_snapshot(uint8_t *frame);
  * @param  frame  : 输出帧缓冲区指针
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_set_pid_target(uint8_t target, uint8_t *frame);
+uint16_t Com_cpld_set_pid_target(uint8_t target, uint8_t *frame);
 
 /**
  * @brief  帧校验: 检查帧头与 CRC
@@ -107,6 +107,6 @@ uint16_t Com_protocol_set_pid_target(uint8_t target, uint8_t *frame);
  * @param  payload_len : [out] 校验通过时的载荷长度
  * @return 1=校验通过, 0=校验失败或参数非法
  */
-uint8_t  Com_protocol_check_frame(const uint8_t *frame, uint16_t len, uint8_t *type, const uint8_t **payload, uint8_t *payload_len);
+uint8_t  Com_cpld_check_frame(const uint8_t *frame, uint16_t len, uint8_t *type, const uint8_t **payload, uint8_t *payload_len);
 
-#endif /* __COM_PROTOCOL_H */
+#endif /* __COM_CPLD_PROTOCOL_H */

+ 19 - 0
Com/Inc/Com_cpld_usart.h

@@ -0,0 +1,19 @@
+#ifndef __COM_CPLD_USART_H
+#define __COM_CPLD_USART_H
+
+#include <stdint.h>
+
+/* 本模块专用 USART3:PB10=TX, PB11=RX, 波特率 921600 */
+
+#define COM_CPLD_USART_STREAM_SIZE   4096
+#define COM_CPLD_USART_RX_DMA_SIZE   1024
+
+#define COM_CPLD_USART_TX_TASK_PRIORITY 3
+#define COM_CPLD_USART_TX_TASK_STACK    512
+
+void     Com_cpld_usart_init(void);
+uint32_t Com_cpld_usart_send(const uint8_t *data, uint32_t len);
+uint16_t Com_cpld_usart_available(void);
+uint32_t Com_cpld_usart_read(uint8_t *buf, uint32_t len);
+
+#endif /* __COM_CPLD_USART_H */

+ 3 - 3
Com/Inc/Com_pc.h

@@ -1,5 +1,5 @@
-#ifndef __COM_PC_H
-#define __COM_PC_H
+#ifndef __COM_PC_PROTOCOL_H
+#define __COM_PC_PROTOCOL_H
 
 #include <stdint.h>
 
@@ -87,4 +87,4 @@ uint16_t Com_pc_temp_reply(const uint8_t *temps, uint8_t *frame);
 uint8_t Com_pc_check_frame(const uint8_t *frame, uint16_t len, uint8_t *cmd,
                            const uint8_t **payload, uint8_t *payload_len);
 
-#endif /* __COM_PC_H */
+#endif /* __COM_PC_PROTOCOL_H */

+ 19 - 0
Com/Inc/Com_pc_usart.h

@@ -0,0 +1,19 @@
+#ifndef __COM_PC_USART_H
+#define __COM_PC_USART_H
+
+#include <stdint.h>
+#include "usart.h"
+
+/* 本模块专用 USART1: PA9=TX, PA10=RX, 波特率 115200 (PC 上位机) */
+
+#define COM_PC_USART_STREAM_SIZE    4096
+
+void     Com_pc_usart_init(void);
+uint32_t Com_pc_usart_send(const uint8_t *data, uint32_t len);
+uint16_t Com_pc_usart_available(void);
+uint32_t Com_pc_usart_read(uint8_t *buf, uint32_t len);
+
+/* 供共享 HAL_UART_RxCpltCallback (Com_cpld_usart.c 内定义) 分发的 RX 完成处理 */
+void     Com_pc_usart_rxcplt(UART_HandleTypeDef *huart);
+
+#endif /* __COM_PC_USART_H */

+ 0 - 19
Com/Inc/Com_usart1.h

@@ -1,19 +0,0 @@
-#ifndef __COM_USART1_H
-#define __COM_USART1_H
-
-#include <stdint.h>
-#include "usart.h"
-
-/* 本模块专用 USART1: PA9=TX, PA10=RX, 波特率 115200 (PC 上位机) */
-
-#define COM_USART1_STREAM_SIZE    4096
-
-void     Com_usart1_init(void);
-uint32_t Com_usart1_send(const uint8_t *data, uint32_t len);
-uint16_t Com_usart1_available(void);
-uint32_t Com_usart1_read(uint8_t *buf, uint32_t len);
-
-/* 供共享 HAL_UART_RxCpltCallback (Com_usart3.c 内定义) 分发的 RX 完成处理 */
-void     Com_usart1_rxcplt(UART_HandleTypeDef *huart);
-
-#endif /* __COM_USART1_H */

+ 0 - 19
Com/Inc/Com_usart3.h

@@ -1,19 +0,0 @@
-#ifndef __COM_USART3_H
-#define __COM_USART3_H
-
-#include <stdint.h>
-
-/* 本模块专用 USART3:PB10=TX, PB11=RX, 波特率 921600 */
-
-#define COM_USART3_STREAM_SIZE   4096
-#define COM_USART3_RX_DMA_SIZE   1024
-
-#define COM_USART3_TX_TASK_PRIORITY 3
-#define COM_USART3_TX_TASK_STACK    512
-
-void     Com_usart3_init(void);
-uint32_t Com_usart3_send(const uint8_t *data, uint32_t len);
-uint16_t Com_usart3_available(void);
-uint32_t Com_usart3_read(uint8_t *buf, uint32_t len);
-
-#endif /* __COM_USART3_H */

+ 17 - 19
Com/Src/Com_protocol.c

@@ -1,10 +1,8 @@
 /* 
- * 用于USART3 通信模块
- *
- * 当前模块是用来封装和CPLD下位机进行串口通信的协议
+ * CPLD (USART3) 通信模块——与下位机 CPLD 进行串口通信的协议封装
  */
 
-#include "Com_protocol.h"
+#include "Com_cpld_protocol.h"
 #include "stdio.h"
 
 /**
@@ -14,7 +12,7 @@
  * @param  len  : 数据长度 (字节数)
  * @return 16 位 CRC 校验值
  */
-uint16_t Com_protocol_crc16(const uint8_t *data, uint16_t len)
+uint16_t Com_cpld_crc16(const uint8_t *data, uint16_t len)
 {
     uint16_t crc = 0xFFFF;
     uint16_t i;
@@ -51,10 +49,10 @@ uint16_t Com_protocol_crc16(const uint8_t *data, uint16_t len)
  * @param  type    : 命令类型 (如 0x01 SET_ALL)
  * @param  payload : 载荷数据指针
  * @param  len     : 载荷长度 (0..255)
- * @param  frame   : 输出帧缓冲区指针 (需 >= COM_PROTOCOL_FRAME_MAX_LEN)
+ * @param  frame   : 输出帧缓冲区指针 (需 >= COM_CPLD_FRAME_MAX_LEN)
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_encode(uint8_t type, const uint8_t *payload, uint8_t len, uint8_t *frame)
+uint16_t Com_cpld_encode(uint8_t type, const uint8_t *payload, uint8_t len, uint8_t *frame)
 {
     uint16_t crc;
     uint16_t idx;
@@ -65,8 +63,8 @@ uint16_t Com_protocol_encode(uint8_t type, const uint8_t *payload, uint8_t len,
         return 0;
     }
 
-    frame[0] = COM_PROTOCOL_HEADER_H;
-    frame[1] = COM_PROTOCOL_HEADER_L;
+    frame[0] = COM_CPLD_HEADER_H;
+    frame[1] = COM_CPLD_HEADER_L;
     frame[2] = type;
     frame[3] = len;
 
@@ -76,7 +74,7 @@ uint16_t Com_protocol_encode(uint8_t type, const uint8_t *payload, uint8_t len,
     }
 
     /* CRC 覆盖 Type+Length+Payload */
-    crc = Com_protocol_crc16(&frame[2], (uint16_t)(2 + len));
+    crc = Com_cpld_crc16(&frame[2], (uint16_t)(2 + len));
     idx = (uint16_t)(4 + len);
     frame[idx]     = (uint8_t)(crc & 0xFF);       /* CRC 低字节 */
     frame[idx + 1] = (uint8_t)(crc >> 8);         /* CRC 高字节 */
@@ -91,14 +89,14 @@ uint16_t Com_protocol_encode(uint8_t type, const uint8_t *payload, uint8_t len,
  * @param  frame : 输出帧缓冲区指针
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_set_all(const uint8_t *duty, uint8_t *frame)
+uint16_t Com_cpld_set_all(const uint8_t *duty, uint8_t *frame)
 {
     if (duty == NULL || frame == NULL)
     {
         return 0;
     }
 
-    return Com_protocol_encode(COM_PROTOCOL_TYPE_SET_ALL, duty, COM_PROTOCOL_PAYLOAD_SET_ALL, frame);
+    return Com_cpld_encode(COM_CPLD_TYPE_SET_ALL, duty, COM_CPLD_PAYLOAD_SET_ALL, frame);
 }
 
 /**
@@ -106,14 +104,14 @@ uint16_t Com_protocol_set_all(const uint8_t *duty, uint8_t *frame)
  * @param  frame : 输出帧缓冲区指针
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_get_snapshot(uint8_t *frame)
+uint16_t Com_cpld_get_snapshot(uint8_t *frame)
 {
     if (frame == NULL)
     {
         return 0;
     }
 
-    return Com_protocol_encode(COM_PROTOCOL_TYPE_GET_SNAPSHOT, NULL, 0, frame);
+    return Com_cpld_encode(COM_CPLD_TYPE_GET_SNAPSHOT, NULL, 0, frame);
 }
 
 /**
@@ -122,14 +120,14 @@ uint16_t Com_protocol_get_snapshot(uint8_t *frame)
  * @param  frame  : 输出帧缓冲区指针
  * @return 帧总长度; 输入非法返回 0
  */
-uint16_t Com_protocol_set_pid_target(uint8_t target, uint8_t *frame)
+uint16_t Com_cpld_set_pid_target(uint8_t target, uint8_t *frame)
 {
     if (frame == NULL)
     {
         return 0;
     }
 
-    return Com_protocol_encode(COM_PROTOCOL_TYPE_SET_PID_TARGET, &target, COM_PROTOCOL_PAYLOAD_SET_PID_TARGET, frame);
+    return Com_cpld_encode(COM_CPLD_TYPE_SET_PID_TARGET, &target, COM_CPLD_PAYLOAD_SET_PID_TARGET, frame);
 }
 
 /**
@@ -142,7 +140,7 @@ uint16_t Com_protocol_set_pid_target(uint8_t target, uint8_t *frame)
  * @param  payload_len : [out] 校验通过时的载荷长度
  * @return 1=校验通过, 0=校验失败或参数非法
  */
-uint8_t Com_protocol_check_frame(const uint8_t *frame, uint16_t len, uint8_t *type, const uint8_t **payload, uint8_t *payload_len)
+uint8_t Com_cpld_check_frame(const uint8_t *frame, uint16_t len, uint8_t *type, const uint8_t **payload, uint8_t *payload_len)
 {
     uint16_t expect_len;
     uint16_t exp_crc, got_crc;
@@ -153,7 +151,7 @@ uint8_t Com_protocol_check_frame(const uint8_t *frame, uint16_t len, uint8_t *ty
     }
 
     /* 帧头 */
-    if (frame[0] != COM_PROTOCOL_HEADER_H || frame[1] != COM_PROTOCOL_HEADER_L)
+    if (frame[0] != COM_CPLD_HEADER_H || frame[1] != COM_CPLD_HEADER_L)
     {
         return 0;
     }
@@ -166,7 +164,7 @@ uint8_t Com_protocol_check_frame(const uint8_t *frame, uint16_t len, uint8_t *ty
 
     /* CRC */
     exp_crc = (uint16_t)(frame[len - 2] | ((uint16_t)frame[len - 1] << 8));
-    got_crc = Com_protocol_crc16(&frame[2], (uint16_t)(frame[3] + 2));
+    got_crc = Com_cpld_crc16(&frame[2], (uint16_t)(frame[3] + 2));
     if (exp_crc != got_crc)
     {
         return 0;

+ 33 - 33
Com/Src/Com_usart3.c

@@ -1,16 +1,16 @@
 /* 
- * USART3 通信模块 
+ * CPLD 通信模块 (USART3: PB10=TX, PB11=RX, 921600)
  *
- * 当前模块是和CPLD下位机进行串口通信
+ * 与 CPLD 下位机进行串口通信 (传输层)
  */
-#include "Com_usart3.h"
+#include "Com_cpld_usart.h"
 
 #include "usart.h"
 #include "FreeRTOS.h"
 #include "task.h"
 #include "stream_buffer.h"
 
-#include "Com_usart1.h"
+#include "Com_pc_usart.h"
 
 /* usart.c(USART3) 内定义的 DMA 句柄 */
 extern DMA_HandleTypeDef hdma_usart3_rx;
@@ -25,11 +25,11 @@ extern DMA_HandleTypeDef hdma_usart3_rx;
  * 注意:s_tx_stream/s_rx_stream 为 FreeRTOS 动态堆分配(heap_4),
  *       不落 AXI SRAM——与 USB CDC 的 xUsbTxStream 处理方式一致。
  */
-#define COM_USART3_AXI_SRAM_SECTION  __attribute__((section(".ARM.__at_0x24000000")))
+#define COM_CPLD_USART_AXI_SRAM_SECTION  __attribute__((section(".ARM.__at_0x24000000")))
 
-COM_USART3_AXI_SRAM_SECTION static uint8_t s_rx_dma_buf[COM_USART3_RX_DMA_SIZE];
+COM_CPLD_USART_AXI_SRAM_SECTION static uint8_t s_rx_dma_buf[COM_CPLD_USART_RX_DMA_SIZE];
 /* 暂存待发送的数据块(TX 发送任务从 TX 流缓冲取出后经此交给 DMA) */
-COM_USART3_AXI_SRAM_SECTION static uint8_t s_tx_chunk[COM_USART3_STREAM_SIZE];
+COM_CPLD_USART_AXI_SRAM_SECTION static uint8_t s_tx_chunk[COM_CPLD_USART_STREAM_SIZE];
 
 static StreamBufferHandle_t s_tx_stream = NULL;
 static StreamBufferHandle_t s_rx_stream = NULL;
@@ -41,15 +41,15 @@ static volatile uint32_t s_rx_prev_pos = 0;
 
 static uint8_t s_rx_started = 0;
 
-static void Task_Usart3_Send(void *argument);
+static void Task_CpldUsart_Send(void *argument);
 
 /**
  * @brief (USART3) 从 DMA 缓冲读取新接收的数据(空闲事件 + 半满/全满皆调用)
  * @note  在中断上下文中执行
  */
-static void Usart3_Drain_Rx(void)
+static void CpldUsart_Drain_Rx(void)
 {
-    uint32_t cur_pos = (uint32_t)(COM_USART3_RX_DMA_SIZE - __HAL_DMA_GET_COUNTER(&hdma_usart3_rx));
+    uint32_t cur_pos = (uint32_t)(COM_CPLD_USART_RX_DMA_SIZE - __HAL_DMA_GET_COUNTER(&hdma_usart3_rx));
     uint32_t new_bytes;
     BaseType_t xHigherPriorityTaskWoken = pdFALSE;
 
@@ -59,12 +59,12 @@ static void Usart3_Drain_Rx(void)
     }
     else
     {
-        new_bytes = (COM_USART3_RX_DMA_SIZE - s_rx_prev_pos) + cur_pos;
+        new_bytes = (COM_CPLD_USART_RX_DMA_SIZE - s_rx_prev_pos) + cur_pos;
     }
 
-    if (new_bytes > COM_USART3_RX_DMA_SIZE)
+    if (new_bytes > COM_CPLD_USART_RX_DMA_SIZE)
     {
-        new_bytes = COM_USART3_RX_DMA_SIZE;
+        new_bytes = COM_CPLD_USART_RX_DMA_SIZE;
     }
 
     if (new_bytes == 0)
@@ -75,20 +75,20 @@ static void Usart3_Drain_Rx(void)
     /* DMA 已写入 AXI SRAM,先使缓存失效再读取。
        回绕时两段分别是 [prev..尾) 与 [0..remainder),须分段失效,
        一次性跨缓冲区尾失效无法覆盖 [0..remainder) 对应的缓存行。 */
-    if ((s_rx_prev_pos + new_bytes) <= COM_USART3_RX_DMA_SIZE)
+    if ((s_rx_prev_pos + new_bytes) <= COM_CPLD_USART_RX_DMA_SIZE)
     {
         SCB_InvalidateDCache_by_Addr((uint32_t *)&s_rx_dma_buf[s_rx_prev_pos], (int32_t)new_bytes);
     }
     else
     {
-        uint32_t first_len = COM_USART3_RX_DMA_SIZE - s_rx_prev_pos;
+        uint32_t first_len = COM_CPLD_USART_RX_DMA_SIZE - s_rx_prev_pos;
         SCB_InvalidateDCache_by_Addr((uint32_t *)&s_rx_dma_buf[s_rx_prev_pos], (int32_t)first_len);
         SCB_InvalidateDCache_by_Addr((uint32_t *)&s_rx_dma_buf[0],
                                      (int32_t)(new_bytes - first_len));
     }
 
     /* 环形回绕:跨过 DMA 缓冲末尾时拆成两段写入流缓冲(满则丢弃余下) */
-    if ((s_rx_prev_pos + new_bytes) <= COM_USART3_RX_DMA_SIZE)
+    if ((s_rx_prev_pos + new_bytes) <= COM_CPLD_USART_RX_DMA_SIZE)
     {
         xStreamBufferSendFromISR(s_rx_stream,
                                  &s_rx_dma_buf[s_rx_prev_pos],
@@ -97,7 +97,7 @@ static void Usart3_Drain_Rx(void)
     }
     else
     {
-        uint32_t first_len = COM_USART3_RX_DMA_SIZE - s_rx_prev_pos;
+        uint32_t first_len = COM_CPLD_USART_RX_DMA_SIZE - s_rx_prev_pos;
         xStreamBufferSendFromISR(s_rx_stream,
                                  &s_rx_dma_buf[s_rx_prev_pos],
                                  first_len,
@@ -122,24 +122,24 @@ void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
     if (huart->Instance == USART3)
     {
         (void)Size;
-        Usart3_Drain_Rx();
+        CpldUsart_Drain_Rx();
     }
 }
 
 /**
  * @brief (USART1/USART3) 接收完成回调
  * @note  USART3: 半满/全满, CIRCULAR 模式下由 DMA 触发;
- *        USART1: 中断单字节接收 (分发到 Com_usart1)
+ *        USART1: 中断单字节接收 (分发到 Com_pc_usart)
  */
 void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
 {
     if (huart->Instance == USART1)
     {
-        Com_usart1_rxcplt(huart);
+        Com_pc_usart_rxcplt(huart);
     }
     else if (huart->Instance == USART3)
     {
-        Usart3_Drain_Rx();
+        CpldUsart_Drain_Rx();
     }
 }
 
@@ -147,7 +147,7 @@ void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart)
 {
     if (huart->Instance == USART3)
     {
-        Usart3_Drain_Rx();
+        CpldUsart_Drain_Rx();
     }
 }
 
@@ -169,14 +169,14 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
  * @brief USART3 发送任务:从 TX 流缓冲取数据块,经 DMA 发送。
  *        xStreamBufferReceive 无数据时阻塞,有数据自动唤醒(无需手动 notify)。
  */
-static void Task_Usart3_Send(void *argument)
+static void Task_CpldUsart_Send(void *argument)
 {
     (void)argument;
 
     for (;;)
     {
         size_t n = xStreamBufferReceive(s_tx_stream, s_tx_chunk,
-                                        COM_USART3_STREAM_SIZE, portMAX_DELAY);
+                                        COM_CPLD_USART_STREAM_SIZE, portMAX_DELAY);
 
         /* DMA 读取前将数据刷出到内存(避 AXI SRAM 缓存) */
         SCB_CleanDCache_by_Addr((uint32_t *)s_tx_chunk, (int32_t)n);
@@ -191,29 +191,29 @@ static void Task_Usart3_Send(void *argument)
  * @brief 初始化 USART3 通信:启动 RX DMA 接收、创建发送任务
  * @note  需在 MX_USART3_UART_Init() 之后、调度器启动之前调用
  */
-void Com_usart3_init(void)
+void Com_cpld_usart_init(void)
 {
     if (s_tx_stream == NULL)
     {
-        s_tx_stream = xStreamBufferCreate(COM_USART3_STREAM_SIZE, 1);
+        s_tx_stream = xStreamBufferCreate(COM_CPLD_USART_STREAM_SIZE, 1);
     }
     if (s_rx_stream == NULL)
     {
-        s_rx_stream = xStreamBufferCreate(COM_USART3_STREAM_SIZE, 1);
+        s_rx_stream = xStreamBufferCreate(COM_CPLD_USART_STREAM_SIZE, 1);
     }
 
     /* 启动 RX:CIRCULAR DMA + 空闲中断 */
     if (s_rx_started == 0)
     {
-        HAL_UARTEx_ReceiveToIdle_DMA(&huart3, s_rx_dma_buf, COM_USART3_RX_DMA_SIZE);
+        HAL_UARTEx_ReceiveToIdle_DMA(&huart3, s_rx_dma_buf, COM_CPLD_USART_RX_DMA_SIZE);
         s_rx_started = 1;
     }
 
     /* 创建发送任务 */
     if (s_tx_task_handle == NULL)
     {
-        xTaskCreate(Task_Usart3_Send, "usart3SendTask", COM_USART3_TX_TASK_STACK,
-                    NULL, COM_USART3_TX_TASK_PRIORITY, &s_tx_task_handle);
+        xTaskCreate(Task_CpldUsart_Send, "cpldUsartSendTask", COM_CPLD_USART_TX_TASK_STACK,
+                    NULL, COM_CPLD_USART_TX_TASK_PRIORITY, &s_tx_task_handle);
     }
 }
 
@@ -221,7 +221,7 @@ void Com_usart3_init(void)
  * @brief (USART3) 发送数据:阻塞最多 100ms 写入 TX 流缓冲
  * @return 实际写入 TX 流缓冲的字节数(满则丢弃余下)
  */
-uint32_t Com_usart3_send(const uint8_t *data, uint32_t len)
+uint32_t Com_cpld_usart_send(const uint8_t *data, uint32_t len)
 {
     if (s_tx_stream == NULL || data == NULL)
     {
@@ -233,7 +233,7 @@ uint32_t Com_usart3_send(const uint8_t *data, uint32_t len)
 /**
  * @brief (USART3) 查询 RX 流缓冲可读字节数
  */
-uint16_t Com_usart3_available(void)
+uint16_t Com_cpld_usart_available(void)
 {
     if (s_rx_stream == NULL)
     {
@@ -246,7 +246,7 @@ uint16_t Com_usart3_available(void)
  * @brief (USART3) 从 RX 流缓冲读取数据(非阻塞)
  * @return 实际读取字节数
  */
-uint32_t Com_usart3_read(uint8_t *buf, uint32_t len)
+uint32_t Com_cpld_usart_read(uint8_t *buf, uint32_t len)
 {
     if (s_rx_stream == NULL || buf == NULL)
     {

+ 1 - 2
Com/Src/Com_pc.c

@@ -2,10 +2,9 @@
  * PC 上位机通信协议 (Com 层, 仅协议封装, 走 USART1)
  *
  * 帧格式: | AA 55 | CMD | LEN | Payload | CRC8 |
- * 详见 Com_pc.h / 参考资料/PC 上位机 24路温度控制串口通信协议_精简版.md
  */
 
-#include "Com_pc.h"
+#include "Com_pc_protocol.h"
 #include <stddef.h>
 
 /**

+ 14 - 15
Com/Src/Com_usart1.c

@@ -1,28 +1,27 @@
 /* 
- * USART1 通信模块
+ * PC 上位机串口 (USART1: PA9=TX, PA10=RX, 115200 8N1) 传输层
  *
- * 本模块是 PC 上位机串口 (PA9=TX, PA10=RX, 115200 8N1) 的传输层。
  * RX: 中断单字节接收 (HAL_UART_Receive_IT 链条), 字节写入 RX 流缓冲;
  * TX: 阻塞 HAL_UART_Transmit (帧短、应答低频, 在任务上下文调用)。
  *
- * 注意: HAL_UART_RxCpltCallback 等 weak 回调由 Com_usart3.c 统一分发
+ * 注意: HAL_UART_RxCpltCallback 等 weak 回调由 Com_cpld_usart.c 统一分发
  *       (按 Instance 区分 USART3/USART1), 本模块只提供被调用的处理函数。
  */
-#include "Com_usart1.h"
+#include "Com_pc_usart.h"
 
 #include "FreeRTOS.h"
 #include "stream_buffer.h"
 
 /*
  * 底层使用 AXI SRAM (0x24000000)。
- * 原因: 与 USART3 收发缓冲保持一致, 中断共用该区域无缓存别名问题。
- * 注意: USART3 缓冲占用 0x24000000~0x240013FF (1024+4096), 本模块起始
+ * 原因: 与 CPLD (USART3) 收发缓冲保持一致, 中断共用该区域无缓存别名问题。
+ * 注意: CPLD (USART3) 缓冲占用 0x24000000~0x240013FF (1024+4096), 本模块起始
  *       置于 0x24001400, 避免 Keil AT 段重叠 (L6982E)。
  */
-#define COM_USART1_AXI_SRAM_SECTION  __attribute__((section(".ARM.__at_0x24001400")))
+#define COM_PC_USART_AXI_SRAM_SECTION  __attribute__((section(".ARM.__at_0x24001400")))
 
 /* 单字节中断接收缓冲 (逐字节链式挂载) */
-COM_USART1_AXI_SRAM_SECTION static uint8_t s_rx_byte;
+COM_PC_USART_AXI_SRAM_SECTION static uint8_t s_rx_byte;
 
 static StreamBufferHandle_t s_rx_stream = NULL;
 
@@ -30,11 +29,11 @@ static uint8_t s_rx_started = 0;
 
 /**
  * @brief (USART1) RX 完成处理: 单字节送入 RX 流缓冲并重新挂载
- * @note  由 Com_usart3.c 的 HAL_UART_RxCpltCallback 按 Instance 分发, 中断上下文
+ * @note  由 Com_cpld_usart.c 的 HAL_UART_RxCpltCallback 按 Instance 分发, 中断上下文
  * @param  huart : 触发中断的 UART 句柄 (须为 USART1)
  * @return 无
  */
-void Com_usart1_rxcplt(UART_HandleTypeDef *huart)
+void Com_pc_usart_rxcplt(UART_HandleTypeDef *huart)
 {
     BaseType_t xHigherPriorityTaskWoken = pdFALSE;
 
@@ -61,11 +60,11 @@ void Com_usart1_rxcplt(UART_HandleTypeDef *huart)
  * @param  无
  * @return 无
  */
-void Com_usart1_init(void)
+void Com_pc_usart_init(void)
 {
     if (s_rx_stream == NULL)
     {
-        s_rx_stream = xStreamBufferCreate(COM_USART1_STREAM_SIZE, 1);
+        s_rx_stream = xStreamBufferCreate(COM_PC_USART_STREAM_SIZE, 1);
     }
 
     if (s_rx_started == 0)
@@ -83,7 +82,7 @@ void Com_usart1_init(void)
  * @param  len  : 数据长度 (字节数)
  * @return 实际发送字节数; 参数非法返回 0
  */
-uint32_t Com_usart1_send(const uint8_t *data, uint32_t len)
+uint32_t Com_pc_usart_send(const uint8_t *data, uint32_t len)
 {
     if (data == NULL || len == 0)
     {
@@ -100,7 +99,7 @@ uint32_t Com_usart1_send(const uint8_t *data, uint32_t len)
  * @param  无
  * @return 可读字节数
  */
-uint16_t Com_usart1_available(void)
+uint16_t Com_pc_usart_available(void)
 {
     if (s_rx_stream == NULL)
     {
@@ -115,7 +114,7 @@ uint16_t Com_usart1_available(void)
  * @param  len : 期望读取字节数
  * @return 实际读取字节数
  */
-uint32_t Com_usart1_read(uint8_t *buf, uint32_t len)
+uint32_t Com_pc_usart_read(uint8_t *buf, uint32_t len)
 {
     if (s_rx_stream == NULL || buf == NULL)
     {

+ 5 - 5
Core/Src/main.c

@@ -38,8 +38,8 @@
 #include "FreeRTOS.h"
 #include "task.h"
 #include "App_main.h"
-#include "Com_usart3.h"
-#include "Com_usart1.h"
+#include "Com_cpld_usart.h"
+#include "Com_pc_usart.h"
 #include "Com_usb_cdc.h"
 #include "Com_parameter.h"
 /* USER CODE END Includes */
@@ -136,14 +136,14 @@ int main(void)
   Int_lcd_init();
   Com_parameter_init();
   Com_usb_cdc_init();
-  Com_usart3_init();
-  Com_usart1_init();
+  Com_cpld_usart_init();
+  Com_pc_usart_init();
   printf("System Init OK\r\n");
   /* USER CODE END 2 */
 
   /* Infinite loop */
   /* USER CODE BEGIN WHILE */
-  /* 创建应用任务 (vTaskStartScheduler 之前, 依次建 cpld/display/preheat/pidControl) */
+  /* 创建应用任务 */
   App_Task_Create();
 
   vTaskStartScheduler();

+ 8 - 8
MDK-ARM/STMH7_temperature_control_board.uvprojx

@@ -2610,24 +2610,24 @@
               <FilePath>../Com/Src/Com_usb_cdc.c</FilePath>
             </File>
             <File>
-              <FileName>Com_usart3.c</FileName>
+              <FileName>Com_cpld_usart.c</FileName>
               <FileType>1</FileType>
-              <FilePath>../Com/Src/Com_usart3.c</FilePath>
+              <FilePath>../Com/Src/Com_cpld_usart.c</FilePath>
             </File>
             <File>
-              <FileName>Com_protocol.c</FileName>
+              <FileName>Com_cpld_protocol.c</FileName>
               <FileType>1</FileType>
-              <FilePath>../Com/Src/Com_protocol.c</FilePath>
+              <FilePath>../Com/Src/Com_cpld_protocol.c</FilePath>
             </File>
             <File>
-              <FileName>Com_usart1.c</FileName>
+              <FileName>Com_pc_usart.c</FileName>
               <FileType>1</FileType>
-              <FilePath>../Com/Src/Com_usart1.c</FilePath>
+              <FilePath>../Com/Src/Com_pc_usart.c</FilePath>
             </File>
             <File>
-              <FileName>Com_pc.c</FileName>
+              <FileName>Com_pc_protocol.c</FileName>
               <FileType>1</FileType>
-              <FilePath>../Com/Src/Com_pc.c</FilePath>
+              <FilePath>../Com/Src/Com_pc_protocol.c</FilePath>
             </File>
             <File>
               <FileName>Com_parameter.c</FileName>