BCU.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. #include "BCU.h"
  2. static process_Bcu gProcess_Bcu_Task;
  3. #define PROC_BCU_STATE_SWITCH(a) (gProcess_Bcu_Task = a)
  4. //=========================================================================
  5. //=========================================================================
  6. //=========================================================================
  7. void BCU(void)
  8. {
  9. uint16_T i;
  10. uint16_T RecvCounter = 0;
  11. static boolean_T Flg;
  12. //启动延迟没做
  13. PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
  14. while (TRUE)
  15. {
  16. switch (gProcess_Bcu_Task)
  17. {
  18. //=========================初始化===============================
  19. case PROCESS_STATE_INIT:
  20. {
  21. BCU_Init();
  22. Flg = 1;
  23. // cmnc_num_cellUNum = AppDataInfo.BattCellCount; /* 电压采样点实际个数; */
  24. // cmnc_num_modTNum = AppDataInfo.BattTempCount; /* 温度采样点实际个数; */
  25. // ihd_st_EOLState = AppNVMData.EOLState;
  26. // memcpy(blcv_Q_totalCpEi, BcuDataInfo.blcv_Q_totalCpE, sizeof(blcv_Q_totalCpEi));
  27. // memcpy(blcv_Q_reqCpEi, BcuDataInfo.blcv_Q_reqCpE, sizeof(blcv_Q_reqCpEi));
  28. // socd_pct_bcuSocEi = BcuDataInfo.socd_pct_bcuSocE;
  29. // socd_pct_battSocEi = BcuDataInfo.socd_pct_battSocE;
  30. // sohd_tm_chrgStartStatEi = BcuDataInfo.sohd_tm_chrgStartStatE;
  31. // sohd_flg_chrgEndEi = BcuDataInfo.sohd_flg_chrgEndE;
  32. // memcpy(sohv_V_chrgStartStatEi, BcuDataInfo.sohv_V_chrgStartStatE, sizeof(sohv_V_chrgStartStatEi));
  33. // sohd_Q_chrgEi = BcuDataInfo.sohd_Q_chrgE;
  34. // memcpy(sohv_Q_packCapArrEi, BcuDataInfo.sohv_Q_packCapArrE, sizeof(sohv_Q_packCapArrEi));
  35. // memcpy(sohv_Q_cellCapArrEi, BcuDataInfo.sohv_Q_cellCapArrE, sizeof(sohv_Q_cellCapArrEi));
  36. // memcpy(iscv_Q_remainCpEi, BcuDataInfo.iscv_Q_remainCpE, sizeof(iscv_Q_remainCpEi));
  37. // memcpy(sorv_R_cellEi, BcuDataInfo.sorv_ohm_cellRE, sizeof(sorv_R_cell));
  38. // iscd_tm_totalEi = BcuDataInfo.iscd_tm_totalE;
  39. // sfmd_flg_mainCirClosFltEi = BcuDataInfo.sfmd_flg_mainCirClosFltE;
  40. // sfmd_flg_heatCirClosFltEi = BcuDataInfo.sfmd_flg_heatCirClosFltE;
  41. // sfmd_flg_heatCirOpenFltEi = BcuDataInfo.sfmd_flg_heatCirOpenFltE;
  42. // sfmd_flg_heatRunFltEi = BcuDataInfo.sfmd_flg_heatRunFltE;
  43. // sfmd_flg_iscFltEi = BcuDataInfo.sfmd_flg_iscFltE;
  44. // ihd_tm_parkTime = BcuDataInfo.ihd_tm_parkTimeE;
  45. PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
  46. break;
  47. }
  48. //============================工作模式==========================
  49. case PROCESS_STATE_WORK:
  50. {
  51. //数据得到之后再运行没做
  52. while (TRUE)
  53. {
  54. if (TimerCounter % 10 == 0)
  55. {
  56. // if (gProcess_app == LISTEN)
  57. // {
  58. // PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
  59. // break;
  60. // }
  61. //数据获取
  62. // ihd_st_reSet = SysResetFlag;
  63. // ihd_I_curr = (int16_T)(-(battI - 10000));
  64. // memcpy(ihv_V_cellU, battCellU, sizeof(battCellU));
  65. // for (i = 0; i < cmnc_num_modTNum; i++)
  66. // {
  67. // ihv_T_modT[i] = battCellTemp[i];
  68. // }
  69. // ihd_T_mosT = MOSTemp;
  70. // ihd_T_DCPlugT = fastChargeTemp;
  71. // ihd_T_ACPlugT = normalChargeTemp;
  72. // ihd_T_heatPanT1 = heatTemp1;
  73. // ihd_T_heatPanT2 = heatTemp2;
  74. // ihd_pct_soc = battSOC * 10;
  75. // ihd_pct_soh = battSOH * 10;
  76. // ihd_flg_HVILFlt = Lockstatus;
  77. // ihd_st_workStat = BattWorkStateDelay;
  78. // ihd_flg_urtRecFlt = UartErrorFlag;
  79. // ihd_flg_urtRecFlg = UartRecvFlag;
  80. // ihd_st_chrgConnect = chargerConnectState;
  81. // ihd_flg_cellULowFlt = (getbit(battProtectState, 8)) == 1;
  82. // ihd_flg_battULowFlt = (getbit(battProtectState, 9)) == 1;
  83. // ihd_flg_cellUOverFlt = (getbit(battProtectState, 24)) == 1;
  84. // ihd_flg_battUOverFlt = (getbit(battProtectState, 25)) == 1;
  85. // ihd_flg_disChrgCurrOverFlt = (getbit(battProtectState, 1)) == 1;
  86. // ihd_flg_chrgCurrOverFlt = (getbit(battProtectState, 2)) == 1;
  87. // ihd_flg_disChrgModTOverFlt = (getbit(battProtectState, 20)) == 1;
  88. // ihd_flg_chrgModTOverFlt = (getbit(battProtectState, 16)) == 1;
  89. // ihd_flg_chrgMosTOverFlt = (getbit(battProtectState, 18)) == 1;
  90. // ihd_flg_disChrgMosClosFlt = ((battWarningState >> 18) & 0x01) == 1;
  91. // ihd_flg_chrgMosClosFlt = ((battWarningState >> 19) & 0x01) == 1;
  92. // ihd_flg_disChrgModTLowFlt = (getbit(battProtectState, 21)) == 1;
  93. // ihd_flg_chrgModTLowFlt = (getbit(battProtectState, 17)) == 1;
  94. // ihd_flg_currOpenFlt = 0;
  95. // ihd_st_heatForceControl = HeatForceControl;
  96. // ihd_st_chrgMosControl = ChargeForbiddenControl == 0;
  97. // ihd_st_disChrgMosControl = DisChargeForbiddenControl == 0;
  98. // ihd_st_relayControl = RelayForbiddenControl == 0;
  99. // ihd_st_heatStat = battHeatEnableState;
  100. //调用算法
  101. SFM();
  102. TMS();
  103. CSM();
  104. SPM();
  105. ISC();
  106. //实时存储
  107. if (socd_flg_EEsave == 1 || ihd_flg_DTCClear)
  108. {
  109. BCUEEDataSave();
  110. ihd_flg_DTCClear = false;
  111. }
  112. if (ihd_st_workStat == 0)
  113. {
  114. memcpy(appv_V_cellU, sfmv_V_cellU, sizeof(sfmv_V_cellU));
  115. }
  116. if(Flg == 1 && ihd_st_workStat != 0)
  117. {
  118. AppConfigInfo.BcuDataInfo.ihd_tm_parkTimeE = 0;
  119. AppConfigInfo.appSaveFlg = TRUE;
  120. Flg = 0;
  121. }
  122. if (ihd_st_wakeUpStat == 8)
  123. {
  124. if(bcud_flg_firstRun)
  125. {
  126. appd_st_preCyc = 1;
  127. }
  128. if(ihd_st_workStat != 0)
  129. {
  130. appd_st_preCyc = 0;
  131. }
  132. }
  133. bcud_flg_firstRun = false;
  134. }
  135. vTaskDelay(100);
  136. }
  137. break;
  138. }
  139. //======================休眠模式===============================
  140. // case PROCESS_STATE_SLEEP:
  141. // {
  142. // BCUEEDataSave();
  143. // ihd_tm_parkTime = 0;
  144. // while (TRUE)
  145. // {
  146. // if (TimerCounter % 10 == 0)
  147. // {
  148. // ihd_tm_parkTime++;
  149. // }
  150. // if (TimeCounter % 1000 == 0)
  151. // {
  152. // BcuDataInfo.ihd_tm_parkTimeE = ihd_tm_parkTime;
  153. // BcuDataInfo.appDataModify = TRUE;
  154. // }
  155. // if (gProcess_app == WORK)
  156. // {
  157. // BcuDataInfo.ihd_tm_parkTimeE = ihd_tm_parkTime;
  158. // BcuDataInfo.appDataModify = TRUE;
  159. // PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
  160. // break;
  161. // }
  162. // vTaskDelay(100);
  163. // }
  164. // break;
  165. // }
  166. default:
  167. {
  168. PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
  169. break;
  170. }
  171. }
  172. }
  173. }
  174. //========================算法初始化========================================
  175. void BCU_Init(void)
  176. {
  177. bcud_flg_firstRun = true;
  178. SFM_Init();
  179. TMS_Init();
  180. CSM_Init();
  181. SPM_Init();
  182. ISC_Init();
  183. }
  184. //==========================主线程调用======================================
  185. void AppTaskBcuInit(void *arg)
  186. {
  187. }
  188. //=========================数据存储========================================
  189. void BCUEEDataSave(void)
  190. {
  191. memcpy(AppConfigInfo.BcuDataInfo.blcv_Q_totalCpE, blcv_Q_totalCpEo, sizeof(blcv_Q_totalCpEo));
  192. memcpy(AppConfigInfo.BcuDataInfo.blcv_Q_reqCpE, blcv_Q_reqCpEo, sizeof(blcv_Q_reqCpEo));
  193. AppConfigInfo.BcuDataInfo.socd_pct_bcuSocE = socd_pct_bcuSocEo;
  194. AppConfigInfo.BcuDataInfo.socd_pct_battSocE = socd_pct_battSocEo;
  195. AppConfigInfo.BcuDataInfo.sohd_tm_chrgStartStatE = sohd_tm_chrgStartStatEo;
  196. AppConfigInfo.BcuDataInfo.sohd_flg_chrgEndE = sohd_flg_chrgEndEo;
  197. memcpy(AppConfigInfo.BcuDataInfo.sohv_V_chrgStartStatE, sohv_V_chrgStartStatEo, sizeof(sohv_V_chrgStartStatEo));
  198. AppConfigInfo.BcuDataInfo.sohd_Q_chrgE = sohd_Q_chrgEo;
  199. memcpy(AppConfigInfo.BcuDataInfo.sohv_Q_packCapArrE, sohv_Q_packCapArrEo, sizeof(sohv_Q_packCapArrEo));
  200. memcpy(AppConfigInfo.BcuDataInfo.sohv_Q_cellCapArrE, sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
  201. memcpy(AppConfigInfo.BcuDataInfo.iscv_Q_remainCpE, iscv_Q_remainCpEo, sizeof(iscv_Q_remainCpEo));
  202. memcpy(AppConfigInfo.BcuDataInfo.sorv_ohm_cellRE, sorv_R_cellEo, sizeof(sorv_R_cellEo));
  203. AppConfigInfo.BcuDataInfo.iscd_tm_totalE = iscd_tm_totalEo;
  204. AppConfigInfo.BcuDataInfo.sfmd_flg_mainCirClosFltE = sfmd_flg_mainCirClosFltEo;
  205. AppConfigInfo.BcuDataInfo.sfmd_flg_heatCirClosFltE = sfmd_flg_heatCirClosFltEo;
  206. AppConfigInfo.BcuDataInfo.sfmd_flg_heatCirOpenFltE = sfmd_flg_heatCirOpenFltEo;
  207. AppConfigInfo.BcuDataInfo.sfmd_flg_heatRunFltE = sfmd_flg_heatRunFltEo;
  208. AppConfigInfo.BcuDataInfo.sfmd_flg_iscFltE = sfmd_flg_iscFltEo;
  209. AppConfigInfo.appSaveFlg = TRUE;
  210. }