main.h 23 KB

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