25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

83 lines
2.8 KiB

  1. /**
  2. * @file main.h
  3. * @brief 主程序公共定义、PLC 输出和连接指示灯引脚映射。
  4. * @version 2.0
  5. * @author zengbingjie
  6. * @date 2026-07-29
  7. * @copyright 版权所有信捷科技股份有限公司
  8. * @note 修改记录:2.0 将 PF6 用作 Modbus 连接指示灯。
  9. */
  10. #ifndef MAIN_H
  11. #define MAIN_H
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. #include "stm32f4xx_hal.h"
  16. #include "app_cfg.h"
  17. #include "modbus.h"
  18. #include "os_cfg.h"
  19. #include "ucos_ii.h"
  20. /** @brief USART1 的 HAL 句柄,仅由初始化和中断回调路径共享。 */
  21. extern UART_HandleTypeDef Uart1Handle;
  22. /**
  23. * @brief 处理 TIM5 更新中断中的 RTU 静默计时状态。
  24. * @note 本函数由 TIM5_IRQHandler 在 OSIntEnter/OSIntExit 之间调用,
  25. * 不执行 Modbus 帧解析或阻塞操作。
  26. */
  27. void AppModbusRtuTimerIrqHandler(void);
  28. /**
  29. * @brief 普通保持寄存器数据区,可在 IAR Live Watch 中直接查看或调试写入。
  30. * @note 地址范围为 0x0000 至 0x270F;该数组不参与掉电保持。
  31. */
  32. extern volatile uint16_t holdingRegisters[MODBUS_DATA_POINT_COUNT];
  33. /**
  34. * @brief 按位压缩的普通线圈数据区,可在 IAR Live Watch 中直接查看。
  35. * @note 地址范围为 0x0000 至 0x270F;线圈 1 至 7 在有效写入后同步至 Q1 至 Q7。
  36. */
  37. extern volatile uint8_t coilStorage[MODBUS_COIL_STORAGE_SIZE];
  38. /**
  39. * @brief 私有地址 0x00010000 对应的唯一扩展保持寄存器。
  40. * @note 仅此变量由 0x42 成功写入后的 RTC 备份流程保存和恢复。
  41. */
  42. extern volatile uint16_t extendedHoldingRegister;
  43. /* Q0 保留给低电平有效的通信/连接指示灯。Modbus 用户线圈从线圈 1 开始,
  44. * 因此 Q1..Q7 作为 7 个可控输出。 */
  45. #define PLC_Q0_PORT (GPIOF)
  46. #define PLC_Q0_PIN (GPIO_PIN_6)
  47. #define PLC_Q1_PORT (GPIOF)
  48. #define PLC_Q1_PIN (GPIO_PIN_8)
  49. #define PLC_Q2_PORT (GPIOF)
  50. #define PLC_Q2_PIN (GPIO_PIN_7)
  51. #define PLC_Q3_PORT (GPIOF)
  52. #define PLC_Q3_PIN (GPIO_PIN_9)
  53. #define PLC_Q4_PORT (GPIOI)
  54. #define PLC_Q4_PIN (GPIO_PIN_8)
  55. #define PLC_Q5_PORT (GPIOE)
  56. #define PLC_Q5_PIN (GPIO_PIN_6)
  57. #define PLC_Q6_PORT (GPIOE)
  58. #define PLC_Q6_PIN (GPIO_PIN_5)
  59. #define PLC_Q7_PORT (GPIOE)
  60. #define PLC_Q7_PIN (GPIO_PIN_4)
  61. #define PLC_LINK_LED_PORT (PLC_Q0_PORT)
  62. #define PLC_LINK_LED_PIN (PLC_Q0_PIN)
  63. /** @brief 关闭中断并停留在不可恢复错误状态。 */
  64. void Error_Handler(void);
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif