common.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #ifndef _COMMON_H_
  2. #define _COMMON_H_
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. #include <string.h>
  6. #include <stdlib.h>
  7. #include <math.h>
  8. #include <ctype.h>
  9. #include "gd32f10x.h"
  10. #include "gd32f10x_libopt.h"
  11. #include "delay.h"
  12. #define DEBUG_MODE (1)
  13. #define CONFIG_CAN_IAP
  14. #define USART_BAUND (38400)
  15. #define NVIC_OFFSET (0x00)
  16. #define THER_NUM_CON 2u
  17. #define SN_FLASH_ADDRESS (2048)
  18. #define SYLC_FLASH_ADDRESS (SN_FLASH_ADDRESS + 1024)
  19. #define HARD_TEST_FLASH_ADDRESS (SYLC_FLASH_ADDRESS + 1024)
  20. #define TEST_INFO_FLASH_ADDRESS (HARD_TEST_FLASH_ADDRESS + 1024)
  21. #define PS100_SERIAL_NUM_SIZE 18
  22. #define PS100_SOFTWARE_SIZE 20
  23. #define println(fmt, args ...) \
  24. printf(fmt "\n", ##args)
  25. extern const uint8_t soft_version[];
  26. extern uint8_t sn[PS100_SERIAL_NUM_SIZE];
  27. typedef struct
  28. {
  29. uint8_t set;
  30. uint16_t count;
  31. }DELAY_COMMON;
  32. typedef struct
  33. {
  34. uint8_t enable;
  35. uint8_t set;
  36. uint16_t count;
  37. }CTR_DELAY_COMMON;
  38. enum
  39. {
  40. WS_BATTER_BING_LIAN,
  41. WS_BATTER_CHUAN_LIAN,
  42. WS_BATTER_MAX
  43. };
  44. #define NO_EVENT 0x00000000UL
  45. #define RS485_RECEIVE_END_EVENT 0x00000001UL
  46. #define EVENT_CAN_RECEIVE_FINISH 0x00000002UL
  47. #define RS485_2_RECEIVE_END_EVENT 0x00000004UL
  48. #define SUB_BMS_1_RS485_DISC_EVENT 0x00000008UL
  49. #define SUB_BMS_2_RS485_DISC_EVENT 0x00000010UL
  50. #define MEASURE_TEMPERATURE_EVENT 0x00000020UL
  51. #define SUB_BMS_1_SEND_CMD_EVENT 0x00000040UL
  52. #define SUB_BMS_2_SEND_CMD_EVENT 0x00000080UL
  53. #define BMS_1_RESEND_CMD_EVENT 0x00000100UL
  54. #define BMS_2_RESEND_CMD_EVENT 0x00000200UL
  55. #define END_CTR_RESEND_CMD_EVENT 0x00000400UL
  56. #define ADAS_RESEND_CMD_EVENT 0x00000800UL
  57. #define BMS_1_SELF_TIMEOUT_EVENT 0x00001000UL
  58. #define BMS_2_SELF_TIMEOUT_EVENT 0x00002000UL
  59. #define END_CTR_SELF_TIMEOUT_EVENT 0x00004000UL
  60. #define ADAS_SELF_TIMEOUT_EVENT 0x00008000UL
  61. #define ADAS_PWM_1_TIMEOUT_EVENT 0x00010000UL
  62. #define ADAS_PWM_2_TIMEOUT_EVENT 0x00020000UL
  63. #define ADAS_MEAS_1_FINISH_EVENT 0x00040000UL
  64. #define ADAS_MEAS_2_FINISH_EVENT 0x00080000UL
  65. #define RE_INITIAL_CAN_EVENT 0x00100000UL
  66. #define ENTER_SLEEP_EVENT 0x00200000UL
  67. #define DEVICE_REBOOT_EVENT 0x00400000UL
  68. #define SAVE_PARAM_EVENT 0x00800000UL
  69. extern uint32_t g_event;
  70. #define ST_NORMAL (0x0000u)
  71. #define ST_OVRCHRG_VOL (0x0001u)
  72. #define ST_OVRDISCHRG_VOL (0x0002u)
  73. #define ST_SMALL_CURRENT_OVER (0x0004u)
  74. #define ST_SHORT_CUR (0x0008u)
  75. #define ST_CHRG_CUR (0x0010u)
  76. #define ST_DISCHRG_CUR (0x0020u)
  77. #define ST_OVRCHRG_CUR (0x0040u)
  78. #define ST_OVRDISCHRG_CUR (0x0080u)
  79. #define ST_TOTAL_CHRG (0x0100u)
  80. #define ST_CELLDIFF_CHRG (0x0200u)
  81. #define ST_PSAVE (0x0400u)
  82. #define ST_PDOWN (0x0800u)
  83. #define ST_UDR_TEMPE_CHRG (0x1000u)//Detect the charge inhibit temperature (high)
  84. #define ST_UDR_TEMPE_DISCHRG (0x2000u)
  85. #define ST_OVR_TEMPE_CHRG (0x4000u)
  86. #define ST_OVR_TEMPE_DISCHRG (0x8000u)
  87. //#define HAN_GUO_VERSION
  88. uint8_t Get_RS485_CRC(uint8_t *data,uint16_t size);
  89. void Writer_SN(uint8_t *data);
  90. #endif