123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- /*
- * File: BCU.c
- *
- * Code generated for Simulink model 'BCU'.
- *
- * Model version : 1.19
- * Simulink Coder version : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Fri Aug 20 13:49:53 2021
- *
- * Target selection: ert.tlc
- * Embedded hardware selection: Intel->x86-64 (Windows64)
- * Code generation objectives: Unspecified
- * Validation result: Not run
- */
- #include "BCU.h"
- #include "BCU_private.h"
- static StaticTask_t gProcess_Bcu_Task_t;
- static UINT8 gProcess_Bcu_TaskStack[PROC_BCU_TASK_STACK_SIZE];
- static osThreadId_t BcuTaskId = NULL;
- static process_Bcu gProcess_Bcu_Task;
- #define PROC_BCU_STATE_SWITCH(a) (gProcess_Bcu_Task = a)
- /* Real-time model */
- static RT_MODEL_BCU_T BCU_M_;
- RT_MODEL_BCU_T *const BCU_M = &BCU_M_;
- /* Model step function */
- void BCU_step(void)
- { uint8_T i;
- osDelay(1000);
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
- while (TRUE)
- {
- switch(gProcess_Bcu_Task)
- {
- case PROCESS_STATE_INIT:
- { BCU_initialize();
- memcpy(blcv_Q_totalCpEi,AppDataInfo.blcv_Q_totalCpE, 28*sizeof(uint32_T));
- memcpy(blcv_Q_reqCpEi,AppDataInfo.blcv_Q_reqCpE, 28*sizeof(uint16_T));
- socd_pct_bcuSocEi = AppDataInfo.socd_pct_bcuSocE;
- socd_pct_battSocEi = AppDataInfo.socd_pct_battSocE;
- sohd_tm_chrgStartStatEi = AppDataInfo.sohd_tm_chrgStartStatE;
- sohd_flg_chrgEndEi = AppDataInfo.sohd_flg_chrgEndE;
- memcpy(sohv_V_chrgStartStatEi,AppDataInfo.sohv_V_chrgStartStatE, 28*sizeof(uint16_T));
- sohd_Q_chrgEi = AppDataInfo.sohd_Q_chrgE;
- memcpy(sohv_Q_packCapArrEi,AppDataInfo.sohv_Q_packCapArrE, 10*sizeof(uint16_T));
- memcpy(sohv_Q_cellCapArrEi,AppDataInfo.sohv_Q_cellCapArrE, 28*sizeof(uint16_T));
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_IDLE);
- break;
- }
- case PROCESS_STATE_IDLE:
- {
- while (TRUE)
- {
- osDelay(100);
- if(gProcess_app!=LISTEN)
- {
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
- break;
- }
- else
- {
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
- break;
- }
- }
- break;
- }
- case PROCESS_STATE_WORK:
- {
- while (TRUE)
- {
- osDelay(1000);
- if(gProcess_app==LISTEN)
- {
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
- break;
- }
- //***************
- ihd_I_curr = (int16_T)(-(battI - 10000)*10);
- ihd_V_cellUMax = maxCellVol;
- ihd_V_cellUMin = minCellVol;
- ihd_V_cellUAvrg = avrgCellVol;
- memcpy(ihv_V_cellU,battCellU,AppNVMData.BattCellCount*sizeof(uint16_T));
- memcpy(ihv_T_modT,battCellTemp,AppNVMData.BattTempCount*sizeof(uint16_T));
- ihd_T_modTMax = maxCellTemp;
- ihd_T_modTMin = minCellTemp;
- ihd_st_workStat = battWorkState;//BattWorkStateDelay;
- ihd_st_fault = 0;
- // socd_pct_battSocEi=300;
- ihd_T_bdtemp = 400;
- /* Constant: '<Root>/Constant' */
-
- //****************************
- /* ModelReference: '<Root>/SOH' incorporates:
- * Inport: '<Root>/ihd_I_curr'
- * Inport: '<Root>/ihd_st_workStat'
- * Inport: '<Root>/ihd_tm_packTime'
- * Inport: '<Root>/ihv_V_cellU'
- * Inport: '<Root>/sohd_Q_chrgEi '
- * Inport: '<Root>/sohd_flg_chrgEndEi '
- * Inport: '<Root>/sohd_tm_chrgStartStatEi '
- * Inport: '<Root>/sohv_Q_packCapArrEi '
- * Inport: '<Root>/sohv_V_chrgStartStatEi '
- */
- SOH();
-
- /* ModelReference: '<Root>/SOC' incorporates:
- * Inport: '<Root>/ihd_I_curr'
- * Inport: '<Root>/ihd_V_cellUAvrg'
- * Inport: '<Root>/ihd_V_cellUMax'
- * Inport: '<Root>/ihd_V_cellUMin'
- * Inport: '<Root>/ihd_st_workStat'
- * Inport: '<Root>/ihd_tm_packTime'
- * Inport: '<Root>/socd_pct_battSocEi'
- * Inport: '<Root>/socd_pct_bcuSocEi'
- */
- SOC();
- // printf("[%d]-:socd_pct_battSocEi:%d,socd_pct_battSoc:%d,socd_pct_ekfSoc:%d,socd_pct_bcuSoc:%d,Umax:%d,Umin:%d,ocv:%f,UL:%f,Up:%f,k1:%f,k2:%f\n",__LINE__,socd_pct_battSocEi,socd_pct_battSoc,socd_pct_ekfSoc,socd_pct_bcuSoc,ihd_V_cellUMax,ihd_V_cellUMin,OCV,UL,Up,k1,k2);
- /* Constant: '<Root>/Constant' */
- /* ModelReference: '<Root>/BLC' incorporates:
- * Inport: '<Root>/blcv_Q_reqCpEi'
- * Inport: '<Root>/blcv_Q_totalCpEi'
- * Inport: '<Root>/ihd_V_cellUMin'
- * Inport: '<Root>/ihd_st_fault'
- * Inport: '<Root>/ihd_tm_packTime'
- * Inport: '<Root>/ihv_V_cellU'
- */
- BLC();
- //
- //
- if(socd_flg_EEsave==1)
- {
- memcpy(AppDataInfo.blcv_Q_totalCpE,blcv_Q_totalCpEo, 28*sizeof(uint32_T));
- memcpy(AppDataInfo.blcv_Q_reqCpE,blcv_Q_reqCpEo, 28*sizeof(uint16_T));
- AppDataInfo.socd_pct_bcuSocE = socd_pct_bcuSocEo;
- AppDataInfo.socd_pct_battSocE = socd_pct_battSocEo;
- AppDataInfo.sohd_tm_chrgStartStatE = sohd_tm_chrgStartStatEo;
- AppDataInfo.sohd_flg_chrgEndE = sohd_flg_chrgEndEo;
- memcpy(AppDataInfo.sohv_V_chrgStartStatE,sohv_V_chrgStartStatEo, 28*sizeof(uint16_T));
- AppDataInfo. sohd_Q_chrgE = sohd_Q_chrgEo;
- memcpy(AppDataInfo.sohv_Q_packCapArrE,sohv_Q_packCapArrEo, 10*sizeof(uint16_T));
- memcpy(AppDataInfo.sohv_Q_cellCapArrE,sohv_Q_cellCapArrEo, 28*sizeof(uint16_T));
- AppDataInfo.appDataModify = TRUE;
- }
- }
- break;
- }
- case PROCESS_STATE_SLEEP:
- {
- memcpy(AppDataInfo.blcv_Q_totalCpE,blcv_Q_totalCpEo, 28*sizeof(uint32_T));
- memcpy(AppDataInfo.blcv_Q_reqCpE,blcv_Q_reqCpEo, 28*sizeof(uint16_T));
- AppDataInfo.socd_pct_bcuSocE = socd_pct_bcuSocEo;
- AppDataInfo.socd_pct_battSocE = socd_pct_battSocEo;
- AppDataInfo.sohd_tm_chrgStartStatE = sohd_tm_chrgStartStatEo;
- AppDataInfo.sohd_flg_chrgEndE = sohd_flg_chrgEndEo;
- memcpy(AppDataInfo.sohv_V_chrgStartStatE,sohv_V_chrgStartStatEo, 28*sizeof(uint16_T));
- AppDataInfo. sohd_Q_chrgE = sohd_Q_chrgEo;
- memcpy(AppDataInfo.sohv_Q_packCapArrE,sohv_Q_packCapArrEo, 10*sizeof(uint16_T));
- memcpy(AppDataInfo.sohv_Q_cellCapArrE,sohv_Q_cellCapArrEo, 28*sizeof(uint16_T));
- AppDataInfo.appDataModify = TRUE;
- //
- Time=0;
- ihd_tm_parkTime=0;
- while (TRUE)
- {
- osDelay(1000);
- ihd_tm_parkTime++;
- if(gProcess_app!=LISTEN)
- {
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
- break;
- }
- }
- break;
- }
- default:
- {
- PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
- break;
- }
- }
- }
- }
- /* Model initialize function */
- void BCU_initialize(void)
- {
- /* Registration code */
- /* block I/O */
- /* custom signals */
- {
- int32_T i;
- for (i = 0; i < 28; i++) {
- sohv_Q_cellCap[i] = 300U;
- }
- }
- sohd_pct_bcuSoh = 1000U;
- /* Model Initialize function for ModelReference Block: '<Root>/BLC' */
- BLC_initialize(rtmGetErrorStatusPointer(BCU_M));
- /* Model Initialize function for ModelReference Block: '<Root>/SOC' */
- SOC_initialize(rtmGetErrorStatusPointer(BCU_M));
- /* Model Initialize function for ModelReference Block: '<Root>/SOH' */
- SOH_initialize(rtmGetErrorStatusPointer(BCU_M));
- //SFM_initialize(rtmGetErrorStatusPointer(BCU_M));
- /* SystemInitialize for ModelReference: '<Root>/SOH' incorporates:
- * Inport: '<Root>/battI '
- * Inport: '<Root>/ihd_st_workStat'
- * Inport: '<Root>/ihd_tm_packTime'
- * Inport: '<Root>/ihv_V_cellU'
- * Inport: '<Root>/sohd_Q_chrgEi '
- * Inport: '<Root>/sohd_flg_chrgEndEi '
- * Inport: '<Root>/sohd_tm_chrgStartStatEi '
- * Inport: '<Root>/sohv_Q_packCapArrEi '
- * Inport: '<Root>/sohv_V_chrgStartStatEi '
- */
- SOH_Init();
- /* SystemInitialize for ModelReference: '<Root>/SOC' incorporates:
- * Inport: '<Root>/battI '
- * Inport: '<Root>/ihd_V_cellUAvrg'
- * Inport: '<Root>/ihd_V_cellUMax'
- * Inport: '<Root>/ihd_V_cellUMin'
- * Inport: '<Root>/ihd_st_workStat'
- * Inport: '<Root>/ihd_tm_packTime'
- * Inport: '<Root>/socd_pct_battSocEi'
- * Inport: '<Root>/socd_pct_bcuSocEi'
- */
- SOC_Init();
- /* SystemInitialize for ModelReference: '<Root>/BLC' incorporates:
- * Inport: '<Root>/blcv_Q_reqCpEi'
- * Inport: '<Root>/blcv_Q_totalCpEi'
- * Inport: '<Root>/ihd_V_cellUMin'
- * Inport: '<Root>/ihd_st_fault'
- * Inport: '<Root>/ihd_tm_packTime'
- * Inport: '<Root>/ihv_V_cellU'
- */
- BLC_Init();
- //SFM_Init();
- }
- /* Model terminate function */
- void BCU_terminate(void)
- {
- /* (no terminate code required) */
- }
- /*
- * File trailer for generated code.
- *
- * [EOF]
- */
- void AppTaskBcuInit(void *arg)
- {
- osThreadAttr_t task_attr;
- memset(&task_attr,0,sizeof(task_attr));
- memset(gProcess_Bcu_TaskStack, 0xA5, PROC_BCU_TASK_STACK_SIZE);
- task_attr.name = "Bcu_Task";
- task_attr.stack_mem = gProcess_Bcu_TaskStack;
- task_attr.stack_size = PROC_BCU_TASK_STACK_SIZE;
- task_attr.priority = osPriorityBelowNormal7;
- task_attr.cb_mem = &gProcess_Bcu_Task_t;
- task_attr.cb_size = sizeof(StaticTask_t);
- BcuTaskId = osThreadNew(BCU_step, NULL, &task_attr);
- }
|