/*
 * File: BCCR_RlyCtlDiag.c
 *
 * Code generated for Simulink model 'BCCR_RlyCtlDiag'.
 *
 * Model version                  : 1.743
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Wed Mar 03 11:30:47 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 "BCCR_RlyCtlDiag.h"
#include "BCCR_RlyCtlDiag_private.h"

/* Named constants for Chart: '<S139>/RS' */
#define BCCR_RlyCtlD_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define BCCR_RlyCtlDiag_IN_RS_FlipFlop ((uint8_T)1U)

/* Named constants for Chart: '<S8>/DChrgCtrCtlCalc' */
#define BCCR_Rl_IN_DChrgCtlFaultEnd_Stt ((uint8_T)2U)
#define BCCR_RlyCt_IN_DChrgCtlFault_Stt ((uint8_T)3U)
#define BCCR_RlyCt_IN_NO_ACTIVE_CHILD_g ((uint8_T)0U)
#define BCCR_RlyCtlD_IN_DChrgCtlEnd_Stt ((uint8_T)1U)
#define BCCR_RlyCtlDia_IN_DChrgWait_Stt ((uint8_T)6U)
#define BCCR_RlyCtlDiag_IN_DChrgWrk_Stt ((uint8_T)7U)
#define BCCR_RlyCtlDiag_IN_Default_Stt ((uint8_T)8U)
#define BCCR_RlyCtlDiag_IN_EOL0_Stt    ((uint8_T)1U)
#define BCCR_RlyCtlDiag_IN_EOL1_Stt    ((uint8_T)2U)
#define BCCR_RlyCtlDiag_IN_EOL2_Stt    ((uint8_T)3U)
#define BCCR_RlyCtlDiag_IN_EOL3_Stt    ((uint8_T)4U)
#define BCCR_RlyCtlDiag_IN_EOL_Stt     ((uint8_T)9U)
#define BCCR__IN_DChrgCtrCnntCtlEnd_Stt ((uint8_T)4U)
#define BCCR__IN_DChrgCtrDisConnCtl_Stt ((uint8_T)5U)

/* Named constants for Chart: '<S54>/ContactorCtlCalc' */
#define BCCR_RlyC_IN_PreChargeFault_Stt ((uint8_T)5U)
#define BCCR_RlyCt_IN_PreChargeHld1_Stt ((uint8_T)6U)
#define BCCR_RlyCt_IN_PreChargeHld2_Stt ((uint8_T)7U)
#define BCCR_RlyCt_IN_PreChargeStrt_Stt ((uint8_T)8U)
#define BCCR_RlyCt_IN_PwrUpDwnAbort_Stt ((uint8_T)12U)
#define BCCR_RlyCtlD_IN_PwrUpDwnEnd_Stt ((uint8_T)13U)
#define BCCR_RlyCtlDi_IN_PwrDwnStrt_Stt ((uint8_T)10U)
#define BCCR_RlyCtlDia_IN_Default_Stt_e ((uint8_T)1U)
#define BCCR_RlyCtlDia_IN_PwrDwnEnd_Stt ((uint8_T)9U)
#define BCCR_RlyCtlDia_IN_PwrOnAbrt_Stt ((uint8_T)11U)
#define BCCR_RlyCtlDiag_IN_HvOn_Stt    ((uint8_T)2U)
#define BCCR_RlyCtlDiag_IN_Ini_Stt     ((uint8_T)3U)
#define BCCR_RlyCtlDiag_IN_Wait_Stt    ((uint8_T)14U)
#define BCCR_RlyCtl_IN_PreChargeEnd_Stt ((uint8_T)4U)

/* Exported data definition */

/* Definition for custom storage class: FileScope */
static boolean_T BCMR_stDChrgCnntEdg;

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

/* Definition for custom storage class: Volatile */
volatile real32_T BCCR_uDChrgNegVoltStgFrstMax;/* Max dc charge voltage of negative contactor before switching on */
volatile real32_T BSPR_uPackVoltRawEnd;/* Pack voltage after main contactor disconnected */
volatile uint8_T DFC_DChrgPwrUpFail_ASW;   /* Power up faile of dc charge control  */
volatile uint8_T DFC_DcNegRlyDrvFault_ASW;
volatile uint8_T DFC_DcNegRlyDrvOL_ASW;
volatile uint8_T DFC_DcNegRlyDrvScb_ASW;
volatile uint8_T DFC_DcNegRlyDrvScg_ASW;
volatile uint8_T DFC_DcPosRlyDrvFault_ASW;
volatile uint8_T DFC_DcPosRlyDrvOL_ASW;
volatile uint8_T DFC_DcPosRlyDrvScb_ASW;
volatile uint8_T DFC_DcPosRlyDrvScg_ASW;
volatile uint8_T DFC_HvPwrUpFail_ASW;      /* Precharge control failed */
volatile uint8_T DFC_MNegRlyDrvFault_ASW;
volatile uint8_T DFC_MNegRlyDrvOL_ASW;
volatile uint8_T DFC_MNegRlyDrvScb_ASW;
volatile uint8_T DFC_MNegRlyDrvScg_ASW;
volatile uint8_T DFC_MPosRlyDrvFault_ASW;
volatile uint8_T DFC_MPosRlyDrvOL_ASW;
volatile uint8_T DFC_MPosRlyDrvScb_ASW;
volatile uint8_T DFC_MPosRlyDrvScg_ASW;
volatile uint8_T DFC_PrechgEngyFail_ASW;   /* Precharge resistance energy failed */

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BCCR_bCtrStuckChkCond;/* Condition for contactors stuck diagnosis */
volatile boolean_T BCCR_bDChrgFaultDet;/* Fault detect for DC charge control */
volatile boolean_T BCCR_bDChrgFaultHeal;/* Fault healing for DC charge control */
volatile boolean_T BCCR_bDChrgNegCtrSwtOn;/* Switch on flag for  DC charge negative contactor */
volatile boolean_T BCCR_bDChrgPosCtrSwtOn;/* Switch on flag for  DC charge positive contactor */
volatile boolean_T BCCR_bDcChNegCtrHsdEna;/* High side I/O control for DC charge negative contactor */
volatile boolean_T BCCR_bDcChPosCtrHsdEna;/* High side I/O control for DC charge positive contactor */
volatile boolean_T BCCR_bMNegCtrHsdEna;/* High side I/O control for main negative contactor */
volatile boolean_T BCCR_bMNegCtrSwtOn; /* Switch on flag for main negative contactor */
volatile boolean_T BCCR_bMPosCtrHsdEna;/* High side I/O control for main positive contactor */
volatile boolean_T BCCR_bMPosCtrSwtOn; /* Switch on flag for main positive contactor */
volatile boolean_T BCCR_bPreChCtrLsdEna;/* Low side I/O control for precharge contactor */
volatile boolean_T BCCR_bPreChCtrSwtOn;/* Switch on flag for  precharge contactor */
volatile boolean_T BCCR_bPreChargeFaultDet;/* Error detect flag for precharge control */
volatile boolean_T BCCR_bPreChargeFaultHeal;/* Error heal flag for precharge control */
volatile boolean_T BCCR_bStuckClsdDChrgNegErrDet;/* Error flag for dc negative contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckClsdDChrgNegErrHeal;/* Healing flag for dc negative contactor stuck closed diagnosis */
volatile boolean_T BCCR_bStuckClsdDChrgPosErrDet;/* Healing flag for dc positive contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckClsdDChrgPosErrHeal;/* Error flag for dc positive contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckClsdMnErrDet;/* Error flag for main negative contactor stuck closed diagnosis */
volatile boolean_T BCCR_bStuckClsdMnErrHeal;/* Healing flag for main negative contactor stuck closed diagnosis */
volatile boolean_T BCCR_bStuckClsdMnStgFrstErrDet;/* Error flag for main negative contactor stuck closed diagnosis first stage during power up */
volatile boolean_T BCCR_bStuckClsdMnStgFrstErrHeal;/* Healing flag for main negative contactor stuck closed diagnosis first stage during power up */
volatile boolean_T BCCR_bStuckClsdMnStgScndErrDet;/* Error flag for main negative stuck closed diagnosis second stage during power dowm */
volatile boolean_T BCCR_bStuckClsdMnStgScndErrHeal;/* Healing flag for main negative contactor stuck closed diagnosis second stage during power dowm */
volatile boolean_T BCCR_bStuckClsdMpPrErrDet;/* Error flag for postive contactor stuck closed diagnosis */
volatile boolean_T BCCR_bStuckClsdMpPrErrHeal;/* Healing flag for postive contactor stuck closed diagnosis */
volatile boolean_T BCCR_bStuckClsdMpPrFastErrDet;/* Healing flag for main negative contactor stuck closed diagnosis first stage during fast diagnosis */
volatile boolean_T BCCR_bStuckClsdMpPrFastErrHeal;/* Error flag for main negative contactor stuck closed diagnosis first stage during fast diagnosis */
volatile boolean_T BCCR_bStuckClsdMpPrStgFrstErrDet;/* Error flag for postive contactor stuck closed diagnosis first stage during power up */
volatile boolean_T BCCR_bStuckClsdMpPrStgFrstErrHeal;/* Healing flag for postive contactor stuck closed diagnosis first stage during power up */
volatile boolean_T BCCR_bStuckClsdMpPrStgScndErrDet;/* Error flag for postive contactor stuck closed diagnosis second stage during power dowm */
volatile boolean_T BCCR_bStuckClsdMpPrStgScndErrHeal;/* Healing flag for postive contactor stuck closed diagnosis second stage during power dowm */
volatile boolean_T BCCR_bStuckClsdPosDiagAct;
volatile boolean_T BCCR_bStuckOpnDChrgNegErrDet;/* Error flag for dc negative contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnDChrgNegErrHeal;/* Healing flag for dc negative contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnDChrgPosErrDet;/* Error flag for dc positive contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnDChrgPosErrHeal;/* Healing flag for dc positive contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnMnErrDet;/* Error flag for main negative contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnMnErrHeal;/* Healing flag for main negative contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnMpErrDet;/* Error flag for main positive contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnMpErrHeal;/* Healing flag for main positive contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnPrErrDet;/* Error flag for precharge contactor stuck open diagnosis */
volatile boolean_T BCCR_bStuckOpnPrErrHeal;/* Healing flag for precharge contactor stuck open diagnosis */
volatile boolean_T BCCR_bSw5CtrDiagSwt;/* Switch flag of sw5 used for negative contactor diagnosis */
volatile boolean_T BCCR_bVoffDiffPwrUpAvl;/* Error heal flag for precharge control */
volatile boolean_T BCCR_bVoffRisePwrUpAvl;/* Error heal flag for precharge control */
volatile boolean_T BCCR_bkl15UpEdg;    /* Edge rising detected flag for kl15 wake up  signal  */
volatile uint8_T BCCR_cntDChrgFault;   /* Counter for DC charge control failed in current driving cycle */
volatile uint8_T BCCR_cntPreChFault;   /* Counter for precharge control failed in current driving cycle */
volatile uint8_T BCCR_cntStuckOpnMnErr;/* Counter for precharge failed times during power on */
volatile uint8_T BCCR_cntStuckOpnPrErr;/* Counter for precharge failed times during power on */
volatile boolean_T BCCR_dcDcChNegCtrLsdEna;/* Low side pwm control for DC charge negative contactor */
volatile boolean_T BCCR_dcDcChPosCtrLsdEna;/* Low side pwm control for DC charge positive contactor */
volatile boolean_T BCCR_dcMNegCtrLsdEna;/* Low side pwm control for main positive contactor */
volatile boolean_T BCCR_dcMPosCtrLsdEna;/* Low side pwm control for main positive contactor */
volatile boolean_T BCCR_flgCctDrvDiagEna;/* 继电器线圈诊断使能标志 */
volatile boolean_T BCCR_flgDChrgCtrCtrlEn;/* Enable condition for DC charge contactor control */
volatile boolean_T BCCR_flgDChrgPwrUpReq;/* Power up request for DC charge command */
volatile boolean_T BCCR_flgPackCtrCtrlEna;/* Enable condition for main contactor control */
volatile boolean_T BCCR_flgPwrDwnReq;  /* Power down request after coordinating */
volatile boolean_T BCCR_flgPwrUpReq;   /* Power up request after coordinating */
volatile real32_T BCCR_iBattCurrBgn;   /* Battery current before precharge connected */
volatile real32_T BCCR_iBattCurrPreChLoThres;/* Battery current before precharge connected */
volatile real32_T BCCR_iBattCurrStgFrstMax;/* Max battery current before precharge connected */
volatile real32_T BCCR_jPreChgResEnrg; /* The energy of the precharge resistor during the precharge process */
volatile real32_T BCCR_jPreChgResEnrgCycl;/* The energy of the precharge resistor during the precharge process */
volatile uint8_T BCCR_stBmsCtrMode;    /* Status for battery main contactor connect and disconnect */
volatile uint8_T BCCR_stBmsDChrgCtrMode;/* Control status of DC charge contatctor */
volatile uint8_T BCCR_stDChrgCtrDiag;  /* Status for dc charge contactor diagnosis */
volatile uint8_T BCCR_stMainCtrDiagMode;/* Status for main contactor diagnosis */
volatile uint8_T BCCR_stMainCtrDisConn;
volatile uint8_T BCCR_stPreChRslt;     /* Status of battery precharge control */
volatile real32_T BCCR_tiDChrgCtrWait; /* Waitting time for positive contactor switch on */
volatile real32_T BCCR_tiDChrgHld;     /* Total time for  DC charge Contactor power up control */
volatile real32_T BCCR_uBattDChrgVoltDiff;/* Difference between battery voltage and DC charge voltage */
volatile real32_T BCCR_uDChrgVoltStgFrstMax;/* Max dc charge voltage of positive contactor before switching on */
volatile real32_T BCCR_uEcuVoltagetoDID;/* The ecuVoltage to did */
volatile real32_T BCCR_uKl30cPreChgStMin;/* The Minium voltage of Kl30c in the pre-charged state */
volatile real32_T BCCR_uPackVoltHopMax;/* Max pack voltage after main positive contactor connected */
volatile real32_T BCCR_uPackVoltStgFrstBgn;/* Pack voltage when negative contactor is connected */
volatile real32_T BSPR_iBattCurrPreChMax;/* Max battery current before precharge connected */
volatile real32_T BSPR_uPackVoltOpenRaw;/* Pack voltage after main contactor disconnected */
volatile boolean_T COMR_bBattVoltCtrDiagEn;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BCCR_RlyCtlDiag_T BCCR_RlyCtlDiag_B;

/* Block states (auto storage) */
DW_BCCR_RlyCtlDiag_T BCCR_RlyCtlDiag_DW;

/* Previous zero-crossings (trigger) states */
PrevZCX_BCCR_RlyCtlDiag_T BCCR_RlyCtlDiag_PrevZCX;

/* External outputs (root outports fed by signals with auto storage) */
ExtY_BCCR_RlyCtlDiag_T BCCR_RlyCtlDiag_Y;

/* Forward declaration for local functions */
static void BCCR_enter_internal_RS_FlipFlop(boolean_T rtu_S, boolean_T rtu_R,
  B_RS_BCCR_RlyCtlDiag_T *localB);
static void BCCR_RlyCtlDiag_RS_FlipFlop(boolean_T rtu_S, boolean_T rtu_R,
  B_RS_BCCR_RlyCtlDiag_T *localB, DW_RS_BCCR_RlyCtlDiag_T *localDW);

/* Forward declaration for local functions */
static void enter_atomic_PwrUpDwnAbort_Stt(void);
static void BCCR_RlyCtlDiag_Wait_Stt(void);

/* Function for Chart: '<S139>/RS' */
static void BCCR_enter_internal_RS_FlipFlop(boolean_T rtu_S, boolean_T rtu_R,
  B_RS_BCCR_RlyCtlDiag_T *localB)
{
  if (rtu_R) {
    localB->Q = false;
    localB->nQ = true;
  } else {
    if (rtu_S) {
      localB->Q = true;
      localB->nQ = false;
    }
  }
}

