/*
 * File: BCMR_AChrg.c
 *
 * Code generated for Simulink model 'BCMR_AChrg'.
 *
 * Model version                  : 1.1156
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Wed Nov 17 17:27:56 2021
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Infineon->TriCore
 * Code generation objectives:
 *    1. MISRA C:2012 guidelines
 *    2. Execution efficiency
 * Validation result: Not run
 */

#include "BCMR_AChrg.h"
#include "BCMR_AChrg_private.h"

/* Named constants for Chart: '<S123>/Chart' */
#define BCMR_AChrg_IN_NO_ACTIVE_CHILD  ((uint8_T)0U)
#define BCMR_A_IN_BCMR_AcChrgHeatActive ((uint8_T)1U)
#define BCMR_IN_BCMR_AcChrgHeatInActive ((uint8_T)2U)

/* Named constants for Chart: '<S125>/Chart' */
#define BCMR_AC_IN_AChrgTrickle_Default ((uint8_T)1U)
#define BCMR_AC_IN_AChrgTrickle_StepSet ((uint8_T)3U)
#define BCMR_IN_AChrgTrickle_StepStable ((uint8_T)4U)
#define BCMR__IN_AChrgTrickle_StepClear ((uint8_T)2U)

/* Named constants for Chart: '<S7>/AcChrg' */
#define BCMR_AChr_IN_HoldTempEndPending ((uint8_T)1U)
#define BCMR_AChrg_IN_AppChrg          ((uint8_T)1U)
#define BCMR_AChrg_IN_AppChrgOrdCancel ((uint8_T)1U)
#define BCMR_AChrg_IN_AppChrgOrdFail   ((uint8_T)2U)
#define BCMR_AChrg_IN_AppChrgWait      ((uint8_T)3U)
#define BCMR_AChrg_IN_ChgEnd           ((uint8_T)2U)
#define BCMR_AChrg_IN_ChgEndFlt        ((uint8_T)1U)
#define BCMR_AChrg_IN_ChgFault         ((uint8_T)1U)
#define BCMR_AChrg_IN_ChgFobid         ((uint8_T)3U)
#define BCMR_AChrg_IN_ChgFul           ((uint8_T)4U)
#define BCMR_AChrg_IN_ChgHVOn          ((uint8_T)1U)
#define BCMR_AChrg_IN_ChgInit          ((uint8_T)5U)
#define BCMR_AChrg_IN_ChgManualStop    ((uint8_T)2U)
#define BCMR_AChrg_IN_ChgObcReady      ((uint8_T)2U)
#define BCMR_AChrg_IN_ChgPending       ((uint8_T)3U)
#define BCMR_AChrg_IN_ChgStandby       ((uint8_T)4U)
#define BCMR_AChrg_IN_ChgWaiting       ((uint8_T)6U)
#define BCMR_AChrg_IN_ChgWarning       ((uint8_T)3U)
#define BCMR_AChrg_IN_ChgWkup          ((uint8_T)1U)
#define BCMR_AChrg_IN_Chging           ((uint8_T)7U)
#define BCMR_AChrg_IN_Chging_h         ((uint8_T)4U)
#define BCMR_AChrg_IN_ChgwaitingFlt    ((uint8_T)5U)
#define BCMR_AChrg_IN_DisChgEndFlt     ((uint8_T)1U)
#define BCMR_AChrg_IN_DischgEnd        ((uint8_T)8U)
#define BCMR_AChrg_IN_DischgFault      ((uint8_T)1U)
#define BCMR_AChrg_IN_DischgHVOn       ((uint8_T)1U)
#define BCMR_AChrg_IN_DischgManualStop ((uint8_T)2U)
#define BCMR_AChrg_IN_DischgObcReady   ((uint8_T)2U)
#define BCMR_AChrg_IN_DischgPending    ((uint8_T)3U)
#define BCMR_AChrg_IN_DischgStandby    ((uint8_T)4U)
#define BCMR_AChrg_IN_DischgWaiting    ((uint8_T)9U)
#define BCMR_AChrg_IN_DischgWarning    ((uint8_T)3U)
#define BCMR_AChrg_IN_Dischging        ((uint8_T)10U)
#define BCMR_AChrg_IN_Dischging_m      ((uint8_T)4U)
#define BCMR_AChrg_IN_DischgwaitingFlt ((uint8_T)5U)
#define BCMR_AChrg_IN_HVOFF            ((uint8_T)2U)
#define BCMR_AChrg_IN_HVON             ((uint8_T)3U)
#define BCMR_AChrg_IN_HVOnReady        ((uint8_T)1U)
#define BCMR_AChrg_IN_HoldTemp         ((uint8_T)11U)
#define BCMR_AChrg_IN_HoldTempHVOff    ((uint8_T)2U)
#define BCMR_AChrg_IN_HoldTempInit     ((uint8_T)3U)
#define BCMR_AChrg_IN_HoldTempPending  ((uint8_T)4U)
#define BCMR_AChrg_IN_HoldTempPending1 ((uint8_T)5U)
#define BCMR_AChrg_IN_HoldTempPending2 ((uint8_T)6U)
#define BCMR_AChrg_IN_HoldTempStandby  ((uint8_T)7U)
#define BCMR_AChrg_IN_HoldTempStart    ((uint8_T)8U)
#define BCMR_AChrg_IN_HoldTempStart1   ((uint8_T)9U)
#define BCMR_AChrg_IN_Init             ((uint8_T)2U)
#define BCMR_AChrg_IN_OFF              ((uint8_T)1U)
#define BCMR_AChrg_IN_PreHeatAbnormal  ((uint8_T)2U)
#define BCMR_AChrg_IN_PreHeatEnd       ((uint8_T)3U)
#define BCMR_AChrg_IN_PreHeatEndPending ((uint8_T)4U)
#define BCMR_AChrg_IN_PreHeatHVOff     ((uint8_T)5U)
#define BCMR_AChrg_IN_PreHeatInit      ((uint8_T)6U)
#define BCMR_AChrg_IN_PreHeatPending   ((uint8_T)7U)
#define BCMR_AChrg_IN_PreHeatStandby   ((uint8_T)8U)
#define BCMR_AChrg_IN_PreHeatStandby1  ((uint8_T)9U)
#define BCMR_AChrg_IN_PreHeatStart     ((uint8_T)10U)
#define BCMR_AChrg_IN_PreHeatStop      ((uint8_T)11U)
#define BCMR_AChrg_IN_PreThemal        ((uint8_T)12U)
#define BCMR_AChrg_IN_Sleep            ((uint8_T)2U)
#define BCMR_AChrg_IN_WaitCurrZero     ((uint8_T)5U)

/* Named constants for Chart: '<S334>/circulateDispay' */
#define BCMR_AChrg_IN_one              ((uint8_T)1U)
#define BCMR_AChrg_IN_two              ((uint8_T)2U)

/* Named constants for Chart: '<S25>/AcChrg' */
#define BCMR_AChrg_IN_A                ((uint8_T)1U)
#define BCMR_AChrg_IN_B                ((uint8_T)2U)

/* Named constants for Chart: '<S30>/AcChrg' */
#define BCMR_AChrg_IN_A_1              ((uint8_T)2U)
#define BCMR_AChrg_IN_B_m              ((uint8_T)3U)

/* Exported block signals */
real32_T Local_iLCurrReqCalc;          /* '<S5>/Add' */
real32_T Local_iBattCurrReqCalc;       /* '<S108>/Data Type Conversion1' */
real32_T AffixCurrTp4;                 /* '<S107>/Divide' */
real32_T Local_AffixCurrCalc;          /* '<S107>/Gain' */
boolean_T Local_PreCoolChk;            /* '<S338>/TONV_TimeDebounce1' */
boolean_T Local_flgPwrRdc;             /* '<S63>/Compare' */
boolean_T Local_flgAcChgWarn;          /* '<S39>/Logical Operator1' */
boolean_T DutyCycleAbnorm;             /* '<S65>/Relational Operator' */
boolean_T Local_stPreHeatVoltOutput;   /* '<S158>/Relational Operator' */

/* Exported data definition */

/* Definition for custom storage class: FileScope */
static real32_T BCMR_pActPwrChrgCalc;
static boolean_T Local_flgAcChgFobdTmpA;
static boolean_T Local_flgAcChgFobdTmpB;
static boolean_T VoltCpreTmpA;

/* Volatile memory section */
#define ASW1_OEM_START_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: Volatile */
volatile uint8_T DFC_AChgFobd_ASW;
volatile uint8_T DFC_AChgHVOffTmt_ASW;
volatile uint8_T DFC_AChgHVOnTmt_ASW;
volatile uint8_T DFC_AChgRdyPndiTmt_ASW;
volatile uint8_T DFC_AChgRdyTmt_ASW;
volatile uint8_T DFC_AChgingErr_ASW;
volatile uint8_T DFC_AChrgCellOvrTemp_ASW;
volatile uint8_T DFC_AChrgCnntErr_ASW;
volatile uint8_T DFC_AChrgCurrMish_ASW;
volatile uint8_T DFC_AChrgVoltMish_ASW;
volatile uint8_T DFC_AcDischgFobd_ASW;
volatile uint8_T DFC_PreHeatObcStatusErr_ASW;
volatile uint8_T DFC_PreHeatPtcErr_ASW;
volatile uint8_T DFC_PreHeatVcuReqTmt_ASW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T AcChrgCnnt;
volatile boolean_T AcChrgWkup;
volatile boolean_T BCMR_bAChgHVOffTmOut;
volatile boolean_T BCMR_bAChgHVOnTmOut;
volatile boolean_T BCMR_bAChgRdyPendingTmOut;
volatile boolean_T BCMR_bAChgRdyTmOut;
volatile boolean_T BCMR_bAChgWaitingTmOut;
volatile boolean_T BCMR_bAChgingFlt;
volatile boolean_T BCMR_bAChrgCellOvrTemp;
volatile boolean_T BCMR_bAChrgCnntFlt;
volatile boolean_T BCMR_bAChrgCurrMish;
volatile boolean_T BCMR_bAChrgCurrOutRngErrDet;
volatile boolean_T BCMR_bAChrgCurrOutRngErrHeal;
volatile boolean_T BCMR_bAChrgFul;
volatile boolean_T BCMR_bAChrgOvrCurrErrDet;
volatile boolean_T BCMR_bAChrgOvrCurrErrHeal;
volatile boolean_T BCMR_bAChrgOvrVoltErrDet;
volatile boolean_T BCMR_bAChrgOvrVoltErrHeal;
volatile boolean_T BCMR_bAChrgPwrDwnReq;
volatile boolean_T BCMR_bAChrgPwrUpReq;
volatile boolean_T BCMR_bAChrgRdy;
volatile boolean_T BCMR_bAChrgVoltMish;
volatile boolean_T BCMR_bAChrgVoltOutRngErrDet;
volatile boolean_T BCMR_bAChrgVoltOutRngErrHeal;
volatile boolean_T BCMR_bAcChgFobd;
volatile boolean_T BCMR_bAcChrgHeatFbd;
volatile boolean_T BCMR_bAcDischgFobd;
volatile boolean_T BCMR_bAcDischgRdy;
volatile boolean_T BCMR_bPreHeatObcStatusErr;
volatile boolean_T BCMR_bPreHeatPtcErr;
volatile boolean_T BCMR_bPreHeatVcuReqTmt;
volatile boolean_T BCMR_flgChgStop;
volatile boolean_T BCMR_flgChrgCmd;
volatile boolean_T BCMR_flgDischgCmd;
volatile uint8_T BCMR_holdtemp;
volatile boolean_T BCMR_holdtempreq;
volatile boolean_T BCMR_holdtemprise;
volatile real32_T BCMR_holdtempti;
volatile real32_T BCMR_iCurrReqCalcTmpA;
volatile real32_T BCMR_iReqCurrChrg;
volatile real32_T BCMR_pActPwrChrg;
volatile real32_T BCMR_pHeatPwrReq;
volatile uint8_T BCMR_stAChgDischg;
volatile uint8_T BCMR_stAChrgCnnt;
volatile uint8_T BCMR_stAChrgFltCode;
volatile uint8_T BCMR_stAChrgMode;
volatile uint8_T BCMR_stAChrgObsr;
volatile uint8_T BCMR_stAChrgPreThmMode;
volatile uint8_T BCMR_stAChrgPreThmReq;
volatile uint8_T BCMR_stAChrgTrickle;
volatile uint8_T BCMR_stAppChrgMode;
volatile uint8_T BCMR_stChrgAbnmExit;
volatile uint8_T BCMR_stHoldTempObsvr;
volatile uint8_T BCMR_stHoldTempReq;
volatile uint8_T BCMR_stIviDischg;
volatile uint8_T BCMR_stPreThmFltCode;
volatile uint8_T BCMR_stPreThmObsvr;
volatile uint8_T BCMR_stV2xMod;
volatile real32_T BCMR_tTempCurrReq;
volatile real32_T BCMR_tiRemAChgTime;
volatile real32_T BCMR_uMaxVoltChrg;
volatile real32_T BCMR_uReqVoltChrg;
volatile real32_T BCMR_uVoltCurrReq;
volatile boolean_T HoldTempTimax;
volatile boolean_T Local_HoldtempChk;
volatile boolean_T Local_flgPreHeatFobd;

/* Block signals (auto storage) */
B_BCMR_AChrg_T BCMR_AChrg_B;

/* Block states (auto storage) */
DW_BCMR_AChrg_T BCMR_AChrg_DW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
/* Forward declaration for local functions */
static void BCMR_AChrg_PreHeatHVOff(const uint8_T *Switch2);
static void BCMR_AChrg_PreHeatStandby(const uint8_T *Switch2);
static void BCMR_AChrg_PreHeatStandby1(const uint8_T *Switch2);
static void BCMR_AChrg_PreHeatStart(const boolean_T *Switch3, const boolean_T
  *LogicalOperator4);
static void BCMR_AChr_enter_internal_ChgEnd(void);
static void BCMR_AChrg_PreThemal(const uint8_T *Switch2, const boolean_T
  *Switch3, const boolean_T *LogicalOperator4);
static void BCMR_A_enter_internal_PreThemal(const boolean_T *Switch3);
static void BCMR_AChrg_AppChrg(const boolean_T *RelationalOperator, const
  boolean_T *Switch3, const boolean_T *RelationalOperator_k, boolean_T *Switch);
static void BCMR_AChrg_enter_atomic_Init(void);
static void BCMR_AChrg_ChgEnd(const boolean_T *RelationalOperator, boolean_T
  *RelationalOperator_ev);
static void BCMR_AChrg_ChgInit(const boolean_T *RelationalOperator, const
  boolean_T *Switch3, const boolean_T *RelationalOperator_k, boolean_T
  *RelationalOperator_h, boolean_T *Switch, boolean_T *RelationalOperator_ev);
static void BCMR_AChrg_ChgWaiting(const uint8_T *Switch1, const uint8_T *Switch2,
  boolean_T *RelationalOperator_ev);
static void BCMR_AChrg_Chging(const uint16_T *DataTypeConversion2, boolean_T
  *RelationalOperator_ev);
static void BCMR_A_enter_internal_DischgEnd(void);
static void BCMR_AChrg_Dischging(boolean_T *RelationalOperator_ev);
static void BCMR_AChrg_HoldTemp(const uint8_T *Switch2);
static void BCMR_AChrg_calu(const uint8_T *MinMax_h);

/*
 * System reset for atomic system:
 *    '<S105>/BMSDebounceStartZero'
 *    '<S125>/BMSDebounceStartZero'
 *    '<S34>/BMSDebounceStartZero'
 *    '<S34>/BMSDebounceStartZero1'
 */
void BCMR_BMSDebounceStartZero_Reset(DW_BMSDebounceStartZero_BCMR__T *localDW)
{
  localDW->StateName_hn = false;
  localDW->StateName_a = false;
  localDW->StateName = 0U;
  localDW->StateName_g = false;
  localDW->StateName_h = 0U;
}

/*
 * Output and update for atomic system:
 *    '<S105>/BMSDebounceStartZero'
 *    '<S125>/BMSDebounceStartZero'
 *    '<S34>/BMSDebounceStartZero'
 *    '<S34>/BMSDebounceStartZero1'
 */
void BCMR_AChrg_BMSDebounceStartZero(boolean_T rtu_Signal, uint16_T
  rtu_Hearl2Fault, uint8_T rtu_FaultStep, uint16_T rtu_Fault2Heal, uint8_T
  rtu_HealStep, B_BMSDebounceStartZero_BCMR_A_T *localB,
  DW_BMSDebounceStartZero_BCMR__T *localDW)
{
  boolean_T rtb_RelationalOperator_jq;
  boolean_T rtb_RelationalOperator_bb;
  uint16_T rtb_Switch2_hj;
  uint16_T rtb_Switch2_p4;
  if (localDW->StateName_a) {
    rtb_Switch2_hj = 0U;
  } else {
    rtb_Switch2_hj = localDW->StateName;
  }

  if (rtu_Signal) {
    rtb_Switch2_hj = (uint16_T)((uint32_T)rtu_FaultStep + rtb_Switch2_hj);
    if (!(rtb_Switch2_hj <= 60000)) {
      rtb_Switch2_hj = 60000U;
    }
  } else if (rtb_Switch2_hj >= rtu_FaultStep) {
    rtb_Switch2_hj = (uint16_T)((uint32_T)rtb_Switch2_hj - rtu_FaultStep);
  } else {
    rtb_Switch2_hj = 0U;
  }

  rtb_RelationalOperator_jq = (rtb_Switch2_hj > rtu_Hearl2Fault);
  if (localDW->StateName_g) {
    rtb_Switch2_p4 = 0U;
  } else {
    rtb_Switch2_p4 = localDW->StateName_h;
  }

  if (!rtu_Signal) {
    rtb_Switch2_p4 = (uint16_T)((uint32_T)rtu_HealStep + rtb_Switch2_p4);
    if (!(rtb_Switch2_p4 <= 60000)) {
      rtb_Switch2_p4 = 60000U;
    }
  } else if (rtb_Switch2_p4 >= rtu_HealStep) {
    rtb_Switch2_p4 = (uint16_T)((uint32_T)rtb_Switch2_p4 - rtu_HealStep);
  } else {
    rtb_Switch2_p4 = 0U;
  }

  rtb_RelationalOperator_bb = (rtb_Switch2_p4 > rtu_Fault2Heal);
  if (!localDW->StateName_hn) {
    localB->Switch = (rtb_RelationalOperator_jq || localDW->StateName_hn);
  } else {
    localB->Switch = ((!rtb_RelationalOperator_bb) && localDW->StateName_hn);
  }

  localDW->StateName_hn = localB->Switch;
  localDW->StateName_a = rtb_RelationalOperator_jq;
  localDW->StateName = rtb_Switch2_hj;
  localDW->StateName_g = rtb_RelationalOperator_bb;
  localDW->StateName_h = rtb_Switch2_p4;
}

/* Output and update for atomic system: '<S156>/TONV_TimeDebounce' */
void BCMR_AChrg_TONV_TimeDebounce(boolean_T rtu_u,
  DW_TONV_TimeDebounce_BCMR_ACh_T *localDW, real32_T rtp_dT, real32_T rtp_T)
{
  real32_T rtb_Product_g0;
  real32_T tmp;
  if (rtu_u) {
    rtb_Product_g0 = rtp_dT;
  } else {
    rtb_Product_g0 = 0.0F;
  }

  if (rtp_T <= localDW->Delay_DSTATE) {
    tmp = rtp_T;
  } else {
    tmp = localDW->Delay_DSTATE;
  }

  rtb_Product_g0 = (rtb_Product_g0 + tmp) * (real32_T)rtu_u;
  Local_stPreHeatVoltOutput = (rtb_Product_g0 > rtp_T);
  localDW->Delay_DSTATE = rtb_Product_g0;
}

/* Output and update for function-call system: '<S1>/AcChgPreThemalCalc' */
void BCMR_AChrg_AcChgPreThemalCalc(real32_T rtu_BSPR_uBattVolt, real32_T
  rtu_COMR_uVoltObcChrg, DW_AcChgPreThemalCalc_BCMR_AC_T *localDW)
{
  BCMR_AChrg_TONV_TimeDebounce((real32_T)fabs(rtu_COMR_uVoltObcChrg -
    rtu_BSPR_uBattVolt) <= BCMR_uPreHeatVoltReqObcDiff_C,
    &localDW->TONV_TimeDebounce, BCMR_tiBase_C, BCMR_tiDetDebs_C);
}

/*
 * Output and update for atomic system:
 *    '<S338>/1-D Hysteresis1'
 *    '<S338>/1-D Hysteresis2'
 */
void HysteresisCalc(real32_T rtu_u, uint8_T rtu_para1, uint8_T rtu_para2,
                    B_HysteresisCalc_T *localB, real32_T rtp_RngDwnLmt, real32_T
                    rtp_RngUpLmt)
{
  if (rtp_RngUpLmt < rtu_u) {
    localB->Switch = rtu_para1;
  } else {
    if (rtu_u < rtp_RngDwnLmt) {
      localB->Switch = rtu_para2;
    }
  }
}

/* Output and update for atomic system: '<S338>/TONV_TimeDebounce1' */
void BCMR_AChrg_TONV_TimeDebounce1(uint8_T rtu_u,
  B_TONV_TimeDebounce_BCMR_AC_b_T *localB, DW_TONV_TimeDebounce_BCMR_A_p_T
  *localDW, real32_T rtp_dT, real32_T rtp_T)
{
  real32_T rtb_Product_cc;
  real32_T tmp;
  if (rtu_u != 0) {
    rtb_Product_cc = rtp_dT;
  } else {
    rtb_Product_cc = 0.0F;
  }

  if (rtp_T <= localDW->Delay_DSTATE) {
    tmp = rtp_T;
  } else {
    tmp = localDW->Delay_DSTATE;
  }

  rtb_Product_cc = (real32_T)(rtu_u != 0) * (rtb_Product_cc + tmp);
  localB->RelationalOperator = (rtb_Product_cc > rtp_T);
  localDW->Delay_DSTATE = rtb_Product_cc;
}

/*
 * System initialize for enable system:
 *    '<S361>/BCMR_AChrgTiRevTimCalc'
 *    '<S362>/BCMR_AChrgTiRevTimCalc'
 */
void BCM_BCMR_AChrgTiRevTimCalc_Init(DW_BCMR_AChrgTiRevTimCalc_BCM_T *localDW)
{
  localDW->Delay_DSTATE = 1.0F;
}

/*
 * System reset for enable system:
 *    '<S361>/BCMR_AChrgTiRevTimCalc'
 *    '<S362>/BCMR_AChrgTiRevTimCalc'
 */
void BC_BCMR_AChrgTiRevTimCalc_Reset(DW_BCMR_AChrgTiRevTimCalc_BCM_T *localDW)
{
  localDW->Delay_DSTATE = 1.0F;
}

/*
 * Disable for enable system:
 *    '<S361>/BCMR_AChrgTiRevTimCalc'
 *    '<S362>/BCMR_AChrgTiRevTimCalc'
 */
void BCMR_AChrgTiRevTimCalc_Disable(DW_BCMR_AChrgTiRevTimCalc_BCM_T *localDW)
{
  localDW->BCMR_AChrgTiRevTimCalc_MODE = false;
}

/*
 * Output and update for enable system:
 *    '<S361>/BCMR_AChrgTiRevTimCalc'
 *    '<S362>/BCMR_AChrgTiRevTimCalc'
 */
void BCMR_ACh_BCMR_AChrgTiRevTimCalc(boolean_T rtu_Enable,
  B_BCMR_AChrgTiRevTimCalc_BCMR_T *localB, DW_BCMR_AChrgTiRevTimCalc_BCM_T
  *localDW)
{
  real32_T u0;
  if (rtu_Enable) {
    if (!localDW->BCMR_AChrgTiRevTimCalc_MODE) {
      BC_BCMR_AChrgTiRevTimCalc_Reset(localDW);
      localDW->BCMR_AChrgTiRevTimCalc_MODE = true;
    }

    u0 = localDW->Delay_DSTATE - BCMR_vAChrgTimNrmVelLmt_C * BCMR_tiAChrgRunT_C /
      60000.0F;
    if (u0 > 2000.0F) {
      localB->Saturation3 = 2000.0F;
    } else if (u0 < 1.0F) {
      localB->Saturation3 = 1.0F;
    } else {
      localB->Saturation3 = u0;
    }

    localDW->Delay_DSTATE = localB->Saturation3;
  } else {
    if (localDW->BCMR_AChrgTiRevTimCalc_MODE) {
      BCMR_AChrgTiRevTimCalc_Disable(localDW);
    }
  }
}

/*
 * System reset for atomic system:
 *    '<S372>/AI_Filter'
 *    '<S383>/AI_Filter'
 *    '<S399>/AI_Filter1'
 *    '<S410>/AI_Filter'
 */
void RemChgTimeCalc_AI_Filter_Reset(DW_RemChgTimeCalc_AI_Filter_T *localDW)
{
  int32_T i;
  for (i = 0; i < 600; i++) {
    localDW->TappedDelay_X[i] = 0.0F;
  }
}

/*
 * Outputs for atomic system:
 *    '<S372>/AI_Filter'
 *    '<S383>/AI_Filter'
 *    '<S399>/AI_Filter1'
 *    '<S410>/AI_Filter'
 */
void RemChgTimeCalc_AI_Filter(B_RemChgTimeCalc_AI_Filter_T *localB,
  DW_RemChgTimeCalc_AI_Filter_T *localDW)
{
  real32_T minV;
  int32_T sigIdx;
  real32_T rtb_SumofElements;
  real32_T rtb_Add1_lc;
  rtb_SumofElements = localDW->TappedDelay_X[0];
  rtb_Add1_lc = localDW->TappedDelay_X[0];
  minV = localDW->TappedDelay_X[0];
  for (sigIdx = 0; sigIdx < 599; sigIdx++) {
    rtb_SumofElements += localDW->TappedDelay_X[sigIdx + 1];
    if (!(rtb_Add1_lc >= localDW->TappedDelay_X[sigIdx + 1])) {
      rtb_Add1_lc = localDW->TappedDelay_X[sigIdx + 1];
    }

    if (!(minV <= localDW->TappedDelay_X[sigIdx + 1])) {
      minV = localDW->TappedDelay_X[sigIdx + 1];
    }
  }

  rtb_Add1_lc = (rtb_SumofElements - rtb_Add1_lc) - minV;
  if (rtb_Add1_lc == 0.0F) {
    localB->DataTypeConversion1 = 0.0F;
  } else {
    localB->DataTypeConversion1 = rtb_Add1_lc / 598.0F;
  }
}

/*
 * Update for atomic system:
 *    '<S372>/AI_Filter'
 *    '<S383>/AI_Filter'
 *    '<S399>/AI_Filter1'
 *    '<S410>/AI_Filter'
 */
