bsp.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * @Description:
  3. * @Version: 2.0
  4. * @Author: Seven
  5. * @Date: 2022-08-22 09:55:26
  6. * @LastEditors: Seven
  7. * @LastEditTime: 2023-04-28 15:39:14
  8. */
  9. #ifndef __BSP_H
  10. #define __BSP_H
  11. #include "includes.h"
  12. #include "tools.h"
  13. //app版本号
  14. #define SOFTWARE_VERSION_APP 0X02013130
  15. #define EEPROM_VER 0X01
  16. #define EEPROM_FIRST_INIT_FLAG 0x55AA
  17. extern const char PowerOn_Info[][64];
  18. extern FunctionalState irq_state;
  19. //任务执行次数
  20. typedef struct _task_count_t
  21. {
  22. uint32_t uart_count_cur;
  23. uint32_t uart_count_prev;
  24. uint32_t prog_count_cur;
  25. uint32_t prog_count_prev;
  26. uint32_t ota_count_cur;
  27. uint32_t ota_count_prev;
  28. uint32_t lora_count_cur;
  29. uint32_t lora_count_prev;
  30. uint32_t encoder_count_cur;
  31. uint32_t encoder_count_prev;
  32. }__attribute__((packed)) task_count_t;
  33. extern task_count_t task_count;
  34. void watchdog_feed(void);
  35. //共用体(float与u32)
  36. union data_u
  37. {
  38. float dataf;
  39. uint32_t datai;
  40. };
  41. extern union data_u Voltage,Temperature;
  42. #define REAL_TIME_TIMEOUT (10*1000) //实时参数读取(电压、温度)
  43. //工作模式
  44. typedef enum DEV_WORK_STATE
  45. {
  46. DEV_WORK_STATE_NORMAL, //正常工作模式
  47. DEV_WORK_STATE_UPDATING, //升级模式
  48. DEV_WORK_STATE_PT, //产测模式
  49. DEV_WORK_STATE_UNINIT, //出厂信息未初始化模式
  50. DEV_WORK_STATE_XSP_UPDATING, //显示屏升级模式
  51. // DEV_WORK_STATE_UPDATE_RETRANSMIT, //
  52. // DEV_WORK_STATE_ONLOOKER, //旁观者模式
  53. // DEV_WORK_STATE_OTA_BEGIN, //开始升级模式
  54. // DEV_WORK_STATE_OTA_CONTINUOUS, //升级中连续收包模式
  55. // DEV_WORK_STATE_OTA_RETRANSMIT, //升级中重传模式
  56. // DEV_WORK_STATE_OTA_UPGRADE_RCV_END, //升级中升级包接收完成模式
  57. // DEV_WORK_STATE_UPDATE_MASTER, //主设备升级模式
  58. // DEV_WORK_STATE_UPLOAD_SLAVE, //从设备主动上报升级状态模式
  59. DEV_WORK_STATE_MAX
  60. }DEV_WORK_STATE_T;
  61. //设备可配置信息,需存eeprom
  62. typedef struct _device_info
  63. {
  64. uint8_t alrd; //是否配置的标记
  65. uint32_t device_sn; //设备sn
  66. uint16_t device_type; //设备类型
  67. uint16_t manufactures; //产品制造商
  68. uint16_t batch_number; //批次号
  69. uint32_t production_data; //出厂日期
  70. uint8_t pcb_ver; //PCB版本
  71. }__attribute__((packed)) device_info_t;
  72. extern device_info_t device_info;
  73. //设备固定信息,不需在app中写eeprom
  74. typedef struct _device_fixed_info
  75. {
  76. uint32_t Soft_ver_app; //app版本号
  77. uint32_t Soft_ver_boot; //bootloader版本号
  78. uint8_t MCU_UUID[12]; //MCU的UUID
  79. uint16_t MCU_Type_ID; //MCU的芯片类型
  80. uint32_t Reset_total_cnt; //复位总次数
  81. uint8_t Last_reset_flag; //上次复位类型
  82. uint8_t Encrypt; //明密文状态
  83. uint8_t Work_State; //当前工作状态
  84. uint32_t Voltage; //电压
  85. uint32_t Temperature; //温度
  86. uint8_t lora_para_group; //lora参数选择
  87. uint8_t master_updata_start; //主设备开始升级标志
  88. uint8_t slave_uploade_start; //从设备主动上报标志
  89. uint8_t reset_flag; //采集器复位标记
  90. uint8_t xsp_update_start; //显示屏开始升级标记
  91. }device_fixed_info_t;
  92. extern device_fixed_info_t device_fixed_info;
  93. #define RS485_RX() {GPIO_ResetBits(GPIOA, GPIO_Pin_1);}
  94. #define RS485_TX() {GPIO_SetBits(GPIOA, GPIO_Pin_1);}
  95. void GPIO_COMM_Init(u32 clk, GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin, GPIOMode_TypeDef mode, GPIOSpeed_TypeDef speed);
  96. void BSP_Init(void);
  97. void key_task_handle(uint8_t num);
  98. uint8_t device_type_cmp(uint32_t device_fixed, uint16_t device_rcv);
  99. int device_type_and_id_cmp_NoBroadcast(uint16_t device_type, uint32_t device_sn);
  100. void device_real_time_para_read(void);
  101. void device_irq_set(FunctionalState state);
  102. void run_irq_set(void);
  103. void device_module_reset(void);
  104. #endif