/* Function for Chart: '<S139>/RS' */
static void BCCR_RlyCtlDiag_RS_FlipFlop(boolean_T rtu_S, boolean_T rtu_R,
  B_RS_BCCR_RlyCtlDiag_T *localB, DW_RS_BCCR_RlyCtlDiag_T *localDW)
{
  localDW->is_c2_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_RS_FlipFlop;
  BCCR_enter_internal_RS_FlipFlop(rtu_S, rtu_R, localB);
}

/*
 * System reset for atomic system:
 *    '<S139>/RS'
 *    '<S146>/RS'
 *    '<S147>/RS'
 *    '<S148>/RS'
 *    '<S149>/RS'
 *    '<S158>/RS'
 *    '<S159>/RS'
 */
void BCCR_RlyCtlDiag_RS_Reset(B_RS_BCCR_RlyCtlDiag_T *localB,
  DW_RS_BCCR_RlyCtlDiag_T *localDW)
{
  localDW->is_active_c2_BCCR_RlyCtlDiag = 0U;
  localDW->is_c2_BCCR_RlyCtlDiag = BCCR_RlyCtlD_IN_NO_ACTIVE_CHILD;
  localB->Q = false;
  localB->nQ = false;
}

/*
 * Output and update for atomic system:
 *    '<S139>/RS'
 *    '<S146>/RS'
 *    '<S147>/RS'
 *    '<S148>/RS'
 *    '<S149>/RS'
 *    '<S158>/RS'
 *    '<S159>/RS'
 */
void BCCR_RlyCtlDiag_RS(boolean_T rtu_S, boolean_T rtu_R, B_RS_BCCR_RlyCtlDiag_T
  *localB, DW_RS_BCCR_RlyCtlDiag_T *localDW)
{
  if (localDW->is_active_c2_BCCR_RlyCtlDiag == 0U) {
    localDW->is_active_c2_BCCR_RlyCtlDiag = 1U;
    localDW->is_c2_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_RS_FlipFlop;
    BCCR_enter_internal_RS_FlipFlop(rtu_S, rtu_R, localB);
  } else {
    BCCR_RlyCtlDiag_RS_FlipFlop(rtu_S, rtu_R, localB, localDW);
  }
}

/* Function for Chart: '<S54>/ContactorCtlCalc' */
static void enter_atomic_PwrUpDwnAbort_Stt(void)
{
  BCCR_bPreChargeFaultDet = true;
  BCCR_bPreChargeFaultHeal = false;
  BCCR_bMPosCtrSwtOn = false;
  BCCR_bMNegCtrSwtOn = false;
  BCCR_bPreChCtrSwtOn = false;
  BCCR_stBmsCtrMode = 14U;
  BCCR_stMainCtrDiagMode = 14U;
  BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
  BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait = 0.0F;
  BCCR_RlyCtlDiag_DW.BCCR_tiMNegCtrSwtOffWait = 0.0F;
  BCCR_stPreChRslt = 2U;
  BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
}

/* Function for Chart: '<S54>/ContactorCtlCalc' */
static void BCCR_RlyCtlDiag_Wait_Stt(void)
{
  if (BCCR_flgPwrUpReq && BCCR_flgPackCtrCtrlEna &&
      (BCCR_RlyCtlDiag_DW.BCCR_tiIniHld >= BCCR_tiIsoCheckStaus_C)) {
    BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCt_IN_PreChargeStrt_Stt;
    BCCR_stBmsCtrMode = 3U;
    BCCR_stMainCtrDiagMode = 31U;
    if (BCCR_bMnCtlHwSel_C) {
      BCCR_bMNegCtrSwtOn = true;
    } else {
      BCCR_bPreChCtrSwtOn = true;
    }

    BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait = 0.0F;
    BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
    BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
  } else if (BCCR_flgPwrUpReq && (!BCCR_flgPackCtrCtrlEna) &&
             (BCCR_RlyCtlDiag_DW.BCCR_tiIniHld >= 0.8F)) {
    BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCt_IN_PwrUpDwnAbort_Stt;
    enter_atomic_PwrUpDwnAbort_Stt();
  } else if (!BCCR_flgPwrUpReq) {
    BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDia_IN_PwrOnAbrt_Stt;
    BCCR_stBmsCtrMode = 17U;
    BCCR_stMainCtrDiagMode = 17U;
    BCCR_bMPosCtrSwtOn = false;
    BCCR_bMNegCtrSwtOn = false;
    BCCR_bPreChCtrSwtOn = false;
  } else {
    BCCR_RlyCtlDiag_DW.BCCR_tiIniHld += 0.01F;
  }
}