void RemChgTimeCalc_AI_Filter_Update(real32_T rtu_In1,
  DW_RemChgTimeCalc_AI_Filter_T *localDW)
{
  int_T i;
  for (i = 0; i < 599; i++) {
    localDW->TappedDelay_X[i] = localDW->TappedDelay_X[i + 1];
  }

  localDW->TappedDelay_X[599] = rtu_In1;
}

/* Output and update for atomic system: '<S1>/flt_debounce' */
void AChrg_debounce(boolean_T rtu_In1, B_AChrg_debounce_T *localB,
                    DW_AChrg_debounce_T *localDW, int16_T rtp_subVal, int16_T
                    rtp_addVal, int16_T rtp_setVal)
{
  int16_T rtb_Saturation_a;
  int32_T tmp;
  if (rtu_In1) {
    rtb_Saturation_a = rtp_addVal;
  } else {
    rtb_Saturation_a = (int16_T)-rtp_subVal;
  }

  tmp = rtb_Saturation_a + localDW->UnitDelay1_DSTATE;
  if (tmp > 32767) {
    tmp = 32767;
  } else {
    if (tmp < -32768) {
      tmp = -32768;
    }
  }

  if ((int16_T)tmp > rtp_setVal) {
    rtb_Saturation_a = rtp_setVal;
  } else if ((int16_T)tmp < 0) {
    rtb_Saturation_a = 0;
  } else {
    rtb_Saturation_a = (int16_T)tmp;
  }

  if (rtb_Saturation_a >= rtp_setVal) {
    localDW->Relay_Mode = true;
  } else {
    if (rtb_Saturation_a <= 0) {
      localDW->Relay_Mode = false;
    }
  }

  localB->Relay = localDW->Relay_Mode;
  localDW->UnitDelay1_DSTATE = rtb_Saturation_a;
}

/* Output and update for atomic system: '<S1>/hld_ai_LVSupFb1' */
void AChrg_AI_Filter(real32_T rtu_In1, B_AChrg_AI_Filter_T *localB,
                     DW_AChrg_AI_Filter_T *localDW)
{
  real32_T minV;
  int32_T sigIdx;
  real32_T rtb_SumofElements;
  real32_T rtb_Add1_a;
  rtb_SumofElements = localDW->TappedDelay_X[0];
  rtb_Add1_a = localDW->TappedDelay_X[0];
  minV = localDW->TappedDelay_X[0];
  for (sigIdx = 0; sigIdx < 49; sigIdx++) {
    rtb_SumofElements += localDW->TappedDelay_X[sigIdx + 1];
    if (!(rtb_Add1_a >= localDW->TappedDelay_X[sigIdx + 1])) {
      rtb_Add1_a = localDW->TappedDelay_X[sigIdx + 1];
    }

    if (!(minV <= localDW->TappedDelay_X[sigIdx + 1])) {
      minV = localDW->TappedDelay_X[sigIdx + 1];
    }
  }

  rtb_Add1_a = (rtb_SumofElements - rtb_Add1_a) - minV;
  if (rtb_Add1_a == 0.0F) {
    localB->DataTypeConversion1 = 0.0F;
  } else {
    localB->DataTypeConversion1 = rtb_Add1_a / 48.0F;
  }

  for (sigIdx = 0; sigIdx < 49; sigIdx++) {
    localDW->TappedDelay_X[sigIdx] = localDW->TappedDelay_X[sigIdx + 1];
  }

  localDW->TappedDelay_X[49] = rtu_In1;
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_PreHeatHVOff(const uint8_T *Switch2)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  boolean_T guard3 = false;
  if ((BCCR_stBmsCtrMode == 7) && (COMR_stPreThmEna == 1) && (*Switch2 == 8)) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatStart;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
      &BCMR_AChrg_DW.AcChgPreThemalCalc);
    BCMR_bAChrgPwrUpReq = false;
    BCMR_bAChrgRdy = false;
    BCMR_bAChrgPwrDwnReq = false;
    BCMR_pHeatPwrReq = BCMR_pPreHeatPwrReq_C;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 31.0F;
    BCMR_uReqVoltChrg = BSPR_uBattVolt;
    BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
  } else {
    guard1 = false;
    guard2 = false;
    guard3 = false;
    if ((Local_flgPreHeatFobd || (BCCR_stBmsCtrMode != 7)) &&
        (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
         (BCMR_tiPreChgThemalTimeOut_C / 0.1F - 1.0E-9F))) {
      BCMR_stPreThmFltCode = 7U;
      if (BCMR_stPreThmFltCode == 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

        /* BCMR_uReqVoltChrg = 0; */
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
      } else if (BCMR_stPreThmFltCode != 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
      } else {
        guard3 = true;
      }
    } else {
      guard3 = true;
    }

    if (guard3) {
      if ((COMR_stPreThmEna != 1) && (BCMR_AChrg_DW.temporalCounter_i1 >=
           (uint32_T)ceil(BCMR_tiPreChgThemalTimeOut_C / 0.1F - 1.0E-9F))) {
        BCMR_stPreThmFltCode = 12U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard2 = true;
        }
      } else {
        guard2 = true;
      }
    }

    if (guard2) {
      if ((*Switch2 != 8) && (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                              (BCMR_tiPreChgThemalTimeOut_C / 0.1F - 1.0E-9F))) {
        BCMR_stPreThmFltCode = 13U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard1 = true;
        }
      } else {
        guard1 = true;
      }
    }

    if (guard1) {
      BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
        &BCMR_AChrg_DW.AcChgPreThemalCalc);/* BCMR_bAChrgPwrUpReq = false; */
      BCMR_bAChrgRdy = false;

      /* BCMR_bAChrgPwrDwnReq = true; */
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 31.0F;
      BCMR_uReqVoltChrg = BSPR_uBattVolt;
      BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 5U;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_PreHeatStandby(const uint8_T *Switch2)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  if (BCMR_AChrg_B.RelationalOperator_o && (*Switch2 == 1)) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatPending;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
      &BCMR_AChrg_DW.AcChgPreThemalCalc);
    BCMR_bAChrgPwrUpReq = true;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
    BCMR_bAChrgRdy = false;
    BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 3U;
  } else {
    guard1 = false;
    guard2 = false;
    if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
         (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) &&
        (!BCMR_AChrg_B.RelationalOperator_o)) {
      BCMR_stPreThmFltCode = 3U;
      if (BCMR_stPreThmFltCode == 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

        /* BCMR_uReqVoltChrg = 0; */
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
      } else if (BCMR_stPreThmFltCode != 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
      } else {
        guard2 = true;
      }
    } else {
      guard2 = true;
    }

    if (guard2) {
      if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
           ((BCMR_tiPreThemalTimeOut_C + 100.0F) / 0.1F - 1.0E-9F)) && (*Switch2
           != 1)) {
        BCMR_stPreThmFltCode = 4U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard1 = true;
        }
      } else {
        guard1 = true;
      }
    }

    if (guard1) {
      BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
        &BCMR_AChrg_DW.AcChgPreThemalCalc);
      BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 2U;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_PreHeatStandby1(const uint8_T *Switch2)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  if (BCMR_AChrg_B.RelationalOperator_o && (*Switch2 == 1) &&
      (COMR_stPwrUpDwnVcuReq == 2)) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatHVOff;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
      &BCMR_AChrg_DW.AcChgPreThemalCalc);/* BCMR_bAChrgPwrUpReq = false;	 */
    BCMR_bAChrgRdy = false;

    /* BCMR_bAChrgPwrDwnReq = true; */
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 31.0F;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
    BCMR_uReqVoltChrg = BSPR_uBattVolt;
    BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
  } else {
    guard1 = false;
    guard2 = false;
    if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
         (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) &&
        (!BCMR_AChrg_B.RelationalOperator_o)) {
      BCMR_stPreThmFltCode = 3U;
      if (BCMR_stPreThmFltCode == 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

        /* BCMR_uReqVoltChrg = 0; */
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
      } else if (BCMR_stPreThmFltCode != 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
      } else {
        guard2 = true;
      }
    } else {
      guard2 = true;
    }

    if (guard2) {
      if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
           ((BCMR_tiPreThemalTimeOut_C + 100.0F) / 0.1F - 1.0E-9F)) && (*Switch2
           != 1)) {
        BCMR_stPreThmFltCode = 4U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard1 = true;
        }
      } else {
        guard1 = true;
      }
    }

    if (guard1) {
      BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
        &BCMR_AChrg_DW.AcChgPreThemalCalc);
      BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 11U;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_PreHeatStart(const boolean_T *Switch3, const boolean_T
  *LogicalOperator4)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  if ((!*Switch3) || (!BCMR_AChrg_B.RelationalOperator_o)) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEndPending;
    BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
      &BCMR_AChrg_DW.AcChgPreThemalCalc);
    BCMR_bAChrgPwrUpReq = false;
    BCMR_bAChrgRdy = false;
    BCMR_bAChrgPwrDwnReq = false;
    BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
    BCMR_stAChrgPreThmReq = 0U;

    /* BCMR_pHeatPwrReq=0; */
    BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 7U;
  } else {
    guard1 = false;
    guard2 = false;
    if (BCMR_AChrg_B.RelationalOperator_e || (*LogicalOperator4)) {
      BCMR_stPreThmFltCode = 10U;
      if (BCMR_stPreThmFltCode == 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

        /* BCMR_uReqVoltChrg = 0; */
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
      } else if (BCMR_stPreThmFltCode != 10) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
      } else {
        guard2 = true;
      }
    } else {
      guard2 = true;
    }

    if (guard2) {
      if (Local_flgPreHeatFobd && (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)
           ceil(BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F))) {
        BCMR_stPreThmFltCode = 8U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard1 = true;
        }
      } else {
        guard1 = true;
      }
    }

    if (guard1) {
      BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
        &BCMR_AChrg_DW.AcChgPreThemalCalc);
      BCMR_bAChrgPwrUpReq = false;
      BCMR_bAChrgRdy = false;
      BCMR_bAChrgPwrDwnReq = false;
      BCMR_pHeatPwrReq = BCMR_pPreHeatPwrReq_C;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 31.0F;
      BCMR_uReqVoltChrg = BSPR_uBattVolt;
      BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 6U;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChr_enter_internal_ChgEnd(void)
{
  BCMR_AChrg_DW.is_ChgEnd = BCMR_AChrg_IN_HVON;
  BCMR_AChrg_DW.temporalCounter_i1 = 0U;
  BCMR_bAChrgPwrDwnReq = true;
  BCMR_bAChrgPwrUpReq = false;
  BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
  BCMR_bAChrgRdy = false;
  BCMR_pActPwrChrg = 0.0F;
  BCMR_uReqVoltChrg = 0.0F;
  BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
  BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
  BCMR_uMaxVoltChrg = 0.0F;
  BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
  BCMR_stAChrgMode = 4U;
  BCMR_AChrg_B.BCMR_stAChrgObsr_l = 10U;
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_PreThemal(const uint8_T *Switch2, const boolean_T
  *Switch3, const boolean_T *LogicalOperator4)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  if ((!*Switch3) && (!Local_PreCoolChk) && (BCMR_AChrg_B.BCMR_stPreThmObsvr_i ==
       0)) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgWaiting;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
    BCMR_uReqVoltChrg = 0.0F;
    BCMR_pActPwrChrg = 0.0F;
    BCMR_AChrg_B.BCMR_tiRemChgTime = 2047U;
    BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgStandby;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;

    /* BCMR_stAChrgCnnt = uint8(1); */
    BCMR_stAChrgMode = 1U;
    BCMR_bAChrgPwrUpReq = false;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
    BCMR_bAChrgRdy = false;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 2U;
  } else if (BCMR_AChrg_B.BCMR_stPreThmObsvr_i == 9) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
    BCMR_AChr_enter_internal_ChgEnd();
  } else {
    guard1 = false;
    guard2 = false;
    switch (BCMR_AChrg_DW.is_PreThemal) {
     case BCMR_AChrg_IN_HVOnReady:
      if (COMR_stPreThmVcuPmt == 1) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatStandby1;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 11U;
      } else {
        if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
             (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) && (COMR_stPreThmVcuPmt
             == 0)) {
          BCMR_stPreThmFltCode = 2U;
          if (BCMR_stPreThmFltCode == 10) {
            BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
            BCMR_AChrg_DW.temporalCounter_i1 = 0U;
            BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
              &BCMR_AChrg_DW.AcChgPreThemalCalc);
            BCMR_bAChrgPwrUpReq = false;
            BCMR_bAChrgRdy = false;
            BCMR_bAChrgPwrDwnReq = false;
            BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
            BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

            /* BCMR_uReqVoltChrg = 0; */
            BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
            BCMR_stAChrgPreThmReq = 0U;
            BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
          } else {
            if (BCMR_stPreThmFltCode != 10) {
              BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
              BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
                &BCMR_AChrg_DW.AcChgPreThemalCalc);
              BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
              BCMR_stAChrgPreThmReq = 0U;
              BCMR_bAChrgPwrUpReq = false;
              BCMR_bAChrgRdy = false;
              BCMR_bAChrgPwrDwnReq = true;
              BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
              BCMR_uReqVoltChrg = 0.0F;
              BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
            }
          }
        }
      }
      break;

     case BCMR_AChrg_IN_PreHeatAbnormal:
      break;

     case BCMR_AChrg_IN_PreHeatEnd:
      if (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
          (BCMR_tiPreThmDlyTime_C / 0.1F - 1.0E-9F)) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatStop;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 0U;
      }
      break;

     case BCMR_AChrg_IN_PreHeatEndPending:
      if (Local_flgPreHeatFobd || (!BCMR_AChrg_B.RelationalOperator_o)) {
        BCMR_stPreThmFltCode = 9U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard1 = true;
        }
      } else {
        guard1 = true;
      }
      break;

     case BCMR_AChrg_IN_PreHeatHVOff:
      BCMR_AChrg_PreHeatHVOff(Switch2);
      break;

     case BCMR_AChrg_IN_PreHeatInit:
      if (COMR_stPreThmVcuPmt == 1) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatStandby;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 2U;
      } else {
        if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
             (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) && (COMR_stPreThmVcuPmt
             == 0)) {
          BCMR_stPreThmFltCode = 1U;
          if (BCMR_stPreThmFltCode == 10) {
            BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
            BCMR_AChrg_DW.temporalCounter_i1 = 0U;
            BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
              &BCMR_AChrg_DW.AcChgPreThemalCalc);
            BCMR_bAChrgPwrUpReq = false;
            BCMR_bAChrgRdy = false;
            BCMR_bAChrgPwrDwnReq = false;
            BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
            BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

            /* BCMR_uReqVoltChrg = 0; */
            BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
            BCMR_stAChrgPreThmReq = 0U;
            BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
          } else {
            if (BCMR_stPreThmFltCode != 10) {
              BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
              BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
                &BCMR_AChrg_DW.AcChgPreThemalCalc);
              BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
              BCMR_stAChrgPreThmReq = 0U;
              BCMR_bAChrgPwrUpReq = false;
              BCMR_bAChrgRdy = false;
              BCMR_bAChrgPwrDwnReq = true;
              BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
              BCMR_uReqVoltChrg = 0.0F;
              BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
            }
          }
        }
      }
      break;

     case BCMR_AChrg_IN_PreHeatPending:
      if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
           (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) && (COMR_stPwrUpDwnVcuReq
           != 1)) {
        BCMR_stPreThmFltCode = 5U;
        if (BCMR_stPreThmFltCode == 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

          /* BCMR_uReqVoltChrg = 0; */
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
        } else if (BCMR_stPreThmFltCode != 10) {
          BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
          BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
            &BCMR_AChrg_DW.AcChgPreThemalCalc);
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgRdy = false;
          BCMR_bAChrgPwrDwnReq = true;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
        } else {
          guard2 = true;
        }
      } else {
        guard2 = true;
      }
      break;

     case BCMR_AChrg_IN_PreHeatStandby:
      BCMR_AChrg_PreHeatStandby(Switch2);
      break;

     case BCMR_AChrg_IN_PreHeatStandby1:
      BCMR_AChrg_PreHeatStandby1(Switch2);
      break;

     case BCMR_AChrg_IN_PreHeatStart:
      BCMR_AChrg_PreHeatStart(Switch3, LogicalOperator4);
      break;

     default:
      if (*Switch3) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatAbnormal;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 5U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 9U;
      }
      break;
    }

    if (guard2) {
      if (COMR_stPwrUpDwnVcuReq == 2) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatHVOff;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);/* BCMR_bAChrgPwrUpReq = false;	 */
        BCMR_bAChrgRdy = false;

        /* BCMR_bAChrgPwrDwnReq = true; */
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 31.0F;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      }
    }

    if (guard1) {
      if (COMR_stPreThmEna == 0) {
        BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatEnd;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
          &BCMR_AChrg_DW.AcChgPreThemalCalc);
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgRdy = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

        /* BCMR_uReqVoltChrg = 0; */
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 8U;
      }
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_A_enter_internal_PreThemal(const boolean_T *Switch3)
{
  if ((COMR_stPwrUpDwnVcuReq == 1) && (BCCR_stBmsCtrMode == 4)) {
    BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_HVOnReady;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
      &BCMR_AChrg_DW.AcChgPreThemalCalc);/* BCMR_stAChrgCnnt = uint8(1); */
    BCMR_stAChrgMode = 2U;
    BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 2U;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
    BCMR_bAChrgRdy = true;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
    BCMR_uReqVoltChrg = 0.0F;
    BCMR_stAChrgPreThmReq = 1U;
    BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 10U;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 22U;
  } else {
    if (*Switch3) {
      BCMR_AChrg_DW.is_PreThemal = BCMR_AChrg_IN_PreHeatInit;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_AChrg_AcChgPreThemalCalc(BSPR_uBattVolt, COMR_uVoltObcChrg,
        &BCMR_AChrg_DW.AcChgPreThemalCalc);/* BCMR_stAChrgCnnt = uint8(1); */
      BCMR_stAChrgMode = 2U;
      BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 2U;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_bAChrgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_stAChrgPreThmReq = 1U;
      BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 1U;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 22U;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_AppChrg(const boolean_T *RelationalOperator, const
  boolean_T *Switch3, const boolean_T *RelationalOperator_k, boolean_T *Switch)
{
  boolean_T guard1 = false;
  guard1 = false;
  if (COMR_stAppChrgOrdStart == 1) {
    if ((!Local_flgPreHeatFobd) && BCMR_AChrg_B.RelationalOperator_o &&
        (*Switch3) && (*RelationalOperator) && (BCMR_stAChgDischg == 1) &&
        (*RelationalOperator_k) && (!*Switch)) {
      BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_PreThemal;
      BCMR_A_enter_internal_PreThemal(Switch3);
    } else if ((!BCMR_AChrg_B.Local_flgAcChgFobd) &&
               BCMR_AChrg_B.RelationalOperator_o && (*RelationalOperator) &&
               (BCMR_stAChgDischg == 1) && (!*Switch3) &&
               (!BCMR_AChrg_B.TempAbnorm)) {
      BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgWaiting;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 2047U;
      BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgStandby;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;

      /* BCMR_stAChrgCnnt = uint8(1); */
      BCMR_stAChrgMode = 1U;
      BCMR_bAChrgPwrUpReq = false;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_bAChrgRdy = false;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 2U;
    } else if ((!BCMR_AChrg_B.LogicalOperator7) && (BCMR_stAChgDischg == 2)) {
      BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_DischgWaiting;
      BCMR_stAChrgMode = 0U;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_bAChrgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgStandby;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_bAChrgPwrUpReq = false;
      BCMR_flgDischgCmd = false;
      BCMR_bAcDischgRdy = false;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 24U;
    } else if ((!BCMR_AChrg_B.LogicalOperator6) &&
               BCMR_AChrg_B.RelationalOperator_o && (BCMR_stAChgDischg == 1) &&
               (!*RelationalOperator) && (!BSPR_bKl15WkUp) &&
               (BCMR_stHoldTempReq == 1) && (!HoldTempTimax)) {
      BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_HoldTemp;
      BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempInit;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_stAChrgPreThmReq = 2U;
    } else {
      guard1 = true;
    }
  } else {
    guard1 = true;
  }

  if (guard1) {
    if ((BCMR_stAppChrgMode == 0) || (BCMR_stAppChrgMode == 5)) {
      BCMR_stChrgAbnmExit = 9U;
      BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
      BCMR_AChr_enter_internal_ChgEnd();
    } else {
      switch (BCMR_AChrg_DW.is_AppChrg) {
       case BCMR_AChrg_IN_AppChrgOrdCancel:
       case BCMR_AChrg_IN_AppChrgOrdFail:
        break;

       default:
        if (COMR_stAppChrgOrdCmd == 2) {
          BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_AppChrgOrdCancel;
          BCMR_stAppChrgMode = 0U;
          BCMR_AChrg_B.BCMR_stAChrgObsr_l = 21U;
        } else {
          if (BCMR_AChrg_B.Local_flgAcChgFobd) {
            BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_AppChrgOrdFail;
            BCMR_stAppChrgMode = 5U;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 20U;
          }
        }
        break;
      }
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_enter_atomic_Init(void)
{
  BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
  BCMR_flgDischgCmd = false;
  BCMR_pActPwrChrg = 0.0F;
  BCMR_uMaxVoltChrg = 0.0F;
  BCMR_uReqVoltChrg = 0.0F;
  BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
  BCMR_AChrg_B.BCMR_tiRemChgTime = 2047U;
  BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
  BCMR_bAChrgPwrUpReq = false;
  BCMR_bAChrgPwrDwnReq = false;
  BCMR_bAChrgRdy = false;

  /* BCMR_stAChrgCnnt = uint8(0); */
  BCMR_stAChrgMode = 0U;
  BCMR_stAChrgPreThmReq = 0U;
  BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
  BCMR_stAppChrgMode = 0U;
  BCMR_AChrg_B.BCMR_stAChrgObsr_l = 0U;
  BCMR_AChrg_DW.BCMR_ChgWaitingFlt = 0.0F;
  BCMR_stChrgAbnmExit = 0U;
  BCMR_stIviDischg = 0U;
  BCMR_AChrg_DW.BCMR_DischgWaitingFlt = 0.0F;
  BCMR_stHoldTempObsvr = 0U;
  BCMR_AChrg_B.BCMR_stPreThmObsvr_i = 0U;
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_ChgEnd(const boolean_T *RelationalOperator, boolean_T
  *RelationalOperator_ev)
{
  switch (BCMR_AChrg_DW.is_ChgEnd) {
   case BCMR_AChrg_IN_ChgEndFlt:
    if ((BCCR_stBmsCtrMode == 7) || (BCCR_stBmsCtrMode == 0) ||
        (BCCR_stBmsCtrMode == 14) || (BCCR_stBmsCtrMode == 17)) {
      BCMR_AChrg_DW.is_ChgEnd = BCMR_AChrg_IN_HVOFF;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_AChrg_DW.is_HVOFF = BCMR_AChrg_IN_OFF;
      BCMR_bAChrgPwrDwnReq = false;
      BCMR_stAChrgMode = 4U;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 11U;
    }
    break;

   case BCMR_AChrg_IN_HVOFF:
    if ((*RelationalOperator_ev) && (!BCMR_AChrg_B.LogicalOperator6) &&
        BCMR_AChrg_B.RelationalOperator_o && (BCMR_stAChgDischg == 1) &&
        (!*RelationalOperator) && (!BSPR_bKl15WkUp) && (BCMR_stHoldTempReq == 1)
        && (!HoldTempTimax)) {
      BCMR_AChrg_DW.is_HVOFF = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_ChgEnd = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_HoldTemp;
      BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempInit;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_stAChrgPreThmReq = 2U;
    } else if (((*RelationalOperator_ev) && (*RelationalOperator) &&
                (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                 (BCMR_tiChrgWaitTime_C / 0.1F - 1.0E-9F))) ||
               ((*RelationalOperator_ev) && (BCMR_stAChgDischg == 2))) {
      BCMR_AChrg_DW.is_HVOFF = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_ChgEnd = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgInit;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_Init;
      BCMR_AChrg_enter_atomic_Init();
    } else {
      if ((BCMR_AChrg_DW.is_HVOFF == BCMR_AChrg_IN_OFF) &&
          (!*RelationalOperator_ev)) {
        BCMR_AChrg_DW.is_HVOFF = BCMR_AChrg_IN_Sleep;
        BCMR_bAChrgPwrDwnReq = false;

        /* BCMR_stAChrgCnnt = uint8(0); */
        BCMR_stAChrgMode = 4U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 13U;
        BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
      }
    }
    break;

   default:
    if ((BCCR_stBmsCtrMode == 7) || (BCCR_stBmsCtrMode == 0) ||
        (BCCR_stBmsCtrMode == 14) || (BCCR_stBmsCtrMode == 17) ||
        (BMCR_stBmsModeCtrl == BCMR_HVOn)) {
      BCMR_AChrg_DW.is_ChgEnd = BCMR_AChrg_IN_HVOFF;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_AChrg_DW.is_HVOFF = BCMR_AChrg_IN_OFF;
      BCMR_bAChrgPwrDwnReq = false;
      BCMR_stAChrgMode = 4U;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 11U;
    } else {
      if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
           (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) && (BCCR_stBmsCtrMode != 7)
          && (BMCR_stBmsModeCtrl != BCMR_HVOn)) {
        BCMR_stChrgAbnmExit = 14U;
        BCMR_AChrg_DW.is_ChgEnd = BCMR_AChrg_IN_ChgEndFlt;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
        BCMR_uMaxVoltChrg = 0.0F;
        BCMR_stAChrgMode = 4U;
        BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 23U;
      }
    }
    break;
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_ChgInit(const boolean_T *RelationalOperator, const
  boolean_T *Switch3, const boolean_T *RelationalOperator_k, boolean_T
  *RelationalOperator_h, boolean_T *Switch, boolean_T *RelationalOperator_ev)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  boolean_T guard3 = false;
  guard1 = false;
  guard2 = false;
  guard3 = false;
  if (BCMR_AChrg_B.BCMR_stAChrgObsr_l == 1) {
    if ((!BCMR_AChrg_B.Local_flgAcChgFobd) && BCMR_AChrg_B.RelationalOperator_o &&
        (*RelationalOperator) && (COMR_stAppChrgOrdCmd == 1) &&
        (BCMR_stAChgDischg == 1) && (BSPR_uCellVoltMax < BCMR_uCellVoltMax_C)) {
      BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_AppChrg;
      BCMR_AChrg_DW.is_AppChrg = BCMR_AChrg_IN_AppChrgWait;
      BCMR_stAppChrgMode = 1U;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 19U;
    } else if ((COMR_stAppChrgOrdCmd == 0) && (*RelationalOperator_h)) {
      if ((!Local_flgPreHeatFobd) && BCMR_AChrg_B.RelationalOperator_o &&
          (*Switch3) && (*RelationalOperator) && (BCMR_stAChgDischg == 1) &&
          (*RelationalOperator_k) && (!*Switch)) {
        BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_PreThemal;
        BCMR_A_enter_internal_PreThemal(Switch3);
      } else if ((!BCMR_AChrg_B.Local_flgAcChgFobd) &&
                 BCMR_AChrg_B.RelationalOperator_o && (*RelationalOperator) &&
                 (BCMR_stAChgDischg == 1) && (!*Switch3) &&
                 (!BCMR_AChrg_B.TempAbnorm)) {
        BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgWaiting;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 2047U;
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgStandby;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;

        /* BCMR_stAChrgCnnt = uint8(1); */
        BCMR_stAChrgMode = 1U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 2U;
      } else if ((!BCMR_AChrg_B.LogicalOperator7) && (BCMR_stAChgDischg == 2)) {
        BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_DischgWaiting;
        BCMR_stAChrgMode = 0U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgStandby;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_flgDischgCmd = false;
        BCMR_bAcDischgRdy = false;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 24U;
      } else if ((!BCMR_AChrg_B.LogicalOperator6) &&
                 BCMR_AChrg_B.RelationalOperator_o && (BCMR_stAChgDischg == 1) &&
                 (!*RelationalOperator) && (!BSPR_bKl15WkUp) &&
                 (BCMR_stHoldTempReq == 1) && (!HoldTempTimax)) {
        guard1 = true;
      } else {
        guard3 = true;
      }
    } else {
      guard3 = true;
    }
  } else {
    guard2 = true;
  }

  if (guard3) {
    if ((!BCMR_AChrg_B.LogicalOperator6) && BCMR_AChrg_B.RelationalOperator_o &&
        (BCMR_stAChgDischg == 1) && (!*RelationalOperator) && (!BSPR_bKl15WkUp) &&
        (BCMR_stHoldTempReq == 1) && (!HoldTempTimax)) {
      guard1 = true;
    } else {
      guard2 = true;
    }
  }

  if (guard2) {
    if (BCMR_AChrg_DW.is_ChgInit == BCMR_AChrg_IN_ChgWkup) {
      if (!*RelationalOperator_ev) {
        BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_Init;
        BCMR_AChrg_enter_atomic_Init();
      } else {
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 1U;
      }
    } else {
      if (*RelationalOperator_ev) {
        BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_ChgWkup;
      }
    }
  }

  if (guard1) {
    BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_HoldTemp;
    BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempInit;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
    BCMR_uReqVoltChrg = 0.0F;
    BCMR_stAChrgPreThmReq = 2U;
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_ChgWaiting(const uint8_T *Switch1, const uint8_T *Switch2,
  boolean_T *RelationalOperator_ev)
{
  if ((BCMR_AChrg_B.RelationalOperator_o && BCMR_AChrg_B.Local_flgAcChgFobd) ||
      BCMR_flgChgStop || (BCMR_AChrg_DW.BCMR_ChgWaitingFlt == 1.0F)) {
    BCMR_stChrgAbnmExit = 8U;
    BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgFobid;
    BCMR_stAChrgMode = 6U;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 18U;
  } else if ((BMCR_stBmsModeCtrl == BCMR_AcChrgMode) && ((*Switch2 == 2) ||
              (*Switch2 == 6)) && (*Switch1 == CP6VPWM) && (BCCR_stBmsCtrMode ==
              4)) {
    BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_Chging;
    BCMR_bAChrgPwrUpReq = true;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
    BCMR_bAChrgRdy = true;
    BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_Chging_h;
    BCMR_stAChrgMode = 3U;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 7U;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
    BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
    BCMR_pActPwrChrg = BCMR_AChrg_B.Abs;
    BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
  } else if ((!BCMR_AChrg_B.RelationalOperator_o) || (!*RelationalOperator_ev) ||
             (COMR_stAppChrgOrdStart == 2) || ((COMR_stAppChrgOrdCmd == 1) &&
              (COMR_stAppChrgOrdStart == 0))) {
    BCMR_stChrgAbnmExit = 9U;
    BCMR_bAChrgPwrDwnReq = true;
    BCMR_bAChrgPwrUpReq = false;
    BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
    BCMR_AChr_enter_internal_ChgEnd();
  } else {
    switch (BCMR_AChrg_DW.is_ChgWaiting) {
     case BCMR_AChrg_IN_ChgHVOn:
      if ((*Switch2 == 2) || (*Switch2 == 6)) {
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgObcReady;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_stAChrgMode = 1U;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_bAChrgRdy = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 5U;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
      } else if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                  (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) && ((*Switch2 != 2) &&
                  (*Switch2 != 6))) {
        BCMR_stChrgAbnmExit = 6U;
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgwaitingFlt;
        BCMR_AChrg_DW.BCMR_ChgWaitingFlt = 1.0F;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 14U;
      } else {
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
      }
      break;

     case BCMR_AChrg_IN_ChgObcReady:
      if (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
          (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) {
        BCMR_stChrgAbnmExit = 7U;
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgwaitingFlt;
        BCMR_AChrg_DW.BCMR_ChgWaitingFlt = 1.0F;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 14U;
      } else {
        BCMR_bAChrgPwrUpReq = true;
        BCMR_bAChrgRdy = true;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      }
      break;

     case BCMR_AChrg_IN_ChgPending:
      if (BCCR_stBmsCtrMode == 4) {
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgHVOn;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_stAChrgMode = 1U;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 4U;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
      } else if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                  (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) &&
                 (BCCR_stBmsCtrMode != 4)) {
        BCMR_stChrgAbnmExit = 3U;
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgwaitingFlt;
        BCMR_AChrg_DW.BCMR_ChgWaitingFlt = 1.0F;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 14U;
      } else {
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
      }
      break;

     case BCMR_AChrg_IN_ChgStandby:
      if (((*Switch1 == 2) || (*Switch1 == 4)) && (*Switch2 == 1)) {
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgPending;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_stAChrgMode = 1U;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 3U;
      } else if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                  (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) && (*Switch2 != 1))
      {
        BCMR_stChrgAbnmExit = 4U;
        BCMR_AChrg_DW.is_ChgWaiting = BCMR_AChrg_IN_ChgwaitingFlt;
        BCMR_AChrg_DW.BCMR_ChgWaitingFlt = 1.0F;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 14U;
      } else {
        BCMR_bAChrgPwrUpReq = false;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      }
      break;

     default:
      BCMR_AChrg_DW.BCMR_ChgWaitingFlt = 1.0F;
      break;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_Chging(const uint16_T *DataTypeConversion2, boolean_T
  *RelationalOperator_ev)
{
  if (BCMR_AChrg_B.Delay2) {
    BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_uReqVoltChrg = 0.0F;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgFul;
    BCMR_stAChrgMode = 4U;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 9U;
    BCMR_AChrg_B.BCMR_bChrgFul = 1.0F;
    BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
    BCMR_bAChrgRdy = false;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;

    /* BCMR_uReqVoltChrg = 0; */
    BCMR_pActPwrChrg = 0.0F;
    BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
    BCMR_AChrg_DW.BCMR_tiChrgFulCnt = 0.0F;
  } else {
    switch (BCMR_AChrg_DW.is_Chging) {
     case BCMR_AChrg_IN_ChgFault:
      BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_WaitCurrZero;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_stAChrgMode = 4U;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 17U;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_bAChrgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      break;

     case BCMR_AChrg_IN_ChgManualStop:
      BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_WaitCurrZero;
      BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      BCMR_stAChrgMode = 4U;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 17U;
      BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      BCMR_bAChrgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      break;

     case BCMR_AChrg_IN_ChgWarning:
      if ((!BCMR_AChrg_B.Local_flgAcChgFobd) && (!Local_flgAcChgWarn)) {
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_Chging_h;
        BCMR_stAChrgMode = 3U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 7U;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
        BCMR_pActPwrChrg = BCMR_AChrg_B.Abs;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      } else if ((!BCMR_AChrg_B.RelationalOperator_o) ||
                 (!*RelationalOperator_ev) || (COMR_stPwrUpDwnVcuReq == 2) ||
                 (COMR_stAppChrgOrdStart == 2) || ((COMR_stAppChrgOrdCmd == 1) &&
                  (COMR_stAppChrgOrdStart == 0))) {
        BCMR_stChrgAbnmExit = 11U;
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_ChgManualStop;
        BCMR_stAChrgMode = 4U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 15U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;

        /* BCMR_stAChrgCnnt = uint8(0); */
      } else if (BCMR_AChrg_B.Local_flgAcChgFobd) {
        BCMR_stChrgAbnmExit = 10U;
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_ChgFault;
        BCMR_stAChrgMode = 6U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 16U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      } else {
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
        BCMR_pActPwrChrg = BCMR_AChrg_B.Abs;
        BCMR_AChrg_B.BCMR_tiRemChgTime = *DataTypeConversion2;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
        BCMR_bAChrgRdy = true;
      }
      break;

     case BCMR_AChrg_IN_Chging_h:
      if (BCMR_AChrg_B.Local_flgAcChgFobd) {
        BCMR_stChrgAbnmExit = 10U;
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_ChgFault;
        BCMR_stAChrgMode = 6U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 16U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      } else if ((!BCMR_AChrg_B.Local_flgAcChgFobd) && Local_flgAcChgWarn) {
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_ChgWarning;
        BCMR_stAChrgMode = 3U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 8U;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
        BCMR_pActPwrChrg = BCMR_AChrg_B.Abs;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      } else if ((!BCMR_AChrg_B.RelationalOperator_o) ||
                 (!*RelationalOperator_ev) || (COMR_stPwrUpDwnVcuReq == 2) ||
                 (COMR_stAppChrgOrdStart == 2) || ((COMR_stAppChrgOrdCmd == 1) &&
                  (COMR_stAppChrgOrdStart == 0))) {
        BCMR_stChrgAbnmExit = 11U;
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_ChgManualStop;
        BCMR_stAChrgMode = 4U;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 15U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;

        /* BCMR_stAChrgCnnt = uint8(0); */
      } else {
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = -BCMR_AChrg_B.MinMax;
        BCMR_uReqVoltChrg = BCMR_AChrg_B.BCMR_vVoltReqCalc;
        BCMR_pActPwrChrg = BCMR_AChrg_B.Abs;
        BCMR_AChrg_B.BCMR_tiRemChgTime = *DataTypeConversion2;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
        BCMR_bAChrgRdy = true;
      }
      break;

     default:
      if ((BSPR_iBattCurr > BCMR_iAChrgStopCurrLim_C) ||
          (BCMR_AChrg_DW.temporalCounter_i1 >= 50U)) {
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_AChrg_DW.is_Chging = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
        BCMR_AChr_enter_internal_ChgEnd();
      } else {
        BCMR_stAChrgMode = 6U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_pActPwrChrg = 0.0F;
        BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      }
      break;
    }
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_A_enter_internal_DischgEnd(void)
{
  BCMR_AChrg_DW.is_DischgEnd = BCMR_AChrg_IN_HVON;
  BCMR_AChrg_DW.temporalCounter_i1 = 0U;
  BCMR_bAChrgPwrDwnReq = true;
  BCMR_bAChrgPwrUpReq = false;
  BCMR_flgDischgCmd = false;
  BCMR_bAcDischgRdy = false;
  BCMR_pActPwrChrg = 0.0F;
  BCMR_uReqVoltChrg = 0.0F;
  BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
  BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
  BCMR_uMaxVoltChrg = 0.0F;
  BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
  BCMR_AChrg_B.BCMR_stAChrgObsr_l = 34U;
  BCMR_stIviDischg = 0U;
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_Dischging(boolean_T *RelationalOperator_ev)
{
  switch (BCMR_AChrg_DW.is_Dischging) {
   case BCMR_AChrg_IN_DischgFault:
    BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_WaitCurrZero;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 33U;
    BCMR_flgDischgCmd = false;
    BCMR_bAcDischgRdy = false;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
    BCMR_uReqVoltChrg = 0.0F;
    BCMR_pActPwrChrg = 0.0F;
    BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
    BCMR_stIviDischg = 0U;
    break;

   case BCMR_AChrg_IN_DischgManualStop:
    BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_WaitCurrZero;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_B.BCMR_stAChrgObsr_l = 33U;
    BCMR_flgDischgCmd = false;
    BCMR_bAcDischgRdy = false;
    BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
    BCMR_uReqVoltChrg = 0.0F;
    BCMR_pActPwrChrg = 0.0F;
    BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
    BCMR_stIviDischg = 0U;
    break;

   case BCMR_AChrg_IN_DischgWarning:
    if ((!BCMR_AChrg_B.LogicalOperator7) && (!Local_flgAcChgWarn)) {
      BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_Dischging_m;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 29U;
      BCMR_stIviDischg = 1U;

      /* BCMR_iReqCurrChrg = -BCMR_iReqCurrChrgCalc;
         BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc;
         BCMR_pActPwrChrg = BCMR_pActPwrChrgCalc; */
      BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      BCMR_flgDischgCmd = true;
      BCMR_bAcDischgRdy = true;
    } else if ((!*RelationalOperator_ev) || (BCMR_stAChgDischg != 2) ||
               BCMR_AChrg_B.LogicalOperator7 || (COMR_stPwrUpDwnVcuReq == 2)) {
      BCMR_stChrgAbnmExit = 22U;
      BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_DischgFault;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 32U;
      BCMR_flgDischgCmd = false;
      BCMR_bAcDischgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
    } else {
      /* BCMR_iReqCurrChrg = -BCMR_iReqCurrChrgCalc;
         BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc;
         BCMR_pActPwrChrg = BCMR_pActPwrChrgCalc;
         BCMR_tiRemChgTime = BCMR_tiRemChgTimeCalc; */
      BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      BCMR_bAChrgPwrUpReq = true;
      BCMR_flgDischgCmd = true;
      BCMR_bAcDischgRdy = true;
    }
    break;

   case BCMR_AChrg_IN_Dischging_m:
    if ((!*RelationalOperator_ev) || (BCMR_stAChgDischg != 2) ||
        BCMR_AChrg_B.LogicalOperator7 || (COMR_stPwrUpDwnVcuReq == 2)) {
      BCMR_stChrgAbnmExit = 22U;
      BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_DischgFault;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 32U;
      BCMR_flgDischgCmd = false;
      BCMR_bAcDischgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
    } else if ((!BCMR_AChrg_B.LogicalOperator7) && Local_flgAcChgWarn) {
      BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_DischgWarning;
      BCMR_AChrg_B.BCMR_stAChrgObsr_l = 30U;
      BCMR_stIviDischg = 1U;

      /* BCMR_iReqCurrChrg = -BCMR_iReqCurrChrgCalc;
         BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc;
         BCMR_pActPwrChrg = BCMR_pActPwrChrgCalc; */
      BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
    } else {
      /* BCMR_iReqCurrChrg = -BCMR_iReqCurrChrgCalc;
         BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc;
         BCMR_pActPwrChrg = BCMR_pActPwrChrgCalc;
         BCMR_tiRemChgTime = BCMR_tiRemChgTimeCalc; */
      BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      BCMR_bAChrgPwrUpReq = true;
      BCMR_flgDischgCmd = true;
      BCMR_bAcDischgRdy = true;
    }
    break;

   default:
    if ((BSPR_iBattCurr < -BCMR_iAChrgStopCurrLim_C) ||
        (BCMR_AChrg_DW.temporalCounter_i1 >= 50U)) {
      BCMR_bAChrgPwrDwnReq = true;
      BCMR_bAChrgPwrUpReq = false;
      BCMR_bAcDischgRdy = false;
      BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_DischgEnd;
      BCMR_A_enter_internal_DischgEnd();
    } else {
      BCMR_flgDischgCmd = false;
      BCMR_bAcDischgRdy = false;
      BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
      BCMR_uReqVoltChrg = 0.0F;
      BCMR_pActPwrChrg = 0.0F;
      BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
      BCMR_stIviDischg = 0U;
    }
    break;
  }
}

/* Function for Chart: '<S7>/AcChrg' */
static void BCMR_AChrg_HoldTemp(const uint8_T *Switch2)
{
  if (BCMR_stHoldTempObsvr == 1) {
    BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgInit;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_Init;
    BCMR_AChrg_enter_atomic_Init();
  } else {
    switch (BCMR_AChrg_DW.is_HoldTemp) {
     case BCMR_AChr_IN_HoldTempEndPending:
      break;

     case BCMR_AChrg_IN_HoldTempHVOff:
      if ((BCMR_stHoldTempReq == 3) || HoldTempTimax ||
          (!BCMR_AChrg_B.RelationalOperator_o) || ((*Switch2 != 4) &&
           (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
            (BCMR_tiPreChgThemalTimeOut_C / 0.1F - 1.0E-9F))) ||
          ((COMR_stPreThmEna != 2) && (BCMR_AChrg_DW.temporalCounter_i1 >=
            (uint32_T)ceil(BCMR_tiPreChgThemalTimeOut_C / 0.1F - 1.0E-9F))) ||
          ((BCMR_AChrg_B.LogicalOperator6 || (BCCR_stBmsCtrMode != 7)) &&
           (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
            (BCMR_tiPreChgThemalTimeOut_C / 0.1F - 1.0E-9F)))) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_stHoldTempObsvr = 1U;
      } else if ((BCCR_stBmsCtrMode == 7) && (COMR_stPreThmEna == 2) &&
                 (*Switch2 == 4) && (!Local_HoldtempChk)) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempStart1;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_pHeatPwrReq = BCMR_pHoldtempPwrReq_C;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 3U;
      } else if ((BCCR_stBmsCtrMode == 7) && (COMR_stPreThmEna == 2) &&
                 (*Switch2 == 4) && Local_HoldtempChk) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempStart;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_pHeatPwrReq = BCMR_pPreHeatPwrReq_C;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 3U;
      } else {
        /* BCMR_bAChrgPwrDwnReq = true; */
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      }
      break;

     case BCMR_AChrg_IN_HoldTempInit:
      if (COMR_stPreThmVcuPmt == 2) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempStandby;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
      } else {
        if (((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
              (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) &&
             (COMR_stPreThmVcuPmt != 2)) || ((BCMR_stHoldTempReq == 3) ||
             HoldTempTimax)) {
          BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_stHoldTempObsvr = 1U;
        }
      }
      break;

     case BCMR_AChrg_IN_HoldTempPending:
      if (BCCR_stBmsCtrMode == 4) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempPending1;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      } else {
        if (((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
              (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) &&
             (COMR_stPwrUpDwnVcuReq != 1)) || ((BCMR_stHoldTempReq == 3) ||
             HoldTempTimax)) {
          BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_stHoldTempObsvr = 1U;
        }
      }
      break;

     case BCMR_AChrg_IN_HoldTempPending1:
      if (COMR_stPwrUpDwnVcuReq == 2) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempPending2;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      }
      break;

     case BCMR_AChrg_IN_HoldTempPending2:
      if (BCCR_stBmsCtrMode == 7) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempHVOff;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;

        /* BCMR_bAChrgPwrUpReq =  false; */
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = true;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
      }
      break;

     case BCMR_AChrg_IN_HoldTempStandby:
      if (BCMR_AChrg_B.RelationalOperator_o && (*Switch2 == 1)) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempPending;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
      } else {
        if (((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
              (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F)) &&
             (!BCMR_AChrg_B.RelationalOperator_o)) ||
            ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
              ((BCMR_tiPreThemalTimeOut_C + 100.0F) / 0.1F - 1.0E-9F)) &&
             (*Switch2 != 1)) || ((BCMR_stHoldTempReq == 3) || HoldTempTimax)) {
          BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
          BCMR_bAChrgPwrUpReq = false;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_stAChrgPreThmReq = 0U;
          BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
          BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
          BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
          BCMR_uReqVoltChrg = 0.0F;
          BCMR_stHoldTempObsvr = 1U;
        }
      }
      break;

     case BCMR_AChrg_IN_HoldTempStart:
      if ((!BCMR_AChrg_B.RelationalOperator_o) || HoldTempTimax ||
          (BCMR_stHoldTempReq == 3)) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_stHoldTempObsvr = 1U;
      } else if (BCMR_AChrg_B.LogicalOperator6 &&
                 (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                  (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F))) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_stHoldTempObsvr = 1U;
      } else if (!Local_HoldtempChk) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempStart1;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_pHeatPwrReq = BCMR_pHoldtempPwrReq_C;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 3U;
      } else {
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_pHeatPwrReq = BCMR_pPreHeatPwrReq_C;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 3U;
      }
      break;

     default:
      if ((!BCMR_AChrg_B.RelationalOperator_o) || HoldTempTimax ||
          (BCMR_stHoldTempReq == 3)) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_stHoldTempObsvr = 1U;
      } else if (BCMR_AChrg_B.LogicalOperator6 &&
                 (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                  (BCMR_tiPreThemalTimeOut_C / 0.1F - 1.0E-9F))) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChr_IN_HoldTempEndPending;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_stAChrgPreThmReq = 0U;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 0U;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
        BCMR_uReqVoltChrg = 0.0F;
        BCMR_stHoldTempObsvr = 1U;
      } else if (Local_HoldtempChk) {
        BCMR_AChrg_DW.is_HoldTemp = BCMR_AChrg_IN_HoldTempStart;
        BCMR_AChrg_DW.temporalCounter_i1 = 0U;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_pHeatPwrReq = BCMR_pPreHeatPwrReq_C;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 3U;
      } else {
        BCMR_bAChrgPwrUpReq = false;
        BCMR_bAChrgPwrDwnReq = false;
        BCMR_pHeatPwrReq = BCMR_pHoldtempPwrReq_C;
        BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 20.0F;
        BCMR_uReqVoltChrg = BSPR_uBattVolt;
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_AChrg_B.BCMR_stAChrgPreThemalMode = 3U;
      }
      break;
    }
  }
}

