main.h.bak 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file : main.h
  5. * @brief : Header for main.c file.
  6. * This file contains the common defines of the application.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* USER CODE END Header */
  21. /* Define to prevent recursive inclusion -------------------------------------*/
  22. #ifndef __MAIN_H
  23. #define __MAIN_H
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm32f4xx_hal.h"
  29. /* Private includes ----------------------------------------------------------*/
  30. /* USER CODE BEGIN Includes */
  31. #include "stdio.h"
  32. #include "string.h"
  33. #include "iwdg.h"
  34. /* USER CODE END Includes */
  35. /* Exported types ------------------------------------------------------------*/
  36. /* USER CODE BEGIN ET */
  37. #define DEBUG_INFO(format, args...) printf("[%s:%d][Info] "format, __FUNCTION__, __LINE__, ##args)
  38. #define DEBUG_WARN(format, args...) printf("[%s:%d][Warn] "format, __FUNCTION__, __LINE__, ##args)
  39. #define DEBUG_ERROR(format, args...) printf("[%s:%d][Error] "format, __FUNCTION__, __LINE__, ##args)
  40. #define ARRAY_SIZE(A) (sizeof(A) / sizeof(A[0]))
  41. #define MEMORY_LENGTH_CONFIG 0x1000
  42. #define MEM_REAL_LENGTH 27 //27 two word = 52 word
  43. #define bool char
  44. //#define DEBUG
  45. enum
  46. {
  47. Fan1 = 0,
  48. Fan2,
  49. Fan3,
  50. Fan4,
  51. Fan5,
  52. Fan6,
  53. Fan7,
  54. Fan8
  55. };
  56. enum
  57. {
  58. AC_L1_GAIN = 0,
  59. AC_L2_GAIN,
  60. AC_L3_GAIN,
  61. DC_SMR1_GAIN,
  62. DC_SMR2_GAIN
  63. };
  64. enum
  65. {
  66. MainRelay = 0x10,
  67. GunRelay = 0x12,
  68. MainBridge1 = 0x13,
  69. MainBridge2 = 0x14,
  70. MainBridge3 = 0x15,
  71. };
  72. enum
  73. {
  74. Input_L1_AC_voltage = 0x01,
  75. Input_L2_AC_voltage,
  76. Input_L3_AC_voltage,
  77. Output_L1_AC_current = 0x11,
  78. Output_L2_AC_current,
  79. Output_L3_AC_current,
  80. Leak_current = 0x21,
  81. GMI_voltage = 0x31,
  82. GFD_Resister_Left = 0x46,
  83. GFD_Resister_Right = 0x47,
  84. Battery1_input_voltage = 0x51,
  85. Battery2_input_voltage,
  86. SMR1_output_voltage = 0x61,
  87. SMR2_output_voltage,
  88. SMR3_output_voltage,
  89. SMR4_output_voltage,
  90. SMR5_output_voltage,
  91. SMR6_output_voltage,
  92. };
  93. enum
  94. {
  95. Parallel_relay_n = 0,
  96. Parallel_relay_p,
  97. SMR1_relay_n,
  98. SMR1_relay_p,
  99. SMR2_relay_n,
  100. SMR2_relay_p,
  101. LED1,
  102. Chdemo_Delay,
  103. Reserved,
  104. };
  105. typedef union
  106. {
  107. uint64_t All;
  108. uint8_t Status[8];
  109. struct __attribute__ ((packed))
  110. {
  111. uint8_t AC_Contactor :1;
  112. uint8_t Precharge1 :1;
  113. uint8_t Precharge2 :1;
  114. uint8_t Reserved_0 :5;
  115. uint8_t SMR1_relay_n :1;
  116. uint8_t SMR1_relay_p :1;
  117. uint8_t Reserved_1 :6;
  118. uint8_t SMR2_relay_n :1;
  119. uint8_t SMR2_relay_p :1;
  120. uint8_t Reserved_2 :6;
  121. uint8_t SMR3_relay_n :1;
  122. uint8_t SMR3_relay_p :1;
  123. uint8_t Reserved_3 :6;
  124. uint8_t SMR4_relay_n :1;
  125. uint8_t SMR4_relay_p :1;
  126. uint8_t Reserved_4 :6;
  127. uint8_t SMR5_relay_n :1;
  128. uint8_t SMR5_relay_p :1;
  129. uint8_t Reserved_5 :6;
  130. uint8_t SMR6_relay_n :1;
  131. uint8_t SMR6_relay_p :1;
  132. uint8_t Reserved_6 :6;
  133. uint8_t Reserved_7 :8;
  134. } flags;
  135. } RLY_STATUS;
  136. typedef struct
  137. {
  138. uint8_t AC_Contactor :1;
  139. uint8_t Precharge1 :1;
  140. uint8_t Precharge2 :1;
  141. uint8_t Reserved_0 :5;
  142. uint8_t SMR1_relay_n :1;
  143. uint8_t SMR1_relay_p :1;
  144. uint8_t Reserved_1 :6;
  145. uint8_t SMR2_relay_n :1;
  146. uint8_t SMR2_relay_p :1;
  147. uint8_t Reserved_2 :6;
  148. uint8_t SMR3_relay_n :1;
  149. uint8_t SMR3_relay_p :1;
  150. uint8_t Reserved_3 :6;
  151. uint8_t SMR4_relay_n :1;
  152. uint8_t SMR4_relay_p :1;
  153. uint8_t Reserved_4 :6;
  154. uint8_t SMR5_relay_n :1;
  155. uint8_t SMR5_relay_p :1;
  156. uint8_t Reserved_5 :6;
  157. uint8_t SMR6_relay_n :1;
  158. uint8_t SMR6_relay_p :1;
  159. uint8_t Reserved_6 :6;
  160. } RLY_ST;
  161. typedef union
  162. {
  163. uint64_t All;
  164. struct __attribute__ ((packed))
  165. {
  166. uint8_t AC_Contactor :1;
  167. uint8_t Precharge1 :1;
  168. uint8_t Precharge2 :1;
  169. uint8_t Reserved_0 :5;
  170. uint8_t SMR1_relay_n :1;
  171. uint8_t SMR1_relay_p :1;
  172. uint8_t Reserved_1 :6;
  173. uint8_t SMR2_relay_n :1;
  174. uint8_t SMR2_relay_p :1;
  175. uint8_t Reserved_2 :6;
  176. uint8_t SMR3_relay_n :1;
  177. uint8_t SMR3_relay_p :1;
  178. uint8_t Reserved_3 :6;
  179. uint8_t SMR4_relay_n :1;
  180. uint8_t SMR4_relay_p :1;
  181. uint8_t Reserved_4 :6;
  182. uint8_t SMR5_relay_n :1;
  183. uint8_t SMR5_relay_p :1;
  184. uint8_t Reserved_5 :6;
  185. uint8_t SMR6_relay_n :1;
  186. uint8_t SMR6_relay_p :1;
  187. uint8_t Reserved_6 :6;
  188. uint8_t Reserved_7 :8;
  189. } flags;
  190. } RLY_GPIO;
  191. typedef union
  192. {
  193. uint16_t All;
  194. struct __attribute__ ((packed))
  195. {
  196. uint8_t Relay1_Fail :1;
  197. uint8_t Relay2_Fail :1;
  198. uint8_t Relay3_Fail :1;
  199. uint8_t Relay4_Fail :1;
  200. uint8_t Relay5_Fail :1;
  201. uint8_t Relay6_Fail :1;
  202. uint8_t Relay7_Fail :1;
  203. uint8_t Relay8_Fail :1;
  204. uint8_t Gfd_Alarm_0 :1;
  205. uint8_t Gfd_Alarm_1 :1;
  206. uint8_t Reserved_1 :6;
  207. } flags;
  208. } ALARM;
  209. typedef union
  210. {
  211. uint8_t All;
  212. struct __attribute__ ((packed))
  213. {
  214. // LSB to begin
  215. uint8_t Fan_Enable:1;
  216. uint8_t Drv_Up:1;
  217. uint8_t Drv_Down:1;
  218. uint8_t Reversed:5;
  219. // MSB to End
  220. } flags;
  221. } _GPIO_;
  222. typedef union
  223. {
  224. uint8_t Mode;
  225. struct __attribute__ ((packed))
  226. {
  227. // LSB to begin
  228. uint8_t SW0:1;
  229. uint8_t SW1:1;
  230. uint8_t SW2:1;
  231. uint8_t Reversed:5;
  232. // MSB to End
  233. } flags;
  234. } _DIP_SW_;
  235. typedef struct COEFFICIENT
  236. {
  237. float gain_volt;
  238. float offset_volt;
  239. } Coefficient;
  240. typedef struct SF_TEST
  241. {
  242. struct
  243. {
  244. uint8_t SF_test_status;
  245. uint8_t SF_Act;
  246. uint8_t SF_State;
  247. union
  248. {
  249. uint64_t value;
  250. struct
  251. {
  252. uint8_t test_item1 :1;
  253. uint8_t test_item2 :1;
  254. uint8_t test_item3 :1;
  255. uint8_t test_item4 :1;
  256. uint8_t test_item5 :1;
  257. uint8_t test_item6 :1;
  258. uint8_t test_item7 :1;
  259. uint8_t test_item8 :1;
  260. uint8_t test_item9 :1;
  261. uint8_t test_item10 :1;
  262. uint8_t test_item11 :1;
  263. uint8_t test_item12 :1;
  264. uint8_t test_item13 :1;
  265. uint8_t test_item14 :1;
  266. uint8_t test_item15 :1;
  267. uint8_t test_item16 :1;
  268. uint8_t test_item17 :1;
  269. uint8_t test_item18 :1;
  270. uint8_t test_item19 :1;
  271. uint8_t test_item20 :1;
  272. uint8_t test_item21 :1;
  273. uint8_t test_item22 :1;
  274. uint8_t test_item23 :1;
  275. uint8_t test_item24 :1;
  276. uint8_t test_item25 :1;
  277. uint8_t test_item26 :1;
  278. uint8_t test_item27 :1;
  279. uint8_t test_item28 :1;
  280. uint8_t test_item29 :1;
  281. uint8_t test_item30 :1;
  282. uint8_t test_item31 :1;
  283. uint8_t test_item32 :1;
  284. uint8_t test_item33 :1;
  285. uint8_t test_item34 :1;
  286. } items;
  287. } data;
  288. } SF_Config;
  289. } SF_test;
  290. // V18 memory structure.
  291. typedef struct MEM
  292. {
  293. struct
  294. {
  295. union
  296. {
  297. // 0x1000 = 10240 byte , uint32_t = 4byte , array size = 10240/4 = 1000
  298. uint32_t value[MEMORY_LENGTH_CONFIG];
  299. struct
  300. {
  301. // 16 Byte -> Voltage correction point data(adc & meter) [point][adc & meter], unit: 0.1V
  302. uint16_t Correction_Volt[9][2]; // [L1-point1~L3-point3][ADC,Set Value]
  303. uint16_t DC_Correction_Volt[12][2]; // [SMR1 point1~SMR6 point2][ADC,Set Value]
  304. uint16_t GFD_Correction_Resistor[4][2]; // [L-GFD point1~R-GFD point2][ADC,Set Value]
  305. uint16_t DCIn_Correction_Volt[2][2]; // [DC In 2 point][ADC,Set Value]
  306. } item;
  307. } data;
  308. struct
  309. {
  310. uint8_t update:1; // Update ram content to external flash request
  311. uint8_t clear:1; // Clear ram & external flash content request
  312. uint8_t read:1; // Read external flash content to ram request
  313. uint8_t reserved:5;
  314. } op_bits;
  315. } Module_Config;
  316. }Mem;
  317. struct Detet_Fan_IO
  318. {
  319. uint32_t Difference;
  320. uint32_t Frequency;
  321. uint32_t ubFan_RPM;
  322. uint8_t Rpm_Idx;
  323. uint16_t Second;
  324. uint8_t Fan_Fail;
  325. };
  326. struct Gun_Gfd_Check
  327. {
  328. uint8_t Rfd_State;
  329. uint8_t Csu_State;
  330. uint8_t Gfd_Running_Count;
  331. uint8_t Gfd_Warning_Count;
  332. uint8_t bResult_Gfd;
  333. uint32_t R_GFD;
  334. uint32_t R_GFD_v;
  335. uint32_t R_GFD_Fail;
  336. uint8_t Rfd_State_Fail;
  337. uint32_t SMR_Voltage_Fail;
  338. uint8_t bFirstGfd;
  339. };
  340. extern const uint16_t nRPM_Tbl[11][2];
  341. extern uint16_t serial_n;
  342. extern SF_test sf_t;
  343. extern float Avg_offset_v;
  344. extern uint16_t Freq_CLC_Grid_v;
  345. extern uint8_t bGfd_Correct[2];
  346. extern uint32_t nGfd_Temp[2][17];
  347. extern uint32_t R_GFD_Total[2];
  348. extern uint8_t nGfd_Idx[2];
  349. extern uint16_t pwmVal;
  350. extern uint8_t dir;
  351. extern uint8_t bRelayFeedback;
  352. extern uint8_t nBoard_Addr;
  353. extern float c_vadc[2];
  354. extern uint8_t nGun;
  355. extern bool GainCaliFlag;
  356. #define vsense1 24.42 // for ADC1 (330 / 4095 / 0.0033) = 24.42
  357. #define vsense2 0.002919
  358. //#define vsense3 4.118 // for current (330 / 4095 / 0.01957 ) = 4.118
  359. #define vsense3 24448.7 // 5000 / (5.1*4.01) * 100 = 24448.7 (5000:CT �I��v 5.1:�q���q�� 20.5K/5.11K=4.01 OP���v)
  360. #define v_div_1K 0.8059 // 3300 / 4095
  361. #define v_div 0.0008059 // 3.3 / 4095
  362. #define FAN_RPM_DEF 6200
  363. #define FAN_PWM_PERIOD 4200
  364. #define FAN_TOLERANCE 50 // 50 Percent
  365. #define PWM_Limit 9980
  366. #define OFF 0
  367. #define ON 1
  368. #define FAIL 0
  369. #define PASS 1
  370. #define NO 0
  371. #define YES 1
  372. #define true 1
  373. #define false 0
  374. #define SMR1_Relay_Shift_V 0 // 27
  375. #define SMR1_Fuse_Shift_V 0
  376. #define SMR2_Relay_Shift_V 0 // 14
  377. #define SMR2_Fuse_Shift_V 0
  378. #define LINE_VOLTAGE_POINT 100
  379. #define LINE_VOLTAGE_TOLERANCE 200
  380. #define V165_OFFSET 7
  381. //<<<<<<< HEAD
  382. #define DC_LOW_GAIN 1
  383. #define DC_HIGH_GAIN 1 // 1.0035
  384. //=======
  385. //#define DC_LOW_GAIN 1.0314
  386. //#define DC_HIGH_GAIN 1.02 // 1.0035
  387. //>>>>>>> be39927da1874c206c78d2be3fcbaa101e72d2ea
  388. #define GFD_UNKNOW 0
  389. #define GFD_PASS 1
  390. #define GFD_FAIL 2
  391. #define GFD_WARNING 3
  392. //<<<<<<< HEAD
  393. #define GFD_TEST_TIMES 15
  394. #define GFD_SLEF_TEST_RESISTOR_TOLERANCE 45000 // 30K -> 45K ohm
  395. //#define GFD_SELF_TEST_RESISTOR 55000
  396. #define GFD_SELF_TEST_RESISTOR (50000 + GFD_SLEF_TEST_RESISTOR_TOLERANCE) // 95K ohm
  397. #define GFD_FILTER_LIMIT 16
  398. //=======
  399. //#define GFD_OPT_COUP_RESISTER 35000
  400. //#define GFD_TEST_TIMES 15
  401. //>>>>>>> be39927da1874c206c78d2be3fcbaa101e72d2ea
  402. #define ISOLATION_TEST_VOLTAGE 5000
  403. #define WAIT_FOR_RESISTER_CALC 30 // mini_second
  404. #define WAIT_FOR_RESISTER_CALC_LONG 50
  405. #define WAIT_FOR_RESISTER_CALC_FAST 30
  406. #define MCU_DATA 0
  407. #define METER_DATA 1
  408. #define PREVENT_REPEAT_OFF 1
  409. #define RELAY_ALL_ON 0
  410. #define FEEDBACK_PIN 1
  411. #define DEBUG_PRINTF 1
  412. #define GFD_SELF_TEST 1
  413. #define GFD_DEFAULT_V4 1
  414. #define READ_IO_NO_DELAY 1
  415. #define AC_INPUT_1ST_POINT 2800 // OVP +10
  416. #define AC_INPUT_2ND_POINT 2200 // UVP -10
  417. #define AC_INPUT_3RD_POINT 1600 // UVP -10
  418. #define DC_OUTPUT_1ST_POINT 9500
  419. #define DC_OUTPUT_2ND_POINT 1500
  420. #define GFD_RESISTOR_WARNING 100
  421. #define GFD_RESISTOR_PRE_WARNING 500
  422. #define EVSE_MAX_OUTPUT_VOLTAGE 950
  423. #define GFD_EXTRA_FAIL_RESISTOR 5000
  424. #define GFD_RESISTOR_COEFFICIENT 73.8 // 73.8 , 51.3
  425. #define GFD_SENSE_VOLTAGE_UP_LIMIT 1.75 // 1.75
  426. #define GFD_SENSE_VOLTAGE_DOWN_LIMIT 1.55 // 1.55
  427. #define GFD_SENSE_CENTER_VOLTAGE 1.65
  428. #define GFD_WORKING_VOLTAGE 2000 // 200v, for Safety Test : 1400
  429. //#define AC_CORRECT_GAIN_MAX_NUM 6
  430. #define DC_CORRECT_GAIN_MAX_NUM 6
  431. #define GFD_CORRECT_GAIN_MAX_NUM 2
  432. //#define DC_CORR_2ND_SHIFT 7
  433. //#define DEFAULT_COFF_3 1.00768
  434. //#define DEFAULT_OFFST_3 -15.556
  435. //#define DEFAULT_COFF_4 1.00553
  436. //#define DEFAULT_OFFST_4 -2.262
  437. //
  438. //#define DEFAULT_COFF_5 1.086
  439. //#define DEFAULT_OFFST_5 -358.322
  440. //#define DEFAULT_COFF_6 1.241
  441. //#define DEFAULT_OFFST_6 -481.362
  442. /* USER CODE END ET */
  443. /* Exported constants --------------------------------------------------------*/
  444. /* USER CODE BEGIN EC */
  445. /* USER CODE END EC */
  446. /* Exported macro ------------------------------------------------------------*/
  447. /* USER CODE BEGIN EM */
  448. /* USER CODE END EM */
  449. /* Exported functions prototypes ---------------------------------------------*/
  450. void Error_Handler(void);
  451. /* USER CODE BEGIN EFP */
  452. #define PWM_CH_FAN_START 0
  453. //void user_pwm_setvalue(uint8_t ch, uint16_t value);
  454. /* USER CODE END EFP */
  455. /* Private defines -----------------------------------------------------------*/
  456. #define CP0_EXTI_Pin GPIO_PIN_0
  457. #define CP0_EXTI_GPIO_Port GPIOF
  458. #define CP0_EXTI_EXTI_IRQn EXTI0_IRQn
  459. #define CP1_EXTI_Pin GPIO_PIN_1
  460. #define CP1_EXTI_GPIO_Port GPIOF
  461. #define CP1_EXTI_EXTI_IRQn EXTI1_IRQn
  462. #define CP2_EXTI_Pin GPIO_PIN_2
  463. #define CP2_EXTI_GPIO_Port GPIOF
  464. #define CP2_EXTI_EXTI_IRQn EXTI2_IRQn
  465. #define CP3_EXTI_Pin GPIO_PIN_3
  466. #define CP3_EXTI_GPIO_Port GPIOF
  467. #define CP3_EXTI_EXTI_IRQn EXTI3_IRQn
  468. #define CP4_EXTI_Pin GPIO_PIN_4
  469. #define CP4_EXTI_GPIO_Port GPIOF
  470. #define CP4_EXTI_EXTI_IRQn EXTI4_IRQn
  471. #define CP5_EXTI_Pin GPIO_PIN_5
  472. #define CP5_EXTI_GPIO_Port GPIOF
  473. #define CP5_EXTI_EXTI_IRQn EXTI9_5_IRQn
  474. #define SMR1_Gfd_Sense_Pin GPIO_PIN_6
  475. #define SMR1_Gfd_Sense_GPIO_Port GPIOF
  476. #define SMR2_Gfd_Sense_Pin GPIO_PIN_7
  477. #define SMR2_Gfd_Sense_GPIO_Port GPIOF
  478. #define DC_In_Pin GPIO_PIN_10
  479. #define DC_In_GPIO_Port GPIOF
  480. #define SMR3_Relay_Voltage_Pin GPIO_PIN_1
  481. #define SMR3_Relay_Voltage_GPIO_Port GPIOC
  482. #define SMR4_Relay_Voltage_Pin GPIO_PIN_2
  483. #define SMR4_Relay_Voltage_GPIO_Port GPIOC
  484. #define SMR5_Relay_Voltage_Pin GPIO_PIN_3
  485. #define SMR5_Relay_Voltage_GPIO_Port GPIOC
  486. #define SMR6_Relay_Voltage_Pin GPIO_PIN_0
  487. #define SMR6_Relay_Voltage_GPIO_Port GPIOA
  488. #define CSRHB_VER_Pin GPIO_PIN_3
  489. #define CSRHB_VER_GPIO_Port GPIOA
  490. #define SMR1_Relay_Voltage_Pin GPIO_PIN_4
  491. #define SMR1_Relay_Voltage_GPIO_Port GPIOA
  492. #define SMR1_Current_Pin GPIO_PIN_5
  493. #define SMR1_Current_GPIO_Port GPIOA
  494. #define SMR2_Relay_Voltage_Pin GPIO_PIN_6
  495. #define SMR2_Relay_Voltage_GPIO_Port GPIOA
  496. #define SMR2_Current_Pin GPIO_PIN_7
  497. #define SMR2_Current_GPIO_Port GPIOA
  498. #define AC_Input_L1_Pin GPIO_PIN_4
  499. #define AC_Input_L1_GPIO_Port GPIOC
  500. #define AC_Input_L2_Pin GPIO_PIN_5
  501. #define AC_Input_L2_GPIO_Port GPIOC
  502. #define AC_Input_L3_Pin GPIO_PIN_0
  503. #define AC_Input_L3_GPIO_Port GPIOB
  504. #define Vref_165_Pin GPIO_PIN_1
  505. #define Vref_165_GPIO_Port GPIOB
  506. #define Contactor_Enable_Pin GPIO_PIN_13
  507. #define Contactor_Enable_GPIO_Port GPIOF
  508. #define PSU_Enable1_Pin GPIO_PIN_14
  509. #define PSU_Enable1_GPIO_Port GPIOF
  510. #define PSU_Enable2_Pin GPIO_PIN_15
  511. #define PSU_Enable2_GPIO_Port GPIOF
  512. #define SW1_Pin GPIO_PIN_1
  513. #define SW1_GPIO_Port GPIOG
  514. #define SW0_Pin GPIO_PIN_7
  515. #define SW0_GPIO_Port GPIOE
  516. #define SW2_Pin GPIO_PIN_8
  517. #define SW2_GPIO_Port GPIOE
  518. #define SMR5_Relay_p_Ret_Pin GPIO_PIN_13
  519. #define SMR5_Relay_p_Ret_GPIO_Port GPIOB
  520. #define SMR5_Relay_n_Ret_Pin GPIO_PIN_14
  521. #define SMR5_Relay_n_Ret_GPIO_Port GPIOB
  522. #define SMR6_Relay_p_Ret_Pin GPIO_PIN_8
  523. #define SMR6_Relay_p_Ret_GPIO_Port GPIOD
  524. #define SMR6_Relay_n_Ret_Pin GPIO_PIN_9
  525. #define SMR6_Relay_n_Ret_GPIO_Port GPIOD
  526. #define Sys2_Self_Test_DC_n_Pin GPIO_PIN_10
  527. #define Sys2_Self_Test_DC_n_GPIO_Port GPIOD
  528. #define Sys2_Self_Test_DC_p_Pin GPIO_PIN_11
  529. #define Sys2_Self_Test_DC_p_GPIO_Port GPIOD
  530. #define Drv_Down_2_Pin GPIO_PIN_12
  531. #define Drv_Down_2_GPIO_Port GPIOD
  532. #define Drv_Up_2_Pin GPIO_PIN_13
  533. #define Drv_Up_2_GPIO_Port GPIOD
  534. #define SMR4_Relay_p_Ret_Pin GPIO_PIN_14
  535. #define SMR4_Relay_p_Ret_GPIO_Port GPIOD
  536. #define SMR4_Relay_n_Ret_Pin GPIO_PIN_15
  537. #define SMR4_Relay_n_Ret_GPIO_Port GPIOD
  538. #define AC_Contactor_Ret_Pin GPIO_PIN_2
  539. #define AC_Contactor_Ret_GPIO_Port GPIOG
  540. #define SMR1_Relay_p_Ret_Pin GPIO_PIN_3
  541. #define SMR1_Relay_p_Ret_GPIO_Port GPIOG
  542. #define SMR1_Relay_n_Ret_Pin GPIO_PIN_4
  543. #define SMR1_Relay_n_Ret_GPIO_Port GPIOG
  544. #define SMR2_Relay_p_Ret_Pin GPIO_PIN_5
  545. #define SMR2_Relay_p_Ret_GPIO_Port GPIOG
  546. #define SMR2_Relay_n_Ret_Pin GPIO_PIN_6
  547. #define SMR2_Relay_n_Ret_GPIO_Port GPIOG
  548. #define SMR3_Relay_p_Ret_Pin GPIO_PIN_7
  549. #define SMR3_Relay_p_Ret_GPIO_Port GPIOG
  550. #define SMR3_Relay_n_Ret_Pin GPIO_PIN_8
  551. #define SMR3_Relay_n_Ret_GPIO_Port GPIOG
  552. #define Precharge1_Ret_Pin GPIO_PIN_6
  553. #define Precharge1_Ret_GPIO_Port GPIOC
  554. #define DBG_RX_Pin GPIO_PIN_7
  555. #define DBG_RX_GPIO_Port GPIOC
  556. #define Precharge2_Ret_Pin GPIO_PIN_8
  557. #define Precharge2_Ret_GPIO_Port GPIOC
  558. #define RS485_DE_Pin GPIO_PIN_9
  559. #define RS485_DE_GPIO_Port GPIOC
  560. #define RS485_RE_Pin GPIO_PIN_8
  561. #define RS485_RE_GPIO_Port GPIOA
  562. #define Sys1_Self_Test_DC_p_Pin GPIO_PIN_12
  563. #define Sys1_Self_Test_DC_p_GPIO_Port GPIOA
  564. #define SMR1_RLY_p_Enable_Pin GPIO_PIN_15
  565. #define SMR1_RLY_p_Enable_GPIO_Port GPIOA
  566. #define SMR1_RLY_n_Enable_Pin GPIO_PIN_10
  567. #define SMR1_RLY_n_Enable_GPIO_Port GPIOC
  568. #define SMR3_RLY_p_Enable_Pin GPIO_PIN_11
  569. #define SMR3_RLY_p_Enable_GPIO_Port GPIOC
  570. #define SMR2_RLY_p_Enable_Pin GPIO_PIN_12
  571. #define SMR2_RLY_p_Enable_GPIO_Port GPIOC
  572. #define SMR2_RLY_n_Enable_Pin GPIO_PIN_0
  573. #define SMR2_RLY_n_Enable_GPIO_Port GPIOD
  574. #define Precharge1_Enable_Pin GPIO_PIN_1
  575. #define Precharge1_Enable_GPIO_Port GPIOD
  576. #define Drv_Up_Pin GPIO_PIN_2
  577. #define Drv_Up_GPIO_Port GPIOD
  578. #define Drv_Down_Pin GPIO_PIN_3
  579. #define Drv_Down_GPIO_Port GPIOD
  580. #define SMR3_RLY_n_Enable_Pin GPIO_PIN_4
  581. #define SMR3_RLY_n_Enable_GPIO_Port GPIOD
  582. #define Precharge2_Enable_Pin GPIO_PIN_5
  583. #define Precharge2_Enable_GPIO_Port GPIOD
  584. #define SMR4_RLY_p_Enable_Pin GPIO_PIN_6
  585. #define SMR4_RLY_p_Enable_GPIO_Port GPIOD
  586. #define SMR4_RLY_n_Enable_Pin GPIO_PIN_7
  587. #define SMR4_RLY_n_Enable_GPIO_Port GPIOD
  588. #define SMR5_RLY_p_Enable_Pin GPIO_PIN_10
  589. #define SMR5_RLY_p_Enable_GPIO_Port GPIOG
  590. #define SMR5_RLY_n_Enable_Pin GPIO_PIN_11
  591. #define SMR5_RLY_n_Enable_GPIO_Port GPIOG
  592. #define SMR6_RLY_p_Enable_Pin GPIO_PIN_12
  593. #define SMR6_RLY_p_Enable_GPIO_Port GPIOG
  594. #define SMR6_RLY_n_Enable_Pin GPIO_PIN_13
  595. #define SMR6_RLY_n_Enable_GPIO_Port GPIOG
  596. #define DBG_TX_Pin GPIO_PIN_14
  597. #define DBG_TX_GPIO_Port GPIOG
  598. #define Sys1_Self_Test_DC_n_Pin GPIO_PIN_5
  599. #define Sys1_Self_Test_DC_n_GPIO_Port GPIOB
  600. #define LED1_Pin GPIO_PIN_7
  601. #define LED1_GPIO_Port GPIOB
  602. #define LED2_Pin GPIO_PIN_0
  603. #define LED2_GPIO_Port GPIOE
  604. #define LED3_Pin GPIO_PIN_1
  605. #define LED3_GPIO_Port GPIOE
  606. /* USER CODE BEGIN Private defines */
  607. extern struct MODULE_INFO
  608. {
  609. // Board info
  610. uint8_t Soft_Ver_Ptr[16];
  611. uint8_t Hard_Ver_Ptr[16];
  612. uint8_t SN[20];
  613. // Dip_Switch Status
  614. _DIP_SW_ Dip_status;
  615. // Relay DC voltage info
  616. uint32_t SMR1_Relay_V;
  617. uint32_t SMR1_Relay_C;
  618. uint32_t SMR2_Relay_V;
  619. uint32_t SMR2_Relay_C;
  620. uint32_t SMR3_Relay_V;
  621. uint32_t SMR4_Relay_V;
  622. uint32_t SMR5_Relay_V;
  623. uint32_t SMR6_Relay_V;
  624. uint32_t Verf_165_V;
  625. uint32_t BAT_Voltage;
  626. // Ground sense info
  627. float Vref_165;
  628. float SMR_Gfd_Sense[2];
  629. float SMR_Gfd_Diff[2];
  630. uint32_t R_GFD;
  631. struct Gun_Gfd_Check gfd_chk[2];
  632. // GPIO info
  633. RLY_STATUS Relay_Status;
  634. RLY_GPIO Relay_IO;
  635. _GPIO_ Gpio_status;
  636. struct Detet_Fan_IO fan[1];
  637. // Memory info
  638. Mem memory;
  639. // Coefficient info
  640. Coefficient ACVcoeff[3]; // 0~2:AC,3~8:DC SMR1~SMR6,9~10:GRD
  641. Coefficient DCVcoeff[6];
  642. Coefficient GFDcoeff[2];
  643. Coefficient DCINcoeff;
  644. // Alarm info
  645. ALARM Alarm_CSU;
  646. }Module_Info;
  647. extern RLY_ST RelayStatus;
  648. extern struct COUNTER
  649. {
  650. uint8_t nAC_Drop;
  651. uint8_t nInterLock;
  652. uint8_t nRelay_Timeout[8];
  653. }Counter;
  654. extern struct OP_FLAG
  655. {
  656. uint8_t bRelay_Config_Change:1;
  657. uint8_t bInterLock:1;
  658. }OpFlag;
  659. extern struct EXT_inupt
  660. {
  661. bool Exti_SMR1_Flag:1;
  662. bool Exti_SMR2_Flag:1;
  663. bool Exti_SMR3_Flag:1;
  664. bool Exti_SMR4_Flag:1;
  665. bool Exti_SMR5_Flag:1;
  666. bool Exti_SMR6_Flag:1;
  667. bool reserve :2;
  668. }Exti;
  669. extern uint8_t EXTI_SMR1_Count;
  670. extern uint8_t EXTI_SMR2_Count;
  671. extern uint8_t EXTI_SMR3_Count;
  672. extern uint8_t EXTI_SMR4_Count;
  673. extern uint8_t EXTI_SMR5_Count;
  674. extern uint8_t EXTI_SMR6_Count;
  675. extern uint8_t EXTI_Test_Count;
  676. extern uint8_t EXTI_TestFlag1;
  677. extern uint8_t EXTI_TestFlag2;
  678. extern uint8_t EXTI_TestFlag3;
  679. extern uint8_t EXTI_TestFlag4;
  680. extern uint8_t EXTI_TestFlag5;
  681. extern uint8_t EXTI_TestFlag6;
  682. extern CAN_TxHeaderTypeDef TxHeader;
  683. extern CAN_RxHeaderTypeDef RxHeader;
  684. extern uint8_t TxData[8];
  685. extern uint8_t RxData[8];
  686. extern uint32_t TxMailbox;
  687. extern uint32_t canError;
  688. extern uint8_t temp1,temp2,temp3,temp4;
  689. extern float temp5,temp6,temp7,temp8;
  690. /* USER CODE END Private defines */
  691. #ifdef __cplusplus
  692. }
  693. #endif
  694. #endif /* __MAIN_H */