/* Model step function */
void BCCR_RlyCtlDiag_step(void)
{
  real32_T rtb_Constant14;
  boolean_T rtb_Compare_k3;
  boolean_T rtb_Switch_nf;
  boolean_T rtb_Switch2_o;
  boolean_T rtb_Compare_lr;
  boolean_T rtb_LogicalOperator5_l;
  boolean_T rtb_LogicalOperator2_n;
  boolean_T rtb_RelationalOperator2_k;
  boolean_T rtb_RelationalOperator1_ch;
  boolean_T rtb_LogicalOperator1_j;
  boolean_T rtb_LogicalOperator6_hf;
  real32_T rtb_Product_ga;
  real32_T rtb_Product_go;
  real32_T rtb_Product_mj;
  uint8_T rtb_Switch4_fd;
  int32_T tmp;
  if (BCCR_bDchrgCtrStdSel_C) {
    rtb_Constant14 = BSPR_uBattVolt - BSPR_uDChrgVoltRaw;
  } else {
    rtb_Constant14 = BSPR_uDChrgVoltRaw;
  }

  BCCR_uBattDChrgVoltDiff = fabsf(rtb_Constant14);
  rtb_Compare_k3 = (DSMR_stFaultRank != 3);
  rtb_Switch_nf = (DSMR_stFaultRank != 4);
  if (BCCR_bDchrgCtlHwSel_C) {
    rtb_Compare_lr = !(BSER_flgDChrgVoltSnsrFault || BSER_flgDChrgCtrCtrlFault);
  } else {
    rtb_Compare_lr = true;
  }

  BCCR_flgDChrgCtrCtrlEn = (rtb_Compare_lr && rtb_Compare_k3 && rtb_Switch_nf);
  BCCR_flgDChrgPwrUpReq = (rtb_Compare_k3 && rtb_Switch_nf &&
    BMCR_bDChrgPwrUpReq);
  BCMR_stDChrgCnntEdg = ((!BCCR_RlyCtlDiag_DW.Delay1_DSTATE_ef) &&
    BCMR_stDChrgCnnt);
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_ef = BCMR_stDChrgCnnt;
  rtb_Switch2_o = !BCCR_RlyCtlDiag_DW.Delay1_DSTATE_g;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_g = BCMR_bDChrgAbrtWait;
  COMR_bBattVoltCtrDiagEn = (COMR_uBattVolt >= COMR_uBattVoltDiagCtrLo_C);
  if (BCCR_bMnDiagHwSel_C) {
    rtb_Compare_lr = (BSWBatteryHVDataMsgRx && BSWBusHVDataMsgRx);
  } else {
    rtb_Compare_lr = true;
  }

  BCCR_bCtrStuckChkCond = ((COMR_stEol == 0) && ((BSPR_uKl30c <=
    BCCR_uKl30cCtrPlausDiagHi_C) && (BSPR_uKl30c >= BCCR_uKl30cCtrPlausDiagLo_C))
    && rtb_Compare_lr && COMR_bBattVoltCtrDiagEn);
  if (BCCR_bCtrStuckChkCond) {
    if (!BCCR_RlyCtlDiag_DW.BCCR_DChrgCtrDiag_MODE) {
      BCCR_RlyCtlDiag_DW.BCCR_DChrgCtrDiag_MODE = true;
    }

    rtb_Switch_nf = (BCCR_RlyCtlDiag_DW.Delay7_DSTATE ==
                     BCCR_RlyCtlDiag_ConstB.DataTypeConversion1_o);
    if (BCCR_bDchrgDiagStdSel_C) {
      rtb_Compare_k3 = BCCR_RlyCtlDiag_ConstB.DataTypeConversion1_g;
    } else {
      rtb_Compare_k3 = BCCR_RlyCtlDiag_ConstB.DataTypeConversion_n;
    }

    if (rtb_Compare_k3 && ((BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 0) ||
                           (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 1)) &&
        rtb_Switch_nf) {
      if (!BCCR_RlyCtlDiag_DW.DcPosStuckClsdDiag_MODE) {
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_b = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_n = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_m = false;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_hk = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_gc = 0.0F;
        BCCR_RlyCtlDiag_DW.DcPosStuckClsdDiag_MODE = true;
      }

      BCCR_stDChrgCtrDiag = 4U;
      rtb_Compare_lr = (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 0);
      rtb_Constant14 = 0.01F + fminf(BCCR_tiStuckClsdDChrgPosWait_C,
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_n);
      rtb_LogicalOperator5_l = (rtb_Constant14 < BCCR_tiStuckClsdDChrgPosWait_C);
      rtb_LogicalOperator2_n = !rtb_LogicalOperator5_l;
      rtb_LogicalOperator5_l = (rtb_LogicalOperator5_l || BCCR_flgPwrUpDiagEn_C);
      rtb_RelationalOperator2_k = (BSPR_uDChrgVoltRaw > BCCR_uStuckClsdDcPosHi_C);
      rtb_RelationalOperator1_ch = (fabsf(BSPR_uDChrgVoltRaw - BSPR_uPackVoltRaw)
        < BCCR_uStuckClsdDcPosDiff_C);
      rtb_LogicalOperator1_j = !BCCR_RlyCtlDiag_DW.Delay2_DSTATE_o;
      rtb_LogicalOperator6_hf = (rtb_LogicalOperator5_l && rtb_Compare_lr &&
        (!rtb_RelationalOperator2_k) && (!rtb_RelationalOperator1_ch) &&
        rtb_LogicalOperator1_j);
      if (rtb_LogicalOperator6_hf) {
        rtb_Product_ga = 0.01F;
      } else {
        rtb_Product_ga = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_ga + fminf(BCCR_tiStuckClsdDChrgThres_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_hk)) * (real32_T)rtb_LogicalOperator6_hf;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_hk = rtb_Product_ga;
      BCCR_bStuckClsdDChrgPosErrHeal = (BCCR_RlyCtlDiag_DW.Delay3_DSTATE_m ||
        rtb_LogicalOperator2_n || (rtb_Product_ga > BCCR_tiStuckClsdDChrgThres_C));
      rtb_Compare_lr = (rtb_LogicalOperator5_l && rtb_Compare_lr &&
                        rtb_RelationalOperator2_k && rtb_RelationalOperator1_ch &&
                        rtb_LogicalOperator1_j);
      BCCR_RlyCtlDiag_B.MinMax_k = fmaxf(BCCR_RlyCtlDiag_DW.Delay1_DSTATE_b,
        BSPR_uDChrgVoltRaw);
      if (rtb_Compare_lr) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiStuckClsdDChrgDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_gc)) * (real32_T)rtb_Compare_lr;
      BCCR_bStuckClsdDChrgPosErrDet = (rtb_Product_ga >
        BCCR_tiStuckClsdDChrgDet_C);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_gc = rtb_Product_ga;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_b = BCCR_RlyCtlDiag_B.MinMax_k;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_n = rtb_Constant14;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_m = BCCR_bStuckClsdDChrgPosErrHeal;
    } else {
      if (BCCR_RlyCtlDiag_DW.DcPosStuckClsdDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcPosStuckClsdDiag_MODE = false;
      }
    }

    BCCR_uDChrgVoltStgFrstMax = BCCR_RlyCtlDiag_B.MinMax_k;
    if (((BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 0) ||
         (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 1)) && rtb_Switch_nf) {
      if (!BCCR_RlyCtlDiag_DW.DchrgNegVoltMax_MODE) {
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_j = 0.0F;
        BCCR_RlyCtlDiag_DW.DchrgNegVoltMax_MODE = true;
      }

      BCCR_RlyCtlDiag_B.MinMax1_h = fmaxf(BCCR_RlyCtlDiag_DW.Delay3_DSTATE_j,
        BSPR_uDchrgNegVolt);
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_j = BCCR_RlyCtlDiag_B.MinMax1_h;
    } else {
      if (BCCR_RlyCtlDiag_DW.DchrgNegVoltMax_MODE) {
        BCCR_RlyCtlDiag_DW.DchrgNegVoltMax_MODE = false;
      }
    }

    BCCR_uDChrgNegVoltStgFrstMax = BCCR_RlyCtlDiag_B.MinMax1_h;
    if (((!BCMR_stDChrgCnnt) || (!BCCR_bDchrgNegClsdHealSel_C)) &&
        (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 0) &&
        ((BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 31) ||
         (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 32))) {
      if (!BCCR_RlyCtlDiag_DW.DcNegStuckClsdDiag_MODE) {
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_bi = false;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bo = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_dx = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_ho = 0.0F;
        BCCR_RlyCtlDiag_DW.DcNegStuckClsdDiag_MODE = true;
      }

      BCCR_stDChrgCtrDiag = 1U;
      rtb_Compare_lr = (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 0);
      rtb_Constant14 = 0.01F + fminf(BCCR_tiStuckClsdDChrgNegWait_C,
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bo);
      rtb_LogicalOperator5_l = (rtb_Constant14 < BCCR_tiStuckClsdDChrgNegWait_C);
      rtb_LogicalOperator2_n = (BSPR_uDchrgNegVolt >= BCCR_uStuckClsdDcNeg_C);
      rtb_RelationalOperator2_k = ((!BCCR_bDchrgDiagHwSel_C) ||
        BCCR_bSw5CtrDiagSwt);
      rtb_RelationalOperator1_ch = (rtb_LogicalOperator5_l && rtb_Compare_lr &&
        (!rtb_LogicalOperator2_n) && rtb_RelationalOperator2_k);
      if (rtb_RelationalOperator1_ch) {
        rtb_Product_ga = 0.01F;
      } else {
        rtb_Product_ga = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_ga + fminf(BCCR_tiStuckClsdDChrgNegHeal_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_dx)) * (real32_T)
        rtb_RelationalOperator1_ch;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_dx = rtb_Product_ga;
      BCCR_bStuckClsdDChrgNegErrHeal = (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_bi || (
        !rtb_LogicalOperator5_l) || (rtb_Product_ga >
        BCCR_tiStuckClsdDChrgNegHeal_C));
      rtb_Compare_lr = (rtb_RelationalOperator2_k && (fabsf(BSPR_uNegVolt -
        BSPR_uDchrgNegVolt) < BCCR_uStuckClsdDcNegDiff_C) &&
                        rtb_LogicalOperator2_n && rtb_Compare_lr &&
                        rtb_LogicalOperator5_l);
      if (rtb_Compare_lr) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiStuckClsdDChrgNegErr_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_ho)) * (real32_T)rtb_Compare_lr;
      BCCR_bStuckClsdDChrgNegErrDet = (rtb_Product_ga >
        BCCR_tiStuckClsdDChrgNegErr_C);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_ho = rtb_Product_ga;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_bi = BCCR_bStuckClsdDChrgNegErrHeal;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bo = rtb_Constant14;
    } else {
      if (BCCR_RlyCtlDiag_DW.DcNegStuckClsdDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcNegStuckClsdDiag_MODE = false;
      }
    }

    if ((BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 3) && rtb_Switch_nf) {
      if (!BCCR_RlyCtlDiag_DW.DcNegStuckOpnDiag_MODE) {
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_m = false;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_b = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_ou = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_eb = 0.0F;
        BCCR_RlyCtlDiag_DW.DcNegStuckOpnDiag_MODE = true;
      }

      BCCR_stDChrgCtrDiag = 3U;
      BCCR_bStuckOpnDChrgPosErrHeal = true;
      rtb_Constant14 = 0.01F + fminf(BCCR_tiStuckOpnDChrgNegWait_C,
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_b);
      rtb_Compare_lr = (rtb_Constant14 < BCCR_tiStuckOpnDChrgNegWait_C);
      rtb_LogicalOperator5_l = (BSPR_uDchrgNegVolt > BCCR_uStuckOpnDcNegHi_C);
      rtb_LogicalOperator2_n = (rtb_Compare_lr && (BSPR_uDchrgNegVolt <=
        BCCR_uDChrgNegVoltStgFrstMax + 2.0F) && (!rtb_LogicalOperator5_l));
      if (rtb_LogicalOperator2_n) {
        rtb_Product_ga = 0.01F;
      } else {
        rtb_Product_ga = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_ga + fminf(BCCR_tiStuckOpnDChrgNegHeal_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_ou)) * (real32_T)rtb_LogicalOperator2_n;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_ou = rtb_Product_ga;
      BCCR_bStuckOpnDChrgNegErrHeal = (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_m ||
        (!rtb_Compare_lr) || (rtb_Product_ga > BCCR_tiStuckOpnDChrgNegHeal_C));
      rtb_Compare_lr = (rtb_Compare_lr && rtb_LogicalOperator5_l);
      if (rtb_Compare_lr) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiStuckOpnDChrgNegErr_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_eb)) * (real32_T)rtb_Compare_lr;
      BCCR_bStuckOpnDChrgNegErrDet = (rtb_Product_ga >
        BCCR_tiStuckOpnDChrgNegErr_C);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_eb = rtb_Product_ga;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_m = BCCR_bStuckOpnDChrgNegErrHeal;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_b = rtb_Constant14;
    } else {
      if (BCCR_RlyCtlDiag_DW.DcNegStuckOpnDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcNegStuckOpnDiag_MODE = false;
      }
    }

    if (rtb_Compare_k3 && (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f == 2) &&
        rtb_Switch_nf) {
      if (!BCCR_RlyCtlDiag_DW.DcPosStuckOpnDiag_MODE) {
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ex = false;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_kh = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_cr = 0.0F;
        BCCR_RlyCtlDiag_DW.DcPosStuckOpnDiag_MODE = true;
      }

      rtb_Constant14 = fabsf(BSPR_uDChrgVoltRaw - BSPR_uPackVoltRaw);
      rtb_Switch_nf = (BSPR_uPackVoltRaw > BCCR_uStuckOpnDiffHiThres_C);
      rtb_Compare_k3 = ((rtb_Constant14 < BCCR_uStuckOpnDiffThres_C) &&
                        rtb_Switch_nf);
      if (rtb_Compare_k3) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_go + fminf(BCCR_tiStuckOpnDChrgPosHeal_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_kh)) * (real32_T)rtb_Compare_k3;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_kh = rtb_Product_ga;
      rtb_Compare_k3 = (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ex || (rtb_Product_ga >
        BCCR_tiStuckOpnDChrgPosHeal_C));
      BCCR_bStuckOpnDChrgPosErrHeal = rtb_Compare_k3;
      BCCR_stDChrgCtrDiag = 2U;
      rtb_Switch_nf = ((rtb_Constant14 >= BCCR_uStuckOpnDiffLoThres_C) &&
                       rtb_Switch_nf);
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiStuckOpnDChrgPosErr_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_cr)) * (real32_T)rtb_Switch_nf;
      BCCR_bStuckOpnDChrgPosErrDet = (rtb_Constant14 >
        BCCR_tiStuckOpnDChrgPosErr_C);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_cr = rtb_Constant14;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ex = rtb_Compare_k3;
    } else {
      if (BCCR_RlyCtlDiag_DW.DcPosStuckOpnDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcPosStuckOpnDiag_MODE = false;
      }
    }
  } else {
    if (BCCR_RlyCtlDiag_DW.BCCR_DChrgCtrDiag_MODE) {
      if (BCCR_RlyCtlDiag_DW.DcPosStuckClsdDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcPosStuckClsdDiag_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DchrgNegVoltMax_MODE) {
        BCCR_RlyCtlDiag_DW.DchrgNegVoltMax_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DcNegStuckClsdDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcNegStuckClsdDiag_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DcNegStuckOpnDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcNegStuckOpnDiag_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DcPosStuckOpnDiag_MODE) {
        BCCR_RlyCtlDiag_DW.DcPosStuckOpnDiag_MODE = false;
      }

      BCCR_RlyCtlDiag_DW.BCCR_DChrgCtrDiag_MODE = false;
    }
  }

  if (BCCR_RlyCtlDiag_DW.is_active_c9_BCCR_RlyCtlDiag == 0U) {
    BCCR_RlyCtlDiag_DW.is_active_c9_BCCR_RlyCtlDiag = 1U;
    BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_Default_Stt;
    BCCR_stBmsDChrgCtrMode = 0U;
    BCCR_cntDChrgFault = 0U;
    BCCR_bDChrgFaultDet = false;
    BCCR_bDChrgFaultHeal = false;
    BCCR_bDChrgPosCtrSwtOn = false;
    BCCR_bDChrgNegCtrSwtOn = false;
  } else {
    switch (BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag) {
     case BCCR_RlyCtlD_IN_DChrgCtlEnd_Stt:
      if (BCMR_stDChrgCnntEdg || (rtb_Switch2_o && BCMR_bDChrgAbrtWait)) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDiag_IN_Default_Stt;
        BCCR_stBmsDChrgCtrMode = 0U;
        BCCR_cntDChrgFault = 0U;
        BCCR_bDChrgFaultDet = false;
        BCCR_bDChrgFaultHeal = false;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      }
      break;

     case BCCR_Rl_IN_DChrgCtlFaultEnd_Stt:
      break;

     case BCCR_RlyCt_IN_DChrgCtlFault_Stt:
      if (BCCR_cntDChrgFault >= BCCR_numPreChgCtlCnt_C) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_Rl_IN_DChrgCtlFaultEnd_Stt;
        BCCR_tiDChrgHld = 0.0F;
        BCCR_stBmsDChrgCtrMode = 4U;
        BCCR_bDChrgFaultDet = true;
        BCCR_bDChrgFaultHeal = false;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      } else if ((BCCR_cntDChrgFault < BCCR_numPreChgCtlCnt_C) &&
                 (BCCR_tiDChrgHld >= 0.1F)) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDia_IN_DChrgWait_Stt;
        BCCR_stBmsDChrgCtrMode = 1U;
        BCCR_bDChrgNegCtrSwtOn = true;
        BCCR_tiDChrgCtrWait = 0.0F;
      } else {
        BCCR_tiDChrgHld = BCCR_tiDChrgHld + 0.01F;
      }
      break;

     case BCCR__IN_DChrgCtrCnntCtlEnd_Stt:
      if ((BCCR_uBattDChrgVoltDiff <= BCCR_uDChrgVoltDiff_C) && (BCCR_tiDChrgHld
           >= BCCR_tiDChrgWrkSwtThres_C)) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDiag_IN_DChrgWrk_Stt;
        BCCR_stBmsDChrgCtrMode = 3U;
        BCCR_cntDChrgFault = 0U;
        BCCR_tiDChrgHld = 0.0F;
        BCCR_bDChrgFaultDet = false;
        BCCR_bDChrgFaultHeal = true;
      } else if (BCCR_tiDChrgHld > BCCR_tiDChrgHldThres_C) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCt_IN_DChrgCtlFault_Stt;
        BCCR_tiDChrgHld = 0.0F;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_stBmsDChrgCtrMode = 7U;
        tmp = (int32_T)(BCCR_cntDChrgFault + 1U);
        if ((uint32_T)tmp > 255U) {
          tmp = 255;
        }

        BCCR_cntDChrgFault = (uint8_T)tmp;
      } else {
        BCCR_tiDChrgHld = BCCR_tiDChrgHld + 0.01F;
      }
      break;

     case BCCR__IN_DChrgCtrDisConnCtl_Stt:
      if ((BSPR_uDChrgVoltRaw <= BCCR_uDChrgVoltLo_C) || (BCCR_tiDChrgCtrWait >
           BCCR_tiDChrgCtrWaitThres_C)) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlD_IN_DChrgCtlEnd_Stt;
        BCCR_stBmsDChrgCtrMode = 6U;
        BCCR_tiDChrgCtrWait = 0.0F;
        BCCR_tiDChrgHld = 0.0F;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      } else {
        BCCR_tiDChrgCtrWait = BCCR_tiDChrgCtrWait + 0.01F;
      }
      break;

     case BCCR_RlyCtlDia_IN_DChrgWait_Stt:
      if ((BCCR_RlyCtlDiag_DW.Delay7_DSTATE == 4) && BCCR_flgDChrgPwrUpReq &&
          BCCR_flgDChrgCtrCtrlEn && (BCCR_tiDChrgCtrWait >=
           BCCR_tiDChrgPwrUpThres_C)) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR__IN_DChrgCtrCnntCtlEnd_Stt;
        BCCR_tiDChrgCtrWait = 0.0F;
        BCCR_tiDChrgHld = 0.0F;
        BCCR_stBmsDChrgCtrMode = 2U;
        BCCR_bDChrgPosCtrSwtOn = true;
      } else if (BCCR_flgDChrgCtrCtrlEn && (!BCMR_stDChrgCnnt)) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDiag_IN_Default_Stt;
        BCCR_stBmsDChrgCtrMode = 0U;
        BCCR_cntDChrgFault = 0U;
        BCCR_bDChrgFaultDet = false;
        BCCR_bDChrgFaultHeal = false;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      } else if (!BCCR_flgDChrgCtrCtrlEn) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_Rl_IN_DChrgCtlFaultEnd_Stt;
        BCCR_tiDChrgHld = 0.0F;
        BCCR_stBmsDChrgCtrMode = 4U;
        BCCR_bDChrgFaultDet = true;
        BCCR_bDChrgFaultHeal = false;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      } else {
        BCCR_tiDChrgCtrWait = BCCR_tiDChrgCtrWait + 0.01F;
      }
      break;

     case BCCR_RlyCtlDiag_IN_DChrgWrk_Stt:
      if (BMCR_bDChrgPwrDwnReq) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR__IN_DChrgCtrDisConnCtl_Stt;
        BCCR_stBmsDChrgCtrMode = 5U;
        BCCR_tiDChrgCtrWait = 0.0F;
        BCCR_bDChrgPosCtrSwtOn = false;
      }
      break;

     case BCCR_RlyCtlDiag_IN_Default_Stt:
      if (COMR_stEol == 1) {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_EOL_Stt;
        BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCtlDiag_IN_EOL0_Stt;
        BCCR_stBmsDChrgCtrMode = 90U;
        BCCR_tiDChrgCtrWait = 0.0F;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      } else if (BCMR_stDChrgCnnt && (BCCR_RlyCtlDiag_DW.Delay7_DSTATE == 4) &&
                 BCCR_flgDChrgPwrUpReq && BCCR_flgDChrgCtrCtrlEn &&
                 (BCCR_bStuckClsdDChrgNegErrHeal || BCCR_bDchrgNegClsdHealSel_C)
                 && (BCCR_bStuckClsdDChrgPosErrHeal || (!BCCR_bDchrgDiagStdSel_C)))
      {
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDia_IN_DChrgWait_Stt;
        BCCR_stBmsDChrgCtrMode = 1U;
        BCCR_bDChrgNegCtrSwtOn = true;
        BCCR_tiDChrgCtrWait = 0.0F;
      } else {
        if (BCCR_flgDChrgPwrUpReq && (!BCCR_flgDChrgCtrCtrlEn)) {
          BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
            BCCR_Rl_IN_DChrgCtlFaultEnd_Stt;
          BCCR_tiDChrgHld = 0.0F;
          BCCR_stBmsDChrgCtrMode = 4U;
          BCCR_bDChrgFaultDet = true;
          BCCR_bDChrgFaultHeal = false;
          BCCR_bDChrgPosCtrSwtOn = false;
          BCCR_bDChrgNegCtrSwtOn = false;
        }
      }
      break;

     default:
      if (COMR_stEol == 0) {
        BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCt_IN_NO_ACTIVE_CHILD_g;
        BCCR_RlyCtlDiag_DW.is_c9_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDiag_IN_Default_Stt;
        BCCR_stBmsDChrgCtrMode = 0U;
        BCCR_cntDChrgFault = 0U;
        BCCR_bDChrgFaultDet = false;
        BCCR_bDChrgFaultHeal = false;
        BCCR_bDChrgPosCtrSwtOn = false;
        BCCR_bDChrgNegCtrSwtOn = false;
      } else {
        switch (BCCR_RlyCtlDiag_DW.is_EOL_Stt) {
         case BCCR_RlyCtlDiag_IN_EOL0_Stt:
          if (BCCR_flgDChrgPwrUpReq) {
            BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCtlDiag_IN_EOL1_Stt;
            BCCR_stBmsDChrgCtrMode = 91U;
            BCCR_bDChrgNegCtrSwtOn = true;
            BCCR_tiDChrgCtrWait = 0.0F;
          }
          break;

         case BCCR_RlyCtlDiag_IN_EOL1_Stt:
          if (BCCR_flgDChrgPwrUpReq && (BCCR_tiDChrgCtrWait >=
               BCCR_tiDChrgCtrWaitThres_C)) {
            BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCtlDiag_IN_EOL2_Stt;
            BCCR_stBmsDChrgCtrMode = 92U;
            BCCR_tiDChrgCtrWait = 0.0F;
            BCCR_bDChrgPosCtrSwtOn = true;
          } else if (BMCR_bDChrgPwrDwnReq) {
            BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCtlDiag_IN_EOL0_Stt;
            BCCR_stBmsDChrgCtrMode = 90U;
            BCCR_tiDChrgCtrWait = 0.0F;
            BCCR_bDChrgPosCtrSwtOn = false;
            BCCR_bDChrgNegCtrSwtOn = false;
          } else {
            BCCR_tiDChrgCtrWait = BCCR_tiDChrgCtrWait + 0.01F;
          }
          break;

         case BCCR_RlyCtlDiag_IN_EOL2_Stt:
          if (BMCR_bDChrgPwrDwnReq) {
            BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCtlDiag_IN_EOL3_Stt;
            BCCR_stBmsDChrgCtrMode = 93U;
            BCCR_tiDChrgCtrWait = 0.0F;
            BCCR_bDChrgPosCtrSwtOn = false;
          }
          break;

         default:
          if (BCCR_tiDChrgCtrWait > BCCR_tiDChrgCtrWaitThres_C) {
            BCCR_RlyCtlDiag_DW.is_EOL_Stt = BCCR_RlyCtlDiag_IN_EOL0_Stt;
            BCCR_stBmsDChrgCtrMode = 90U;
            BCCR_tiDChrgCtrWait = 0.0F;
            BCCR_bDChrgPosCtrSwtOn = false;
            BCCR_bDChrgNegCtrSwtOn = false;
          } else {
            BCCR_tiDChrgCtrWait = BCCR_tiDChrgCtrWait + 0.01F;
          }
          break;
        }
      }
      break;
    }
  }

  if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j3) {
    rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgPwrUpFail_ASW | 8U);
  } else if (BCCR_bDChrgFaultDet) {
    rtb_Switch4_fd = (uint8_T)(DFC_DChrgPwrUpFail_ASW | 152U);
  } else if (BCCR_bDChrgFaultHeal) {
    rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgPwrUpFail_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_dh;
  }

  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j3 = false;
  BCCR_RlyCtlDiag_DW.Delay3_DSTATE_dh = rtb_Switch4_fd;
  DFC_DChrgPwrUpFail_ASW = rtb_Switch4_fd;
  if (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_l && (!BCCR_bDChrgPosCtrSwtOn)) {
    rtb_Constant14 = 1.0F;
  } else {
    rtb_Constant14 = fmaxf(1.0F, BCCR_RlyCtlDiag_DW.Delay_DSTATE_a);
  }

  BCCR_RlyCtlDiag_DW.Delay_DSTATE_a = rtb_Constant14 - 1.0F;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_l = BCCR_bDChrgPosCtrSwtOn;
  if (BCCR_bDChrgPosCtrSwtOn) {
    BCCR_bDcChPosCtrHsdEna = true;
  } else {
    BCCR_bDcChPosCtrHsdEna = (rtb_Constant14 - 1.0F > 0.0F);
  }

  rtb_Constant14 = ((real32_T)BCCR_bDChrgPosCtrSwtOn + fminf(1.0F,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_du)) * (real32_T)BCCR_bDChrgPosCtrSwtOn;
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_du = rtb_Constant14;
  BCCR_dcDcChPosCtrLsdEna = (rtb_Constant14 > 1.0F);
  rtb_Switch2_o = (BCCR_bDChrgNegCtrSwtOn || BCCR_bDCNegCtrSwtOnReq_C);
  if (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_c && (!rtb_Switch2_o)) {
    rtb_Constant14 = 1.0F;
  } else {
    rtb_Constant14 = fmaxf(1.0F, BCCR_RlyCtlDiag_DW.Delay_DSTATE_nu);
  }

  BCCR_RlyCtlDiag_DW.Delay_DSTATE_nu = rtb_Constant14 - 1.0F;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_c = rtb_Switch2_o;
  if (rtb_Switch2_o) {
    BCCR_bDcChNegCtrHsdEna = true;
  } else {
    BCCR_bDcChNegCtrHsdEna = (rtb_Constant14 - 1.0F > 0.0F);
  }

  rtb_Constant14 = ((real32_T)rtb_Switch2_o + fminf(1.0F,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_oau)) * (real32_T)rtb_Switch2_o;
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_oau = rtb_Constant14;
  BCCR_dcDcChNegCtrLsdEna = (rtb_Constant14 > 1.0F);
  if (BCCR_stPwrUpCondHvil_C > 0) {
    rtb_Switch2_o = !(HVSR_flgHvilFault != 0);
  } else {
    rtb_Switch2_o = ((!((DFC_HvilSig_ASW & 16) == 16)) && (((DFC_HvilSig_ASW & 8) == 8) ||
      ((DFC_HvilMax_ASW & 8) == 8) || ((DFC_HvilMin_ASW & 8) == 8)));
  }

  rtb_Switch_nf = !COMR_bKl30cLowDet;
  if (rtb_Switch_nf) {
    rtb_Product_go = 0.01F;
  } else {
    rtb_Product_go = 0.0F;
  }

  rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiPwrUpCondLv_C,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_ke)) * (real32_T)rtb_Switch_nf;
  rtb_Switch_nf = (rtb_Constant14 > BCCR_tiPwrUpCondLv_C);
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_ke = rtb_Constant14;
  if (BCCR_bMnCtlHwSel_C) {
    if (BCCR_stPwrUpCondIso_C > 0) {
      rtb_Compare_lr = HVSR_flgIsoFault;
    } else {
      rtb_Compare_lr = ((DFC_IsoChkLv2_ASW & 16) == 16);
    }

    BCCR_flgPackCtrCtrlEna = ((BSPR_tCellTempMax <= BCCR_tBattTempCtrCtrlHi_C) &&
      (BSPR_tCellTempMin >= BCCR_tBattTempCtrCtrlLo_C) && (!BSER_flgCtrCtrlFault)
      && (rtb_Switch2_o && ((!rtb_Compare_lr) && (fabsf(BSPR_uSumVoltCell -
      BSPR_uBattVolt) <= BCCR_uBattCellVoltDiff_C) && rtb_Switch_nf)));
  } else {
    BCCR_flgPackCtrCtrlEna = (rtb_Switch2_o && rtb_Switch_nf);
  }

  BCCR_bkl15UpEdg = ((!BCCR_RlyCtlDiag_DW.Delay1_DSTATE_k) && BSPR_bKl15WkUp);
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_k = BSPR_bKl15WkUp;
  rtb_Switch2_o = ((fabsf(COMR_uMcuVolt - BSPR_uBattVolt) <= BCCR_uVoltDiff_C) &&
                   (fabsf(BSPR_uBattVolt - BSPR_uPackVoltRaw) <=
                    BCCR_uVoltDiff_C) && (fabsf(BSPR_uBattVolt - BSPR_uPackVolt)
    <= BCCR_uVoltDiff_C));
  if (rtb_Switch2_o) {
    rtb_Product_mj = 0.01F;
  } else {
    rtb_Product_mj = 0.0F;
  }

  rtb_Constant14 = (rtb_Product_mj + fminf(0.05F,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_n3)) * (real32_T)rtb_Switch2_o;
  BCCR_bVoffDiffPwrUpAvl = (rtb_Constant14 > 0.05F);
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_n3 = rtb_Constant14;
  BCCR_bVoffRisePwrUpAvl = (BSPR_uPackVolt > 0.3F * BSPR_uBattVolt);
  BCCR_flgPwrDwnReq = ((DSMR_stFaultRank == 4) || BMCR_bPwrDwnReq);
  BCCR_flgPwrUpReq = (BMCR_bPwrUpReq && (DSMR_stFaultRank != 3) &&
                      (DSMR_stFaultRank != 4));
  if (BCCR_bCtrStuckChkCond) {
    if (!BCCR_RlyCtlDiag_DW.DiagCalc_MODE) {
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_j0 = 0U;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_d = 0U;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_he = false;
      BCCR_RlyCtlDiag_DW.Delay4_DSTATE = false;
      BCCR_RlyCtlDiag_DW.DiagCalc_MODE = true;
    }

    if (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 31) {
      if (!BCCR_RlyCtlDiag_DW.DiagMode_31_MODE) {
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_f = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_c = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_o = false;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_g2 = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_oa = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_e0 = 0.0F;
        BCCR_RlyCtlDiag_DW.DiagMode_31_MODE = true;
      }

      rtb_Constant14 = 0.01F + fminf(BCCR_tiStuckClsdMnUpWait_C,
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_f);
      rtb_Switch2_o = (rtb_Constant14 < BCCR_tiStuckClsdMnUpWait_C);
      rtb_Compare_k3 = (rtb_Switch2_o || BCCR_flgPwrUpDiagEn_C);
      rtb_Product_ga = 0.01F + fminf(0.05F, BCCR_RlyCtlDiag_DW.Delay_DSTATE_g2);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_g2 = rtb_Product_ga;
      BCCR_bSw5CtrDiagSwt = (BCCR_bMnDiagHwSel_C && (rtb_Product_ga > 0.05F));
      BCCR_bStuckClsdMpPrFastErrDet = false;
      BCCR_bStuckClsdMpPrFastErrHeal = false;
      BCCR_RlyCtlDiag_B.MinMax1 = fmaxf(fmaxf(BCCR_RlyCtlDiag_DW.Delay3_DSTATE_c,
        BSPR_iBattCurr), BCCR_iBattCurrBgn);
      rtb_Switch_nf = (rtb_Compare_k3 && (BSPR_uPackVoltRaw >=
        BCCR_uPackPreRlyOk_C) && (BSPR_uNegVolt <= BCCR_uNegStuckClsdMnLo_C));
      rtb_Compare_k3 = (rtb_Compare_k3 && (BSPR_uNegVolt >=
        BCCR_uNegStuckClsdMnHi_C));
      if (rtb_Compare_k3) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_go + fminf(BCCR_tiStuckClsdMnUpOk_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_oa)) * (real32_T)rtb_Compare_k3;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_oa = rtb_Product_ga;
      BCCR_RlyCtlDiag_B.LogicalOperator3 = (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_o ||
        ((!rtb_Switch2_o) || (rtb_Product_ga > BCCR_tiStuckClsdMnUpOk_C)));
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_go + fminf(BCCR_tiStuckClsdMnUpDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_e0)) * (real32_T)rtb_Switch_nf;
      BCCR_RlyCtlDiag_B.RelationalOperator_l = (rtb_Product_ga >
        BCCR_tiStuckClsdMnUpDet_C);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_e0 = rtb_Product_ga;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_f = rtb_Constant14;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_c = BCCR_RlyCtlDiag_B.MinMax1;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_o = BCCR_RlyCtlDiag_B.LogicalOperator3;
    } else {
      if (BCCR_RlyCtlDiag_DW.DiagMode_31_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_31_MODE = false;
      }
    }

    BCCR_iBattCurrStgFrstMax = BCCR_RlyCtlDiag_B.MinMax1;
    if (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 0) {
      if (!BCCR_RlyCtlDiag_DW.DiagMode_0_MODE) {
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_d = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_l1 = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_iq = false;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_hl = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_pb = 0.0F;
        BCCR_RlyCtlDiag_DW.DiagMode_0_MODE = true;
      }

      BCCR_RlyCtlDiag_B.MinMax_i = fmaxf(BCCR_RlyCtlDiag_DW.Delay1_DSTATE_d,
        BSPR_iBattCurr);
      rtb_Product_ga = BSPR_uPackVoltRaw - BSPR_uBattVolt;
      rtb_Constant14 = fabsf(rtb_Product_ga);
      rtb_Product_ga = fmaxf(rtb_Product_ga, BCCR_RlyCtlDiag_DW.Delay_DSTATE_l1);
      rtb_Switch2_o = (rtb_Product_ga >= BCCR_uDiffMpPrDisable_C);
      rtb_Switch_nf = (BSPR_uBattVolt - BSPR_uPackVoltOpenRaw >=
                       BCCR_uDiffStuckClsdMpPrDet_C);
      rtb_Compare_k3 = ((rtb_Constant14 >= BCCR_uDiffStuckClsdMpPrHi_C) &&
                        rtb_Switch_nf);
      if (rtb_Compare_k3) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Product_go = (rtb_Product_go + fminf(BCCR_tiStuckClsdMpOk_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_hl)) * (real32_T)rtb_Compare_k3;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_hl = rtb_Product_go;
      if (rtb_Switch2_o) {
        rtb_Compare_k3 = BCCR_RlyCtlDiag_ConstB.DataTypeConversion_h;
      } else {
        rtb_Compare_k3 = (rtb_Product_go > BCCR_tiStuckClsdMpOk_C);
      }

      BCCR_RlyCtlDiag_B.LogicalOperator_o = (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_iq
        || rtb_Compare_k3);
      rtb_Switch_nf = ((rtb_Constant14 <= BCCR_uDiffStuckClsdMpPrLo_C) &&
                       rtb_Switch_nf);
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiStuckClsdPosFrstDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_pb)) * (real32_T)rtb_Switch_nf;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_pb = rtb_Constant14;
      if (rtb_Switch2_o) {
        BCCR_RlyCtlDiag_B.Switch1 = BCCR_RlyCtlDiag_ConstB.DataTypeConversion1_n;
      } else {
        BCCR_RlyCtlDiag_B.Switch1 = (rtb_Constant14 >
          BCCR_tiStuckClsdPosFrstDet_C);
      }

      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_d = BCCR_RlyCtlDiag_B.MinMax_i;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_l1 = rtb_Product_ga;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_iq = BCCR_RlyCtlDiag_B.LogicalOperator_o;
    } else {
      if (BCCR_RlyCtlDiag_DW.DiagMode_0_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_0_MODE = false;
      }
    }

    BCCR_iBattCurrBgn = BCCR_RlyCtlDiag_B.MinMax_i;
    if ((BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 33) ||
        (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 34)) {
      if (!BCCR_RlyCtlDiag_DW.DiagMode_33_34_MODE) {
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_j = 0.0F;
        BCCR_RlyCtlDiag_DW.DiagMode_33_34_MODE = true;
      }

      BCCR_bSw5CtrDiagSwt = false;
      BCCR_RlyCtlDiag_B.MinMax = fmaxf(BCCR_RlyCtlDiag_DW.Delay1_DSTATE_j,
        BSPR_uPackVoltRaw);
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_j = BCCR_RlyCtlDiag_B.MinMax;
    } else {
      if (BCCR_RlyCtlDiag_DW.DiagMode_33_34_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_33_34_MODE = false;
      }
    }

    BCCR_uPackVoltHopMax = BCCR_RlyCtlDiag_B.MinMax;
    if (BCCR_bMnDiagHwSel_C) {
      rtb_Switch2_o = (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 32);
    } else {
      rtb_Switch2_o = (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 31);
    }

    if (rtb_Switch2_o && (BCCR_RlyCtlDiag_PrevZCX.SglProc2_Trig_ZCE != POS_ZCSIG))
    {
      BCCR_RlyCtlDiag_B.BSPR_uPackVoltRaw_l = BSPR_uPackVoltRaw;
      BCCR_RlyCtlDiag_B.BCCR_iBattCurrPreChLoThres_CU_b = look1_iflf_binlxpw
        (BSPR_uBattVolt - BCCR_RlyCtlDiag_B.BSPR_uPackVoltRaw_l, ((const
           real32_T *)&(BCCR_iBattCurrPreChLoThres_CUR_X[0])), ((const real32_T *)
          &(BCCR_iBattCurrPreChLoThres_CUR[0])), 7U);
    }

    BCCR_RlyCtlDiag_PrevZCX.SglProc2_Trig_ZCE = rtb_Switch2_o;
    BCCR_iBattCurrPreChLoThres =
      BCCR_RlyCtlDiag_B.BCCR_iBattCurrPreChLoThres_CU_b;
    if (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 32) {
      if (!BCCR_RlyCtlDiag_DW.SglProc1_MODE) {
        BCCR_RlyCtlDiag_DW.Delay5_DSTATE = 0.0F;
        BCCR_RlyCtlDiag_DW.SglProc1_MODE = true;
      }

      BCCR_RlyCtlDiag_B.MinMax3 = fmaxf(BSPR_iBattCurr,
        BCCR_RlyCtlDiag_DW.Delay5_DSTATE);
      BCCR_RlyCtlDiag_DW.Delay5_DSTATE = BCCR_RlyCtlDiag_B.MinMax3;
    } else {
      if (BCCR_RlyCtlDiag_DW.SglProc1_MODE) {
        BCCR_RlyCtlDiag_DW.SglProc1_MODE = false;
      }
    }

    BSPR_iBattCurrPreChMax = BCCR_RlyCtlDiag_B.MinMax3;
    BCCR_uPackVoltStgFrstBgn = BCCR_RlyCtlDiag_B.BSPR_uPackVoltRaw_l;
    rtb_Switch2_o = (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 32);
    if ((!rtb_Switch2_o) && (BCCR_RlyCtlDiag_PrevZCX.StuckOpnDiag_Trig_ZCE !=
         ZERO_ZCSIG)) {
      rtb_Constant14 = BSPR_uPackVoltRaw - BCCR_uPackVoltStgFrstBgn;
      rtb_Switch_nf = (BCCR_uPackVoltStgFrstBgn < BCCR_uPackBgnThres_C);
      BCCR_RlyCtlDiag_B.LogicalOperator_ho =
        (BCCR_RlyCtlDiag_DW.Delay3_DSTATE_he || ((rtb_Constant14 >=
           BCCR_uPackDeltRiseHi_C) && rtb_Switch_nf));
      BCCR_RlyCtlDiag_B.LogicalOperator4 = (BCCR_RlyCtlDiag_DW.Delay4_DSTATE ||
        ((BSPR_uNegVolt < BCCR_uNegStuckClsdMnLo_C) || (BSPR_iBattCurrPreChMax >
        BCCR_iCurrStuckOpnMnHi_C)));
      BCCR_cntStuckOpnMnErr = (uint8_T)((uint32_T)((BSPR_iBattCurrPreChMax <
        BCCR_iCurrStuckOpnMnLo_C) && (BSPR_uNegVolt > BCCR_uNegStuckClsdMnHi_C))
        + BCCR_RlyCtlDiag_DW.Delay1_DSTATE_j0);
      BCCR_RlyCtlDiag_B.RelationalOperator10 = (BCCR_cntStuckOpnMnErr >=
        BCCR_numPreChgDiagCnt_C);
      BCCR_cntStuckOpnPrErr = (uint8_T)((uint32_T)((rtb_Constant14 <
        BCCR_uPackDeltRiseLo_C) && rtb_Switch_nf && (BSPR_iBattCurrPreChMax -
        BCCR_iBattCurrStgFrstMax < BCCR_iBattCurrPreChLoThres)) +
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_d);
      BCCR_RlyCtlDiag_B.RelationalOperator2 = (BCCR_cntStuckOpnPrErr >=
        BCCR_numPreChgDiagCnt_C);
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_j0 = BCCR_cntStuckOpnMnErr;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_d = BCCR_cntStuckOpnPrErr;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_he = BCCR_RlyCtlDiag_B.LogicalOperator_ho;
      BCCR_RlyCtlDiag_DW.Delay4_DSTATE = BCCR_RlyCtlDiag_B.LogicalOperator4;
    }

    BCCR_RlyCtlDiag_PrevZCX.StuckOpnDiag_Trig_ZCE = rtb_Switch2_o;
    if ((BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 17) ||
        (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 1)) {
      BCCR_bSw5CtrDiagSwt = false;
    }

    rtb_Switch2_o = (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 5);
    if (rtb_Switch2_o && (BCCR_RlyCtlDiag_PrevZCX.DiagMode_5_Trig_ZCE !=
                          POS_ZCSIG)) {
      BCCR_bSw5CtrDiagSwt = BCCR_bMnDiagHwSel_C;
    }

    BCCR_RlyCtlDiag_PrevZCX.DiagMode_5_Trig_ZCE = rtb_Switch2_o;
    if ((BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 6) ||
        (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 14)) {
      if (!BCCR_RlyCtlDiag_DW.DiagMode_6_MODE) {
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_h = 0.0F;
        BCCR_RlyCtlDiag_DW.DiagMode_6_MODE = true;
      }

      rtb_Constant14 = fminf(BCCR_RlyCtlDiag_DW.Delay1_DSTATE_h,
        BSPR_uPackVoltRaw);
      BSPR_uPackVoltOpenRaw = rtb_Constant14;
      BSPR_uPackVoltRawEnd = rtb_Constant14;
      BCCR_bSw5CtrDiagSwt = false;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_h = rtb_Constant14;
    } else {
      if (BCCR_RlyCtlDiag_DW.DiagMode_6_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_6_MODE = false;
      }
    }

    if (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 4) {
      if (!BCCR_RlyCtlDiag_DW.DiagMode_4_MODE) {
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_nn = 0.0F;
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS,
          &BCCR_RlyCtlDiag_DW.sf_RS);
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_io = 0.0F;
        BCCR_RlyCtlDiag_DW.DiagMode_4_MODE = true;
      }

      BCCR_stMainCtrDisConn = 0U;
      rtb_Product_ga = fabsf(BSPR_uBattVolt - BSPR_uPackVoltRaw);
      rtb_Constant14 = 0.01F + fminf(BCCR_tiStuckOpnMpWait_C,
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j);
      rtb_Switch2_o = (rtb_Constant14 < BCCR_tiStuckOpnMpWait_C);
      rtb_Switch_nf = ((rtb_Product_ga < BCCR_uDiffStuckOpnMpOk_C) &&
                       rtb_Switch2_o);
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Product_go = (rtb_Product_go + fminf(BCCR_tiStuckOpnMpOk_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_nn)) * (real32_T)rtb_Switch_nf;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_nn = rtb_Product_go;
      rtb_Switch_nf = (fabsf(BSPR_iBattCurr) < BCCR_iCurrStuckOpnMpLo_C);
      BCCR_RlyCtlDiag_B.LogicalOperator1 = ((rtb_Product_go >
        BCCR_tiStuckOpnMpOk_C) || (!rtb_Switch_nf));
      rtb_Switch2_o = ((fabsf(BCCR_uPackVoltHopMax - BSPR_uPackVoltRaw) >
                        BCCR_uDiffStuckOpnMpErr_C) && (rtb_Product_ga >
        BCCR_uDiffStuckOpnMpErr_C) && rtb_Switch_nf && rtb_Switch2_o);
      BCCR_RlyCtlDiag_RS(BCCR_RlyCtlDiag_B.LogicalOperator1, false,
                         &BCCR_RlyCtlDiag_B.sf_RS, &BCCR_RlyCtlDiag_DW.sf_RS);
      if (rtb_Switch2_o) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiStuckOpnMpErr_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_io)) * (real32_T)rtb_Switch2_o;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_io = rtb_Product_ga;
      BCCR_RlyCtlDiag_B.Switch = ((!BCCR_RlyCtlDiag_B.sf_RS.Q) &&
        (rtb_Product_ga > BCCR_tiStuckOpnMpErr_C));
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j = rtb_Constant14;
    } else {
      if (BCCR_RlyCtlDiag_DW.DiagMode_4_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_4_MODE = false;
      }
    }

    if (BCCR_RlyCtlDiag_DW.Delay8_DSTATE == 7) {
      if (!BCCR_RlyCtlDiag_DW.DiagMode_7_MODE) {
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_hu = false;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_c = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_nw = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_he = 0.0F;
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS_j,
          &BCCR_RlyCtlDiag_DW.sf_RS_j);
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_ep = 0.0F;
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS_i,
          &BCCR_RlyCtlDiag_DW.sf_RS_i);
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS_a,
          &BCCR_RlyCtlDiag_DW.sf_RS_a);
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS_i2,
          &BCCR_RlyCtlDiag_DW.sf_RS_i2);
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS_n,
          &BCCR_RlyCtlDiag_DW.sf_RS_n);
        BCCR_RlyCtlDiag_RS_Reset(&BCCR_RlyCtlDiag_B.sf_RS_k,
          &BCCR_RlyCtlDiag_DW.sf_RS_k);
        BCCR_RlyCtlDiag_DW.DiagMode_7_MODE = true;
      }

      rtb_Constant14 = 0.01F + fminf(BCCR_tiStuckClsdMnWait_C,
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE);
      rtb_Switch2_o = (rtb_Constant14 < BCCR_tiStuckClsdMnWait_C);
      rtb_Switch_nf = (rtb_Switch2_o && (BSPR_uNegVolt <=
        BCCR_uNegStuckClsdMnLo_C));
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      BCCR_RlyCtlDiag_DW.Delay_DSTATE_nw = (rtb_Product_go + fminf
        (BCCR_tiStuckClsdMnDet_C, BCCR_RlyCtlDiag_DW.Delay_DSTATE_nw)) *
        (real32_T)rtb_Switch_nf;
      BCCR_RlyCtlDiag_B.LogicalOperator = false;
      rtb_Product_ga = fabsf(BCCR_tiStuckClsdMnOk_C - 0.1F);
      rtb_Product_go = 0.01F + fminf(rtb_Product_ga,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_he);
      rtb_Switch_nf = (rtb_Product_go > rtb_Product_ga);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_he = rtb_Product_go;
      BCCR_RlyCtlDiag_B.LogicalOperator10 = (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_hu
        || rtb_Switch_nf);
      BCCR_RlyCtlDiag_RS((!BCCR_RlyCtlDiag_B.LogicalOperator) &&
                         BCCR_RlyCtlDiag_B.LogicalOperator10, false,
                         &BCCR_RlyCtlDiag_B.sf_RS_j, &BCCR_RlyCtlDiag_DW.sf_RS_j);
      rtb_Switch_nf = (rtb_Switch_nf || (!rtb_Switch2_o));
      rtb_Product_ga = 0.01F + fminf(BCCR_tiStuckClsdPosWait_C,
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_c);
      rtb_Switch2_o = (rtb_Product_ga < BCCR_tiStuckClsdPosWait_C);
      rtb_Compare_k3 = (COMR_uMcuVolt + BCCR_uDiffStuckClsdMcuBatt_C >=
                        BSPR_uBattVolt);
      rtb_Compare_lr = (rtb_Switch2_o && rtb_Compare_k3 && (fabsf(BSPR_uBattVolt
        - BSPR_uPackVoltRaw) >= BCCR_uPackDiffDecrHi_C) &&
                        (BCCR_cntStuckClsdPosFastDiag_CW == 1));
      if (rtb_Compare_lr) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Product_go = (rtb_Product_mj + fminf(BCCR_tiStuckClsdPosFastOk_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_ep)) * (real32_T)rtb_Compare_lr;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_ep = rtb_Product_go;
      BCCR_RlyCtlDiag_RS(rtb_Product_go > BCCR_tiStuckClsdPosFastOk_C, false,
                         &BCCR_RlyCtlDiag_B.sf_RS_i, &BCCR_RlyCtlDiag_DW.sf_RS_i);
      rtb_Compare_k3 = ((!rtb_Switch2_o) || (!rtb_Compare_k3) ||
                        BCCR_RlyCtlDiag_B.sf_RS_i.Q);
      BCCR_RlyCtlDiag_RS(rtb_Switch_nf && rtb_Compare_k3, false,
                         &BCCR_RlyCtlDiag_B.sf_RS_a, &BCCR_RlyCtlDiag_DW.sf_RS_a);
      rtb_Switch_nf = BCCR_RlyCtlDiag_B.sf_RS_a.Q;
      BCCR_bStuckClsdPosDiagAct = (BCCR_RlyCtlDiag_B.sf_RS_a.Q &&
        (rtb_Compare_k3 && (!BCCR_RlyCtlDiag_B.sf_RS_i.Q)));
      if (BCCR_bStuckClsdPosDiagAct) {
        if (!BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE) {
          BCCR_RlyCtlDiag_DW.Delay1_DSTATE_ez = false;
          BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e = 0.0F;
          BCCR_RlyCtlDiag_DW.Delay_DSTATE_o2 = 0.0F;
          BCCR_RlyCtlDiag_DW.Delay_DSTATE_p2 = 0.0F;
          BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE = true;
        }

        BSPR_uPackVoltOpenRaw = BSPR_uPackVoltRaw;
        BSPR_uPackVoltRawEnd = BSPR_uPackVoltRaw;
        rtb_Product_go = 0.01F + fminf(BCCR_tiStuckClsdWait_C,
          BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e);
        rtb_Switch2_o = (rtb_Product_go < BCCR_tiStuckClsdWait_C);
        if (BCCR_bMnDiagHwSel_C) {
          rtb_Compare_k3 = !BCCR_bSw5CtrDiagSwt;
        } else {
          rtb_Compare_k3 = true;
        }

        rtb_Compare_lr = (rtb_Compare_k3 && rtb_Switch2_o && (fabsf
          (BSPR_uBattVolt - BSPR_uPackVoltRaw) >= BCCR_uPackDiffDecrHi_C));
        if (rtb_Compare_lr) {
          rtb_Product_mj = 0.01F;
        } else {
          rtb_Product_mj = 0.0F;
        }

        rtb_Product_mj = (rtb_Product_mj + fminf(BCCR_tiStuckClsdPosScndOk_C,
          BCCR_RlyCtlDiag_DW.Delay_DSTATE_o2)) * (real32_T)rtb_Compare_lr;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_o2 = rtb_Product_mj;
        BCCR_RlyCtlDiag_B.LogicalOperator_h =
          (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_ez || (!rtb_Switch2_o) ||
           (rtb_Product_mj > BCCR_tiStuckClsdPosScndOk_C));
        rtb_Switch2_o = (rtb_Compare_k3 && rtb_Switch2_o && (fabsf
          (BSPR_uBattVolt - BSPR_uPackVoltRaw) <= BCCR_uPackDiffDecrLo_C));
        if (rtb_Switch2_o) {
          rtb_Product_mj = 0.01F;
        } else {
          rtb_Product_mj = 0.0F;
        }

        rtb_Product_mj = (rtb_Product_mj + fminf(BCCR_tiStuckClsdPosScndErr_C,
          BCCR_RlyCtlDiag_DW.Delay_DSTATE_p2)) * (real32_T)rtb_Switch2_o;
        BCCR_RlyCtlDiag_B.RelationalOperator_n = (rtb_Product_mj >
          BCCR_tiStuckClsdPosScndErr_C);
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_p2 = rtb_Product_mj;
        BCCR_RlyCtlDiag_DW.Delay1_DSTATE_ez =
          BCCR_RlyCtlDiag_B.LogicalOperator_h;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e = rtb_Product_go;
      } else {
        if (BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE) {
          BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE = false;
        }
      }

      rtb_Compare_k3 = (BCCR_bStuckClsdMpPrFastErrDet ||
                        BCCR_RlyCtlDiag_B.RelationalOperator_n);
      rtb_Switch2_o = (BCCR_bStuckClsdMpPrFastErrHeal ||
                       BCCR_RlyCtlDiag_B.LogicalOperator_h);
      BCCR_RlyCtlDiag_RS((!rtb_Compare_k3) && rtb_Switch2_o, false,
                         &BCCR_RlyCtlDiag_B.sf_RS_i2,
                         &BCCR_RlyCtlDiag_DW.sf_RS_i2);
      rtb_Compare_lr = (BCCR_RlyCtlDiag_B.sf_RS_j.Q &&
                        BCCR_RlyCtlDiag_B.sf_RS_i2.Q);
      BCCR_RlyCtlDiag_RS(BCCR_RlyCtlDiag_B.LogicalOperator &&
                         (!BCCR_RlyCtlDiag_B.LogicalOperator10), false,
                         &BCCR_RlyCtlDiag_B.sf_RS_n, &BCCR_RlyCtlDiag_DW.sf_RS_n);
      BCCR_RlyCtlDiag_RS(rtb_Compare_k3 && (!rtb_Switch2_o), false,
                         &BCCR_RlyCtlDiag_B.sf_RS_k, &BCCR_RlyCtlDiag_DW.sf_RS_k);
      if (rtb_Compare_lr) {
        BCCR_stMainCtrDisConn = 2U;
      } else if (((!BCCR_RlyCtlDiag_B.sf_RS_j.Q) && BCCR_RlyCtlDiag_B.sf_RS_i2.Q)
                 || (BCCR_RlyCtlDiag_B.sf_RS_j.Q &&
                     (!BCCR_RlyCtlDiag_B.sf_RS_i2.Q))) {
        BCCR_stMainCtrDisConn = 1U;
      } else if (BCCR_RlyCtlDiag_B.sf_RS_n.Q && BCCR_RlyCtlDiag_B.sf_RS_k.Q) {
        BCCR_stMainCtrDisConn = 3U;
      } else {
        BCCR_stMainCtrDisConn = 0U;
      }

      BCCR_bStuckClsdMpPrFastErrHeal = BCCR_RlyCtlDiag_B.sf_RS_i.Q;
      BCCR_bStuckClsdMpPrFastErrDet = BCCR_RlyCtlDiag_B.sf_RS_i.nQ;
      if (BCCR_bMnDiagHwSel_C) {
        BCCR_bSw5CtrDiagSwt = !rtb_Switch_nf;
      } else {
        BCCR_bSw5CtrDiagSwt = false;
      }

      BCCR_RlyCtlDiag_B.OutportBufferForBCCR_bStuckClsd =
        BCCR_RlyCtlDiag_B.RelationalOperator_n;
      BCCR_RlyCtlDiag_B.OutportBufferForBCCR_bStuckCl_j =
        BCCR_RlyCtlDiag_B.LogicalOperator_h;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE = rtb_Constant14;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_hu = BCCR_RlyCtlDiag_B.LogicalOperator10;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_c = rtb_Product_ga;
    } else {
      if (BCCR_RlyCtlDiag_DW.DiagMode_7_MODE) {
        if (BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE) {
          BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE = false;
        }

        BCCR_RlyCtlDiag_DW.DiagMode_7_MODE = false;
      }
    }

    BCCR_bStuckClsdMnStgFrstErrDet = BCCR_RlyCtlDiag_B.RelationalOperator_l;
    BCCR_bStuckClsdMnStgFrstErrHeal = BCCR_RlyCtlDiag_B.LogicalOperator3;
    BCCR_bStuckClsdMnStgScndErrDet = BCCR_RlyCtlDiag_B.LogicalOperator;
    BCCR_bStuckClsdMnStgScndErrHeal = BCCR_RlyCtlDiag_B.LogicalOperator10;
    BCCR_bStuckClsdMpPrStgFrstErrDet = BCCR_RlyCtlDiag_B.Switch1;
    BCCR_bStuckClsdMpPrStgFrstErrHeal = BCCR_RlyCtlDiag_B.LogicalOperator_o;
    BCCR_bStuckClsdMpPrStgScndErrDet =
      BCCR_RlyCtlDiag_B.OutportBufferForBCCR_bStuckClsd;
    BCCR_bStuckClsdMpPrStgScndErrHeal =
      BCCR_RlyCtlDiag_B.OutportBufferForBCCR_bStuckCl_j;
    BCCR_bStuckOpnMnErrDet = BCCR_RlyCtlDiag_B.RelationalOperator10;
    BCCR_bStuckOpnMnErrHeal = BCCR_RlyCtlDiag_B.LogicalOperator4;
    BCCR_bStuckOpnMpErrDet = BCCR_RlyCtlDiag_B.Switch;
    BCCR_bStuckOpnMpErrHeal = BCCR_RlyCtlDiag_B.LogicalOperator1;
    BCCR_bStuckOpnPrErrDet = BCCR_RlyCtlDiag_B.RelationalOperator2;
    BCCR_bStuckOpnPrErrHeal = BCCR_RlyCtlDiag_B.LogicalOperator_ho;
  } else {
    if (BCCR_RlyCtlDiag_DW.DiagCalc_MODE) {
      if (BCCR_RlyCtlDiag_DW.DiagMode_31_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_31_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DiagMode_0_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_0_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DiagMode_33_34_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_33_34_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.SglProc1_MODE) {
        BCCR_RlyCtlDiag_DW.SglProc1_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DiagMode_6_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_6_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DiagMode_4_MODE) {
        BCCR_RlyCtlDiag_DW.DiagMode_4_MODE = false;
      }

      if (BCCR_RlyCtlDiag_DW.DiagMode_7_MODE) {
        if (BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE) {
          BCCR_RlyCtlDiag_DW.DiagMode_7_MpPrStuckClsd_MODE = false;
        }

        BCCR_RlyCtlDiag_DW.DiagMode_7_MODE = false;
      }

      BCCR_RlyCtlDiag_DW.DiagCalc_MODE = false;
    }
  }

  if (BCCR_RlyCtlDiag_DW.is_active_c3_BCCR_RlyCtlDiag == 0U) {
    BCCR_RlyCtlDiag_DW.is_active_c3_BCCR_RlyCtlDiag = 1U;
    BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_Ini_Stt;
    BCCR_stBmsCtrMode = 90U;
    BCCR_stMainCtrDiagMode = 90U;
    BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
  } else {
    switch (BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag) {
     case BCCR_RlyCtlDia_IN_Default_Stt_e:
      if (BCCR_flgPwrUpReq && BCCR_bStuckClsdMpPrStgFrstErrHeal) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_Wait_Stt;
        BCCR_stBmsCtrMode = 1U;
        BCCR_stMainCtrDiagMode = 1U;
        BCCR_stPreChRslt = 0U;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
      }
      break;

     case BCCR_RlyCtlDiag_IN_HvOn_Stt:
      if (BCCR_flgPwrDwnReq && (!BCCR_flgPwrUpReq)) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDi_IN_PwrDwnStrt_Stt;
        BCCR_stBmsCtrMode = 5U;
        BCCR_stMainCtrDiagMode = 5U;
        BCCR_RlyCtlDiag_DW.BCCR_tiMNegCtrSwtOffWait = 0.0F;
        BCCR_RlyCtlDiag_DW.BCCR_tiIsoCheckStaus = 0.0F;
        if (BCCR_RlyCtlDiag_DW.BCCR_tiIsoCheckStaus >= BCCR_tiIsoCheckStaus_C) {
          BCCR_bMPosCtrSwtOn = false;
        } else {
          BCCR_RlyCtlDiag_DW.BCCR_tiIsoCheckStaus += 0.01F;
        }

        if (!BCCR_bMPosCtrSwtOn) {
          BCCR_RlyCtlDiag_DW.BCCR_tiMNegCtrSwtOffWait += 0.01F;
        }
      }
      break;

     case BCCR_RlyCtlDiag_IN_Ini_Stt:
      if (BCCR_RlyCtlDiag_DW.BCCR_tiIniHld >= BCCR_tiIniHldMax_C) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDia_IN_Default_Stt_e;
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
        BCCR_stBmsCtrMode = 0U;
        BCCR_stMainCtrDiagMode = 0U;
        BCCR_cntPreChFault = 0U;
        BCCR_stPreChRslt = 0U;
      } else {
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld += 0.01F;
      }
      break;

     case BCCR_RlyCtl_IN_PreChargeEnd_Stt:
      BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_HvOn_Stt;
      BCCR_stBmsCtrMode = 4U;
      BCCR_stMainCtrDiagMode = 4U;
      BCCR_bPreChargeFaultDet = false;
      BCCR_bPreChargeFaultHeal = true;
      break;

     case BCCR_RlyC_IN_PreChargeFault_Stt:
      if (BCCR_cntPreChFault >= BCCR_numPreChgCtlCnt_C) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCt_IN_PwrUpDwnAbort_Stt;
        enter_atomic_PwrUpDwnAbort_Stt();
      } else if ((BCCR_cntPreChFault < 3) && (BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld
                  >= 2.5F)) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_Wait_Stt;
        BCCR_stBmsCtrMode = 1U;
        BCCR_stMainCtrDiagMode = 1U;
        BCCR_stPreChRslt = 0U;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
      } else {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld += 0.01F;
      }
      break;

     case BCCR_RlyCt_IN_PreChargeHld1_Stt:
      if (BCCR_bVoffDiffPwrUpAvl && (BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld >
           BCCR_tiVoffRisePwrUpPass_C)) {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld += 0.01F;
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCt_IN_PreChargeHld2_Stt;
        BCCR_stBmsCtrMode = 3U;
        BCCR_stMainCtrDiagMode = 33U;
        BCCR_bMPosCtrSwtOn = true;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait = 0.0F;
      } else if (((BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld >
                   BCCR_tiVoffRisePwrUpAvl_C) && (!BCCR_bVoffRisePwrUpAvl)) ||
                 (BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld > BCCR_tiPreChMax_C) ||
                 ((BCCR_jPreChgResEnrg > BCCR_wPreChgResEnrgLmt_C) &&
                  BCCR_flgPreChgEnrgDiagEn_C)) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyC_IN_PreChargeFault_Stt;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
        BCCR_stBmsCtrMode = 6U;
        BCCR_stMainCtrDiagMode = 6U;
        tmp = (int32_T)(BCCR_cntPreChFault + 1U);
        if ((uint32_T)tmp > 255U) {
          tmp = 255;
        }

        BCCR_cntPreChFault = (uint8_T)tmp;
      } else {
        BCCR_jPreChgResEnrgCycl = BSPR_iBattCurr * BSPR_iBattCurr * 0.01F;
        BCCR_jPreChgResEnrg = BCCR_jPreChgResEnrg + BCCR_jPreChgResEnrgCycl;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld += 0.01F;
      }
      break;

     case BCCR_RlyCt_IN_PreChargeHld2_Stt:
      if (BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait >
          BCCR_tiPreChCtrSwtOffWaitThres_C) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCtl_IN_PreChargeEnd_Stt;
        BCCR_stBmsCtrMode = 3U;
        BCCR_stMainCtrDiagMode = 34U;
        BCCR_cntPreChFault = 0U;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait = 0.0F;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_stPreChRslt = 1U;
      } else {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait += 0.01F;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld += 0.01F;
      }
      break;

     case BCCR_RlyCt_IN_PreChargeStrt_Stt:
      if ((BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait >=
           BCCR_tiPreChCtrSwtOnWaitThres_C) && BCCR_bStuckClsdMnStgFrstErrHeal)
      {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCt_IN_PreChargeHld1_Stt;
        BCCR_stBmsCtrMode = 3U;
        BCCR_stMainCtrDiagMode = 32U;
        BCCR_jPreChgResEnrgCycl = 0.0F;
        BCCR_jPreChgResEnrg = 0.0F;
        if (BCCR_bMnCtlHwSel_C) {
          BCCR_bPreChCtrSwtOn = true;
        } else {
          BCCR_bMNegCtrSwtOn = true;
        }
      } else if (!BCCR_flgPwrUpReq) {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDia_IN_PwrOnAbrt_Stt;
        BCCR_stBmsCtrMode = 17U;
        BCCR_stMainCtrDiagMode = 17U;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
      } else if (BCCR_bStuckClsdMnStgFrstErrDet) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyC_IN_PreChargeFault_Stt;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
        BCCR_stBmsCtrMode = 6U;
        BCCR_stMainCtrDiagMode = 6U;
        tmp = (int32_T)(BCCR_cntPreChFault + 1U);
        if ((uint32_T)tmp > 255U) {
          tmp = 255;
        }

        BCCR_cntPreChFault = (uint8_T)tmp;
      } else {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld += 0.01F;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait += 0.01F;
      }
      break;

     case BCCR_RlyCtlDia_IN_PwrDwnEnd_Stt:
      BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlD_IN_PwrUpDwnEnd_Stt;
      BCCR_bMPosCtrSwtOn = false;
      BCCR_bMNegCtrSwtOn = false;
      BCCR_bPreChCtrSwtOn = false;
      BCCR_stBmsCtrMode = 7U;
      BCCR_stMainCtrDiagMode = 7U;
      break;

     case BCCR_RlyCtlDi_IN_PwrDwnStrt_Stt:
      if (BCCR_RlyCtlDiag_DW.BCCR_tiMNegCtrSwtOffWait >=
          BCCR_tiMNegCtrSwtOffWaitThres_C) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDia_IN_PwrDwnEnd_Stt;
        BCCR_stBmsCtrMode = 7U;
        BCCR_stMainCtrDiagMode = 7U;
        BCCR_bMNegCtrSwtOn = false;
      } else {
        if (BCCR_RlyCtlDiag_DW.BCCR_tiIsoCheckStaus >= BCCR_tiIsoCheckStaus_C) {
          BCCR_bMPosCtrSwtOn = false;
        } else {
          BCCR_RlyCtlDiag_DW.BCCR_tiIsoCheckStaus += 0.01F;
        }

        if (!BCCR_bMPosCtrSwtOn) {
          BCCR_RlyCtlDiag_DW.BCCR_tiMNegCtrSwtOffWait += 0.01F;
        }
      }
      break;

     case BCCR_RlyCtlDia_IN_PwrOnAbrt_Stt:
      if (BCCR_flgPwrUpReq) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_Wait_Stt;
        BCCR_stBmsCtrMode = 1U;
        BCCR_stMainCtrDiagMode = 1U;
        BCCR_stPreChRslt = 0U;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
      }
      break;

     case BCCR_RlyCt_IN_PwrUpDwnAbort_Stt:
      break;

     case BCCR_RlyCtlD_IN_PwrUpDwnEnd_Stt:
      if (BCCR_flgPwrUpReq) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag = BCCR_RlyCtlDiag_IN_Wait_Stt;
        BCCR_stBmsCtrMode = 1U;
        BCCR_stMainCtrDiagMode = 1U;
        BCCR_stPreChRslt = 0U;
        BCCR_bMPosCtrSwtOn = false;
        BCCR_bMNegCtrSwtOn = false;
        BCCR_bPreChCtrSwtOn = false;
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
      } else if (BCCR_bkl15UpEdg && (!BCCR_flgPwrUpReq)) {
        BCCR_RlyCtlDiag_DW.is_c3_BCCR_RlyCtlDiag =
          BCCR_RlyCtlDia_IN_Default_Stt_e;
        BCCR_RlyCtlDiag_DW.BCCR_tiIniHld = 0.0F;
        BCCR_stBmsCtrMode = 0U;
        BCCR_stMainCtrDiagMode = 0U;
        BCCR_cntPreChFault = 0U;
        BCCR_stPreChRslt = 0U;
      } else {
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChHld = 0.0F;
        BCCR_RlyCtlDiag_DW.BCCR_tiPreChCtrWait = 0.0F;
        BCCR_RlyCtlDiag_DW.BCCR_tiMNegCtrSwtOffWait = 0.0F;
      }
      break;

     default:
      BCCR_RlyCtlDiag_Wait_Stt();
      break;
    }
  }

  if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_m) {
    rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_HvPwrUpFail_ASW | 8U);
  } else if (BCCR_bPreChargeFaultDet) {
    rtb_Switch4_fd = (uint8_T)(DFC_HvPwrUpFail_ASW | 152U);
  } else if (BCCR_bPreChargeFaultHeal) {
    rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_HvPwrUpFail_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_n;
  }

  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_m = false;
  BCCR_RlyCtlDiag_DW.Delay3_DSTATE_n = rtb_Switch4_fd;
  DFC_HvPwrUpFail_ASW = rtb_Switch4_fd;
  rtb_Switch2_o = (BCCR_jPreChgResEnrg > BCCR_wPreChgResEnrgLmt_C);
  if (rtb_Switch2_o) {
    rtb_Product_mj = 0.01F;
  } else {
    rtb_Product_mj = 0.0F;
  }

  rtb_Constant14 = (rtb_Product_mj + fminf(BCCR_tiPreChgEnrgDet_C,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_lx)) * (real32_T)rtb_Switch2_o;
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_lx = rtb_Constant14;
  if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_o1) {
    DFC_PrechgEngyFail_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_PrechgEngyFail_ASW | 8U);
  } else if (rtb_Constant14 > BCCR_tiPreChgEnrgDet_C) {
    DFC_PrechgEngyFail_ASW = (uint8_T)(DFC_PrechgEngyFail_ASW | 152U);
  } else {
    DFC_PrechgEngyFail_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_PrechgEngyFail_ASW | 16U) | 8U);
  }

  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_o1 = false;
  rtb_Switch2_o = (BCCR_bMNegCtrSwtOn || BCCR_bMNegCtrSwtOnReq_C);
  rtb_Constant14 = ((real32_T)rtb_Switch2_o + fminf(1.0F,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_l0)) * (real32_T)rtb_Switch2_o;
  rtb_Switch_nf = (rtb_Constant14 > 1.0F);
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_l0 = rtb_Constant14;
  if (BCCR_bMnCtlHwSel_C) {
    if (rtb_Switch_nf) {
      rtb_Constant14 = 100.0F;
    } else {
      rtb_Constant14 = 0.0F;
    }
  } else {
    rtb_Constant14 = rtb_Switch_nf;
  }

  BCCR_dcMNegCtrLsdEna = (rtb_Constant14 != 0.0F);
  rtb_Constant14 = ((real32_T)BCCR_bMPosCtrSwtOn + fminf(1.0F,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_dy)) * (real32_T)BCCR_bMPosCtrSwtOn;
  rtb_Switch_nf = (rtb_Constant14 > 1.0F);
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_dy = rtb_Constant14;
  if (BCCR_bMnCtlHwSel_C) {
    if (rtb_Switch_nf) {
      rtb_Constant14 = 100.0F;
    } else {
      rtb_Constant14 = 0.0F;
    }
  } else {
    rtb_Constant14 = rtb_Switch_nf;
  }

  BCCR_dcMPosCtrLsdEna = (rtb_Constant14 != 0.0F);
  if (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_oc && (!BCCR_bMPosCtrSwtOn)) {
    rtb_Constant14 = 1.0F;
  } else {
    rtb_Constant14 = fmaxf(1.0F, BCCR_RlyCtlDiag_DW.Delay_DSTATE_cj);
  }

  BCCR_RlyCtlDiag_DW.Delay_DSTATE_cj = rtb_Constant14 - 1.0F;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_oc = BCCR_bMPosCtrSwtOn;
  if (BCCR_bMPosCtrSwtOn) {
    BCCR_bMPosCtrHsdEna = true;
  } else {
    BCCR_bMPosCtrHsdEna = (rtb_Constant14 - 1.0F > 0.0F);
  }

  if (BCCR_RlyCtlDiag_DW.Delay1_DSTATE_a && (!rtb_Switch2_o)) {
    rtb_Constant14 = 1.0F;
  } else {
    rtb_Constant14 = fmaxf(1.0F, BCCR_RlyCtlDiag_DW.Delay_DSTATE_pb1);
  }

  BCCR_RlyCtlDiag_DW.Delay_DSTATE_pb1 = rtb_Constant14 - 1.0F;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_a = rtb_Switch2_o;
  if (rtb_Switch2_o) {
    BCCR_bMNegCtrHsdEna = true;
  } else {
    BCCR_bMNegCtrHsdEna = (rtb_Constant14 - 1.0F > 0.0F);
  }

  BCCR_bPreChCtrLsdEna = (BCCR_bPreChCtrSwtOn || BCCR_bPreChCtrSwtOnReq_C);
  if (BCCR_stBmsCtrMode == BCCR_stBmsCtrModePrechg_C) {
    if (!BCCR_RlyCtlDiag_DW.Kl30cMinCalc_MODE) {
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_ek = 16.0F;
      BCCR_RlyCtlDiag_DW.Kl30cMinCalc_MODE = true;
    }

    BCCR_uKl30cPreChgStMin = fminf(BCCR_RlyCtlDiag_DW.Delay_DSTATE_ek,
      BSPR_uKl30c);
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_ek = BCCR_uKl30cPreChgStMin;
  } else {
    if (BCCR_RlyCtlDiag_DW.Kl30cMinCalc_MODE) {
      BCCR_RlyCtlDiag_DW.Kl30cMinCalc_MODE = false;
    }
  }

  if ((BCCR_stBmsCtrMode == BCCR_stBmsCtrModeFault_C) || (BCCR_stBmsCtrMode ==
       BCCR_stBmsCtrModePreFault_C)) {
    BCCR_uEcuVoltagetoDID = BCCR_uKl30cPreChgStMin;
  } else {
    BCCR_uEcuVoltagetoDID = BSPR_uKl30c;
  }

  rtb_Switch2_o = ((BSPR_uKl30c <= BCCR_uKl30cCctPlausDiagHi_C) && (BSPR_uKl30c >=
    BCCR_uKl30cCctPlausDiagLo_C));
  if (rtb_Switch2_o) {
    rtb_Product_mj = 0.01F;
  } else {
    rtb_Product_mj = 0.0F;
  }

  rtb_Constant14 = (rtb_Product_mj + fminf(BCCR_tiCctDriveDiagEna_C,
    BCCR_RlyCtlDiag_DW.Delay_DSTATE)) * (real32_T)rtb_Switch2_o;
  BCCR_flgCctDrvDiagEna = (rtb_Constant14 > BCCR_tiCctDriveDiagEna_C);
  BCCR_RlyCtlDiag_DW.Delay_DSTATE = rtb_Constant14;
  if (BCCR_flgCctDrvDiagEna) {
    if (!BCCR_RlyCtlDiag_DW.CctDiag_MODE) {
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_nf = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_b = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ju = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cg = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_n = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_h = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_ck = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_g = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_eu = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_b2 = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_i = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_m = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bp = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_b = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_p = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_e = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_cb = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cb = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_l = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_p = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cy = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_b5 = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e2 = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_l = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_eq = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_k = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_l = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_o = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_dw = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_k2 = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_il = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_eq = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_h = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_a = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_da = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_o = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ia = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_hg = 0U;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_fh = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_c = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j5 = true;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_j3 = 0U;
      BCCR_RlyCtlDiag_DW.CctDiag_MODE = true;
    }

    rtb_Switch_nf = (BSW_uMPosCtrHsdVolt > BCCR_uRlyCctFaultHi_C);
    rtb_Compare_lr = ((BCCR_bMPosCtrHsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion) &&
                      (BCCR_dcMPosCtrLsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion));
    rtb_Compare_k3 = ((uint32_T)(BSPR_stMPosLsdSta & 15) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion1);
    rtb_Switch2_o = (rtb_Switch_nf && rtb_Compare_lr && rtb_Compare_k3);
    if (rtb_Switch2_o) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_nf)) * (real32_T)rtb_Switch2_o;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_nf = rtb_Constant14;
    rtb_Switch2_o = ((BSW_uMPosCtrHsdVolt < BCCR_uRlyCctFaultHi_C) &&
                     (BSW_uMPosCtrHsdVolt > BCCR_uRlyCctFaultLo_C));
    rtb_Compare_k3 = (rtb_Compare_lr && rtb_Compare_k3 && rtb_Switch2_o);
    if (rtb_Compare_k3) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Product_ga = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultHeal_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_b)) * (real32_T)rtb_Compare_k3;
    rtb_Compare_k3 = (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C);
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_b = rtb_Product_ga;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ju) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvScb_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MPosRlyDrvScb_ASW | 152U);
    } else if (rtb_Compare_k3) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvScb_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cg;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ju = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cg = rtb_Switch4_fd;
    DFC_MPosRlyDrvScb_ASW = rtb_Switch4_fd;
    rtb_LogicalOperator5_l = (((uint32_T)(BSPR_stMPosLsdSta & 1) ==
      BCCR_RlyCtlDiag_ConstB.DataTypeConversion2) && (BSW_uMPosCtrHsdVolt <
      BCCR_uRlyCctFaultLo_C) && rtb_Compare_lr);
    if (rtb_LogicalOperator5_l) {
      rtb_Constant14 = 0.01F;
    } else {
      rtb_Constant14 = 0.0F;
    }

    rtb_Constant14 = (rtb_Constant14 + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_n)) * (real32_T)rtb_LogicalOperator5_l;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_n = rtb_Constant14;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_h) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvScg_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MPosRlyDrvScg_ASW | 152U);
    } else if (rtb_Compare_k3) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvScg_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_ck;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_h = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_ck = rtb_Switch4_fd;
    DFC_MPosRlyDrvScg_ASW = rtb_Switch4_fd;
    rtb_Switch2_o = (((uint32_T)(BSPR_stMPosLsdSta & 4) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion3) &&
                     rtb_Switch2_o && rtb_Compare_lr);
    if (rtb_Switch2_o) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_g)) * (real32_T)rtb_Switch2_o;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_g = rtb_Constant14;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_eu) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvOL_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MPosRlyDrvOL_ASW | 152U);
    } else if (rtb_Compare_k3) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvOL_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_b2;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_eu = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_b2 = rtb_Switch4_fd;
    DFC_MPosRlyDrvOL_ASW = rtb_Switch4_fd;
    rtb_Switch2_o = ((BCCR_bMPosCtrHsdEna ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion4) &&
                     (BCCR_dcMPosCtrLsdEna ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion4));
    rtb_Compare_k3 = ((uint32_T)(BSPR_stMPosLsdSta & 15) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion5);
    rtb_Compare_lr = (rtb_Switch2_o && ((!rtb_Switch_nf) || (!rtb_Compare_k3)));
    if (rtb_Compare_lr) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_i)) * (real32_T)rtb_Compare_lr;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_i = rtb_Constant14;
    rtb_Switch2_o = (rtb_Switch2_o && rtb_Compare_k3 && rtb_Switch_nf);
    if (rtb_Switch2_o) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultHeal_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_m)) * (real32_T)rtb_Switch2_o;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_m = rtb_Product_ga;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bp) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MPosRlyDrvFault_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MPosRlyDrvFault_ASW | 152U);
    } else if (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_MPosRlyDrvFault_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_b;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bp = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_b = rtb_Switch4_fd;
    DFC_MPosRlyDrvFault_ASW = rtb_Switch4_fd;
    rtb_Switch2_o = (BSW_uMNegCtrHsdVolt > BCCR_uRlyCctFaultHi_C);
    rtb_Compare_k3 = ((BCCR_bMNegCtrHsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion6) &&
                      (BCCR_dcMNegCtrLsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion6));
    rtb_Compare_lr = ((uint32_T)(BSPR_stMNegLsdSta & 15) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion7);
    rtb_Switch_nf = (rtb_Switch2_o && rtb_Compare_k3 && rtb_Compare_lr);
    if (rtb_Switch_nf) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_p)) * (real32_T)rtb_Switch_nf;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_p = rtb_Constant14;
    rtb_Switch_nf = ((BSW_uMNegCtrHsdVolt < BCCR_uRlyCctFaultHi_C) &&
                     (BSW_uMNegCtrHsdVolt > BCCR_uRlyCctFaultLo_C));
    rtb_Compare_lr = (rtb_Compare_k3 && rtb_Compare_lr && rtb_Switch_nf);
    if (rtb_Compare_lr) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultHeal_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_e)) * (real32_T)rtb_Compare_lr;
    rtb_Compare_lr = (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C);
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_e = rtb_Product_ga;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_cb) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvScb_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MNegRlyDrvScb_ASW | 152U);
    } else if (rtb_Compare_lr) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvScb_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cb;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_cb = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cb = rtb_Switch4_fd;
    DFC_MNegRlyDrvScb_ASW = rtb_Switch4_fd;
    rtb_LogicalOperator5_l = (((uint32_T)(BSPR_stMNegLsdSta & 1) ==
      BCCR_RlyCtlDiag_ConstB.DataTypeConversion8) && (BSW_uMNegCtrHsdVolt <
      BCCR_uRlyCctFaultLo_C) && rtb_Compare_k3);
    if (rtb_LogicalOperator5_l) {
      rtb_Constant14 = 0.01F;
    } else {
      rtb_Constant14 = 0.0F;
    }

    rtb_Constant14 = (rtb_Constant14 + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_l)) * (real32_T)rtb_LogicalOperator5_l;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_l = rtb_Constant14;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_p) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvScg_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MNegRlyDrvScg_ASW | 152U);
    } else if (rtb_Compare_lr) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvScg_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cy;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_p = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_cy = rtb_Switch4_fd;
    DFC_MNegRlyDrvScg_ASW = rtb_Switch4_fd;
    rtb_Switch_nf = (((uint32_T)(BSPR_stMNegLsdSta & 4) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion9) &&
                     rtb_Switch_nf && rtb_Compare_k3);
    if (rtb_Switch_nf) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_b5)) * (real32_T)rtb_Switch_nf;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_b5 = rtb_Constant14;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e2) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvOL_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MNegRlyDrvOL_ASW | 152U);
    } else if (rtb_Compare_lr) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvOL_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_l;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e2 = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_l = rtb_Switch4_fd;
    DFC_MNegRlyDrvOL_ASW = rtb_Switch4_fd;
    rtb_Compare_k3 = ((BCCR_bMNegCtrHsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion10) &&
                      (BCCR_dcMNegCtrLsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion10));
    rtb_Compare_lr = ((uint32_T)(BSPR_stMNegLsdSta & 15) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion11);
    rtb_Switch_nf = (rtb_Compare_k3 && ((!rtb_Switch2_o) || (!rtb_Compare_lr)));
    if (rtb_Switch_nf) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_eq)) * (real32_T)rtb_Switch_nf;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_eq = rtb_Constant14;
    rtb_Switch2_o = (rtb_Compare_k3 && rtb_Compare_lr && rtb_Switch2_o);
    if (rtb_Switch2_o) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultHeal_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_k)) * (real32_T)rtb_Switch2_o;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_k = rtb_Product_ga;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_l) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_MNegRlyDrvFault_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_MNegRlyDrvFault_ASW | 152U);
    } else if (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_MNegRlyDrvFault_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_o;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_l = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_o = rtb_Switch4_fd;
    DFC_MNegRlyDrvFault_ASW = rtb_Switch4_fd;
    rtb_Switch2_o = (BSW_uDcChNegCtrLsdVolt > BCCR_uRlyCctFaultHi_C);
    rtb_Compare_k3 = ((BCCR_bDcChNegCtrHsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion20) &&
                      (BCCR_dcDcChNegCtrLsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion20));
    rtb_Compare_lr = ((uint32_T)(BSPR_stDcNegLsdSta & 15) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion21);
    rtb_Switch_nf = (rtb_Switch2_o && rtb_Compare_k3 && rtb_Compare_lr);
    if (rtb_Switch_nf) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_dw)) * (real32_T)rtb_Switch_nf;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_dw = rtb_Constant14;
    rtb_Switch_nf = ((BSW_uDcChNegCtrLsdVolt < BCCR_uRlyCctFaultHi_C) &&
                     (BSW_uDcChNegCtrLsdVolt > BCCR_uRlyCctFaultLo_C));
    rtb_Compare_lr = (rtb_Compare_k3 && rtb_Compare_lr && rtb_Switch_nf);
    if (rtb_Compare_lr) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultHeal_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_k2)) * (real32_T)rtb_Compare_lr;
    rtb_Compare_lr = (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C);
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_k2 = rtb_Product_ga;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_il) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcNegRlyDrvScb_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_DcNegRlyDrvScb_ASW | 152U);
    } else if (rtb_Compare_lr) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DcNegRlyDrvScb_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_eq;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_il = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_eq = rtb_Switch4_fd;
    DFC_DcNegRlyDrvScb_ASW = rtb_Switch4_fd;
    rtb_LogicalOperator5_l = (((uint32_T)(BSPR_stDcNegLsdSta & 1) ==
      BCCR_RlyCtlDiag_ConstB.DataTypeConversion22) && (BSW_uDcChNegCtrLsdVolt <
      BCCR_uRlyCctFaultLo_C) && rtb_Compare_k3);
    if (rtb_LogicalOperator5_l) {
      rtb_Constant14 = 0.01F;
    } else {
      rtb_Constant14 = 0.0F;
    }

    rtb_Constant14 = (rtb_Constant14 + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_h)) * (real32_T)rtb_LogicalOperator5_l;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_h = rtb_Constant14;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_a) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcNegRlyDrvScg_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_DcNegRlyDrvScg_ASW | 152U);
    } else if (rtb_Compare_lr) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DcNegRlyDrvScg_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_da;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_a = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_da = rtb_Switch4_fd;
    DFC_DcNegRlyDrvScg_ASW = rtb_Switch4_fd;
    rtb_Switch_nf = (((uint32_T)(BSPR_stDcNegLsdSta & 4) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion23) &&
                     rtb_Switch_nf && rtb_Compare_k3);
    if (rtb_Switch_nf) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_o)) * (real32_T)rtb_Switch_nf;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_o = rtb_Constant14;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ia) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcNegRlyDrvOL_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_DcNegRlyDrvOL_ASW | 152U);
    } else if (rtb_Compare_lr) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_DcNegRlyDrvOL_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_hg;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ia = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_hg = rtb_Switch4_fd;
    DFC_DcNegRlyDrvOL_ASW = rtb_Switch4_fd;
    rtb_Compare_k3 = ((BCCR_bDcChNegCtrHsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion18) &&
                      (BCCR_dcDcChNegCtrLsdEna ==
                       BCCR_RlyCtlDiag_ConstB.DataTypeConversion18));
    rtb_Compare_lr = ((uint32_T)(BSPR_stDcNegLsdSta & 15) ==
                      BCCR_RlyCtlDiag_ConstB.DataTypeConversion19);
    rtb_Switch_nf = (rtb_Compare_k3 && ((!rtb_Switch2_o) || (!rtb_Compare_lr)));
    if (rtb_Switch_nf) {
      rtb_Product_go = 0.01F;
    } else {
      rtb_Product_go = 0.0F;
    }

    rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_fh)) * (real32_T)rtb_Switch_nf;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_fh = rtb_Constant14;
    rtb_Switch2_o = (rtb_Compare_k3 && rtb_Compare_lr && rtb_Switch2_o);
    if (rtb_Switch2_o) {
      rtb_Product_mj = 0.01F;
    } else {
      rtb_Product_mj = 0.0F;
    }

    rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultHeal_C,
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_c)) * (real32_T)rtb_Switch2_o;
    BCCR_RlyCtlDiag_DW.Delay_DSTATE_c = rtb_Product_ga;
    if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j5) {
      rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcNegRlyDrvFault_ASW | 8U);
    } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
      rtb_Switch4_fd = (uint8_T)(DFC_DcNegRlyDrvFault_ASW | 152U);
    } else if (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C) {
      rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DcNegRlyDrvFault_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_j3;
    }

    BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j5 = false;
    BCCR_RlyCtlDiag_DW.Delay3_DSTATE_j3 = rtb_Switch4_fd;
    DFC_DcNegRlyDrvFault_ASW = rtb_Switch4_fd;
    if (BCCR_bDchrgDiagStdSel_C) {
      rtb_Compare_lr = BCCR_RlyCtlDiag_ConstB.DataTypeConversion1_i;
    } else {
      rtb_Compare_lr = BCCR_RlyCtlDiag_ConstB.DataTypeConversion_g;
    }

    if (rtb_Compare_lr) {
      if (!BCCR_RlyCtlDiag_DW.BCCR_DcPosRlyCctDiag_MODE) {
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_fq = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_d = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ji = true;
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_a = 0U;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_m3 = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_kg = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_i = true;
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_e = 0U;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_f = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_jb = true;
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_d = 0U;
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_et = 0.0F;
        BCCR_RlyCtlDiag_DW.Delay2_DSTATE_hd = true;
        BCCR_RlyCtlDiag_DW.Delay3_DSTATE_h = 0U;
        BCCR_RlyCtlDiag_DW.BCCR_DcPosRlyCctDiag_MODE = true;
      }

      rtb_Compare_lr = ((BSW_uDcChPosCtrLsdVolt < BCCR_uRlyCctFaultHi_C) &&
                        (BSW_uDcChPosCtrLsdVolt > BCCR_uRlyCctFaultLo_C));
      rtb_Switch2_o = ((BCCR_bDcChPosCtrHsdEna ==
                        BCCR_RlyCtlDiag_ConstB.DataTypeConversion14) &&
                       (BCCR_dcDcChPosCtrLsdEna ==
                        BCCR_RlyCtlDiag_ConstB.DataTypeConversion14));
      rtb_Switch_nf = (((uint32_T)(BSPR_stDcPosLsdSta & 4) ==
                        BCCR_RlyCtlDiag_ConstB.DataTypeConversion17) &&
                       rtb_Compare_lr && rtb_Switch2_o);
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_fq)) * (real32_T)rtb_Switch_nf;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_fq = rtb_Constant14;
      rtb_Compare_k3 = ((uint32_T)(BSPR_stDcPosLsdSta & 15) ==
                        BCCR_RlyCtlDiag_ConstB.DataTypeConversion15);
      rtb_Switch_nf = (rtb_Switch2_o && rtb_Compare_k3 && rtb_Compare_lr);
      if (rtb_Switch_nf) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultHeal_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_d)) * (real32_T)rtb_Switch_nf;
      rtb_Switch_nf = (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C);
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_d = rtb_Product_ga;
      if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ji) {
        rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcPosRlyDrvOL_ASW | 8U);
      } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
        rtb_Switch4_fd = (uint8_T)(DFC_DcPosRlyDrvOL_ASW | 152U);
      } else if (rtb_Switch_nf) {
        rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_DcPosRlyDrvOL_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_a;
      }

      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ji = false;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_a = rtb_Switch4_fd;
      DFC_DcPosRlyDrvOL_ASW = rtb_Switch4_fd;
      rtb_Compare_lr = ((BCCR_bDcChPosCtrHsdEna ==
                         BCCR_RlyCtlDiag_ConstB.DataTypeConversion12) &&
                        (BCCR_dcDcChPosCtrLsdEna ==
                         BCCR_RlyCtlDiag_ConstB.DataTypeConversion12));
      rtb_LogicalOperator5_l = (BSW_uDcChPosCtrLsdVolt > BCCR_uRlyCctFaultHi_C);
      rtb_LogicalOperator2_n = ((uint32_T)(BSPR_stDcPosLsdSta & 15) ==
        BCCR_RlyCtlDiag_ConstB.DataTypeConversion13);
      rtb_RelationalOperator2_k = (rtb_Compare_lr && ((!rtb_LogicalOperator5_l) ||
        (!rtb_LogicalOperator2_n)));
      if (rtb_RelationalOperator2_k) {
        rtb_Constant14 = 0.01F;
      } else {
        rtb_Constant14 = 0.0F;
      }

      rtb_Constant14 = (rtb_Constant14 + fminf(BCCR_tiRlyCctFaultDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_m3)) * (real32_T)
        rtb_RelationalOperator2_k;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_m3 = rtb_Constant14;
      rtb_Compare_lr = (rtb_Compare_lr && rtb_LogicalOperator2_n &&
                        rtb_LogicalOperator5_l);
      if (rtb_Compare_lr) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Product_ga = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultHeal_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_kg)) * (real32_T)rtb_Compare_lr;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_kg = rtb_Product_ga;
      if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_i) {
        rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcPosRlyDrvFault_ASW | 8U);
      } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
        rtb_Switch4_fd = (uint8_T)(DFC_DcPosRlyDrvFault_ASW | 152U);
      } else if (rtb_Product_ga > BCCR_tiRlyCctFaultHeal_C) {
        rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_DcPosRlyDrvFault_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_e;
      }

      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_i = false;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_e = rtb_Switch4_fd;
      DFC_DcPosRlyDrvFault_ASW = rtb_Switch4_fd;
      rtb_Compare_k3 = (rtb_LogicalOperator5_l && rtb_Switch2_o &&
                        rtb_Compare_k3);
      if (rtb_Compare_k3) {
        rtb_Product_go = 0.01F;
      } else {
        rtb_Product_go = 0.0F;
      }

      rtb_Constant14 = (rtb_Product_go + fminf(BCCR_tiRlyCctFaultDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_f)) * (real32_T)rtb_Compare_k3;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_f = rtb_Constant14;
      if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_jb) {
        rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcPosRlyDrvScb_ASW | 8U);
      } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
        rtb_Switch4_fd = (uint8_T)(DFC_DcPosRlyDrvScb_ASW | 152U);
      } else if (rtb_Switch_nf) {
        rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_DcPosRlyDrvScb_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_d;
      }

      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_jb = false;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_d = rtb_Switch4_fd;
      DFC_DcPosRlyDrvScb_ASW = rtb_Switch4_fd;
      rtb_Switch2_o = (((uint32_T)(BSPR_stDcPosLsdSta & 1) ==
                        BCCR_RlyCtlDiag_ConstB.DataTypeConversion16) &&
                       (BSW_uDcChPosCtrLsdVolt < BCCR_uRlyCctFaultLo_C) &&
                       rtb_Switch2_o);
      if (rtb_Switch2_o) {
        rtb_Product_mj = 0.01F;
      } else {
        rtb_Product_mj = 0.0F;
      }

      rtb_Constant14 = (rtb_Product_mj + fminf(BCCR_tiRlyCctFaultDet_C,
        BCCR_RlyCtlDiag_DW.Delay_DSTATE_et)) * (real32_T)rtb_Switch2_o;
      BCCR_RlyCtlDiag_DW.Delay_DSTATE_et = rtb_Constant14;
      if (BCCR_RlyCtlDiag_DW.Delay2_DSTATE_hd) {
        rtb_Switch4_fd = (uint8_T)~(uint8_T)((uint8_T)~DFC_DcPosRlyDrvScg_ASW | 8U);
      } else if (rtb_Constant14 > BCCR_tiRlyCctFaultDet_C) {
        rtb_Switch4_fd = (uint8_T)(DFC_DcPosRlyDrvScg_ASW | 152U);
      } else if (rtb_Switch_nf) {
        rtb_Switch4_fd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_DcPosRlyDrvScg_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fd = BCCR_RlyCtlDiag_DW.Delay3_DSTATE_h;
      }

      BCCR_RlyCtlDiag_DW.Delay2_DSTATE_hd = false;
      BCCR_RlyCtlDiag_DW.Delay3_DSTATE_h = rtb_Switch4_fd;
      DFC_DcPosRlyDrvScg_ASW = rtb_Switch4_fd;
    } else {
      if (BCCR_RlyCtlDiag_DW.BCCR_DcPosRlyCctDiag_MODE) {
        BCCR_RlyCtlDiag_DW.BCCR_DcPosRlyCctDiag_MODE = false;
      }
    }
  } else {
    if (BCCR_RlyCtlDiag_DW.CctDiag_MODE) {
      if (BCCR_RlyCtlDiag_DW.BCCR_DcPosRlyCctDiag_MODE) {
        BCCR_RlyCtlDiag_DW.BCCR_DcPosRlyCctDiag_MODE = false;
      }

      BCCR_RlyCtlDiag_DW.CctDiag_MODE = false;
    }
  }

  if (BCCR_bCtrStuckChkCond) {
    if (!BCCR_RlyCtlDiag_DW.SglCoord_MODE) {
      BCCR_RlyCtlDiag_DW.Delay2_DSTATE = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE = 0.0F;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_p = true;
      BCCR_RlyCtlDiag_DW.Delay1_DSTATE_e = true;
      BCCR_RlyCtlDiag_DW.SglCoord_MODE = true;
    }

    rtb_Switch2_o = (BCCR_bStuckClsdMpPrFastErrDet ||
                     BCCR_bStuckClsdMpPrStgScndErrDet);
    rtb_Switch_nf = (BCCR_bStuckClsdMpPrFastErrHeal ||
                     BCCR_bStuckClsdMpPrStgScndErrHeal);
    rtb_Compare_k3 = (rtb_Switch2_o || rtb_Switch_nf);
    rtb_Compare_lr = ((!BCCR_RlyCtlDiag_DW.Delay1_DSTATE_p) && rtb_Compare_k3);
    BCCR_RlyCtlDiag_DW.Delay1_DSTATE_p = rtb_Compare_k3;
    rtb_Constant14 = fmaxf(BCCR_RlyCtlDiag_DW.Delay2_DSTATE, rtb_Compare_lr);
    if (rtb_Constant14 > 0.0F) {
      BCCR_bStuckClsdMpPrErrDet = rtb_Switch2_o;
      BCCR_bStuckClsdMpPrErrHeal = rtb_Switch_nf;
    } else {
      BCCR_bStuckClsdMpPrErrDet = BCCR_bStuckClsdMpPrStgFrstErrDet;
      BCCR_bStuckClsdMpPrErrHeal = BCCR_bStuckClsdMpPrStgFrstErrHeal;
    }

    rtb_Switch2_o = (BCCR_bStuckClsdMnStgScndErrDet ||
                     BCCR_bStuckClsdMnStgScndErrHeal);
    rtb_Switch_nf = !BCCR_RlyCtlDiag_DW.Delay1_DSTATE_e;
    BCCR_RlyCtlDiag_DW.Delay1_DSTATE_e = rtb_Switch2_o;
    BCCR_bStuckClsdMnErrDet = BCCR_bStuckClsdMnStgFrstErrDet;
    BCCR_bStuckClsdMnErrHeal = BCCR_bStuckClsdMnStgFrstErrHeal;
    BCCR_RlyCtlDiag_DW.Delay2_DSTATE = rtb_Constant14;
    BCCR_RlyCtlDiag_DW.Delay1_DSTATE = fmaxf(BCCR_RlyCtlDiag_DW.Delay1_DSTATE,
      (real32_T)(rtb_Switch_nf && rtb_Switch2_o));
  } else {
    if (BCCR_RlyCtlDiag_DW.SglCoord_MODE) {
      BCCR_RlyCtlDiag_DW.SglCoord_MODE = false;
    }
  }

  BCCR_RlyCtlDiag_Y.BCCR_stBmsCtrMode_p = BCCR_RlyCtlDiag_DW.Delay7_DSTATE;
  BCCR_RlyCtlDiag_Y.BCCR_stMainCtrDiagMode_i = BCCR_RlyCtlDiag_DW.Delay8_DSTATE;
  BCCR_RlyCtlDiag_DW.Delay7_DSTATE = BCCR_stBmsCtrMode;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_f = BCCR_stBmsDChrgCtrMode;
  BCCR_RlyCtlDiag_DW.Delay8_DSTATE = BCCR_stMainCtrDiagMode;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_o = BCCR_bDChrgPosCtrSwtOn;
}