/* Function for Chart: '<S334>/circulateDispay' */
static void BCMR_AChrg_calu(const uint8_T *MinMax_h)
{
  real32_T i;
  boolean_T exitg1;
  i = 0.0F;
  exitg1 = false;
  while ((!exitg1) && (i < BCMR_numFltNumMax_C)) {
    if (BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[(int32_T)i] >
        BCMR_AChrg_DW.num) {
      BCMR_AChrg_DW.b = i + 1.0F;
      BCMR_AChrg_DW.num = BCMR_AChrg_DW.b;
      exitg1 = true;
    } else {
      BCMR_AChrg_DW.b = 0.0F;
      i++;
    }
  }

  if (BCMR_AChrg_DW.num > BCMR_AChrg_DW.b) {
    BCMR_AChrg_DW.b = BCMR_AChrg_DW.num;
  }

  if (BCMR_AChrg_DW.num > (real32_T)*MinMax_h - 1.0F) {
    BCMR_AChrg_DW.num = 0.0F;
  }

  BCMR_AChrg_B.enum_i = (uint8_T)BCMR_AChrg_DW.b;
}

/* Model step function */
void BCMR_AChrg_step(void)
{
  boolean_T rtb_Switch4_m;
  boolean_T rtb_RelationalOperator3_ll;
  boolean_T rtb_LogicalOperator1_gy;
  real32_T rtb_Switch1_iz;
  real32_T rtb_Switch1_lz;
  real32_T rtb_Switch1_fw;
  real32_T rtb_Switch1_a0;
  boolean_T rtb_BCMR_stAChrgCnnt_a;
  boolean_T rtb_Switch_hc;
  real32_T rtb_UnitDelay2;
  real32_T rtb_Abs1;
  uint8_T rtb_Switch4_ef;
  uint8_T rtb_Switch4_ps;
  real32_T rtb_Saturation;
  real32_T rtb_Saturation_a;
  int16_T rtb_DataTypeConversion;
  int16_T rtb_Divide1;
  int16_T rtb_UnitDelay2_p;
  boolean_T rtb_LogicalOperator3_p;
  boolean_T rtb_LogicalOperator3_nn;
  real32_T rtb_Switch;
  real32_T rtb_Product_dt;
  boolean_T rtb_RelationalOperator_ol;
  real32_T rtb_Switch1_f;
  boolean_T rtb_LogicalOperator6_n;
  uint16_T rtb_Switch2_jo;
  uint16_T rtb_Switch2_ix;
  real32_T rtb_Product_of;
  real32_T rtb_Product_nu;
  uint8_T rtb_Switch4_gs;
  uint8_T rtb_Switch4_c;
  uint8_T rtb_Switch4_l;
  uint8_T rtb_Switch4_k;
  uint8_T rtb_Switch4_mq;
  uint8_T rtb_Switch4_oy;
  real32_T rtb_Switch1_id;
  uint8_T Switch4;
  uint8_T Switch1;
  uint8_T Switch2;
  int32_T i;
  boolean_T RelationalOperator_h;
  boolean_T Switch;
  boolean_T RelationalOperator_ev;
  real32_T tmp;
  boolean_T guard1 = false;
  rtb_Switch4_m = (BCMR_flgChrgStopActive_C && COMR_bChrgStopActive);
  if (BCMR_flgIviDischgOrd_C) {
    Switch4 = 0U;
  } else {
    Switch4 = COMR_bIviDischgOrd;
  }

  BCMR_stV2xMod = (uint8_T)((COMR_stObcCC >= 6) && (COMR_stObcCC <= 8));
  if (BCMR_AChrgWkUpCAl_C >= 10.0F) {
    AcChrgWkup = true;
  } else {
    AcChrgWkup = (COMR_flgObcWkUp || BSPR_bACWkUp);
  }

  if (AcChrgWkup) {
    rtb_Switch1_a0 = BCMR_tiBase_C;
  } else {
    rtb_Switch1_a0 = 0.0F;
  }

  if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ji) {
    rtb_UnitDelay2 = BCMR_tiHealDebs_C;
  } else {
    rtb_UnitDelay2 = BCMR_AChrg_DW.Delay_DSTATE_ji;
  }

  rtb_Product_dt = (rtb_Switch1_a0 + rtb_UnitDelay2) * (real32_T)AcChrgWkup;
  RelationalOperator_ev = (rtb_Product_dt > BCMR_tiHealDebs_C);
  BCMR_AChrg_DW.Delay_DSTATE_ji = rtb_Product_dt;
  rtb_BCMR_stAChrgCnnt_a = ((COMR_stObcCC >= 3) && (COMR_stObcCC <= 8));
  BCMR_stAChrgCnnt = (uint8_T)rtb_BCMR_stAChrgCnnt_a;
  if ((COMR_stObcCC >= 3) && (COMR_stObcCC <= 5)) {
    BCMR_stAChgDischg = 1U;
  } else if ((COMR_stObcCC >= 6) && (COMR_stObcCC <= 8)) {
    BCMR_stAChgDischg = 2U;
  } else {
    BCMR_stAChgDischg = 0U;
  }

  if (BCMR_flgAChrgDebug_C != 0) {
    AcChrgCnnt = true;
  } else {
    AcChrgCnnt = (rtb_BCMR_stAChrgCnnt_a && ((COMR_stObcCP == BCMR_stCp9VPWM_C) ||
      (COMR_stObcCP == BCMR_stCp6VPWM_C)));
  }

  if (AcChrgCnnt) {
    rtb_Switch1_a0 = BCMR_tiBase_C;
  } else {
    rtb_Switch1_a0 = 0.0F;
  }

  if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_n) {
    rtb_UnitDelay2 = BCMR_tiHealDebs_C;
  } else {
    rtb_UnitDelay2 = BCMR_AChrg_DW.Delay_DSTATE_n;
  }

  rtb_Product_dt = (rtb_Switch1_a0 + rtb_UnitDelay2) * (real32_T)AcChrgCnnt;
  BCMR_AChrg_B.RelationalOperator_o = (rtb_Product_dt > BCMR_tiHealDebs_C);
  BCMR_AChrg_DW.Delay_DSTATE_n = rtb_Product_dt;
  HysteresisCalc(BSPR_tCellTempMin, 0U, 1U, &BCMR_AChrg_B.uDHysteresis1,
                 BCMR_tPreHeatStart_C, BCMR_tPreHeatStop_C);
  if (BCMR_AChrg_DW.StateName_b3) {
    rtb_Switch2_jo = 0U;
  } else {
    rtb_Switch2_jo = BCMR_AChrg_DW.StateName_m;
  }

  if (BCMR_AChrg_B.uDHysteresis1.Switch != 0) {
    rtb_Switch2_jo = (uint16_T)((uint32_T)BCMR_tiFullBase_C + rtb_Switch2_jo);
    if (!(rtb_Switch2_jo <= 60000)) {
      rtb_Switch2_jo = 60000U;
    }
  } else if (rtb_Switch2_jo >= BCMR_tiFullBase_C) {
    rtb_Switch2_jo = (uint16_T)((uint32_T)rtb_Switch2_jo - BCMR_tiFullBase_C);
  } else {
    rtb_Switch2_jo = 0U;
  }

  rtb_BCMR_stAChrgCnnt_a = (rtb_Switch2_jo > BCMR_tiPreThmDebs_C);
  if (BCMR_AChrg_DW.StateName_p) {
    rtb_Switch2_ix = 0U;
  } else {
    rtb_Switch2_ix = BCMR_AChrg_DW.StateName_f;
  }

  if (BCMR_AChrg_B.uDHysteresis1.Switch == 0) {
    rtb_Switch2_ix = (uint16_T)((uint32_T)BCMR_tiFullBase_C + rtb_Switch2_ix);
    if (!(rtb_Switch2_ix <= 60000)) {
      rtb_Switch2_ix = 60000U;
    }
  } else if (rtb_Switch2_ix >= BCMR_tiFullBase_C) {
    rtb_Switch2_ix = (uint16_T)((uint32_T)rtb_Switch2_ix - BCMR_tiFullBase_C);
  } else {
    rtb_Switch2_ix = 0U;
  }

  rtb_RelationalOperator_ol = (rtb_Switch2_ix > BCMR_tiPreThmDebs_C);
  if (!BCMR_AChrg_DW.StateName_a) {
    rtb_Switch_hc = (rtb_BCMR_stAChrgCnnt_a || BCMR_AChrg_DW.StateName_a);
  } else {
    rtb_Switch_hc = ((!rtb_RelationalOperator_ol) && BCMR_AChrg_DW.StateName_a);
  }

  BCMR_AChrg_DW.StateName_a = rtb_Switch_hc;
  BCMR_AChrg_DW.StateName_b3 = rtb_BCMR_stAChrgCnnt_a;
  BCMR_AChrg_DW.StateName_m = rtb_Switch2_jo;
  BCMR_AChrg_DW.StateName_p = rtb_RelationalOperator_ol;
  BCMR_AChrg_DW.StateName_f = rtb_Switch2_ix;
  BCMR_AChrg_B.Local_PreHeatChk = ((BSPR_tCellTempMin >= BCMR_tLowPreThmTemp_C) &&
    rtb_Switch_hc);
  HysteresisCalc(BSPR_tCellTempMax, 1U, 0U, &BCMR_AChrg_B.uDHysteresis2,
                 BCMR_tPreCoolStop_C, BCMR_tPreCoolStart_C);
  BCMR_AChrg_TONV_TimeDebounce1(BCMR_AChrg_B.uDHysteresis2.Switch,
    &BCMR_AChrg_B.TONV_TimeDebounce1, &BCMR_AChrg_DW.TONV_TimeDebounce1, 0.1F,
    0.3F);
  Local_PreCoolChk = BCMR_AChrg_B.TONV_TimeDebounce1.RelationalOperator;
  if ((BSPR_tCellTempMin >= BCMR_tTempMin2Avg) && (BSPR_tCellTempMax <=
       BCMR_tTempAvg2Max)) {
    rtb_Product_dt = BSPR_tCellTempAvrg;
  } else if (BSPR_tCellTempMin < BCMR_tTempMin2Avg) {
    rtb_Product_dt = BSPR_tCellTempMin;
  } else if (BSPR_tCellTempMax > BCMR_tTempAvg2Max) {
    rtb_Product_dt = BSPR_tCellTempMax;
  } else {
    rtb_Product_dt = BSPR_tCellTempAvrg;
  }

  if (BCMR_flgAChrgDebug_C != 0) {
    Switch1 = 4U;
    Switch2 = 5U;
  } else {
    Switch1 = COMR_stObcCP;
    Switch2 = COMR_stObcChrg;
  }

  rtb_UnitDelay2 = BCMR_AChrg_DW.UnitDelay2_DSTATE;
  BCMR_stAChrgObsr = BCMR_AChrg_DW.UnitDelay_DSTATE_oo;
  if ((BCMR_stAChrgObsr == 18) || ((BCMR_stAChrgObsr >= 1) && (BCMR_stAChrgObsr <=
        9)) || ((BCMR_stAChrgObsr >= 24) && (BCMR_stAChrgObsr <= 36))) {
    if (!BCMR_AChrg_DW.AcChgErrorPro_MODE) {
      BCMR_AChrg_DW.Delay_DSTATE_lf = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_kv = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_hk = 0.0F;
      BCMR_AChrg_DW.Delay2_DSTATE_l0 = true;
      BCMR_AChrg_DW.Delay3_DSTATE_h = 0U;
      BCMR_AChrg_DW.AcChgErrorPro_MODE = true;
    }

    rtb_Abs1 = (real32_T)fabs(BSPR_iBattCurr);
    rtb_BCMR_stAChrgCnnt_a = (COMR_stObcFaultLvl >= 3);
    rtb_Switch4_ef = (uint8_T)(DSMR_stFaultRank >= 3);
    rtb_Switch4_ps = (uint8_T)(COMR_stVcuFalutLvl >= 3);
    Local_flgAcChgFobdTmpA = (rtb_BCMR_stAChrgCnnt_a || (rtb_Switch4_ef != 0) ||
      (rtb_Switch4_ps != 0));
    if (BSPR_iBattCurr < BCMR_ChgCurrVld_C) {
      if (!BCMR_AChrg_DW.OverVoltProc_MODE) {
        BCMR_AChrg_DW.Delay_DSTATE_pu = 0.0F;
        BCMR_AChrg_DW.Delay_DSTATE_hg = 0.0F;
        BCMR_AChrg_DW.Delay_DSTATE_kj = 0.0F;
        BCMR_AChrg_DW.Delay_DSTATE_be = 0.0F;
        BCMR_AChrg_DW.Delay2_DSTATE_o = true;
        BCMR_AChrg_DW.Delay3_DSTATE_m = 0U;
        BCMR_AChrg_DW.OverVoltProc_MODE = true;
      }

      rtb_Switch_hc = (((real32_T)fabs(COMR_uVoltObcChrg) >=
                        BCMR_uAChrgOvrVolt_C) || (BCMR_uAChrgOvrVolt_C <=
        BSPR_uBattVolt));
      if (rtb_Switch_hc) {
        rtb_Saturation_a = BCMR_tiBase_C;
      } else {
        rtb_Saturation_a = 0.0F;
      }

      if (BCMR_tiDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_pu) {
        rtb_Switch1_a0 = BCMR_tiDetDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_pu;
      }

      rtb_Product_of = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
        rtb_Switch_hc;
      BCMR_AChrg_B.RelationalOperator_n = (rtb_Product_of > BCMR_tiDetDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_pu = rtb_Product_of;
      rtb_RelationalOperator_ol = ((BSPR_uBattVolt -
        BCMR_AChrg_DW.UnitDelay4_DSTATE >= BCMR_uAChrgDiffVolt_C) || ((real32_T)
        fabs(BSPR_uBattVolt - COMR_uVoltObcChrg) >= BCMR_uAChrgDiffVolt_C));
      if (rtb_RelationalOperator_ol) {
        rtb_Switch1_id = BCMR_tiBase_C;
      } else {
        rtb_Switch1_id = 0.0F;
      }

      if (BCMR_tiDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_hg) {
        rtb_Switch1_a0 = BCMR_tiDetDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_hg;
      }

      rtb_Product_of = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
        rtb_RelationalOperator_ol;
      BCMR_AChrg_B.RelationalOperator_c = (rtb_Product_of > BCMR_tiDetDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_hg = rtb_Product_of;
      rtb_Switch_hc = !rtb_Switch_hc;
      if (rtb_Switch_hc) {
        rtb_Saturation_a = BCMR_tiBase_C;
      } else {
        rtb_Saturation_a = 0.0F;
      }

      if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_kj) {
        rtb_Switch1_a0 = BCMR_tiHealDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_kj;
      }

      rtb_Product_of = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
        rtb_Switch_hc;
      BCMR_AChrg_B.RelationalOperator_pu = (rtb_Product_of > BCMR_tiHealDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_kj = rtb_Product_of;
      rtb_RelationalOperator_ol = !rtb_RelationalOperator_ol;
      if (rtb_RelationalOperator_ol) {
        rtb_Switch1_id = BCMR_tiBase_C;
      } else {
        rtb_Switch1_id = 0.0F;
      }

      if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_be) {
        rtb_Switch1_a0 = BCMR_tiHealDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_be;
      }

      rtb_Product_of = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
        rtb_RelationalOperator_ol;
      BCMR_AChrg_B.RelationalOperator_p = (rtb_Product_of > BCMR_tiHealDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_be = rtb_Product_of;
      if (BCMR_AChrg_DW.Delay2_DSTATE_o) {
        rtb_Switch4_oy = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChrgVoltMish_ASW | 8U);
      } else if (BCMR_AChrg_B.RelationalOperator_n ||
                 BCMR_AChrg_B.RelationalOperator_c) {
        rtb_Switch4_oy = (uint8_T)(DFC_AChrgVoltMish_ASW | 152U);
      } else if (BCMR_AChrg_B.RelationalOperator_pu &&
                 BCMR_AChrg_B.RelationalOperator_p) {
        rtb_Switch4_oy = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_AChrgVoltMish_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_oy = BCMR_AChrg_DW.Delay3_DSTATE_m;
      }

      BCMR_AChrg_DW.Delay2_DSTATE_o = false;
      BCMR_AChrg_DW.Delay3_DSTATE_m = rtb_Switch4_oy;
      DFC_AChrgVoltMish_ASW = rtb_Switch4_oy;
      BCMR_AChrg_B.DataTypeConversion = ((rtb_Switch4_oy & 24) == 24);
      if (!BCMR_AChrg_DW.OverCurrProc_MODE) {
        BCMR_AChrg_DW.Delay_DSTATE_is = 0.0F;
        BCMR_AChrg_DW.UnitDelay_DSTATE_au = 0.0F;
        BCMR_AChrg_DW.Delay_DSTATE_d = 1.0F;
        BCMR_AChrg_DW.Delay_DSTATE_li = 0.0F;
        BCMR_AChrg_DW.Delay_DSTATE_cg = 0.0F;
        BCMR_AChrg_DW.Delay_DSTATE_ai = 0.0F;
        BCMR_AChrg_DW.Delay2_DSTATE_mi = true;
        BCMR_AChrg_DW.Delay3_DSTATE_ft = 0U;
        BCMR_AChrg_DW.OverCurrProc_MODE = true;
      }

      rtb_Product_of = (real32_T)fabs(COMR_iCurrObcChrg);
      rtb_Switch_hc = ((rtb_Product_of >= BCMR_iAChrgOvrCurr_C) ||
                       (BCMR_iAChrgOvrCurr_C <= rtb_Abs1));
      if (rtb_Switch_hc) {
        rtb_Saturation_a = BCMR_tiBase_C;
      } else {
        rtb_Saturation_a = 0.0F;
      }

      if (BCMR_tiDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_is) {
        rtb_Switch1_a0 = BCMR_tiDetDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_is;
      }

      rtb_Product_nu = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
        rtb_Switch_hc;
      BCMR_AChrg_B.RelationalOperator_bd = (rtb_Product_nu > BCMR_tiDetDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_is = rtb_Product_nu;
      if (!(BCMR_AChrg_DW.Delay_DSTATE_d > 0.0F)) {
        rtb_UnitDelay2 = (rtb_UnitDelay2 - BCMR_AChrg_DW.UnitDelay_DSTATE_au) *
          0.25F + BCMR_AChrg_DW.UnitDelay_DSTATE_au;
      }

      BCMR_AChrg_DW.UnitDelay_DSTATE_au = rtb_UnitDelay2;
      BCMR_AChrg_DW.Delay_DSTATE_d = 0.0F;
      rtb_RelationalOperator_ol = ((rtb_Abs1 - rtb_UnitDelay2 >=
        BCMR_iAChrgDiffCurr_C) || (rtb_Abs1 - rtb_Product_of >=
        BCMR_iAChrgDiffCurr_C));
      if (rtb_RelationalOperator_ol) {
        rtb_Switch1_id = BCMR_tiBase_C;
      } else {
        rtb_Switch1_id = 0.0F;
      }

      if (BCMR_tiDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_li) {
        rtb_Switch1_a0 = BCMR_tiDetDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_li;
      }

      rtb_UnitDelay2 = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
        rtb_RelationalOperator_ol;
      BCMR_AChrg_B.RelationalOperator_b = (rtb_UnitDelay2 > BCMR_tiDetDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_li = rtb_UnitDelay2;
      rtb_Switch_hc = !rtb_Switch_hc;
      if (rtb_Switch_hc) {
        rtb_Saturation_a = BCMR_tiBase_C;
      } else {
        rtb_Saturation_a = 0.0F;
      }

      if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_cg) {
        rtb_Switch1_a0 = BCMR_tiHealDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_cg;
      }

      rtb_UnitDelay2 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
        rtb_Switch_hc;
      BCMR_AChrg_B.RelationalOperator_ja = (rtb_UnitDelay2 > BCMR_tiHealDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_cg = rtb_UnitDelay2;
      rtb_RelationalOperator_ol = !rtb_RelationalOperator_ol;
      if (rtb_RelationalOperator_ol) {
        rtb_Switch1_id = BCMR_tiBase_C;
      } else {
        rtb_Switch1_id = 0.0F;
      }

      if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ai) {
        rtb_Switch1_a0 = BCMR_tiHealDebs_C;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ai;
      }

      rtb_UnitDelay2 = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
        rtb_RelationalOperator_ol;
      BCMR_AChrg_B.RelationalOperator_j = (rtb_UnitDelay2 > BCMR_tiHealDebs_C);
      BCMR_AChrg_DW.Delay_DSTATE_ai = rtb_UnitDelay2;
      if (BCMR_AChrg_DW.Delay2_DSTATE_mi) {
        rtb_Switch4_oy = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChrgCurrMish_ASW | 8U);
      } else if (BCMR_AChrg_B.RelationalOperator_bd ||
                 BCMR_AChrg_B.RelationalOperator_b) {
        rtb_Switch4_oy = (uint8_T)(DFC_AChrgCurrMish_ASW | 152U);
      } else if (BCMR_AChrg_B.RelationalOperator_ja &&
                 BCMR_AChrg_B.RelationalOperator_j) {
        rtb_Switch4_oy = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_AChrgCurrMish_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_oy = BCMR_AChrg_DW.Delay3_DSTATE_ft;
      }

      BCMR_AChrg_DW.Delay2_DSTATE_mi = false;
      BCMR_AChrg_DW.Delay3_DSTATE_ft = rtb_Switch4_oy;
      DFC_AChrgCurrMish_ASW = rtb_Switch4_oy;
      BCMR_AChrg_B.DataTypeConversion_a = ((rtb_Switch4_oy & 24) == 24);
    } else {
      if (BCMR_AChrg_DW.OverVoltProc_MODE) {
        BCMR_AChrg_DW.OverVoltProc_MODE = false;
      }

      if (BCMR_AChrg_DW.OverCurrProc_MODE) {
        BCMR_AChrg_DW.OverCurrProc_MODE = false;
      }
    }

    Local_flgAcChgFobdTmpB = (Local_flgAcChgFobdTmpA ||
      ((BCMR_AChrg_B.DataTypeConversion || BCMR_AChrg_B.DataTypeConversion_a) &&
       ((COMR_stObcChrg == 6) || (COMR_stObcChrg == 2))));
    rtb_RelationalOperator_ol = ((COMR_dcObcCP < 8) || (COMR_dcObcCP > 97));
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_tiBase_C;
    } else {
      rtb_Switch1_id = 0.0F;
    }

    if (2.0F <= BCMR_AChrg_DW.Delay_DSTATE_lf) {
      tmp = 2.0F;
    } else {
      tmp = BCMR_AChrg_DW.Delay_DSTATE_lf;
    }

    rtb_UnitDelay2 = (real32_T)((rtb_Switch1_id + tmp) * (real32_T)
      rtb_RelationalOperator_ol);
    DutyCycleAbnorm = (rtb_UnitDelay2 >= 2.0F);
    BCMR_AChrg_DW.Delay_DSTATE_lf = rtb_UnitDelay2;
    rtb_RelationalOperator_ol = (DutyCycleAbnorm && ((COMR_stObcCP ==
      BCMR_stCp9VPWM_C) || (COMR_stObcCP == BCMR_stCp6VPWM_C)));
    BCMR_AChrg_B.TempAbnorm = ((BCMR_tAChrgPmtTempUpLmt_C <
      BCMR_AChrg_DW.UnitDelay3_DSTATE) || (BCMR_AChrg_DW.UnitDelay3_DSTATE <
      BCMR_tAChrgPmtTempDwnLmt_C));
    if (BCMR_AChrg_B.TempAbnorm) {
      rtb_Switch1_a0 = BCMR_tiBase_C;
    } else {
      rtb_Switch1_a0 = 0.0F;
    }

    if (BCMR_tiDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_kv) {
      rtb_UnitDelay2 = BCMR_tiDetDebs_C;
    } else {
      rtb_UnitDelay2 = BCMR_AChrg_DW.Delay_DSTATE_kv;
    }

    rtb_UnitDelay2 = (rtb_Switch1_a0 + rtb_UnitDelay2) * (real32_T)
      BCMR_AChrg_B.TempAbnorm;
    BCMR_AChrg_DW.Delay_DSTATE_kv = rtb_UnitDelay2;
    rtb_Switch_hc = !BCMR_AChrg_B.TempAbnorm;
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_hk) {
      rtb_Switch1_a0 = BCMR_tiHealDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_hk;
    }

    rtb_Abs1 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)rtb_Switch_hc;
    BCMR_AChrg_DW.Delay_DSTATE_hk = rtb_Abs1;
    if (BCMR_AChrg_DW.Delay2_DSTATE_l0) {
      rtb_Switch4_oy = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChrgCellOvrTemp_ASW | 8U);
    } else if (rtb_UnitDelay2 > BCMR_tiDetDebs_C) {
      rtb_Switch4_oy = (uint8_T)(DFC_AChrgCellOvrTemp_ASW | 152U);
    } else if (rtb_Abs1 > BCMR_tiHealDebs_C) {
      rtb_Switch4_oy = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_AChrgCellOvrTemp_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_oy = BCMR_AChrg_DW.Delay3_DSTATE_h;
    }

    BCMR_AChrg_DW.Delay2_DSTATE_l0 = false;
    BCMR_AChrg_DW.Delay3_DSTATE_h = rtb_Switch4_oy;
    DFC_AChrgCellOvrTemp_ASW = rtb_Switch4_oy;
    BCMR_bAChrgCellOvrTemp = ((rtb_Switch4_oy & 24) == 24);
    BCMR_AChrg_B.Local_flgAcChgFobd = (Local_flgAcChgFobdTmpB ||
      rtb_RelationalOperator_ol || BCMR_bAChrgCellOvrTemp ||
      COMR_bVcuChrgDisable || HVSR_flgIsoFaultLvl2 || HVSR_flgHvilFault);
    BCMR_AChrg_B.LogicalOperator7 = (Local_flgAcChgFobdTmpA ||
      HVSR_flgIsoFaultLvl2 || HVSR_flgHvilFault || (Switch4 == 2) ||
      COMR_bVcuChrgDisable);
    if (rtb_Switch4_ef != 0) {
      rtb_Switch4_ef = 3U;
    }

    if (rtb_Switch4_ps != 0) {
      rtb_Switch4_ps = 4U;
    }

    BCMR_AChrg_B.LogicalOperator6 = (Local_flgAcChgFobdTmpA ||
      rtb_RelationalOperator_ol || HVSR_flgIsoFaultLvl2 || HVSR_flgHvilFault);
    Local_flgPwrRdc = (DSMR_stFaultRank == 2);
    Local_flgAcChgWarn = (Local_flgPwrRdc || (DSMR_stFaultRank == 1) ||
                          (COMR_stObcFaultLvl == 2) || ((COMR_stVcuFalutLvl <= 2)
      && (COMR_stVcuFalutLvl >= 1)));
    BCMR_bAChrgCurrOutRngErrDet = BCMR_AChrg_B.RelationalOperator_bd;
    BCMR_bAChrgCurrOutRngErrHeal = BCMR_AChrg_B.RelationalOperator_ja;
    BCMR_bAChrgOvrCurrErrDet = BCMR_AChrg_B.RelationalOperator_b;
    BCMR_bAChrgOvrCurrErrHeal = BCMR_AChrg_B.RelationalOperator_j;
    BCMR_bAChrgOvrVoltErrDet = BCMR_AChrg_B.RelationalOperator_n;
    BCMR_bAChrgOvrVoltErrHeal = BCMR_AChrg_B.RelationalOperator_p;
    BCMR_bAChrgVoltMish = BCMR_AChrg_B.DataTypeConversion;
    BCMR_bAChrgVoltOutRngErrDet = BCMR_AChrg_B.RelationalOperator_c;
    BCMR_bAChrgVoltOutRngErrHeal = BCMR_AChrg_B.RelationalOperator_pu;
    BCMR_bAChrgCurrMish = BCMR_AChrg_B.DataTypeConversion_a;
    BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[0] =
      BCMR_AChrg_B.Local_flgAcChgFobd;
    if (rtb_BCMR_stAChrgCnnt_a) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[1] = 2U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[1] = 0U;
    }

    BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[2] = rtb_Switch4_ef;
    BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[3] = rtb_Switch4_ps;
    if (BCMR_AChrg_B.DataTypeConversion) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[4] = 5U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[4] = 0U;
    }

    if (BCMR_AChrg_B.DataTypeConversion_a) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[5] = 6U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[5] = 0U;
    }

    BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[6] = 0U;
    if (rtb_RelationalOperator_ol) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[7] = 8U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[7] = 0U;
    }

    if (BCMR_bAChrgCellOvrTemp) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[8] = 9U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[8] = 0U;
    }

    if (HVSR_flgIsoFaultLvl2) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[9] = 10U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[9] = 0U;
    }

    if (HVSR_flgHvilFault) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[10] = 11U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[10] = 0U;
    }

    if (BCMR_AChrg_DW.UnitDelay6_DSTATE) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[11] = 12U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[11] = 0U;
    }

    if (COMR_bVcuChrgDisable) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[12] = 13U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[12] = 0U;
    }

    BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[13] = 0U;
    if (BCMR_AChrg_B.LogicalOperator7) {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[14] = 15U;
    } else {
      BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[14] = 0U;
    }
  } else {
    if (BCMR_AChrg_DW.AcChgErrorPro_MODE) {
      if (BCMR_AChrg_DW.OverVoltProc_MODE) {
        BCMR_AChrg_DW.OverVoltProc_MODE = false;
      }

      if (BCMR_AChrg_DW.OverCurrProc_MODE) {
        BCMR_AChrg_DW.OverCurrProc_MODE = false;
      }

      BCMR_AChrg_B.Local_flgAcChgFobd = false;
      BCMR_bAChrgCurrOutRngErrDet = false;
      BCMR_bAChrgCurrOutRngErrHeal = false;
      BCMR_bAChrgOvrCurrErrDet = false;
      BCMR_bAChrgOvrCurrErrHeal = false;
      BCMR_bAChrgCurrMish = false;
      BCMR_bAChrgVoltOutRngErrDet = false;
      BCMR_bAChrgVoltOutRngErrHeal = false;
      BCMR_bAChrgOvrVoltErrHeal = false;
      BCMR_bAChrgOvrVoltErrDet = false;
      BCMR_bAChrgVoltMish = false;
      for (i = 0; i < 15; i++) {
        BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[i] = 0U;
      }

      BCMR_AChrg_B.LogicalOperator7 = false;
      BCMR_AChrg_DW.AcChgErrorPro_MODE = false;
    }
  }

  if ((BCMR_stAChrgObsr >= BCMR_AChgParaCalcLow_C) && (BCMR_stAChrgObsr <=
       BCMR_AChgParaCalcHigh_C)) {
    if (!BCMR_AChrg_DW.AcChgParaCalc_MODE) {
      BCMR_AChrg_DW.Delay_DSTATE_ju = false;
      BCMR_AChrg_DW.Delay1_DSTATE_he = false;
      BCMR_AChrg_DW.Delay2_DSTATE_ex = false;
      BCMR_BMSDebounceStartZero_Reset(&BCMR_AChrg_DW.BMSDebounceStartZero_e);
      BCMR_AChrg_DW.UnitDelay1_DSTATE_l = true;
      BCMR_AChrg_DW.Delay1_DSTATE_a = 0.0F;
      BCMR_AChrg_DW.Delay2_DSTATE_eg = false;
      BCMR_AChrg_DW.UnitDelay1_DSTATE_k3 = true;
      BCMR_AChrg_DW.Delay1_DSTATE_m = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_f3 = 0U;
      BCMR_AChrg_DW.UnitDelay_DSTATE_h = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_aw = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_a2 = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_es = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_hm = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_ht = 0.0F;
      BCMR_AChrg_DW.is_active_c1_BCMR_AChrg = 0U;
      BCMR_AChrg_DW.is_c1_BCMR_AChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_bAcChrgHeatFbd = false;
      BCMR_BMSDebounceStartZero_Reset(&BCMR_AChrg_DW.BMSDebounceStartZero_g);
      BCMR_AChrg_DW.temporalCounter_i1_i = 0U;
      BCMR_AChrg_DW.is_active_c4_BCMR_AChrg = 0U;
      BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_Default;
      BCMR_AChrg_B.BCMR_rAChrgTrickleCnt = 0U;
      BCMR_AChrg_B.BCMR_bAChrgTrickle = false;
      BCMR_AChrg_DW.Delay1_DSTATE_o = true;
      BCMR_AChrg_DW.AcChgParaCalc_MODE = true;
    }

    BCMR_AChrg_BMSDebounceStartZero((BSPR_uCellVoltMax >=
      BCMR_vChgFullCellVolt_C) && (BSPR_uCellVoltMax <
      BCMR_vChgFullMaxCellVolt_C), BCMR_tiDebs_C, BCMR_tiFullBase_C,
      BCMR_tiDebs_C, BCMR_tiFullBase_C, &BCMR_AChrg_B.BMSDebounceStartZero_e,
      &BCMR_AChrg_DW.BMSDebounceStartZero_e);
    rtb_UnitDelay2 = (real32_T)fabs(COMR_iMaxCurrObcChrg);
    rtb_RelationalOperator_ol = ((real32_T)fabs(rtb_UnitDelay2 -
      BCMR_iAChrgOBCPwrLv3_C) < BCMR_iAChrgOBCPwrDvt_C);
    rtb_BCMR_stAChrgCnnt_a = (((real32_T)fabs(rtb_Product_dt -
      BCMR_AChrg_DW.Delay1_DSTATE_a) > BCMR_tCellTempDec_C) &&
      (!BCMR_AChrg_DW.Delay2_DSTATE_eg));
    if (rtb_BCMR_stAChrgCnnt_a) {
      rtb_Saturation = BCMR_tiBase_C;
    } else {
      rtb_Saturation = 0.0F;
    }

    if (BCMR_tiTempHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_aw) {
      rtb_Switch1_a0 = BCMR_tiTempHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_aw;
    }

    rtb_Abs1 = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
      rtb_BCMR_stAChrgCnnt_a;
    BCMR_AChrg_DW.Delay_DSTATE_aw = rtb_Abs1;
    if (BCMR_AChrg_DW.UnitDelay1_DSTATE_l) {
      BCMR_tTempCurrReq = rtb_Product_dt;
    } else if (rtb_Abs1 > BCMR_tiTempHoldDebs_C) {
      BCMR_tTempCurrReq = rtb_Product_dt;
    } else {
      BCMR_tTempCurrReq = BCMR_AChrg_DW.Delay1_DSTATE_a;
    }

    rtb_Switch_hc = (BSPR_uCellVoltMax > BCMR_AChrg_DW.Delay1_DSTATE_m);
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiVoltHoldBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiVoltHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_a2) {
      rtb_Switch1_a0 = BCMR_tiVoltHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_a2;
    }

    rtb_Abs1 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)rtb_Switch_hc;
    BCMR_AChrg_DW.Delay_DSTATE_a2 = rtb_Abs1;
    rtb_Switch_hc = (BSPR_uCellVoltMax - BCMR_AChrg_DW.Delay1_DSTATE_m <=
                     BCMR_uCellVoltMaxDec_C);
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiVoltHoldBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiVoltHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_es) {
      rtb_Switch1_a0 = BCMR_tiVoltHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_es;
    }

    rtb_Product_of = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
      rtb_Switch_hc;
    BCMR_AChrg_DW.Delay_DSTATE_es = rtb_Product_of;
    if (BCMR_AChrg_DW.UnitDelay1_DSTATE_k3) {
      BCMR_uVoltCurrReq = BSPR_uCellVoltMax;
    } else if (rtb_Abs1 > BCMR_tiVoltHoldDebs_C) {
      BCMR_uVoltCurrReq = BSPR_uCellVoltMax;
    } else if (rtb_Product_of > BCMR_tiVoltHoldDebs_C) {
      BCMR_uVoltCurrReq = BSPR_uCellVoltMax;
    } else {
      BCMR_uVoltCurrReq = BCMR_AChrg_DW.Delay1_DSTATE_m;
    }

    BCMR_iCurrReqCalcTmpA = look2_iflf_binlcapw(BCMR_tTempCurrReq,
      BCMR_uVoltCurrReq, ((const real32_T *)&(BCMR_tTempLder_A[0])), ((const
      real32_T *)&(BCMR_uCellVoltLder_A[0])), ((const real32_T *)
      &(BCMR_iCurrLder_A[0])), rtCP_CurrReq_maxIndex, 17U);
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_iAChrgThmOFFLv2_C;
    } else {
      rtb_Switch1_id = BCMR_iAChrgThmOFFLv1_C;
    }

    rtb_Switch_hc = (BCMR_iCurrReqCalcTmpA > rtb_Switch1_id);
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiThmCtrlBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiThmCtrlDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_hm) {
      rtb_Switch1_a0 = BCMR_tiThmCtrlDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_hm;
    }

    rtb_Abs1 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)rtb_Switch_hc;
    BCMR_AChrg_DW.Delay_DSTATE_hm = rtb_Abs1;
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_iAChrgThmONLv2_C;
    } else {
      rtb_Switch1_id = BCMR_iAChrgThmONLv1_C;
    }

    rtb_RelationalOperator_ol = (BCMR_iCurrReqCalcTmpA < rtb_Switch1_id);
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_tiThmCtrlBase_C;
    } else {
      rtb_Switch1_id = 0.0F;
    }

    if (BCMR_tiThmCtrlDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ht) {
      rtb_Switch1_a0 = BCMR_tiThmCtrlDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ht;
    }

    rtb_Product_of = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
      rtb_RelationalOperator_ol;
    BCMR_AChrg_DW.Delay_DSTATE_ht = rtb_Product_of;
    if (BCMR_AChrg_DW.is_active_c1_BCMR_AChrg == 0U) {
      BCMR_AChrg_DW.is_active_c1_BCMR_AChrg = 1U;
      BCMR_AChrg_DW.is_c1_BCMR_AChrg = BCMR_A_IN_BCMR_AcChrgHeatActive;
      BCMR_bAcChrgHeatFbd = false;
    } else if (BCMR_AChrg_DW.is_c1_BCMR_AChrg == BCMR_A_IN_BCMR_AcChrgHeatActive)
    {
      if (rtb_Abs1 > BCMR_tiThmCtrlDebs_C) {
        BCMR_AChrg_DW.is_c1_BCMR_AChrg = BCMR_IN_BCMR_AcChrgHeatInActive;
        BCMR_bAcChrgHeatFbd = true;
      }
    } else {
      if (rtb_Product_of > BCMR_tiThmCtrlDebs_C) {
        BCMR_AChrg_DW.is_c1_BCMR_AChrg = BCMR_A_IN_BCMR_AcChrgHeatActive;
        BCMR_bAcChrgHeatFbd = false;
      }
    }

    BCMR_AChrg_BMSDebounceStartZero((BSPR_uCellVoltMax >=
      BCMR_vChgFullCellVolt_C) && (BSPR_uCellVoltMax <
      BCMR_vChgFullMaxCellVolt_C), BCMR_tiTrkDebs_C, BCMR_tiFullBase_C,
      BCMR_tiTrkDebs_C, BCMR_tiFullBase_C, &BCMR_AChrg_B.BMSDebounceStartZero_g,
      &BCMR_AChrg_DW.BMSDebounceStartZero_g);
    if (BCMR_AChrg_DW.temporalCounter_i1_i < 127U) {
      BCMR_AChrg_DW.temporalCounter_i1_i++;
    }

    if (BCMR_AChrg_DW.is_active_c4_BCMR_AChrg == 0U) {
      BCMR_AChrg_DW.is_active_c4_BCMR_AChrg = 1U;
      BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR_AC_IN_AChrgTrickle_Default;
      BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_Default;
      BCMR_AChrg_B.BCMR_rAChrgTrickleCnt = 0U;
      BCMR_AChrg_B.BCMR_bAChrgTrickle = false;
    } else {
      switch (BCMR_AChrg_DW.is_c4_BCMR_AChrg) {
       case BCMR_AC_IN_AChrgTrickle_Default:
        if (BCMR_AChrg_B.BMSDebounceStartZero_g.Switch) {
          BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR__IN_AChrgTrickle_StepClear;
          BCMR_AChrg_DW.temporalCounter_i1_i = 0U;
          BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_ReqClr;
          BCMR_AChrg_B.BCMR_bAChrgTrickle = true;
        }
        break;

       case BCMR__IN_AChrgTrickle_StepClear:
        if (BCMR_AChrg_DW.temporalCounter_i1_i >= 100U) {
          BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR_AC_IN_AChrgTrickle_StepSet;
          BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_ReqSet;
          i = BCMR_AChrg_B.BCMR_rAChrgTrickleCnt + 1;
          if (i > 255) {
            i = 255;
          }

          BCMR_AChrg_B.BCMR_rAChrgTrickleCnt = (uint8_T)i;
        }
        break;

       case BCMR_AC_IN_AChrgTrickle_StepSet:
        if (BCMR_AChrg_B.BMSDebounceStartZero_g.Switch &&
            (BCMR_AChrg_DW.Delay_DSTATE_f3 >= BCMR_cntAChrgTrickle_C)) {
          BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR_IN_AChrgTrickle_StepStable;
          BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_ReqStb;
        } else {
          if (BCMR_AChrg_B.BMSDebounceStartZero_g.Switch) {
            BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR__IN_AChrgTrickle_StepClear;
            BCMR_AChrg_DW.temporalCounter_i1_i = 0U;
            BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_ReqClr;
            BCMR_AChrg_B.BCMR_bAChrgTrickle = true;
          }
        }
        break;

       default:
        if (BCMR_AChrg_DW.Delay_DSTATE_ju) {
          BCMR_AChrg_DW.is_c4_BCMR_AChrg = BCMR_AC_IN_AChrgTrickle_Default;
          BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_Default;
          BCMR_AChrg_B.BCMR_rAChrgTrickleCnt = 0U;
          BCMR_AChrg_B.BCMR_bAChrgTrickle = false;
        }
        break;
      }
    }

    BCMR_stAChrgTrickle = BCMR_AChrg_B.BCMR_stAChrgTrickle_h;
    if (BCMR_stAChrgTrickle != BCMR_AChrg_ConstB.DataTypeConversion4) {
      if (BCMR_stAChrgTrickle != BCMR_AChrg_ConstB.DataTypeConversion5) {
        if (BCMR_stAChrgTrickle != BCMR_AChrg_ConstB.DataTypeConversion6) {
          rtb_Abs1 = BCMR_iAChrgTrickleStepStb_C;
        } else {
          rtb_Abs1 = BCMR_iAChrgTrickleStepSet_C;
        }
      } else {
        rtb_Abs1 = BCMR_iAChrgTrickleStepClr_C;
      }
    } else {
      rtb_Abs1 = BCMR_iCurrReqCalcTmpA;
    }

    if (rtb_UnitDelay2 <= rtb_Abs1) {
      Local_iBattCurrReqCalc = rtb_UnitDelay2;
    } else {
      Local_iBattCurrReqCalc = rtb_Abs1;
    }

    rtb_RelationalOperator_ol = !BCMR_AChrg_DW.Delay1_DSTATE_o;
    BCMR_AChrg_DW.Delay1_DSTATE_o = BCMR_AChrg_DW.Delay2_DSTATE_eg;
    if (rtb_RelationalOperator_ol && BCMR_AChrg_DW.Delay2_DSTATE_eg) {
      rtb_Abs1 = 0.0F;
    } else if (rtb_BCMR_stAChrgCnnt_a) {
      rtb_Abs1 = BCMR_tiTaskTime_C + BCMR_AChrg_DW.UnitDelay_DSTATE_h;
    } else {
      rtb_Abs1 = 0.0F;
    }

    BCMR_AChrg_DW.UnitDelay1_DSTATE_l = false;
    BCMR_AChrg_DW.Delay1_DSTATE_a = BCMR_tTempCurrReq;
    BCMR_AChrg_DW.Delay2_DSTATE_eg = (rtb_Abs1 > BCMR_tiTempHoldDebs_C);
    BCMR_AChrg_DW.UnitDelay1_DSTATE_k3 = false;
    BCMR_AChrg_DW.Delay1_DSTATE_m = BCMR_uVoltCurrReq;
    BCMR_AChrg_DW.Delay_DSTATE_f3 = BCMR_AChrg_B.BCMR_rAChrgTrickleCnt;
    BCMR_AChrg_DW.UnitDelay_DSTATE_h = rtb_Abs1;
    VoltCpreTmpA = (BCMR_vBmsVoltReq_C <= COMR_uMaxVoltObcChrg);
    if (VoltCpreTmpA) {
      BCMR_AChrg_B.BCMR_vVoltReqCalc = BCMR_vBmsVoltReq_C;
    } else {
      BCMR_AChrg_B.BCMR_vVoltReqCalc = COMR_uMaxVoltObcChrg;
    }

    if (BCMR_AChrg_B.BCMR_vVoltReqCalc > 0.0F) {
      if (BCMR_AChrg_B.BCMR_vVoltReqCalc <= 100.0F) {
        rtb_Switch1_a0 = 400.0F;
      } else {
        rtb_Switch1_a0 = BCMR_AChrg_B.BCMR_vVoltReqCalc;
      }

      AffixCurrTp4 = COMR_pwrChrgLdReq * 1000.0F / rtb_Switch1_a0;
      Local_AffixCurrCalc = BCMR_kAffixCurrCoe_C * AffixCurrTp4;
    }

    Local_iLCurrReqCalc = Local_iBattCurrReqCalc + Local_AffixCurrCalc;
    rtb_BCMR_stAChrgCnnt_a = BCMR_AChrg_DW.Delay1_DSTATE_he;
    BCMR_AChrg_B.Delay2 = BCMR_AChrg_DW.Delay2_DSTATE_ex;
    if (rtb_UnitDelay2 <= Local_iLCurrReqCalc) {
      BCMR_AChrg_B.MinMax = rtb_UnitDelay2;
    } else {
      BCMR_AChrg_B.MinMax = Local_iLCurrReqCalc;
    }

    BCMR_pActPwrChrgCalc = BSPR_uBattVolt * BSPR_iBattCurr / 1000.0F;
    BCMR_AChrg_B.Abs = (real32_T)fabs(BCMR_pActPwrChrgCalc);
    BCMR_AChrg_DW.Delay_DSTATE_ju = BCMR_AChrg_B.BMSDebounceStartZero_e.Switch;
    BCMR_AChrg_DW.Delay1_DSTATE_he = BCMR_AChrg_B.BMSDebounceStartZero_e.Switch;
    BCMR_AChrg_DW.Delay2_DSTATE_ex = rtb_BCMR_stAChrgCnnt_a;
  } else {
    if (BCMR_AChrg_DW.AcChgParaCalc_MODE) {
      BCMR_AChrg_DW.AcChgParaCalc_MODE = false;
    }
  }

  AChrg_AI_Filter(BSPR_iBattCurr, &BCMR_AChrg_B.hld_ai_LVSupFb1,
                  &BCMR_AChrg_DW.hld_ai_LVSupFb1);
  AChrg_debounce((BCMR_stAChrgObsr <= 8) && (BCMR_stAChrgObsr >= 7),
                 &BCMR_AChrg_B.flt_debounce, &BCMR_AChrg_DW.flt_debounce,
                 BCMR_tiRemTimeStart_C, 1, BCMR_tiRemTimeStart_C);
  if (BCMR_AChrg_B.flt_debounce.Relay > 0) {
    if (!BCMR_AChrg_DW.RemChgTimeCalc_MODE) {
      BCMR_AChrg_DW.UnitDelay1_DSTATE_k = true;
      BCMR_AChrg_DW.Delay1_DSTATE_c = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE = 0.0F;
      BCMR_AChrg_DW.Delay1_DSTATE = 0.0F;
      BCMR_AChrg_DW.UnitDelay1_DSTATE_m = true;
      BCMR_AChrg_DW.Delay1_DSTATE_l = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_b = 0.0F;
      BCMR_AChrg_DW.UnitDelay2_DSTATE_l = 0;
      BCMR_AChrg_DW.UnitDelay7_DSTATE = 0;
      BCMR_AChrg_DW.Delay2_DSTATE_bz = false;
      BCMR_AChrg_DW.Delay1_DSTATE_cy = 0U;
      BCMR_AChrg_DW.Delay_DSTATE_br = false;
      BCMR_AChrg_DW.UnitDelay_DSTATE_cp = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_ao = false;
      BCMR_AChrg_DW.Delay2_DSTATE_h = false;
      BCMR_AChrg_DW.Delay_DSTATE_j = 0.0F;
      BCMR_AChrg_DW.UnitDelay_DSTATE_dv = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_p = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_c = 0.0F;
      RemChgTimeCalc_AI_Filter_Reset(&BCMR_AChrg_DW.AI_Filter);
      BCMR_AChrg_DW.Delay_DSTATE_go = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_i = 0.0F;
      RemChgTimeCalc_AI_Filter_Reset(&BCMR_AChrg_DW.AI_Filter_f);
      BCMR_AChrg_DW.Delay1_DSTATE_k = true;
      BCMR_AChrg_DW.Delay1_DSTATE_lc = true;
      BCMR_AChrg_DW.Delay_DSTATE_d5 = 0.0F;
      BCMR_AChrg_DW.Delay_DSTATE_gi = 0.0F;
      BCMR_AChrg_DW.Delay1_DSTATE_h = true;
      BCMR_AChrg_DW.RemChgTimeCalc_MODE = true;
    }

    BCMR_ACh_BCMR_AChrgTiRevTimCalc(BCMR_AChrg_B.BCMR_bAChrgTrickle,
      &BCMR_AChrg_B.BCMR_AChrgTiRevTimCalc,
      &BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc);
    rtb_BCMR_stAChrgCnnt_a = (BSPR_uCellVoltMax > BCMR_AChrg_DW.Delay1_DSTATE_c);
    if (rtb_BCMR_stAChrgCnnt_a) {
      rtb_Saturation = BCMR_tiVoltHoldBase_C;
    } else {
      rtb_Saturation = 0.0F;
    }

    if (BCMR_tiVoltHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_p) {
      rtb_Switch1_a0 = BCMR_tiVoltHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_p;
    }

    rtb_UnitDelay2 = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
      rtb_BCMR_stAChrgCnnt_a;
    BCMR_AChrg_DW.Delay_DSTATE_p = rtb_UnitDelay2;
    rtb_BCMR_stAChrgCnnt_a = (BSPR_uCellVoltMax - BCMR_AChrg_DW.Delay1_DSTATE_c <=
      BCMR_uCellVoltMaxDec_C);
    if (rtb_BCMR_stAChrgCnnt_a) {
      rtb_Saturation = BCMR_tiVoltHoldBase_C;
    } else {
      rtb_Saturation = 0.0F;
    }

    if (BCMR_tiVoltHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_c) {
      rtb_Switch1_a0 = BCMR_tiVoltHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_c;
    }

    rtb_Abs1 = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
      rtb_BCMR_stAChrgCnnt_a;
    BCMR_AChrg_DW.Delay_DSTATE_c = rtb_Abs1;
    if (BCMR_AChrg_DW.UnitDelay1_DSTATE_k) {
      rtb_UnitDelay2 = BSPR_uCellVoltMax;
    } else if (rtb_UnitDelay2 > BCMR_tiVoltHoldDebs_C) {
      rtb_UnitDelay2 = BSPR_uCellVoltMax;
    } else if (rtb_Abs1 > BCMR_tiVoltHoldDebs_C) {
      rtb_UnitDelay2 = BSPR_uCellVoltMax;
    } else {
      rtb_UnitDelay2 = BCMR_AChrg_DW.Delay1_DSTATE_c;
    }

    rtb_Saturation = COMR_pwrChrgLdReq * 1000.0F / BSPR_uBattVolt;
    rtb_Abs1 = 121.532402F * (real32_T)COMR_dcObcCP / 3300.0F * (rtb_Saturation
      + BCMR_AChrg_B.hld_ai_LVSupFb1.DataTypeConversion1) - rtb_Saturation;
    rtb_BCMR_stAChrgCnnt_a = (rtb_UnitDelay2 >= BCMR_uCellVoltMaxCalOn_C);
    if (rtb_BCMR_stAChrgCnnt_a) {
      if (!BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE) {
        BCMR_AChrg_DW.Delay_DSTATE_m = 0.0F;
        RemChgTimeCalc_AI_Filter_Reset(&BCMR_AChrg_DW.AI_Filter1);
        BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE = true;
      }

      RemChgTimeCalc_AI_Filter(&BCMR_AChrg_B.AI_Filter1,
        &BCMR_AChrg_DW.AI_Filter1);
      rtb_Product_of = rtb_Abs1 * BSPR_uBattVolt;
      if (1.0F + BCMR_AChrg_DW.Delay_DSTATE_m >= 600.0F) {
        rtb_Product_nu = BCMR_AChrg_B.AI_Filter1.DataTypeConversion1;
      } else {
        rtb_Product_nu = rtb_Product_of;
      }

      if (((real32_T)fabs(rtb_Abs1) >= 1.0F) && (rtb_Product_nu < 0.0F)) {
        rtb_Product_nu = look1_iflf_binlcapw(rtb_UnitDelay2, ((const real32_T *)
          &(BCMR_uCellVoltmax_A[0])), ((const real32_T *)&(BCMR_whRem_A[0])), 4U)
          / (real32_T)fabs(rtb_Product_nu);
      } else {
        rtb_Product_nu = BCMR_tiRemTimeMaxObc3_C;
      }

      BCMR_AChrg_B.Sum = 60.0F * rtb_Product_nu + 1.0F;
      RemChgTimeCalc_AI_Filter_Update(rtb_Product_of, &BCMR_AChrg_DW.AI_Filter1);
      BCMR_AChrg_DW.Delay_DSTATE_m++;
    } else {
      if (BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE) {
        BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE = false;
      }
    }

    RemChgTimeCalc_AI_Filter(&BCMR_AChrg_B.AI_Filter, &BCMR_AChrg_DW.AI_Filter);
    if (rtb_Abs1 > 700.0F) {
      rtb_Saturation = 700.0F;
    } else if (rtb_Abs1 < -700.0F) {
      rtb_Saturation = -700.0F;
    } else {
      rtb_Saturation = rtb_Abs1;
    }

    rtb_Abs1 = rtb_Saturation * BSPR_uBattVolt;
    BCMR_ACh_BCMR_AChrgTiRevTimCalc(BCMR_AChrg_B.BCMR_bAChrgTrickle,
      &BCMR_AChrg_B.BCMR_AChrgTiRevTimCalc_b,
      &BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc_b);
    rtb_RelationalOperator_ol = (BSPR_uCellVoltMax >
      BCMR_AChrg_DW.Delay1_DSTATE_l);
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_tiVoltHoldBase_C;
    } else {
      rtb_Switch1_id = 0.0F;
    }

    if (BCMR_tiVoltHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_go) {
      rtb_Switch1_a0 = BCMR_tiVoltHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_go;
    }

    rtb_Product_of = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
      rtb_RelationalOperator_ol;
    BCMR_AChrg_DW.Delay_DSTATE_go = rtb_Product_of;
    rtb_RelationalOperator_ol = (BSPR_uCellVoltMax -
      BCMR_AChrg_DW.Delay1_DSTATE_l <= BCMR_uCellVoltMaxDec_C);
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_tiVoltHoldBase_C;
    } else {
      rtb_Switch1_id = 0.0F;
    }

    if (BCMR_tiVoltHoldDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_i) {
      rtb_Switch1_a0 = BCMR_tiVoltHoldDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_i;
    }

    rtb_Product_nu = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
      rtb_RelationalOperator_ol;
    BCMR_AChrg_DW.Delay_DSTATE_i = rtb_Product_nu;
    if (BCMR_AChrg_DW.UnitDelay1_DSTATE_m) {
      rtb_Product_of = BSPR_uCellVoltMax;
    } else if (rtb_Product_of > BCMR_tiVoltHoldDebs_C) {
      rtb_Product_of = BSPR_uCellVoltMax;
    } else if (rtb_Product_nu > BCMR_tiVoltHoldDebs_C) {
      rtb_Product_of = BSPR_uCellVoltMax;
    } else {
      rtb_Product_of = BCMR_AChrg_DW.Delay1_DSTATE_l;
    }

    rtb_RelationalOperator_ol = (rtb_Product_of >= BCMR_uCellVoltMaxCalOn_C);
    if (rtb_RelationalOperator_ol) {
      if (!BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE_b) {
        BCMR_AChrg_DW.Delay_DSTATE_g = 0.0F;
        RemChgTimeCalc_AI_Filter_Reset(&BCMR_AChrg_DW.AI_Filter_fq);
        BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE_b = true;
      }

      RemChgTimeCalc_AI_Filter(&BCMR_AChrg_B.AI_Filter_fq,
        &BCMR_AChrg_DW.AI_Filter_fq);
      rtb_Product_nu = BCMR_AChrg_B.hld_ai_LVSupFb1.DataTypeConversion1 *
        BSPR_uBattVolt;
      if (1.0F + BCMR_AChrg_DW.Delay_DSTATE_g >= 600.0F) {
        rtb_Switch1_f = BCMR_AChrg_B.AI_Filter_fq.DataTypeConversion1;
      } else {
        rtb_Switch1_f = rtb_Product_nu;
      }

      if (((real32_T)fabs(BCMR_AChrg_B.hld_ai_LVSupFb1.DataTypeConversion1) >=
           1.0F) && (rtb_Switch1_f < 0.0F)) {
        rtb_Switch1_f = look1_iflf_binlcapw(rtb_Product_of, ((const real32_T *)
          &(BCMR_uCellVoltmax_A[0])), ((const real32_T *)&(BCMR_whRem_A[0])), 4U)
          / (real32_T)fabs(rtb_Switch1_f);
      } else {
        rtb_Switch1_f = BCMR_tiRemTimeMaxObc3_C;
      }

      BCMR_AChrg_B.Sum_m = 60.0F * rtb_Switch1_f + 1.0F;
      RemChgTimeCalc_AI_Filter_Update(rtb_Product_nu,
        &BCMR_AChrg_DW.AI_Filter_fq);
      BCMR_AChrg_DW.Delay_DSTATE_g++;
    } else {
      if (BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE_b) {
        BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE_b = false;
      }
    }

    RemChgTimeCalc_AI_Filter(&BCMR_AChrg_B.AI_Filter_f,
      &BCMR_AChrg_DW.AI_Filter_f);
    if (BCMR_AChrg_B.hld_ai_LVSupFb1.DataTypeConversion1 > 700.0F) {
      rtb_Saturation_a = 700.0F;
    } else if (BCMR_AChrg_B.hld_ai_LVSupFb1.DataTypeConversion1 < -700.0F) {
      rtb_Saturation_a = -700.0F;
    } else {
      rtb_Saturation_a = BCMR_AChrg_B.hld_ai_LVSupFb1.DataTypeConversion1;
    }

    rtb_Product_nu = rtb_Saturation_a * BSPR_uBattVolt;
    if (BCMR_AChrg_B.Delay2) {
      rtb_Saturation = 0.0F;
    } else if ((COMR_stObcCC == 5) && (COMR_dcObcCP > 27) && (1.0F +
                BCMR_AChrg_DW.Delay1_DSTATE <= 7.0F) && (COMR_stObcElecLck == 2))
    {
      if (BCMR_AChrg_B.BCMR_bAChrgTrickle) {
        rtb_Saturation = BCMR_AChrg_B.BCMR_AChrgTiRevTimCalc.Saturation3;
      } else if (rtb_BCMR_stAChrgCnnt_a) {
        rtb_Saturation = BCMR_AChrg_B.Sum;
      } else {
        if (COMR_pMaxpwrObcChrg <= 2500) {
          rtb_Saturation_a = BCMR_tiRemTimeMaxObc3_C;
        } else if (COMR_pMaxpwrObcChrg <= 4000) {
          rtb_Saturation_a = BCMR_tiRemTimeMaxObc4_C;
        } else {
          rtb_Saturation_a = BCMR_tiRemTimeMaxObc5_C;
        }

        if (COMR_stObcCC == 3) {
          rtb_Switch1_f = BCMR_tiCalToEndObc3_C;
        } else if (COMR_stObcCC == 4) {
          rtb_Switch1_f = BCMR_tiCalToEndObc4_C;
        } else {
          rtb_Switch1_f = BCMR_tiCalToEndObc5_C;
        }

        if (1.0F + BCMR_AChrg_DW.Delay_DSTATE >= 600.0F) {
          rtb_Switch1_id = BCMR_AChrg_B.AI_Filter.DataTypeConversion1;
        } else {
          rtb_Switch1_id = rtb_Abs1;
        }

        if (((real32_T)fabs(rtb_Saturation) >= 1.0F) && (rtb_Switch1_id < 0.0F))
        {
          if (COMR_stObcCC == 3) {
            rtb_Switch1_a0 = BCMR_tiCalToEndObc3_C;
          } else if (COMR_stObcCC == 4) {
            rtb_Switch1_a0 = BCMR_tiCalToEndObc4_C;
          } else {
            rtb_Switch1_a0 = BCMR_tiCalToEndObc5_C;
          }

          rtb_Saturation = (BCMR_rSOCRealMax_C - BSER_rSoc) * BCMR_whBattCpty_C /
            100.0F * 60.0F / (real32_T)fabs(rtb_Switch1_id) + rtb_Switch1_a0;
        } else {
          rtb_Saturation = BCMR_tiRemTimeMaxObc3_C;
        }

        if (rtb_Saturation_a < rtb_Saturation) {
          rtb_Saturation = rtb_Saturation_a;
        }

        if (!(rtb_Saturation > rtb_Switch1_f)) {
          rtb_Saturation = rtb_Switch1_f;
        }
      }
    } else if (BCMR_AChrg_B.BCMR_bAChrgTrickle) {
      rtb_Saturation = BCMR_AChrg_B.BCMR_AChrgTiRevTimCalc_b.Saturation3;
    } else if (rtb_RelationalOperator_ol) {
      rtb_Saturation = BCMR_AChrg_B.Sum_m;
    } else {
      if (COMR_pMaxpwrObcChrg <= 2500) {
        rtb_Switch1_f = BCMR_tiRemTimeMaxObc3_C;
      } else if (COMR_pMaxpwrObcChrg <= 4000) {
        rtb_Switch1_f = BCMR_tiRemTimeMaxObc4_C;
      } else {
        rtb_Switch1_f = BCMR_tiRemTimeMaxObc5_C;
      }

      if (COMR_stObcCC == 3) {
        rtb_Saturation = BCMR_tiCalToEndObc3_C;
      } else if (COMR_stObcCC == 4) {
        rtb_Saturation = BCMR_tiCalToEndObc4_C;
      } else {
        rtb_Saturation = BCMR_tiCalToEndObc5_C;
      }

      if (1.0F + BCMR_AChrg_DW.Delay_DSTATE_b >= 600.0F) {
        rtb_Switch1_id = BCMR_AChrg_B.AI_Filter_f.DataTypeConversion1;
      } else {
        rtb_Switch1_id = rtb_Product_nu;
      }

      if (((real32_T)fabs(rtb_Saturation_a) >= 1.0F) && (rtb_Switch1_id < 0.0F))
      {
        if (COMR_stObcCC == 3) {
          rtb_Switch1_a0 = BCMR_tiCalToEndObc3_C;
        } else if (COMR_stObcCC == 4) {
          rtb_Switch1_a0 = BCMR_tiCalToEndObc4_C;
        } else {
          rtb_Switch1_a0 = BCMR_tiCalToEndObc5_C;
        }

        rtb_Saturation_a = (BCMR_rSOCRealMax_C - BSER_rSoc) * BCMR_whBattCpty_C /
          100.0F * 60.0F / (real32_T)fabs(rtb_Switch1_id) + rtb_Switch1_a0;
      } else {
        rtb_Saturation_a = BCMR_tiRemTimeMaxObc3_C;
      }

      if (!(rtb_Switch1_f < rtb_Saturation_a)) {
        rtb_Switch1_f = rtb_Saturation_a;
      }

      if (rtb_Switch1_f > rtb_Saturation) {
        rtb_Saturation = rtb_Switch1_f;
      }
    }

    if (rtb_Saturation > 2000.0F) {
      rtb_Saturation = 2000.0F;
    } else {
      if (rtb_Saturation < 0.0F) {
        rtb_Saturation = 0.0F;
      }
    }

    rtb_DataTypeConversion = (int16_T)(uint16_T)(real32_T)fmod((real32_T)floor
      (rtb_Saturation), 65536.0F);
    rtb_Divide1 = (int16_T)((int16_T)div_nzp_s32_floor(rtb_DataTypeConversion, 5)
      * 5);
    rtb_UnitDelay2_p = BCMR_AChrg_DW.UnitDelay2_DSTATE_l;
    rtb_BCMR_stAChrgCnnt_a = (COMR_stObcElecLck == 2);
    rtb_Switch_hc = !BCMR_AChrg_DW.Delay1_DSTATE_k;
    BCMR_AChrg_DW.Delay1_DSTATE_k = rtb_BCMR_stAChrgCnnt_a;
    rtb_RelationalOperator_ol = ((!BCMR_AChrg_DW.Delay1_DSTATE_lc) &&
      BCMR_AChrg_DW.Delay2_DSTATE_bz);
    BCMR_AChrg_DW.Delay1_DSTATE_lc = BCMR_AChrg_DW.Delay2_DSTATE_bz;
    rtb_Switch2_jo = (uint16_T)(1U + BCMR_AChrg_DW.Delay1_DSTATE_cy);
    if (rtb_Switch2_jo <= 7) {
      rtb_Switch_hc = (COMR_stObcElecLck == 2);
    } else {
      rtb_Switch_hc = (rtb_Switch_hc && rtb_BCMR_stAChrgCnnt_a);
    }

    rtb_BCMR_stAChrgCnnt_a = ((BCMR_AChrg_DW.Delay_DSTATE_br || rtb_Switch_hc) &&
      (!BCMR_AChrg_DW.Delay2_DSTATE_bz));
    if (rtb_RelationalOperator_ol || rtb_Switch_hc) {
      rtb_Saturation = 0.0F;
    } else {
      if (rtb_BCMR_stAChrgCnnt_a) {
        rtb_Saturation = BCMR_tiTaskTime_C;
      } else {
        rtb_Saturation = 0.0F;
      }

      rtb_Saturation += BCMR_AChrg_DW.UnitDelay_DSTATE_cp;
    }

    rtb_RelationalOperator_ol = ((BCMR_AChrg_DW.Delay_DSTATE_ao || ((int16_T)
      (BCMR_AChrg_DW.UnitDelay2_DSTATE_l - BCMR_AChrg_DW.UnitDelay7_DSTATE) != 0))
      && (!BCMR_AChrg_DW.Delay2_DSTATE_h));
    rtb_Switch_hc = (rtb_Divide1 > BCMR_AChrg_DW.UnitDelay7_DSTATE);
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiDeb30s_C <= BCMR_AChrg_DW.Delay_DSTATE_d5) {
      rtb_Switch1_a0 = BCMR_tiDeb30s_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_d5;
    }

    rtb_Switch1_f = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
      rtb_Switch_hc;
    BCMR_AChrg_DW.Delay_DSTATE_d5 = rtb_Switch1_f;
    rtb_Switch_hc = (BCMR_AChrg_DW.UnitDelay7_DSTATE > rtb_Divide1);
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiDeb30s_C <= BCMR_AChrg_DW.Delay_DSTATE_gi) {
      rtb_Switch1_a0 = BCMR_tiDeb30s_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_gi;
    }

    rtb_Saturation_a = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
      rtb_Switch_hc;
    BCMR_AChrg_DW.Delay_DSTATE_gi = rtb_Saturation_a;
    rtb_Switch_hc = !BCMR_AChrg_DW.Delay1_DSTATE_h;
    BCMR_AChrg_DW.Delay1_DSTATE_h = BCMR_AChrg_DW.Delay2_DSTATE_h;
    if (rtb_Switch_hc && BCMR_AChrg_DW.Delay2_DSTATE_h) {
      rtb_Switch1_id = 0.0F;
    } else {
      if (rtb_RelationalOperator_ol) {
        rtb_Switch1_id = BCMR_tiTaskTime_C;
      } else {
        rtb_Switch1_id = 0.0F;
      }

      rtb_Switch1_id += BCMR_AChrg_DW.UnitDelay_DSTATE_dv;
    }

    if (1.0F + BCMR_AChrg_DW.Delay_DSTATE_j >= 5.0F) {
      if (rtb_BCMR_stAChrgCnnt_a) {
        rtb_DataTypeConversion = BCMR_AChrg_DW.UnitDelay2_DSTATE_l;
      } else if (rtb_DataTypeConversion >= 10) {
        if (rtb_RelationalOperator_ol) {
          rtb_DataTypeConversion = BCMR_AChrg_DW.UnitDelay2_DSTATE_l;
        } else if (BCMR_AChrg_DW.UnitDelay7_DSTATE != rtb_Divide1) {
          if (BCMR_AChrg_DW.UnitDelay7_DSTATE < rtb_Divide1) {
            if (rtb_Switch1_f >= BCMR_tiDeb30s_C) {
              rtb_DataTypeConversion = (int16_T)(BCMR_AChrg_DW.UnitDelay7_DSTATE
                + 5);
            } else {
              rtb_DataTypeConversion = BCMR_AChrg_DW.UnitDelay7_DSTATE;
            }
          } else if (rtb_Saturation_a >= BCMR_tiDeb30s_C) {
            rtb_DataTypeConversion = (int16_T)(BCMR_AChrg_DW.UnitDelay7_DSTATE -
              5);
          } else {
            rtb_DataTypeConversion = BCMR_AChrg_DW.UnitDelay7_DSTATE;
          }
        } else {
          rtb_DataTypeConversion = BCMR_AChrg_DW.UnitDelay7_DSTATE;
        }

        rtb_DataTypeConversion = (int16_T)((int16_T)div_nzp_s32_floor
          (rtb_DataTypeConversion, 5) * 5);
      } else {
        if (rtb_DataTypeConversion > BCMR_AChrg_DW.UnitDelay2_DSTATE_l) {
          rtb_DataTypeConversion = BCMR_AChrg_DW.UnitDelay2_DSTATE_l;
        }
      }

      BCMR_AChrg_B.Switch6 = rtb_DataTypeConversion;
    } else {
      BCMR_AChrg_B.Switch6 = rtb_Divide1;
    }

    BCMR_AChrg_DW.UnitDelay1_DSTATE_k = false;
    BCMR_AChrg_DW.Delay1_DSTATE_c = rtb_UnitDelay2;
    RemChgTimeCalc_AI_Filter_Update(rtb_Abs1, &BCMR_AChrg_DW.AI_Filter);
    BCMR_AChrg_DW.Delay_DSTATE++;
    BCMR_AChrg_DW.Delay1_DSTATE++;
    BCMR_AChrg_DW.UnitDelay1_DSTATE_m = false;
    BCMR_AChrg_DW.Delay1_DSTATE_l = rtb_Product_of;
    RemChgTimeCalc_AI_Filter_Update(rtb_Product_nu, &BCMR_AChrg_DW.AI_Filter_f);
    BCMR_AChrg_DW.Delay_DSTATE_b++;
    BCMR_AChrg_DW.UnitDelay2_DSTATE_l = BCMR_AChrg_B.Switch6;
    BCMR_AChrg_DW.UnitDelay7_DSTATE = rtb_UnitDelay2_p;
    BCMR_AChrg_DW.Delay2_DSTATE_bz = (rtb_Saturation > BCMR_TiREMTiMEHoldLck_C);
    BCMR_AChrg_DW.Delay1_DSTATE_cy = rtb_Switch2_jo;
    BCMR_AChrg_DW.Delay_DSTATE_br = rtb_BCMR_stAChrgCnnt_a;
    BCMR_AChrg_DW.UnitDelay_DSTATE_cp = rtb_Saturation;
    BCMR_AChrg_DW.Delay_DSTATE_ao = rtb_RelationalOperator_ol;
    BCMR_AChrg_DW.Delay2_DSTATE_h = (rtb_Switch1_id > BCMR_TiREMTiMEHold_C);
    BCMR_AChrg_DW.Delay_DSTATE_j++;
    BCMR_AChrg_DW.UnitDelay_DSTATE_dv = rtb_Switch1_id;
  } else {
    if (BCMR_AChrg_DW.RemChgTimeCalc_MODE) {
      if (BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc.BCMR_AChrgTiRevTimCalc_MODE) {
        BCMR_AChrgTiRevTimCalc_Disable(&BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc);
      }

      if (BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE) {
        BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE = false;
      }

      if (BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc_b.BCMR_AChrgTiRevTimCalc_MODE) {
        BCMR_AChrgTiRevTimCalc_Disable(&BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc_b);
      }

      if (BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE_b) {
        BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc1_MODE_b = false;
      }

      BCMR_AChrg_B.Switch6 = 2047;
      BCMR_AChrg_DW.RemChgTimeCalc_MODE = false;
    }
  }

  rtb_Switch2_jo = (uint16_T)BCMR_AChrg_B.Switch6;
  rtb_BCMR_stAChrgCnnt_a = ((!BCMR_flgPreHeatShieldCmd_C) &&
    BCMR_AChrg_B.Local_PreHeatChk);
  if ((BCMR_stAChrgObsr == 5) || (BCMR_stAChrgObsr == 27)) {
    if (!BCMR_AChrg_DW.ChgStop_MODE) {
      BCMR_AChrg_DW.ChgStop_MODE = true;
    }

    BCMR_flgChgStop = (COMR_stPwrUpDwnVcuReq == 2);
  } else {
    if (BCMR_AChrg_DW.ChgStop_MODE) {
      BCMR_flgChgStop = false;
      BCMR_AChrg_DW.ChgStop_MODE = false;
    }
  }

  rtb_RelationalOperator_ol = (BSER_rSocDspl <= BCMR_rSOCFul_C);
  BCMR_stPreThmObsvr = BCMR_AChrg_DW.UnitDelay7_DSTATE_j;
  if (BCMR_stPreThmObsvr == 6) {
    if (!BCMR_AChrg_DW.PtcWorkFailCheck_MODE) {
      BCMR_AChrg_DW.Delay_DSTATE_jc = 0.0F;
      BCMR_AChrg_DW.PtcWorkFailCheck_MODE = true;
    }

    rtb_Switch_hc = ((real32_T)fabs(COMR_iCurrObcChrg) <= 3.0F);
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiBase_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    if (BCMR_tiPTCDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_jc) {
      rtb_Switch1_a0 = BCMR_tiPTCDetDebs_C;
    } else {
      rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_jc;
    }

    rtb_UnitDelay2 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
      rtb_Switch_hc;
    BCMR_AChrg_B.RelationalOperator_e = (rtb_UnitDelay2 > BCMR_tiPTCDetDebs_C);
    BCMR_AChrg_DW.Delay_DSTATE_jc = rtb_UnitDelay2;
  } else {
    if (BCMR_AChrg_DW.PtcWorkFailCheck_MODE) {
      BCMR_AChrg_B.RelationalOperator_e = false;
      BCMR_AChrg_DW.PtcWorkFailCheck_MODE = false;
    }
  }

  rtb_Switch_hc = (((HVSR_resIso > BCMR_iAChrgHvIsoThres_C) && (HVSR_resIso <
    BCMR_iAChrgHvIsoInit_C)) || (HVSR_resIso > BCMR_iAChrgHvIsoInit_C));
  if (rtb_Switch_hc) {
    rtb_Saturation_a = BCMR_tiHvIsoBase_C;
  } else {
    rtb_Saturation_a = 0.0F;
  }

  if (BCMR_tiHvIsoDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ii) {
    rtb_Switch1_a0 = BCMR_tiHvIsoDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ii;
  }

  rtb_UnitDelay2 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)rtb_Switch_hc;
  rtb_Switch_hc = (rtb_UnitDelay2 > BCMR_tiHvIsoDebs_C);
  BCMR_AChrg_DW.Delay_DSTATE_ii = rtb_UnitDelay2;
  if ((BCMR_stAChrgObsr == 1) || ((BCMR_stPreThmObsvr >= 1) &&
       (BCMR_stPreThmObsvr <= 8))) {
    if (!BCMR_AChrg_DW.Subsystem8_MODE) {
      BCMR_AChrg_DW.Delay_DSTATE_o = 0.0F;
      BCMR_AChrg_DW.Subsystem8_MODE = true;
    }

    rtb_LogicalOperator6_n = ((COMR_dcObcCP < 8) || (COMR_dcObcCP > 97));
    if (rtb_LogicalOperator6_n) {
      rtb_Saturation = BCMR_tiBase_C;
    } else {
      rtb_Saturation = 0.0F;
    }

    if (2.0F <= BCMR_AChrg_DW.Delay_DSTATE_o) {
      tmp = 2.0F;
    } else {
      tmp = BCMR_AChrg_DW.Delay_DSTATE_o;
    }

    rtb_UnitDelay2 = (real32_T)((rtb_Saturation + tmp) * (real32_T)
      rtb_LogicalOperator6_n);
    BCMR_AChrg_DW.Delay_DSTATE_o = rtb_UnitDelay2;
    Local_flgPreHeatFobd = ((COMR_stObcFaultLvl >= 3) || (DSMR_stFaultRank >= 3)
      || (COMR_stVcuFalutLvl >= 3) || ((rtb_UnitDelay2 >= 2.0F) &&
      ((COMR_stObcCP == BCMR_stCp9VPWM_C) || (COMR_stObcCP == BCMR_stCp6VPWM_C)))
      || COMR_bVcuChrgDisable || HVSR_flgIsoFaultLvl2 || HVSR_flgHvilFault);
  } else {
    if (BCMR_AChrg_DW.Subsystem8_MODE) {
      BCMR_AChrg_DW.Subsystem8_MODE = false;
    }
  }

  BCMR_AChrg_BMSDebounceStartZero((BCMR_tHoldTempUpLmtCellmax_C <
    BSPR_tCellTempMax) || (BCMR_tHoldTempUpLmt_C < BSPR_tCellTempMin),
    BCMR_tiPreThmDebs_C, BCMR_tiFullBase_C, BCMR_tiPreThmDebs_C,
    BCMR_tiFullBase_C, &BCMR_AChrg_B.BMSDebounceStartZero,
    &BCMR_AChrg_DW.BMSDebounceStartZero);
  BCMR_AChrg_BMSDebounceStartZero((BSPR_tCellTempMin < BCMR_tHoldTempDwnLmt_C) &&
    (BSPR_tCellTempMax < BCMR_tHoldTempDwnLmtCellmax_C), BCMR_tiPreThmDebs_C,
    BCMR_tiFullBase_C, BCMR_tiPreThmDebs_C, BCMR_tiFullBase_C,
    &BCMR_AChrg_B.BMSDebounceStartZero1, &BCMR_AChrg_DW.BMSDebounceStartZero1);
  if (BCMR_AChrg_B.BMSDebounceStartZero.Switch) {
    Local_HoldtempChk = false;
  } else {
    Local_HoldtempChk = (BCMR_AChrg_B.BMSDebounceStartZero1.Switch ||
                         BCMR_AChrg_DW.Delay_DSTATE_bh);
  }

  BCMR_holdtemp = BCMR_AChrg_DW.UnitDelay5_DSTATE;
  BCMR_holdtempreq = (BCMR_holdtemp == 1);
  rtb_LogicalOperator6_n = (BCMR_holdtemp == 1);
  BCMR_holdtemprise = ((!BCMR_AChrg_DW.Delay1_DSTATE_ma) &&
                       rtb_LogicalOperator6_n);
  BCMR_AChrg_DW.Delay1_DSTATE_ma = rtb_LogicalOperator6_n;
  if (BCMR_holdtemprise) {
    rtb_UnitDelay2 = COMR_tiPreThemaltime;
  } else {
    rtb_UnitDelay2 = BCMR_AChrg_DW.StateName;
  }

  BCMR_holdtempti = rtb_UnitDelay2 * 60000.0F;
  rtb_LogicalOperator6_n = !BCMR_holdtempreq;
  if (rtb_LogicalOperator6_n || (BCMR_AChrg_DW.FixPtUnitDelay2_DSTATE != 0)) {
    rtb_Abs1 = 0.0F;
  } else {
    rtb_Abs1 = BCMR_AChrg_DW.FixPtUnitDelay1_DSTATE;
  }

  HoldTempTimax = (rtb_Abs1 >= BCMR_holdtempti);
  if (rtb_LogicalOperator6_n) {
    BCMR_AChrg_DW.FixPtUnitDelay1_DSTATE = 0.0F;
  } else {
    if (HoldTempTimax) {
      rtb_Switch4_ef = 0U;
    } else {
      rtb_Switch4_ef = BCMR_tiFullBase_C;
    }

    BCMR_AChrg_DW.FixPtUnitDelay1_DSTATE = (real32_T)rtb_Switch4_ef + rtb_Abs1;
  }

  BCMR_AChrg_DW.FixPtUnitDelay2_DSTATE = 0U;
  rtb_LogicalOperator6_n = (COMR_stHoldTempReq == 1);
  rtb_LogicalOperator3_p = !BCMR_AChrg_DW.Delay1_DSTATE_i;
  BCMR_AChrg_DW.Delay1_DSTATE_i = rtb_LogicalOperator6_n;
  rtb_RelationalOperator3_ll = (COMR_stHoldTempReq == 3);
  rtb_LogicalOperator3_nn = !BCMR_AChrg_DW.Delay1_DSTATE_al;
  BCMR_AChrg_DW.Delay1_DSTATE_al = rtb_RelationalOperator3_ll;
  if (rtb_LogicalOperator3_p && rtb_LogicalOperator6_n) {
    BCMR_stHoldTempReq = 1U;
  } else if ((rtb_LogicalOperator3_nn && rtb_RelationalOperator3_ll) ||
             HoldTempTimax) {
    BCMR_stHoldTempReq = 3U;
  } else {
    BCMR_stHoldTempReq = BCMR_AChrg_DW.StateName_j;
  }

  rtb_LogicalOperator6_n = (BCMR_stAChrgObsr == 1);
  if (rtb_LogicalOperator6_n) {
    rtb_Saturation = BCMR_tiBase_C;
  } else {
    rtb_Saturation = 0.0F;
  }

  if (BCMR_tiPreWaitTimeOut_C <= BCMR_AChrg_DW.Delay_DSTATE_e) {
    rtb_Switch1_a0 = BCMR_tiPreWaitTimeOut_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_e;
  }

  rtb_Abs1 = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator6_n;
  RelationalOperator_h = (rtb_Abs1 >= BCMR_tiPreWaitTimeOut_C);
  BCMR_AChrg_DW.Delay_DSTATE_e = rtb_Abs1;
  rtb_LogicalOperator6_n = ((!BCMR_AChrg_DW.Delay1_DSTATE_b) && rtb_Switch4_m);
  BCMR_AChrg_DW.Delay1_DSTATE_b = rtb_Switch4_m;
  rtb_LogicalOperator3_p = BCMR_AChrg_DW.StateName_b;
  rtb_RelationalOperator3_ll = !rtb_LogicalOperator3_p;
  if (rtb_RelationalOperator3_ll || (BCMR_AChrg_DW.FixPtUnitDelay2_DSTATE_n != 0))
  {
    rtb_Switch2_ix = 0U;
  } else {
    rtb_Switch2_ix = BCMR_AChrg_DW.FixPtUnitDelay1_DSTATE_f;
  }

  rtb_LogicalOperator3_nn = (rtb_Switch2_ix >= BCMR_tiTboxPreChrStop_C);
  if (rtb_RelationalOperator3_ll) {
    BCMR_AChrg_DW.FixPtUnitDelay1_DSTATE_f = 0U;
  } else {
    if (rtb_LogicalOperator3_nn) {
      rtb_Switch4_ef = 0U;
    } else {
      rtb_Switch4_ef = BCMR_tiFullBase_C;
    }

    BCMR_AChrg_DW.FixPtUnitDelay1_DSTATE_f = (uint16_T)((uint32_T)rtb_Switch4_ef
      + rtb_Switch2_ix);
  }

  BCMR_AChrg_DW.FixPtUnitDelay2_DSTATE_n = 0U;
  if (rtb_LogicalOperator6_n) {
    Switch = true;
  } else {
    Switch = ((!rtb_LogicalOperator3_nn) && rtb_LogicalOperator3_p);
  }

  if (BCMR_AChrg_DW.temporalCounter_i1 < MAX_uint32_T) {
    BCMR_AChrg_DW.temporalCounter_i1++;
  }

  if (BCMR_AChrg_DW.is_active_c3_BCMR_AChrg == 0U) {
    BCMR_AChrg_DW.is_active_c3_BCMR_AChrg = 1U;
    BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgInit;
    BCMR_AChrg_DW.temporalCounter_i1 = 0U;
    BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_Init;
    BCMR_AChrg_enter_atomic_Init();
  } else {
    guard1 = false;
    switch (BCMR_AChrg_DW.is_c3_BCMR_AChrg) {
     case BCMR_AChrg_IN_AppChrg:
      BCMR_AChrg_AppChrg(&rtb_RelationalOperator_ol, &rtb_BCMR_stAChrgCnnt_a,
                         &rtb_Switch_hc, &Switch);
      break;

     case BCMR_AChrg_IN_ChgEnd:
      BCMR_AChrg_ChgEnd(&rtb_RelationalOperator_ol, &RelationalOperator_ev);
      break;

     case BCMR_AChrg_IN_ChgFobid:
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
      BCMR_AChr_enter_internal_ChgEnd();
      break;

     case BCMR_AChrg_IN_ChgFul:
      if ((!RelationalOperator_ev) || (!BCMR_AChrg_B.RelationalOperator_o) ||
          ((BSPR_iBattCurr > BCMR_iAChrgStopCurrLim_C) &&
           (BCMR_AChrg_DW.BCMR_tiChrgFulCnt > BCMR_tiChrgFulCnt_C))) {
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
        BCMR_AChr_enter_internal_ChgEnd();
      } else if ((BSPR_iBattCurr < BCMR_iAChrgStopCurrLim_C) &&
                 (BCMR_AChrg_DW.BCMR_tiChrgFulCnt > BCMR_tiChrgFulAbnrmCnt_C)) {
        BCMR_stChrgAbnmExit = 12U;
        BCMR_bAChrgPwrDwnReq = true;
        BCMR_bAChrgPwrUpReq = false;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgEnd;
        BCMR_AChr_enter_internal_ChgEnd();
      } else {
        BCMR_stAChrgMode = 4U;
        BCMR_AChrg_B.BCMR_bChrgFul = 1.0F;
        BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
        BCMR_bAChrgRdy = false;
        BCMR_AChrg_DW.BCMR_tiChrgFulCnt++;
      }
      break;

     case BCMR_AChrg_IN_ChgInit:
      BCMR_AChrg_ChgInit(&rtb_RelationalOperator_ol, &rtb_BCMR_stAChrgCnnt_a,
                         &rtb_Switch_hc, &RelationalOperator_h, &Switch,
                         &RelationalOperator_ev);
      break;

     case BCMR_AChrg_IN_ChgWaiting:
      BCMR_AChrg_ChgWaiting(&Switch1, &Switch2, &RelationalOperator_ev);
      break;

     case BCMR_AChrg_IN_Chging:
      BCMR_AChrg_Chging(&rtb_Switch2_jo, &RelationalOperator_ev);
      break;

     case BCMR_AChrg_IN_DischgEnd:
      switch (BCMR_AChrg_DW.is_DischgEnd) {
       case BCMR_AChrg_IN_DisChgEndFlt:
        if ((BCCR_stBmsCtrMode == 7) || (BCCR_stBmsCtrMode == 0) ||
            (BCCR_stBmsCtrMode == 14) || (BCCR_stBmsCtrMode == 17)) {
          BCMR_AChrg_DW.is_DischgEnd = BCMR_AChrg_IN_HVOFF;
          BCMR_AChrg_DW.is_HVOFF_h = BCMR_AChrg_IN_OFF;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_stAChrgObsr_l = 35U;
        }
        break;

       case BCMR_AChrg_IN_HVOFF:
        if (RelationalOperator_ev) {
          BCMR_AChrg_DW.is_HVOFF_h = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
          BCMR_AChrg_DW.is_DischgEnd = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
          BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_ChgInit;
          BCMR_AChrg_DW.temporalCounter_i1 = 0U;
          BCMR_AChrg_DW.is_ChgInit = BCMR_AChrg_IN_Init;
          BCMR_AChrg_enter_atomic_Init();
        } else {
          if (BCMR_AChrg_DW.is_HVOFF_h == BCMR_AChrg_IN_OFF) {
            BCMR_AChrg_DW.is_HVOFF_h = BCMR_AChrg_IN_Sleep;
            BCMR_bAChrgPwrDwnReq = false;

            /* BCMR_stAChrgCnnt = uint8(0); */
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 36U;
            BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
          }
        }
        break;

       default:
        if ((BCCR_stBmsCtrMode == 7) || (BCCR_stBmsCtrMode == 0) ||
            (BCCR_stBmsCtrMode == 14) || (BCCR_stBmsCtrMode == 17) ||
            (BMCR_stBmsModeCtrl == BCMR_HVOn)) {
          BCMR_AChrg_DW.is_DischgEnd = BCMR_AChrg_IN_HVOFF;
          BCMR_AChrg_DW.is_HVOFF_h = BCMR_AChrg_IN_OFF;
          BCMR_bAChrgPwrDwnReq = false;
          BCMR_AChrg_B.BCMR_stAChrgObsr_l = 35U;
        } else {
          if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
               (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) && ((BCCR_stBmsCtrMode
                != 7) && (BCCR_stBmsCtrMode != 0) && (BMCR_stBmsModeCtrl !=
                BCMR_HVOn))) {
            BCMR_stChrgAbnmExit = 23U;
            BCMR_AChrg_DW.is_DischgEnd = BCMR_AChrg_IN_DisChgEndFlt;
            BCMR_bAChrgPwrDwnReq = true;
            BCMR_bAChrgPwrUpReq = false;
            BCMR_flgDischgCmd = false;
            BCMR_bAcDischgRdy = false;
            BCMR_pActPwrChrg = 0.0F;
            BCMR_uReqVoltChrg = 0.0F;
            BCMR_AChrg_B.BCMR_iReqCurrChrg_n = 0.0F;
            BCMR_AChrg_B.BCMR_tiRemChgTime = 0U;
            BCMR_uMaxVoltChrg = 0.0F;
            BCMR_AChrg_B.BCMR_bChrgFul = 0.0F;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 37U;
          }
        }
        break;
      }
      break;

     case BCMR_AChrg_IN_DischgWaiting:
      if (BCMR_AChrg_B.LogicalOperator7 || (BCMR_AChrg_DW.BCMR_DischgWaitingFlt ==
           1.0F)) {
        BCMR_stChrgAbnmExit = 20U;
        guard1 = true;
      } else if ((BMCR_stBmsModeCtrl == BCMR_V2xMode) && ((Switch2 == 3) ||
                  (Switch2 == 5) || (Switch2 == 6)) && (BCCR_stBmsCtrMode == 4))
      {
        BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
        BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_Dischging;
        BCMR_bAChrgPwrUpReq = true;
        BCMR_AChrg_DW.is_Dischging = BCMR_AChrg_IN_Dischging_m;
        BCMR_AChrg_B.BCMR_stAChrgObsr_l = 29U;
        BCMR_stIviDischg = 1U;

        /* BCMR_iReqCurrChrg = -BCMR_iReqCurrChrgCalc;
           BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc;
           BCMR_pActPwrChrg = BCMR_pActPwrChrgCalc; */
        BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
        BCMR_flgDischgCmd = true;
        BCMR_bAcDischgRdy = true;
      } else if ((!RelationalOperator_ev) || (BCMR_stAChgDischg != 2) ||
                 BCMR_flgChgStop) {
        BCMR_stChrgAbnmExit = 25U;
        guard1 = true;
      } else {
        switch (BCMR_AChrg_DW.is_DischgWaiting) {
         case BCMR_AChrg_IN_DischgHVOn:
          if (Switch2 == 1) {
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgObcReady;
            BCMR_AChrg_DW.temporalCounter_i1 = 0U;
            BCMR_bAChrgPwrUpReq = true;
            BCMR_bAcDischgRdy = true;
            BCMR_flgDischgCmd = true;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 27U;
          } else if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                      (BCMR_tiDischgWaitObcReadyTimeOut_C / 0.1F - 1.0E-9F)) &&
                     (Switch2 != 1)) {
            BCMR_stChrgAbnmExit = 18U;
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgwaitingFlt;
            BCMR_AChrg_DW.BCMR_DischgWaitingFlt = 1.0F;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 28U;
          } else {
            BCMR_bAChrgPwrUpReq = true;
            BCMR_flgDischgCmd = false;
            BCMR_bAcDischgRdy = false;
          }
          break;

         case BCMR_AChrg_IN_DischgObcReady:
          if (BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
              (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) {
            BCMR_stChrgAbnmExit = 19U;
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgwaitingFlt;
            BCMR_AChrg_DW.BCMR_DischgWaitingFlt = 1.0F;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 28U;
          } else {
            /* BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc; */
            BCMR_bAChrgPwrUpReq = true;
            BCMR_bAcDischgRdy = true;
            BCMR_flgDischgCmd = true;

            /* BCMR_iReqCurrChrg = 0;
               BCMR_uReqVoltChrg = BCMR_uReqVoltChrgCalc; */
            BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
          }
          break;

         case BCMR_AChrg_IN_DischgPending:
          if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
               ((BCMR_tiChgWaitTimeOut_C + 100.0F) / 0.1F - 1.0E-9F)) &&
              (BCCR_stBmsCtrMode != 4)) {
            BCMR_stChrgAbnmExit = 17U;
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgwaitingFlt;
            BCMR_AChrg_DW.BCMR_DischgWaitingFlt = 1.0F;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 28U;
          } else if (BCCR_stBmsCtrMode == 4) {
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgHVOn;
            BCMR_AChrg_DW.temporalCounter_i1 = 0U;
            BCMR_bAChrgPwrUpReq = true;
            BCMR_flgDischgCmd = false;
            BCMR_bAcDischgRdy = false;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 26U;
          } else {
            BCMR_bAChrgPwrUpReq = true;
            BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
            BCMR_bAChrgRdy = false;
          }
          break;

         case BCMR_AChrg_IN_DischgStandby:
          if (Switch4 == 1) {
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgPending;
            BCMR_AChrg_DW.temporalCounter_i1 = 0U;
            BCMR_bAChrgPwrUpReq = true;
            BCMR_flgDischgCmd = false;
            BCMR_bAcDischgRdy = false;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 25U;
          } else if ((BCMR_AChrg_DW.temporalCounter_i1 >= (uint32_T)ceil
                      (BCMR_tiChgWaitTimeOut_C / 0.1F - 1.0E-9F)) && ((Switch2 !=
                       3) && (Switch2 != 5))) {
            BCMR_stChrgAbnmExit = 16U;
            BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_DischgwaitingFlt;
            BCMR_AChrg_DW.BCMR_DischgWaitingFlt = 1.0F;
            BCMR_AChrg_B.BCMR_stAChrgObsr_l = 28U;
          } else {
            BCMR_bAChrgPwrUpReq = false;
            BCMR_AChrg_B.BCMR_flgChrgCmd_n = false;
            BCMR_bAChrgRdy = false;
            BCMR_uMaxVoltChrg = BCMR_vBmsMaxVoltReq_C;
          }
          break;

         default:
          BCMR_AChrg_DW.BCMR_DischgWaitingFlt = 1.0F;
          break;
        }
      }
      break;

     case BCMR_AChrg_IN_Dischging:
      BCMR_AChrg_Dischging(&RelationalOperator_ev);
      break;

     case BCMR_AChrg_IN_HoldTemp:
      BCMR_AChrg_HoldTemp(&Switch2);
      break;

     default:
      BCMR_AChrg_PreThemal(&Switch2, &rtb_BCMR_stAChrgCnnt_a,
                           &rtb_LogicalOperator6_n);
      break;
    }

    if (guard1) {
      BCMR_bAChrgPwrDwnReq = true;
      BCMR_bAChrgPwrUpReq = false;
      BCMR_bAcDischgRdy = false;
      BCMR_AChrg_DW.is_DischgWaiting = BCMR_AChrg_IN_NO_ACTIVE_CHILD;
      BCMR_AChrg_DW.is_c3_BCMR_AChrg = BCMR_AChrg_IN_DischgEnd;
      BCMR_A_enter_internal_DischgEnd();
    }
  }

  if (RelationalOperator_ev) {
    Switch4 = BCMR_stChrgAbnmExit;
  } else {
    Switch4 = 0U;
  }

  rtb_BCMR_stAChrgCnnt_a = ((BCMR_AChrg_DW.Delay_DSTATE_mp || (Switch4 == 1)) &&
    (!BCMR_AChrg_DW.Delay2_DSTATE));
  if (rtb_BCMR_stAChrgCnnt_a) {
    rtb_Saturation = BCMR_tiBase_C;
  } else {
    rtb_Saturation = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_fk) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_fk;
  }

  rtb_Abs1 = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
    rtb_BCMR_stAChrgCnnt_a;
  BCMR_AChrg_DW.Delay_DSTATE_fk = rtb_Abs1;
  rtb_RelationalOperator_ol = !rtb_BCMR_stAChrgCnnt_a;
  if (rtb_RelationalOperator_ol) {
    rtb_Switch1_id = BCMR_tiBase_C;
  } else {
    rtb_Switch1_id = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ke) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ke;
  }

  rtb_Product_of = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
    rtb_RelationalOperator_ol;
  BCMR_AChrg_DW.Delay_DSTATE_ke = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_jv) {
    Switch1 = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChrgCnntErr_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    Switch1 = (uint8_T)(DFC_AChrgCnntErr_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    Switch1 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChrgCnntErr_ASW | 16U) |
                        8U);
  } else {
    Switch1 = BCMR_AChrg_DW.Delay3_DSTATE_j;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_jv = false;
  BCMR_AChrg_DW.Delay3_DSTATE_j = Switch1;
  DFC_AChrgCnntErr_ASW = Switch1;
  rtb_RelationalOperator_ol = ((BCMR_AChrg_DW.Delay_DSTATE_cj || (Switch4 == 3))
    && (!BCMR_AChrg_DW.Delay2_DSTATE_e));
  if (rtb_RelationalOperator_ol) {
    rtb_Switch1_id = BCMR_tiBase_C;
  } else {
    rtb_Switch1_id = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_f) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_f;
  }

  rtb_Abs1 = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
    rtb_RelationalOperator_ol;
  BCMR_AChrg_DW.Delay_DSTATE_f = rtb_Abs1;
  rtb_Switch_hc = !rtb_RelationalOperator_ol;
  if (rtb_Switch_hc) {
    rtb_Saturation_a = BCMR_tiBase_C;
  } else {
    rtb_Saturation_a = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_l) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_l;
  }

  rtb_Product_of = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)rtb_Switch_hc;
  BCMR_AChrg_DW.Delay_DSTATE_l = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_la) {
    Switch2 = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChgHVOnTmt_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    Switch2 = (uint8_T)(DFC_AChgHVOnTmt_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    Switch2 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChgHVOnTmt_ASW | 16U) |
                        8U);
  } else {
    Switch2 = BCMR_AChrg_DW.Delay3_DSTATE_k4;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_la = false;
  BCMR_AChrg_DW.Delay3_DSTATE_k4 = Switch2;
  DFC_AChgHVOnTmt_ASW = Switch2;
  rtb_Switch_hc = ((BCMR_AChrg_DW.Delay_DSTATE_ma || (Switch4 == 6)) &&
                   (!BCMR_AChrg_DW.Delay2_DSTATE_e2));
  if (rtb_Switch_hc) {
    rtb_Saturation_a = BCMR_tiBase_C;
  } else {
    rtb_Saturation_a = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ca) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ca;
  }

  rtb_Abs1 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)rtb_Switch_hc;
  BCMR_AChrg_DW.Delay_DSTATE_ca = rtb_Abs1;
  rtb_LogicalOperator6_n = !rtb_Switch_hc;
  if (rtb_LogicalOperator6_n) {
    rtb_Saturation = BCMR_tiBase_C;
  } else {
    rtb_Saturation = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_gr) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_gr;
  }

  rtb_Product_of = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator6_n;
  BCMR_AChrg_DW.Delay_DSTATE_gr = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_dl) {
    rtb_Switch4_ef = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChgRdyPndiTmt_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_ef = (uint8_T)(DFC_AChgRdyPndiTmt_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_ef = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChgRdyPndiTmt_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_ef = BCMR_AChrg_DW.Delay3_DSTATE_o0;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_dl = false;
  BCMR_AChrg_DW.Delay3_DSTATE_o0 = rtb_Switch4_ef;
  DFC_AChgRdyPndiTmt_ASW = rtb_Switch4_ef;
  rtb_LogicalOperator6_n = ((BCMR_AChrg_DW.Delay_DSTATE_a22 || (Switch4 == 7)) &&
    (!BCMR_AChrg_DW.Delay2_DSTATE_d));
  if (rtb_LogicalOperator6_n) {
    rtb_Saturation = BCMR_tiBase_C;
  } else {
    rtb_Saturation = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_gox) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_gox;
  }

  rtb_Abs1 = (rtb_Saturation + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator6_n;
  BCMR_AChrg_DW.Delay_DSTATE_gox = rtb_Abs1;
  rtb_LogicalOperator3_p = !rtb_LogicalOperator6_n;
  if (rtb_LogicalOperator3_p) {
    rtb_Saturation_a = BCMR_tiBase_C;
  } else {
    rtb_Saturation_a = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_oi) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_oi;
  }

  rtb_Product_of = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator3_p;
  BCMR_AChrg_DW.Delay_DSTATE_oi = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_ik) {
    rtb_Switch4_ps = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChgRdyTmt_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_ps = (uint8_T)(DFC_AChgRdyTmt_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_ps = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChgRdyTmt_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_ps = BCMR_AChrg_DW.Delay3_DSTATE_e;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_ik = false;
  BCMR_AChrg_DW.Delay3_DSTATE_e = rtb_Switch4_ps;
  DFC_AChgRdyTmt_ASW = rtb_Switch4_ps;
  rtb_LogicalOperator3_p = ((BCMR_AChrg_DW.Delay_DSTATE_o3 || (Switch4 == 10)) &&
    (!BCMR_AChrg_DW.Delay2_DSTATE_i));
  if (rtb_LogicalOperator3_p) {
    rtb_Saturation_a = BCMR_tiBase_C;
  } else {
    rtb_Saturation_a = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_mq) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_mq;
  }

  rtb_Abs1 = (rtb_Saturation_a + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator3_p;
  BCMR_AChrg_DW.Delay_DSTATE_mq = rtb_Abs1;
  rtb_RelationalOperator3_ll = !rtb_LogicalOperator3_p;
  if (rtb_RelationalOperator3_ll) {
    rtb_Switch1_id = BCMR_tiBase_C;
  } else {
    rtb_Switch1_id = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_k) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_k;
  }

  rtb_Product_of = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
    rtb_RelationalOperator3_ll;
  BCMR_AChrg_DW.Delay_DSTATE_k = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_h2) {
    rtb_Switch4_oy = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChgingErr_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_oy = (uint8_T)(DFC_AChgingErr_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_oy = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChgingErr_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_oy = BCMR_AChrg_DW.Delay3_DSTATE_f;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_h2 = false;
  BCMR_AChrg_DW.Delay3_DSTATE_f = rtb_Switch4_oy;
  DFC_AChgingErr_ASW = rtb_Switch4_oy;
  rtb_RelationalOperator3_ll = ((BCMR_AChrg_DW.Delay_DSTATE_hhv || (Switch4 ==
    14)) && (!BCMR_AChrg_DW.Delay2_DSTATE_f));
  if (rtb_RelationalOperator3_ll) {
    rtb_Switch1_id = BCMR_tiBase_C;
  } else {
    rtb_Switch1_id = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_btr) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_btr;
  }

  rtb_Abs1 = (rtb_Switch1_id + rtb_Switch1_a0) * (real32_T)
    rtb_RelationalOperator3_ll;
  BCMR_AChrg_DW.Delay_DSTATE_btr = rtb_Abs1;
  rtb_LogicalOperator3_nn = !rtb_RelationalOperator3_ll;
  if (rtb_LogicalOperator3_nn) {
    rtb_Switch1_fw = BCMR_tiBase_C;
  } else {
    rtb_Switch1_fw = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_h) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_h;
  }

  rtb_Product_of = (rtb_Switch1_fw + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator3_nn;
  BCMR_AChrg_DW.Delay_DSTATE_h = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_a) {
    rtb_Switch4_gs = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChgHVOffTmt_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_gs = (uint8_T)(DFC_AChgHVOffTmt_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_gs = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChgHVOffTmt_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_gs = BCMR_AChrg_DW.Delay3_DSTATE_b;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_a = false;
  BCMR_AChrg_DW.Delay3_DSTATE_b = rtb_Switch4_gs;
  DFC_AChgHVOffTmt_ASW = rtb_Switch4_gs;
  rtb_LogicalOperator3_nn = ((BCMR_AChrg_DW.Delay_DSTATE_i1 ||
    (BCMR_stPreThmFltCode == 10)) && (!BCMR_AChrg_DW.Delay2_DSTATE_l));
  if (rtb_LogicalOperator3_nn) {
    rtb_Switch1_fw = BCMR_tiBase_C;
  } else {
    rtb_Switch1_fw = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_po) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_po;
  }

  rtb_Abs1 = (rtb_Switch1_fw + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator3_nn;
  BCMR_AChrg_DW.Delay_DSTATE_po = rtb_Abs1;
  RelationalOperator_ev = !rtb_LogicalOperator3_nn;
  if (RelationalOperator_ev) {
    rtb_Switch1_iz = BCMR_tiBase_C;
  } else {
    rtb_Switch1_iz = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_g1) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_g1;
  }

  rtb_Product_of = (rtb_Switch1_iz + rtb_Switch1_a0) * (real32_T)
    RelationalOperator_ev;
  BCMR_AChrg_DW.Delay_DSTATE_g1 = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_m) {
    rtb_Switch4_c = (uint8_T)~(uint8_T)((uint8_T)~DFC_PreHeatPtcErr_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_c = (uint8_T)(DFC_PreHeatPtcErr_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_c = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_PreHeatPtcErr_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_c = BCMR_AChrg_DW.Delay3_DSTATE_i;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_m = false;
  BCMR_AChrg_DW.Delay3_DSTATE_i = rtb_Switch4_c;
  DFC_PreHeatPtcErr_ASW = rtb_Switch4_c;
  RelationalOperator_ev = ((BCMR_AChrg_DW.Delay_DSTATE_fd ||
    ((BCMR_stPreThmFltCode == 1) || (BCMR_stPreThmFltCode == 12))) &&
    (!BCMR_AChrg_DW.Delay2_DSTATE_dx));
  if (RelationalOperator_ev) {
    rtb_Switch1_iz = BCMR_tiBase_C;
  } else {
    rtb_Switch1_iz = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ij) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ij;
  }

  rtb_Abs1 = (rtb_Switch1_iz + rtb_Switch1_a0) * (real32_T)RelationalOperator_ev;
  BCMR_AChrg_DW.Delay_DSTATE_ij = rtb_Abs1;
  RelationalOperator_h = !RelationalOperator_ev;
  if (RelationalOperator_h) {
    rtb_Switch1_lz = BCMR_tiBase_C;
  } else {
    rtb_Switch1_lz = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_d2) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_d2;
  }

  rtb_Product_of = (rtb_Switch1_lz + rtb_Switch1_a0) * (real32_T)
    RelationalOperator_h;
  BCMR_AChrg_DW.Delay_DSTATE_d2 = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_da) {
    rtb_Switch4_l = (uint8_T)~(uint8_T)((uint8_T)~DFC_PreHeatVcuReqTmt_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_l = (uint8_T)(DFC_PreHeatVcuReqTmt_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_l = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_PreHeatVcuReqTmt_ASW
      | 16U) | 8U);
  } else {
    rtb_Switch4_l = BCMR_AChrg_DW.Delay3_DSTATE_o;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_da = false;
  BCMR_AChrg_DW.Delay3_DSTATE_o = rtb_Switch4_l;
  DFC_PreHeatVcuReqTmt_ASW = rtb_Switch4_l;
  RelationalOperator_h = ((BCMR_AChrg_DW.Delay_DSTATE_am ||
    ((BCMR_stPreThmFltCode == 3) || (BCMR_stPreThmFltCode == 4) ||
     (BCMR_stPreThmFltCode == 13))) && (!BCMR_AChrg_DW.Delay2_DSTATE_j));
  if (RelationalOperator_h) {
    rtb_Switch1_lz = BCMR_tiBase_C;
  } else {
    rtb_Switch1_lz = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_j3) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_j3;
  }

  rtb_Abs1 = (rtb_Switch1_lz + rtb_Switch1_a0) * (real32_T)RelationalOperator_h;
  BCMR_AChrg_DW.Delay_DSTATE_j3 = rtb_Abs1;
  rtb_LogicalOperator1_gy = !RelationalOperator_h;
  if (rtb_LogicalOperator1_gy) {
    rtb_Product_of = BCMR_tiBase_C;
  } else {
    rtb_Product_of = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_c0) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_c0;
  }

  rtb_Product_of = (rtb_Product_of + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator1_gy;
  BCMR_AChrg_DW.Delay_DSTATE_c0 = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_n) {
    rtb_Switch4_k = (uint8_T)~(uint8_T)((uint8_T)~DFC_PreHeatObcStatusErr_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_k = (uint8_T)(DFC_PreHeatObcStatusErr_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_k = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_PreHeatObcStatusErr_ASW | 16U) | 8U);
  } else {
    rtb_Switch4_k = BCMR_AChrg_DW.Delay3_DSTATE;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_n = false;
  BCMR_AChrg_DW.Delay3_DSTATE = rtb_Switch4_k;
  DFC_PreHeatObcStatusErr_ASW = rtb_Switch4_k;
  rtb_LogicalOperator1_gy = (((BCMR_stAChrgObsr == 1) || ((BCMR_stAChrgObsr >=
    24) && (BCMR_stAChrgObsr <= 36))) && (BCMR_stAChgDischg == 2) &&
    BCMR_AChrg_B.LogicalOperator7);
  if (rtb_LogicalOperator1_gy) {
    rtb_Product_of = BCMR_tiBase_C;
  } else {
    rtb_Product_of = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_ijf) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_ijf;
  }

  rtb_Abs1 = (rtb_Product_of + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator1_gy;
  BCMR_AChrg_DW.Delay_DSTATE_ijf = rtb_Abs1;
  rtb_LogicalOperator1_gy = !rtb_LogicalOperator1_gy;
  if (rtb_LogicalOperator1_gy) {
    rtb_Product_of = BCMR_tiBase_C;
  } else {
    rtb_Product_of = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_hh) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_hh;
  }

  rtb_Product_of = (rtb_Product_of + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator1_gy;
  BCMR_AChrg_DW.Delay_DSTATE_hh = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_nl) {
    rtb_Switch4_mq = (uint8_T)~(uint8_T)((uint8_T)~DFC_AcDischgFobd_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_mq = (uint8_T)(DFC_AcDischgFobd_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_mq = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AcDischgFobd_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_mq = BCMR_AChrg_DW.Delay3_DSTATE_bw;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_nl = false;
  BCMR_AChrg_DW.Delay3_DSTATE_bw = rtb_Switch4_mq;
  DFC_AcDischgFobd_ASW = rtb_Switch4_mq;
  rtb_LogicalOperator1_gy = (((BCMR_stAChrgObsr == 18) || ((BCMR_stAChrgObsr >=
    2) && (BCMR_stAChrgObsr <= 9)) || ((BCMR_stAChrgObsr == 1) &&
    (!BCMR_AChrg_B.Local_PreHeatChk))) && BCMR_AChrg_B.Local_flgAcChgFobd &&
    (BCMR_stAChgDischg == 1));
  if (rtb_LogicalOperator1_gy) {
    rtb_Product_of = BCMR_tiBase_C;
  } else {
    rtb_Product_of = 0.0F;
  }

  if (BCMR_tiChgDetDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_bt) {
    rtb_Switch1_a0 = BCMR_tiChgDetDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_bt;
  }

  rtb_Abs1 = (rtb_Product_of + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator1_gy;
  BCMR_AChrg_DW.Delay_DSTATE_bt = rtb_Abs1;
  rtb_LogicalOperator1_gy = !rtb_LogicalOperator1_gy;
  if (rtb_LogicalOperator1_gy) {
    rtb_Product_of = BCMR_tiBase_C;
  } else {
    rtb_Product_of = 0.0F;
  }

  if (BCMR_tiChgHealDebs_C <= BCMR_AChrg_DW.Delay_DSTATE_a) {
    rtb_Switch1_a0 = BCMR_tiChgHealDebs_C;
  } else {
    rtb_Switch1_a0 = BCMR_AChrg_DW.Delay_DSTATE_a;
  }

  rtb_Product_of = (rtb_Product_of + rtb_Switch1_a0) * (real32_T)
    rtb_LogicalOperator1_gy;
  BCMR_AChrg_DW.Delay_DSTATE_a = rtb_Product_of;
  if (BCMR_AChrg_DW.Delay2_DSTATE_fk) {
    rtb_Switch4_mq = (uint8_T)~(uint8_T)((uint8_T)~DFC_AChgFobd_ASW | 8U);
  } else if (rtb_Abs1 > BCMR_tiChgDetDebs_C) {
    rtb_Switch4_mq = (uint8_T)(DFC_AChgFobd_ASW | 152U);
  } else if (rtb_Product_of > BCMR_tiChgHealDebs_C) {
    rtb_Switch4_mq = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_AChgFobd_ASW | 16U)
      | 8U);
  } else {
    rtb_Switch4_mq = BCMR_AChrg_DW.Delay3_DSTATE_k;
  }

  BCMR_AChrg_DW.Delay2_DSTATE_fk = false;
  BCMR_AChrg_DW.Delay3_DSTATE_k = rtb_Switch4_mq;
  DFC_AChgFobd_ASW = rtb_Switch4_mq;
  BCMR_bAChrgCnntFlt = ((Switch1 & 24) == 24);
  BCMR_bAChgRdyTmOut = ((rtb_Switch4_ps & 24) == 24);
  BCMR_bAChgHVOnTmOut = ((Switch2 & 24) == 24);
  BCMR_bAChgRdyPendingTmOut = ((rtb_Switch4_ef & 24) == 24);
  BCMR_bAChgingFlt = ((rtb_Switch4_oy & 24) == 24);
  BCMR_bAChgHVOffTmOut = ((rtb_Switch4_gs & 24) == 24);
  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_g2;
  BCMR_AChrg_DW.Delay1_DSTATE_g2 = BCMR_AChrg_DW.Delay2_DSTATE;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE) {
    rtb_Abs1 = 0.0F;
  } else {
    if (rtb_BCMR_stAChrgCnnt_a) {
      rtb_Saturation = BCMR_tiTaskTime_C;
    } else {
      rtb_Saturation = 0.0F;
    }

    rtb_Abs1 = rtb_Saturation + BCMR_AChrg_DW.UnitDelay_DSTATE;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_ge;
  BCMR_AChrg_DW.Delay1_DSTATE_ge = BCMR_AChrg_DW.Delay2_DSTATE_e;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_e) {
    rtb_Product_of = 0.0F;
  } else {
    if (rtb_RelationalOperator_ol) {
      rtb_Switch1_id = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_id = 0.0F;
    }

    rtb_Product_of = rtb_Switch1_id + BCMR_AChrg_DW.UnitDelay_DSTATE_d;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_n;
  BCMR_AChrg_DW.Delay1_DSTATE_n = BCMR_AChrg_DW.Delay2_DSTATE_e2;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_e2) {
    rtb_Product_nu = 0.0F;
  } else {
    if (rtb_Switch_hc) {
      rtb_Saturation_a = BCMR_tiTaskTime_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    rtb_Product_nu = rtb_Saturation_a + BCMR_AChrg_DW.UnitDelay_DSTATE_k;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_eg;
  BCMR_AChrg_DW.Delay1_DSTATE_eg = BCMR_AChrg_DW.Delay2_DSTATE_d;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_d) {
    rtb_Saturation = 0.0F;
  } else {
    if (rtb_LogicalOperator6_n) {
      rtb_Saturation = BCMR_tiTaskTime_C;
    } else {
      rtb_Saturation = 0.0F;
    }

    rtb_Saturation += BCMR_AChrg_DW.UnitDelay_DSTATE_dh;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_mz;
  BCMR_AChrg_DW.Delay1_DSTATE_mz = BCMR_AChrg_DW.Delay2_DSTATE_b;
  BCMR_bAChgWaitingTmOut = ((BCMR_bAChgWaitingTmOut || (Switch4 == 8)) &&
    (!BCMR_AChrg_DW.Delay2_DSTATE_b));
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_b) {
    rtb_Switch1_f = 0.0F;
  } else {
    if (BCMR_bAChgWaitingTmOut) {
      rtb_Switch1_a0 = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_a0 = 0.0F;
    }

    rtb_Switch1_f = rtb_Switch1_a0 + BCMR_AChrg_DW.UnitDelay_DSTATE_c;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_mr;
  BCMR_AChrg_DW.Delay1_DSTATE_mr = BCMR_AChrg_DW.Delay2_DSTATE_i;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_i) {
    rtb_Saturation_a = 0.0F;
  } else {
    if (rtb_LogicalOperator3_p) {
      rtb_Saturation_a = BCMR_tiTaskTime_C;
    } else {
      rtb_Saturation_a = 0.0F;
    }

    rtb_Saturation_a += BCMR_AChrg_DW.UnitDelay_DSTATE_o;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_cl;
  BCMR_AChrg_DW.Delay1_DSTATE_cl = BCMR_AChrg_DW.Delay2_DSTATE_f;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_f) {
    rtb_Switch1_id = 0.0F;
  } else {
    if (rtb_RelationalOperator3_ll) {
      rtb_Switch1_id = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_id = 0.0F;
    }

    rtb_Switch1_id += BCMR_AChrg_DW.UnitDelay_DSTATE_ci;
  }

  BCMR_bPreHeatVcuReqTmt = ((rtb_Switch4_l & 24) == 24);
  BCMR_bPreHeatObcStatusErr = ((rtb_Switch4_k & 24) == 24);
  BCMR_bPreHeatPtcErr = ((rtb_Switch4_c & 24) == 24);
  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_d;
  BCMR_AChrg_DW.Delay1_DSTATE_d = BCMR_AChrg_DW.Delay2_DSTATE_dx;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_dx) {
    rtb_Switch1_iz = 0.0F;
  } else {
    if (RelationalOperator_ev) {
      rtb_Switch1_iz = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_iz = 0.0F;
    }

    rtb_Switch1_iz += BCMR_AChrg_DW.UnitDelay_DSTATE_i;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_p;
  BCMR_AChrg_DW.Delay1_DSTATE_p = BCMR_AChrg_DW.Delay2_DSTATE_j;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_j) {
    rtb_Switch1_lz = 0.0F;
  } else {
    if (RelationalOperator_h) {
      rtb_Switch1_lz = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_lz = 0.0F;
    }

    rtb_Switch1_lz += BCMR_AChrg_DW.UnitDelay_DSTATE_f;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_e;
  BCMR_AChrg_DW.Delay1_DSTATE_e = BCMR_AChrg_DW.Delay2_DSTATE_l;
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_l) {
    rtb_Switch1_fw = 0.0F;
  } else {
    if (rtb_LogicalOperator3_nn) {
      rtb_Switch1_fw = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_fw = 0.0F;
    }

    rtb_Switch1_fw += BCMR_AChrg_DW.UnitDelay_DSTATE_a;
  }

  if (BCMR_flgCurrReq_C) {
    rtb_Switch = BCMR_iCurrReq_C;
  } else {
    rtb_Switch = BCMR_AChrg_B.BCMR_iReqCurrChrg_n;
  }

  rtb_LogicalOperator1_gy = ((!BCMR_AChrg_DW.Delay1_DSTATE_g1) && rtb_Switch4_m);
  BCMR_AChrg_DW.Delay1_DSTATE_g1 = rtb_Switch4_m;
  if (BCMR_AChrg_DW.is_active_c6_BCMR_AChrg == 0U) {
    BCMR_AChrg_DW.is_active_c6_BCMR_AChrg = 1U;
    BCMR_AChrg_DW.is_c6_BCMR_AChrg = BCMR_AChrg_IN_A;
    rtb_Switch2_jo = BCMR_AChrg_B.BCMR_tiRemChgTime;
  } else {
    switch (BCMR_AChrg_DW.is_c6_BCMR_AChrg) {
     case BCMR_AChrg_IN_A:
      if (rtb_LogicalOperator1_gy) {
        BCMR_AChrg_DW.is_c6_BCMR_AChrg = BCMR_AChrg_IN_B_m;
        rtb_Switch2_jo = 2047U;
        BCMR_AChrg_DW.time_h = (real32_T)(BCMR_AChrg_DW.time_h + 0.1F);
      } else {
        rtb_Switch2_jo = BCMR_AChrg_B.BCMR_tiRemChgTime;
      }
      break;

     case BCMR_AChrg_IN_A_1:
      if (rtb_LogicalOperator1_gy) {
        BCMR_AChrg_DW.is_c6_BCMR_AChrg = BCMR_AChrg_IN_B_m;
        rtb_Switch2_jo = 2047U;
        BCMR_AChrg_DW.time_h = (real32_T)(BCMR_AChrg_DW.time_h + 0.1F);
      } else if (BCMR_AChrg_DW.ti >= 15.0F) {
        BCMR_AChrg_DW.ti = 0.0F;
        BCMR_AChrg_DW.is_c6_BCMR_AChrg = BCMR_AChrg_IN_A;
        rtb_Switch2_jo = BCMR_AChrg_B.BCMR_tiRemChgTime;
      } else {
        rtb_Switch2_jo = 2047U;
        BCMR_AChrg_DW.ti = (real32_T)(BCMR_AChrg_DW.ti + 0.1F);
      }
      break;

     default:
      if ((BCMR_AChrg_DW.time_h >= 60.0F) || (BCMR_stAChrgMode == 0)) {
        BCMR_AChrg_DW.time_h = 0.0F;
        BCMR_AChrg_DW.is_c6_BCMR_AChrg = BCMR_AChrg_IN_A_1;
        rtb_Switch2_jo = 2047U;
        BCMR_AChrg_DW.ti = (real32_T)(BCMR_AChrg_DW.ti + 0.1F);
      } else {
        rtb_Switch2_jo = 2047U;
        BCMR_AChrg_DW.time_h = (real32_T)(BCMR_AChrg_DW.time_h + 0.1F);
      }
      break;
    }
  }

  BCMR_tiRemAChgTime = (real32_T)rtb_Switch2_jo;
  Switch4 = BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[0];
  for (i = 0; i < 14; i++) {
    if (!(Switch4 >= BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[i + 1])) {
      Switch4 = BCMR_AChrg_B.OutportBufferForLocal_stAChrgFl[i + 1];
    }
  }

  if (BCMR_AChrg_DW.is_active_c33_BCMR_AChrg == 0U) {
    BCMR_AChrg_DW.is_active_c33_BCMR_AChrg = 1U;
    BCMR_AChrg_DW.b = 0.0F;
    BCMR_AChrg_DW.is_c33_BCMR_AChrg = BCMR_AChrg_IN_one;
    BCMR_AChrg_DW.j = 0.0F;
    BCMR_AChrg_calu(&Switch4);
  } else if (BCMR_AChrg_DW.is_c33_BCMR_AChrg == BCMR_AChrg_IN_one) {
    if ((BCMR_AChrg_DW.j > BCMR_tiCodeDisplay_C) || (BCMR_AChrg_B.enum_i == 0))
    {
      BCMR_AChrg_DW.is_c33_BCMR_AChrg = BCMR_AChrg_IN_two;
      BCMR_AChrg_DW.j = 0.0F;
      BCMR_AChrg_calu(&Switch4);
    } else {
      BCMR_AChrg_DW.j += BCMR_tiTaskTime_C;
    }
  } else if ((BCMR_AChrg_DW.j > BCMR_tiCodeDisplay_C) || (BCMR_AChrg_B.enum_i ==
              0)) {
    BCMR_AChrg_DW.is_c33_BCMR_AChrg = BCMR_AChrg_IN_one;
    BCMR_AChrg_DW.j = 0.0F;
    BCMR_AChrg_calu(&Switch4);
  } else {
    BCMR_AChrg_DW.j += BCMR_tiTaskTime_C;
  }

  BCMR_stAChrgFltCode = BCMR_AChrg_B.enum_i;
  BCMR_bAcChgFobd = BCMR_AChrg_B.Local_flgAcChgFobd;
  BCMR_bAcDischgFobd = BCMR_AChrg_B.LogicalOperator7;
  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_ah;
  BCMR_AChrg_DW.Delay1_DSTATE_ah = BCMR_AChrg_DW.Delay2_DSTATE_eo;
  BCMR_bAChrgFul = ((BCMR_bAChrgFul || (BCMR_AChrg_B.BCMR_bChrgFul != 0.0F)) &&
                    (!BCMR_AChrg_DW.Delay2_DSTATE_eo));
  if (rtb_LogicalOperator1_gy && BCMR_AChrg_DW.Delay2_DSTATE_eo) {
    rtb_Switch1_a0 = 0.0F;
  } else {
    if (BCMR_bAChrgFul) {
      rtb_Switch1_a0 = BCMR_tiTaskTime_C;
    } else {
      rtb_Switch1_a0 = 0.0F;
    }

    rtb_Switch1_a0 += BCMR_AChrg_DW.UnitDelay_DSTATE_c5;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_ip;
  BCMR_AChrg_DW.Delay1_DSTATE_ip = rtb_Switch4_m;
  if (BCMR_AChrg_DW.is_active_c7_BCMR_AChrg == 0U) {
    BCMR_AChrg_DW.is_active_c7_BCMR_AChrg = 1U;
    BCMR_AChrg_DW.is_c7_BCMR_AChrg = BCMR_AChrg_IN_A;
  } else if (BCMR_AChrg_DW.is_c7_BCMR_AChrg == BCMR_AChrg_IN_A) {
    if (rtb_LogicalOperator1_gy && rtb_Switch4_m) {
      BCMR_AChrg_DW.is_c7_BCMR_AChrg = BCMR_AChrg_IN_B;
      rtb_Switch = 0.0F;
      BCMR_AChrg_DW.time_hl = (real32_T)(BCMR_AChrg_DW.time_hl + 0.1F);
    }
  } else if ((BCMR_AChrg_DW.time_hl >= 60.0F) || (BCMR_stAChrgMode == 0)) {
    BCMR_AChrg_DW.time_hl = 0.0F;
    BCMR_AChrg_DW.is_c7_BCMR_AChrg = BCMR_AChrg_IN_A;
  } else {
    rtb_Switch = 0.0F;
    BCMR_AChrg_DW.time_hl = (real32_T)(BCMR_AChrg_DW.time_hl + 0.1F);
  }

  if ((real32_T)fabs(rtb_Switch) > 1.0F) {
    BCMR_iReqCurrChrg = rtb_Switch;
  } else {
    BCMR_iReqCurrChrg = 0.0F;
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_my;
  BCMR_AChrg_DW.Delay1_DSTATE_my = rtb_Switch4_m;
  if (BCMR_AChrg_DW.is_active_c5_BCMR_AChrg == 0U) {
    BCMR_AChrg_DW.is_active_c5_BCMR_AChrg = 1U;
    BCMR_AChrg_DW.is_c5_BCMR_AChrg = BCMR_AChrg_IN_A;
    BCMR_flgChrgCmd = BCMR_AChrg_B.BCMR_flgChrgCmd_n;
  } else if (BCMR_AChrg_DW.is_c5_BCMR_AChrg == BCMR_AChrg_IN_A) {
    if (rtb_LogicalOperator1_gy && rtb_Switch4_m) {
      BCMR_AChrg_DW.is_c5_BCMR_AChrg = BCMR_AChrg_IN_B;
      BCMR_flgChrgCmd = false;
      BCMR_AChrg_DW.time_g = (real32_T)(BCMR_AChrg_DW.time_g + 0.1F);
    } else {
      BCMR_flgChrgCmd = BCMR_AChrg_B.BCMR_flgChrgCmd_n;
    }
  } else if ((BCMR_AChrg_DW.time_g >= 60.0F) || (BCMR_stAChrgMode == 0)) {
    BCMR_AChrg_DW.time_g = 0.0F;
    BCMR_AChrg_DW.is_c5_BCMR_AChrg = BCMR_AChrg_IN_A;
    BCMR_flgChrgCmd = BCMR_AChrg_B.BCMR_flgChrgCmd_n;
  } else {
    BCMR_flgChrgCmd = false;
    BCMR_AChrg_DW.time_g = (real32_T)(BCMR_AChrg_DW.time_g + 0.1F);
  }

  rtb_LogicalOperator1_gy = !BCMR_AChrg_DW.Delay1_DSTATE_g;
  BCMR_AChrg_DW.Delay1_DSTATE_g = rtb_Switch4_m;
  if (BCMR_AChrg_DW.is_active_c2_BCMR_AChrg == 0U) {
    BCMR_AChrg_DW.is_active_c2_BCMR_AChrg = 1U;
    BCMR_AChrg_DW.is_c2_BCMR_AChrg = BCMR_AChrg_IN_A;
    BCMR_AChrg_DW.UnitDelay_DSTATE_oo = BCMR_AChrg_B.BCMR_stAChrgObsr_l;
  } else if (BCMR_AChrg_DW.is_c2_BCMR_AChrg == BCMR_AChrg_IN_A) {
    if (rtb_LogicalOperator1_gy && rtb_Switch4_m) {
      BCMR_AChrg_DW.is_c2_BCMR_AChrg = BCMR_AChrg_IN_B;
      BCMR_AChrg_DW.UnitDelay_DSTATE_oo = 12U;
      BCMR_AChrg_DW.time = (real32_T)(BCMR_AChrg_DW.time + 0.1F);
    } else {
      BCMR_AChrg_DW.UnitDelay_DSTATE_oo = BCMR_AChrg_B.BCMR_stAChrgObsr_l;
    }
  } else if ((BCMR_AChrg_DW.time >= 60.0F) || (BCMR_stAChrgMode == 0)) {
    BCMR_AChrg_DW.time = 0.0F;
    BCMR_AChrg_DW.is_c2_BCMR_AChrg = BCMR_AChrg_IN_A;
    BCMR_AChrg_DW.UnitDelay_DSTATE_oo = BCMR_AChrg_B.BCMR_stAChrgObsr_l;
  } else {
    BCMR_AChrg_DW.UnitDelay_DSTATE_oo = 12U;
    BCMR_AChrg_DW.time = (real32_T)(BCMR_AChrg_DW.time + 0.1F);
  }

  BCMR_stAChrgPreThmMode = BCMR_AChrg_DW.UnitDelay1_DSTATE;
  BCMR_AChrg_DW.Delay_DSTATE_mp = rtb_BCMR_stAChrgCnnt_a;
  BCMR_AChrg_DW.UnitDelay2_DSTATE = BCMR_AChrg_B.MinMax;
  BCMR_AChrg_DW.UnitDelay3_DSTATE = rtb_Product_dt;
  BCMR_AChrg_DW.UnitDelay4_DSTATE = BCMR_AChrg_B.BCMR_vVoltReqCalc;
  BCMR_AChrg_DW.UnitDelay6_DSTATE = BCMR_flgChgStop;
  BCMR_AChrg_DW.UnitDelay7_DSTATE_j = BCMR_AChrg_B.BCMR_stPreThmObsvr_i;
  BCMR_AChrg_DW.Delay_DSTATE_bh = Local_HoldtempChk;
  BCMR_AChrg_DW.UnitDelay5_DSTATE = BCMR_stHoldTempReq;
  BCMR_AChrg_DW.StateName = rtb_UnitDelay2;
  BCMR_AChrg_DW.StateName_j = BCMR_stHoldTempReq;
  BCMR_AChrg_DW.StateName_b = Switch;
  BCMR_AChrg_DW.Delay2_DSTATE = (rtb_Abs1 > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_cj = rtb_RelationalOperator_ol;
  BCMR_AChrg_DW.Delay2_DSTATE_e = (rtb_Product_of > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_ma = rtb_Switch_hc;
  BCMR_AChrg_DW.Delay2_DSTATE_e2 = (rtb_Product_nu > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_a22 = rtb_LogicalOperator6_n;
  BCMR_AChrg_DW.Delay2_DSTATE_d = (rtb_Saturation > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_o3 = rtb_LogicalOperator3_p;
  BCMR_AChrg_DW.Delay2_DSTATE_i = (rtb_Saturation_a > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_hhv = rtb_RelationalOperator3_ll;
  BCMR_AChrg_DW.Delay2_DSTATE_f = (rtb_Switch1_id > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_i1 = rtb_LogicalOperator3_nn;
  BCMR_AChrg_DW.Delay2_DSTATE_l = (rtb_Switch1_fw > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_fd = RelationalOperator_ev;
  BCMR_AChrg_DW.Delay2_DSTATE_dx = (rtb_Switch1_iz > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.Delay_DSTATE_am = RelationalOperator_h;
  BCMR_AChrg_DW.Delay2_DSTATE_j = (rtb_Switch1_lz > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.UnitDelay_DSTATE = rtb_Abs1;
  BCMR_AChrg_DW.UnitDelay_DSTATE_d = rtb_Product_of;
  BCMR_AChrg_DW.UnitDelay_DSTATE_k = rtb_Product_nu;
  BCMR_AChrg_DW.UnitDelay_DSTATE_dh = rtb_Saturation;
  BCMR_AChrg_DW.Delay2_DSTATE_b = (rtb_Switch1_f > BCMR_tiFltNumHold_C);
  BCMR_AChrg_DW.UnitDelay_DSTATE_c = rtb_Switch1_f;
  BCMR_AChrg_DW.UnitDelay_DSTATE_o = rtb_Saturation_a;
  BCMR_AChrg_DW.UnitDelay_DSTATE_ci = rtb_Switch1_id;
  BCMR_AChrg_DW.UnitDelay_DSTATE_i = rtb_Switch1_iz;
  BCMR_AChrg_DW.UnitDelay_DSTATE_f = rtb_Switch1_lz;
  BCMR_AChrg_DW.UnitDelay_DSTATE_a = rtb_Switch1_fw;
  BCMR_AChrg_DW.Delay2_DSTATE_eo = (rtb_Switch1_a0 > BCMR_TiChgFullHold_C);
  BCMR_AChrg_DW.UnitDelay_DSTATE_c5 = rtb_Switch1_a0;
  BCMR_AChrg_DW.UnitDelay1_DSTATE = BCMR_AChrg_B.BCMR_stAChrgPreThemalMode;
}

/* Model initialize function */
void BCMR_AChrg_initialize(void)
{
  /* Machine initializer */
  BCMR_AChrg_DW.data = 0.0F;
  BCMR_AChrg_DW.Delay_DSTATE_bh = true;
  BCMR_AChrg_DW.StateName = 1.0F;
  BCMR_AChrg_DW.Delay2_DSTATE_o = true;
  BCMR_AChrg_DW.Delay_DSTATE_d = 1.0F;
  BCMR_AChrg_DW.Delay2_DSTATE_mi = true;
  BCMR_AChrg_DW.Delay2_DSTATE_l0 = true;
  BCMR_AChrg_DW.UnitDelay1_DSTATE_l = true;
  BCMR_AChrg_DW.UnitDelay1_DSTATE_k3 = true;
  BCMR_AChrg_B.BCMR_stAChrgTrickle_h = enmAChrgTrickleSts_Default;
  BCMR_AChrg_DW.Delay1_DSTATE_o = true;
  BCMR_AChrg_DW.UnitDelay1_DSTATE_k = true;
  BCMR_AChrg_DW.UnitDelay1_DSTATE_m = true;
  BCM_BCMR_AChrgTiRevTimCalc_Init(&BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc);
  BCM_BCMR_AChrgTiRevTimCalc_Init(&BCMR_AChrg_DW.BCMR_AChrgTiRevTimCalc_b);
  BCMR_AChrg_DW.Delay1_DSTATE_k = true;
  BCMR_AChrg_DW.Delay1_DSTATE_lc = true;
  BCMR_AChrg_DW.Delay1_DSTATE_h = true;
  BCMR_AChrg_B.Switch6 = 2047;
  BCMR_AChrg_DW.Delay1_DSTATE_ma = true;
  BCMR_AChrg_DW.FixPtUnitDelay2_DSTATE = 1U;
  BCMR_AChrg_DW.Delay1_DSTATE_i = true;
  BCMR_AChrg_DW.Delay1_DSTATE_al = true;
  BCMR_AChrg_DW.Delay1_DSTATE_b = true;
  BCMR_AChrg_DW.FixPtUnitDelay2_DSTATE_n = 1U;
  BCMR_AChrg_DW.Delay2_DSTATE_jv = true;
  BCMR_AChrg_DW.Delay2_DSTATE_la = true;
  BCMR_AChrg_DW.Delay2_DSTATE_dl = true;
  BCMR_AChrg_DW.Delay2_DSTATE_ik = true;
  BCMR_AChrg_DW.Delay2_DSTATE_h2 = true;
  BCMR_AChrg_DW.Delay2_DSTATE_a = true;
  BCMR_AChrg_DW.Delay2_DSTATE_m = true;
  BCMR_AChrg_DW.Delay2_DSTATE_da = true;
  BCMR_AChrg_DW.Delay2_DSTATE_n = true;
  BCMR_AChrg_DW.Delay2_DSTATE_nl = true;
  BCMR_AChrg_DW.Delay2_DSTATE_fk = true;
  BCMR_AChrg_DW.Delay1_DSTATE_g2 = true;
  BCMR_AChrg_DW.Delay1_DSTATE_ge = true;
  BCMR_AChrg_DW.Delay1_DSTATE_n = true;
  BCMR_AChrg_DW.Delay1_DSTATE_eg = true;
  BCMR_AChrg_DW.Delay1_DSTATE_mz = true;
  BCMR_AChrg_DW.Delay1_DSTATE_mr = true;
  BCMR_AChrg_DW.Delay1_DSTATE_cl = true;
  BCMR_AChrg_DW.Delay1_DSTATE_d = true;
  BCMR_AChrg_DW.Delay1_DSTATE_p = true;
  BCMR_AChrg_DW.Delay1_DSTATE_e = true;
  BCMR_AChrg_DW.Delay1_DSTATE_g1 = true;
  BCMR_AChrg_DW.Delay1_DSTATE_ah = true;
  BCMR_AChrg_DW.Delay1_DSTATE_ip = true;
  BCMR_AChrg_DW.Delay1_DSTATE_my = true;
  BCMR_AChrg_DW.Delay1_DSTATE_g = true;
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
