common.h 3.4 KB

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