common.h 3.5 KB

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