common.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. do { \
  25. if (shark_printf_enable) { \
  26. printf(fmt "\n", ##args); \
  27. } \
  28. } while (0)
  29. extern const uint8_t soft_version[];
  30. extern uint8_t sn[PS100_SERIAL_NUM_SIZE];
  31. extern uint8_t shark_printf_enable;
  32. typedef struct
  33. {
  34. uint8_t set;
  35. uint16_t count;
  36. }DELAY_COMMON;
  37. typedef struct
  38. {
  39. uint8_t enable;
  40. uint8_t set;
  41. uint16_t count;
  42. }CTR_DELAY_COMMON;
  43. enum
  44. {
  45. WS_BATTER_BING_LIAN,
  46. WS_BATTER_CHUAN_LIAN,
  47. WS_BATTER_MAX
  48. };
  49. #define NO_EVENT 0x00000000UL
  50. #define RS485_RECEIVE_END_EVENT 0x00000001UL
  51. #define EVENT_CAN_RECEIVE_FINISH 0x00000002UL
  52. #define RS485_2_RECEIVE_END_EVENT 0x00000004UL
  53. #define SUB_BMS_1_RS485_DISC_EVENT 0x00000008UL
  54. #define SUB_BMS_2_RS485_DISC_EVENT 0x00000010UL
  55. #define MEASURE_TEMPERATURE_EVENT 0x00000020UL
  56. #define SUB_BMS_1_SEND_CMD_EVENT 0x00000040UL
  57. #define SUB_BMS_2_SEND_CMD_EVENT 0x00000080UL
  58. #define BMS_1_RESEND_CMD_EVENT 0x00000100UL
  59. #define BMS_2_RESEND_CMD_EVENT 0x00000200UL
  60. #define END_CTR_RESEND_CMD_EVENT 0x00000400UL
  61. #define ADAS_RESEND_CMD_EVENT 0x00000800UL
  62. #define BMS_1_SELF_TIMEOUT_EVENT 0x00001000UL
  63. #define BMS_2_SELF_TIMEOUT_EVENT 0x00002000UL
  64. #define END_CTR_SELF_TIMEOUT_EVENT 0x00004000UL
  65. #define ADAS_SELF_TIMEOUT_EVENT 0x00008000UL
  66. #define ADAS_PWM_1_TIMEOUT_EVENT 0x00010000UL
  67. #define ADAS_PWM_2_TIMEOUT_EVENT 0x00020000UL
  68. #define ADAS_MEAS_1_FINISH_EVENT 0x00040000UL
  69. #define ADAS_MEAS_2_FINISH_EVENT 0x00080000UL
  70. #define RE_INITIAL_CAN_EVENT 0x00100000UL
  71. #define ENTER_SLEEP_EVENT 0x00200000UL
  72. #define DEVICE_REBOOT_EVENT 0x00400000UL
  73. #define SAVE_PARAM_EVENT 0x00800000UL
  74. extern uint32_t g_event;
  75. #define ST_NORMAL (0x0000u)
  76. #define ST_OVRCHRG_VOL (0x0001u)
  77. #define ST_OVRDISCHRG_VOL (0x0002u)
  78. #define ST_SMALL_CURRENT_OVER (0x0004u)
  79. #define ST_SHORT_CUR (0x0008u)
  80. #define ST_CHRG_CUR (0x0010u)
  81. #define ST_DISCHRG_CUR (0x0020u)
  82. #define ST_OVRCHRG_CUR (0x0040u)
  83. #define ST_OVRDISCHRG_CUR (0x0080u)
  84. #define ST_TOTAL_CHRG (0x0100u)
  85. #define ST_CELLDIFF_CHRG (0x0200u)
  86. #define ST_PSAVE (0x0400u)
  87. #define ST_PDOWN (0x0800u)
  88. #define ST_UDR_TEMPE_CHRG (0x1000u)//Detect the charge inhibit temperature (high)
  89. #define ST_UDR_TEMPE_DISCHRG (0x2000u)
  90. #define ST_OVR_TEMPE_CHRG (0x4000u)
  91. #define ST_OVR_TEMPE_DISCHRG (0x8000u)
  92. //#define HAN_GUO_VERSION
  93. uint8_t Get_RS485_CRC(uint8_t *data,uint16_t size);
  94. void Writer_SN(uint8_t *data);
  95. #endif