/* Model initialize function */
void BCCR_RlyCtlDiag_initialize(void)
{
  /* Registration code */

  /* block I/O */

  /* custom signals */
  BCCR_uEcuVoltagetoDID = 0.0F;
  BCCR_tiDChrgHld = 0.0F;
  BCCR_tiDChrgCtrWait = 0.0F;
  BCCR_stPreChRslt = ((uint8_T)0U);
  BCCR_cntPreChFault = ((uint8_T)0U);
  BCCR_stBmsDChrgCtrMode = ((uint8_T)0U);
  BCCR_cntDChrgFault = ((uint8_T)0U);
  BCCR_bCtrStuckChkCond = false;
  BCCR_bDcChPosCtrHsdEna = false;
  BCCR_dcDcChPosCtrLsdEna = false;
  BCCR_bDcChNegCtrHsdEna = false;
  BCCR_dcDcChNegCtrLsdEna = false;
  BCCR_dcMNegCtrLsdEna = false;
  BCCR_dcMPosCtrLsdEna = false;
  BCCR_bMPosCtrHsdEna = false;
  BCCR_bMNegCtrHsdEna = false;
  BCCR_bPreChCtrLsdEna = false;
  BCCR_bStuckClsdMpPrErrDet = false;
  BCCR_bStuckClsdMpPrErrHeal = false;
  BCCR_bStuckClsdMnErrDet = false;
  BCCR_bStuckClsdMnErrHeal = false;
  BCCR_bStuckOpnMnErrDet = false;
  BCCR_bStuckOpnMnErrHeal = false;
  BCCR_bStuckOpnMpErrDet = false;
  BCCR_bStuckOpnMpErrHeal = false;
  BCCR_bStuckOpnPrErrDet = false;
  BCCR_bStuckOpnPrErrHeal = false;
  BCCR_bStuckOpnDChrgPosErrDet = false;
  BCCR_bStuckClsdDChrgPosErrHeal = false;
  BCCR_bStuckClsdDChrgPosErrDet = false;
  BCCR_bStuckOpnDChrgNegErrHeal = false;
  BCCR_bStuckOpnDChrgNegErrDet = false;
  BCCR_bStuckClsdDChrgNegErrHeal = false;
  BCCR_bStuckClsdDChrgNegErrDet = false;

  /* external outputs */
  (void) memset((void *)&BCCR_RlyCtlDiag_Y, 0,
                sizeof(ExtY_BCCR_RlyCtlDiag_T));
  BCCR_RlyCtlDiag_PrevZCX.SglProc2_Trig_ZCE = POS_ZCSIG;
  BCCR_RlyCtlDiag_PrevZCX.StuckOpnDiag_Trig_ZCE = ZERO_ZCSIG;
  BCCR_RlyCtlDiag_PrevZCX.DiagMode_5_Trig_ZCE = POS_ZCSIG;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_ef = true;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_g = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j3 = true;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_k = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_m = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_o1 = true;
  BCCR_RlyCtlDiag_DW.Delay_DSTATE_ek = 16.0F;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ju = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_h = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_eu = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_bp = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_cb = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_p = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_e2 = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_l = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_il = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_a = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ia = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_j5 = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_ji = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_i = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_jb = true;
  BCCR_RlyCtlDiag_DW.Delay2_DSTATE_hd = true;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_p = true;
  BCCR_RlyCtlDiag_DW.Delay1_DSTATE_e = true;
}

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