/** * @file main.h * @brief 主程序公共定义、PLC 输出和连接指示灯引脚映射。 * @version 2.0 * @author zengbingjie * @date 2026-07-29 * @copyright 版权所有信捷科技股份有限公司 * @note 修改记录:2.0 将 PF6 用作 Modbus 连接指示灯。 */ #ifndef MAIN_H #define MAIN_H #ifdef __cplusplus extern "C" { #endif #include "stm32f4xx_hal.h" #include "app_cfg.h" #include "modbus.h" #include "os_cfg.h" #include "ucos_ii.h" /** @brief USART1 的 HAL 句柄,仅由初始化和中断回调路径共享。 */ extern UART_HandleTypeDef Uart1Handle; /** * @brief 处理 TIM5 更新中断中的 RTU 静默计时状态。 * @note 本函数由 TIM5_IRQHandler 在 OSIntEnter/OSIntExit 之间调用, * 不执行 Modbus 帧解析或阻塞操作。 */ void AppModbusRtuTimerIrqHandler(void); /** * @brief 普通保持寄存器数据区,可在 IAR Live Watch 中直接查看或调试写入。 * @note 地址范围为 0x0000 至 0x270F;该数组不参与掉电保持。 */ extern volatile uint16_t holdingRegisters[MODBUS_DATA_POINT_COUNT]; /** * @brief 按位压缩的普通线圈数据区,可在 IAR Live Watch 中直接查看。 * @note 地址范围为 0x0000 至 0x270F;线圈 1 至 7 在有效写入后同步至 Q1 至 Q7。 */ extern volatile uint8_t coilStorage[MODBUS_COIL_STORAGE_SIZE]; /** * @brief 私有地址 0x00010000 对应的唯一扩展保持寄存器。 * @note 仅此变量由 0x42 成功写入后的 RTC 备份流程保存和恢复。 */ extern volatile uint16_t extendedHoldingRegister; /** @brief USART1 恢复诊断量,供 IAR Live Watch 定位断线重连问题。 */ extern volatile uint32_t ModbusUartLastErrorCode; extern volatile uint32_t ModbusUartLastRxState; extern volatile uint32_t ModbusUartRecoveryCount; extern volatile uint32_t ModbusUartRecoveryFailureCount; extern volatile uint32_t ModbusUartRxArmCount; extern volatile uint32_t ModbusUartRxArmFailureCount; extern volatile uint8_t ModbusUartLastRxByte; extern volatile uint16_t ModbusLastCompleteFrameLength; /* Q0 保留给低电平有效的通信/连接指示灯。Modbus 用户线圈从线圈 1 开始, * 因此 Q1..Q7 作为 7 个可控输出。 */ #define PLC_Q0_PORT (GPIOF) #define PLC_Q0_PIN (GPIO_PIN_6) #define PLC_Q1_PORT (GPIOF) #define PLC_Q1_PIN (GPIO_PIN_8) #define PLC_Q2_PORT (GPIOF) #define PLC_Q2_PIN (GPIO_PIN_7) #define PLC_Q3_PORT (GPIOF) #define PLC_Q3_PIN (GPIO_PIN_9) #define PLC_Q4_PORT (GPIOI) #define PLC_Q4_PIN (GPIO_PIN_8) #define PLC_Q5_PORT (GPIOE) #define PLC_Q5_PIN (GPIO_PIN_6) #define PLC_Q6_PORT (GPIOE) #define PLC_Q6_PIN (GPIO_PIN_5) #define PLC_Q7_PORT (GPIOE) #define PLC_Q7_PIN (GPIO_PIN_4) #define PLC_LINK_LED_PORT (PLC_Q0_PORT) #define PLC_LINK_LED_PIN (PLC_Q0_PIN) /** @brief 关闭中断并停留在不可恢复错误状态。 */ void Error_Handler(void); #ifdef __cplusplus } #endif #endif