/*
 * File: HVSR_IsoChk.c
 *
 * Code generated for Simulink model 'HVSR_IsoChk'.
 *
 * Model version                  : 1.862
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Fri Feb 26 16:33:23 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 "HVSR_IsoChk.h"
#include "HVSR_IsoChk_private.h"

/* Named constants for Chart: '<S26>/RS' */
#define HVSR_IsoChk_IN_NO_ACTIVE_CHILD ((uint8_T)0U)

/* Named constants for Chart: '<S51>/Chart' */
#define HVSR_IsoChk_IN_Fast_mode_end   ((uint8_T)1U)
#define HVSR_IsoChk_IN_Fast_mode_filter ((uint8_T)2U)
#define HVSR_IsoChk_IN_Fast_mode_init  ((uint8_T)3U)

/* Named constants for Chart: '<S5>/HVSR_IsoInsModeCtl' */
#define HVSR_IsoChk_IN_Stt_CctChk      ((uint8_T)1U)
#define HVSR_IsoChk_IN_Stt_CctChkA1    ((uint8_T)1U)
#define HVSR_IsoChk_IN_Stt_CctChkA1Err ((uint8_T)2U)
#define HVSR_IsoChk_IN_Stt_CctChkA2    ((uint8_T)3U)
#define HVSR_IsoChk_IN_Stt_CctChkA2Err ((uint8_T)4U)
#define HVSR_IsoChk_IN_Stt_CctChkA3    ((uint8_T)5U)
#define HVSR_IsoChk_IN_Stt_CctChkA3Err ((uint8_T)6U)
#define HVSR_IsoChk_IN_Stt_CctChkA4    ((uint8_T)7U)
#define HVSR_IsoChk_IN_Stt_CctChkA4Err ((uint8_T)8U)
#define HVSR_IsoChk_IN_Stt_CctChkA4OK  ((uint8_T)9U)
#define HVSR_IsoChk_IN_Stt_CctChkA4OKRn ((uint8_T)10U)
#define HVSR_IsoChk_IN_Stt_CctChkA4OKRp ((uint8_T)11U)
#define HVSR_IsoChk_IN_Stt_CctChkA5    ((uint8_T)12U)
#define HVSR_IsoChk_IN_Stt_CctChkInit  ((uint8_T)13U)
#define HVSR_IsoChk_IN_Stt_begin       ((uint8_T)2U)
#define HVSR_IsoChk_IN_Stt_cycle       ((uint8_T)3U)
#define HVSR_IsoChk_IN_Stt_end         ((uint8_T)4U)
#define HVSR_IsoChk_IN_Stt_fastchk     ((uint8_T)5U)
#define HVSR_IsoChk_IN_Stt_fault       ((uint8_T)6U)
#define HVSR_IsoChk_IN_Stt_init        ((uint8_T)7U)
#define HVSR_IsoChk_IN_Stt_standby     ((uint8_T)8U)
#define HVSR_IsoChk_IN_Stt_work        ((uint8_T)9U)

/* Exported data definition */

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

/* Definition for custom storage class: Volatile */
volatile uint8_T DFC_DchrgIsoChkLv1_ASW;
volatile uint8_T DFC_DchrgIsoChkLv2_ASW;
volatile uint8_T DFC_HVOffIsoChkLv1_ASW;
volatile uint8_T DFC_HVOffIsoChkLv2_ASW;
volatile uint8_T DFC_InsResValdFault_ASW;
volatile uint8_T DFC_IsoChkLv1_ASW;
volatile uint8_T DFC_IsoChkLv2_ASW;
volatile uint8_T DFC_IsoS1SwStuckClsd_ASW;
volatile uint8_T DFC_IsoS1SwStuckOpen_ASW;
volatile uint8_T DFC_IsoS2SwStuckClsd_ASW;
volatile uint8_T DFC_IsoS2SwStuckOpen_ASW;
volatile uint8_T DFC_IsoS3SwStuckClsd_ASW;
volatile uint8_T DFC_IsoS3SwStuckOpen_ASW;

#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 HVSR_BattInsResVald;
volatile boolean_T HVSR_InsResValdFault;
volatile boolean_T HVSR_InsResValdFaultHeal;
volatile boolean_T HVSR_bFrstSlopeVld;
volatile boolean_T HVSR_bISOHVOffFlg;  /* 高压继电器未闭合标志位 */
volatile boolean_T HVSR_bInsResValZero;
volatile boolean_T HVSR_bIsoChkStatus;
volatile boolean_T HVSR_bIsoFlgResVld;
volatile boolean_T HVSR_bIsoFlgResVld1;
volatile boolean_T HVSR_bIsoFlgResVld2;
volatile boolean_T HVSR_bIsoFlgResVld3;
volatile boolean_T HVSR_bIsoFlgResVld5;
volatile boolean_T HVSR_bIsoResCalShieldCmd;
volatile boolean_T HVSR_bIsoSwt1Ena;   /* Insulation switch 1 enable control */
volatile boolean_T HVSR_bIsoSwt2Ena;   /* Insulation switch 2 enable control */
volatile boolean_T HVSR_bIsoSwt3Ena;   /* Insulation switch 3 enable control */
volatile boolean_T HVSR_bIsoSwt4Ena;   /* Insulation switch 4 enable control */
volatile boolean_T HVSR_bScndSlopeVld;
volatile boolean_T HVSR_flgBattFilterEnd;
volatile boolean_T HVSR_flgBattInsResVald;/* Insulation detection resistance validity flag */
volatile boolean_T HVSR_flgDCIsoFaultLvl1;
volatile boolean_T HVSR_flgDCIsoFaultLvl1Heal;
volatile boolean_T HVSR_flgDCIsoFaultLvl2;
volatile boolean_T HVSR_flgDCIsoFaultLvl2Heal;
volatile boolean_T HVSR_flgFrstRsKVld;
volatile boolean_T HVSR_flgFrstRsVlotVld;
volatile boolean_T HVSR_flgHVOffIsoFaultLvl1;
volatile boolean_T HVSR_flgHVOffIsoFaultLvl1Heal;
volatile boolean_T HVSR_flgHVOffIsoFaultLvl2;
volatile boolean_T HVSR_flgHVOffIsoFaultLvl2Heal;
volatile boolean_T HVSR_flgIFlipFlopVal;
volatile boolean_T HVSR_flgInsResChngVld;
volatile boolean_T HVSR_flgInsResUpd;  /* Update insuulation resistance */
volatile boolean_T HVSR_flgIsoCctChkOK;
volatile boolean_T HVSR_flgIsoChkFault;/* insulation cheak fault */
volatile boolean_T HVSR_flgIsoChkStart;
volatile uint8_T HVSR_flgIsoFault;     /* Insulation detection resistance pass flag */
volatile boolean_T HVSR_flgIsoFaultLvl1;
volatile boolean_T HVSR_flgIsoFaultLvl1Heal;
volatile boolean_T HVSR_flgIsoFaultLvl2;
volatile boolean_T HVSR_flgIsoFaultLvl2Heal;
volatile boolean_T HVSR_flgIsoUpdtVld;
volatile boolean_T HVSR_flgIsoVldLmt;
volatile boolean_T HVSR_flgScndRsKVld;
volatile boolean_T HVSR_flgScndRsVlotVld;
volatile real32_T HVSR_numA1Val;
volatile real32_T HVSR_numA2Val;
volatile real32_T HVSR_numA3Val;
volatile real32_T HVSR_numA4Val;
volatile real32_T HVSR_numA5Val;
volatile real32_T HVSR_numIsoFrstVal;
volatile real32_T HVSR_numIsoScndVal;
volatile real32_T HVSR_rInsResVal;     /* Insulation detection resistance */
volatile real32_T HVSR_resBattInsRes1;
volatile real32_T HVSR_resBattInsRes2;
volatile real32_T HVSR_resIso;         /* Insulation detection resistance */
volatile real32_T HVSR_resIsoTheory;   /* Insulation detection resistance Theoretical value */
volatile uint8_T HVSR_stIsoCctChkErr;
volatile uint8_T HVSR_stIsoCctChkSta;
volatile uint8_T HVSR_stIsoStateObsr;
volatile real32_T HVSR_tiIsoChkTimer;
volatile boolean_T HVSR_tsIIsoSw1Ena;
volatile boolean_T HVSR_tsIIsoSw2Ena;
volatile boolean_T HVSR_tsIIsoSw3Ena;
volatile boolean_T HVSR_tsbegin_enable;
volatile boolean_T HVSR_tscontrol_enable;
volatile boolean_T HVSR_tsinit_enable;
volatile real32_T HVSR_uBattFilterEnd;
volatile real32_T HVSR_uBattFltDiff;
volatile real32_T HVSR_uFrstRsVlot;
volatile real32_T HVSR_uIsoFrstRsVolt;
volatile real32_T HVSR_uIsoScndRsVolt;
volatile real32_T HVSR_uIsoVoltNeg;    /* Insulated busbar negative to ground voltage */
volatile real32_T HVSR_uIsoVoltPos;    /* Insulated busbar  postive to ground voltage */
volatile real32_T HVSR_uScndRsVlot;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_HVSR_IsoChk_T HVSR_IsoChk_B;

/* Block states (auto storage) */
DW_HVSR_IsoChk_T HVSR_IsoChk_DW;

/* Previous zero-crossings (trigger) states */
PrevZCX_HVSR_IsoChk_T HVSR_IsoChk_PrevZCX;

/* Forward declaration for local functions */
static void HVSR_IsoChk_Stt_CctChk(void);
static void HVSR_enter_internal_RS_FlipFlop(const boolean_T *LogicalOperator4);
static void HVSR_IsoChk_RS_FlipFlop(const boolean_T *LogicalOperator4);

/* Function for Chart: '<S5>/HVSR_IsoInsModeCtl' */
static void HVSR_IsoChk_Stt_CctChk(void)
{
  if (HVSR_flgIsoCctChkOK || (HVSR_IsoChk_DW.CctTotalTime >=
       HVSR_tiIsoCctChkTotMax_T) || HVSR_bIsoCctChkEna_C) {
    HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_NO_ACTIVE_CHILD;
    HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_fastchk;
    HVSR_flgIsoChkStart = false;
    HVSR_stIsoStateObsr = 7U;
  } else {
    HVSR_IsoChk_DW.CctTotalTime += 0.1F;
    switch (HVSR_IsoChk_DW.is_Stt_CctChk) {
     case HVSR_IsoChk_IN_Stt_CctChkA1:
      if ((HVSR_numA1Val >= HVSR_numSwAllOpenMin_C) && (HVSR_numA1Val <=
           HVSR_numSwAllOpenMax_C)) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA2;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_A2CHK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWON;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_numA2Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
      } else if (HVSR_IsoChk_DW.CctCount > HVSR_tiIsoCctChkWait_T) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA1Err;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n = enmCctErr_CCTCLS;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_CCTERR;

        /* S1或S2或S3常闭粘连 */
      } else {
        HVSR_numA1Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
        HVSR_IsoChk_DW.CctCount += 0.1F;
      }
      break;

     case HVSR_IsoChk_IN_Stt_CctChkA1Err:
     case HVSR_IsoChk_IN_Stt_CctChkA2Err:
     case HVSR_IsoChk_IN_Stt_CctChkA3Err:
     case HVSR_IsoChk_IN_Stt_CctChkA4OKRn:
     case HVSR_IsoChk_IN_Stt_CctChkA4OKRp:
     case HVSR_IsoChk_IN_Stt_CctChkA5:
      break;

     case HVSR_IsoChk_IN_Stt_CctChkA2:
      /*   */
      if ((HVSR_numA2Val >= HVSR_numSw1ClsdMin_C) && (HVSR_numA2Val <=
           HVSR_numSw1ClsdMax_C) && ((HVSR_numA2Val - HVSR_numA1Val >=
            HVSR_numA1A2DiffMin_C) && (HVSR_numA2Val - HVSR_numA1Val <=
            HVSR_numA1A2DiffMax_C))) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA3;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_A3CHK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWON;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_numA3Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
      } else if (HVSR_IsoChk_DW.CctCount > HVSR_tiIsoCctChkWait_T) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA2Err;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n = enmCctErr_S1ERR;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_CCTERR;

        /* S1开关回路异常 */
      } else {
        HVSR_numA2Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
        HVSR_IsoChk_DW.CctCount += 0.1F;
      }
      break;

     case HVSR_IsoChk_IN_Stt_CctChkA3:
      if ((HVSR_numA3Val >= HVSR_numSw2ClsdMin_C) && (HVSR_numA3Val <=
           HVSR_numSw2ClsdMax_C) && ((HVSR_numA1Val - HVSR_numA3Val >=
            HVSR_numA1A3DiffMin_C) && (HVSR_numA1Val - HVSR_numA3Val <=
            HVSR_numA1A3DiffMax_C))) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA4;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_A4CHK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWON;
        HVSR_numA4Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
      } else if (HVSR_IsoChk_DW.CctCount > HVSR_tiIsoCctChkWait_T) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA3Err;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n = enmCctErr_S2ERR;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_CCTERR;

        /* S2开关回路异常 */
      } else {
        HVSR_numA3Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
        HVSR_IsoChk_DW.CctCount += 0.1F;
      }
      break;

     case HVSR_IsoChk_IN_Stt_CctChkA4:
      if (fabsf(HVSR_numA4Val - HVSR_numA1Val) >= HVSR_numA1A4Diff_C) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA4OK;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_A4CHK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
      } else if (HVSR_IsoChk_DW.CctCount > HVSR_tiIsoCctChkWait_T) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA4Err;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_A5CHK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWON;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWON;
        HVSR_numA5Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
      } else {
        HVSR_numA4Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
        HVSR_IsoChk_DW.CctCount += 0.1F;
      }
      break;

     case HVSR_IsoChk_IN_Stt_CctChkA4Err:
      if ((HVSR_numA5Val >= HVSR_numSw13ClsdMin_C) && (HVSR_numA5Val <=
           HVSR_numSw13ClsdMax_C)) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA5;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_flgIsoCctChkOK = true;
        HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n = enmCctErr_DEFAULT;

        /* HVSR_stIsoCctChkErr = enmCctErr.S3ERR; */
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_CCTERR;

        /* S3合不上或者Rp和Rn都非常大 */
      } else {
        HVSR_numA5Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
        HVSR_IsoChk_DW.CctCount += 0.1F;
      }
      break;

     case HVSR_IsoChk_IN_Stt_CctChkA4OK:
      if (HVSR_numA4Val - HVSR_numA1Val >= HVSR_numA1A4Diff_C) {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA4OKRn;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_CCTOK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_flgIsoCctChkOK = true;
      } else {
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA4OKRp;
        HVSR_IsoChk_DW.CctCount = 0.0F;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_CCTOK;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_flgIsoCctChkOK = true;
      }
      break;

     default:
      HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkA1;
      HVSR_IsoChk_DW.CctCount = 0.0F;
      HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_A1CHK;
      HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
      HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
      HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
      HVSR_numA1Val = BSPR_uIsoPosVolt / COMR_uBattVolt;
      break;
    }
  }
}

/* Function for Chart: '<S26>/RS' */
static void HVSR_enter_internal_RS_FlipFlop(const boolean_T *LogicalOperator4)
{
  if (*LogicalOperator4) {
    HVSR_IsoChk_B.Q = true;
  }
}

/* Function for Chart: '<S26>/RS' */
static void HVSR_IsoChk_RS_FlipFlop(const boolean_T *LogicalOperator4)
{
  HVSR_enter_internal_RS_FlipFlop(LogicalOperator4);
}

/* Model step function */
void HVSR_IsoChk_step(void)
{
  boolean_T rtb_RelationalOperator;
  boolean_T rtb_Compare;
  int8_T rtPrevAction;
  int8_T rtAction;
  real32_T rtb_Product_ai;
  real32_T rtb_Delay;
  real32_T rtb_Switch1_p;
  boolean_T rtb_RelationalOperator3_m;
  boolean_T rtb_LogicalOperator9;
  real32_T rtb_Product_ih;
  real32_T rtb_Switch_p;
  uint8_T rtb_Switch_cd;
  uint8_T rtb_BitwiseOperator4;
  uint8_T rtb_BitwiseOperator7;
  uint8_T rtb_BitwiseOperator6;
  uint8_T rtb_Switch4_e;
  uint8_T rtb_Switch4_l;
  uint8_T rtb_Switch4_o1;
  uint8_T rtb_Switch4_lr;
  boolean_T rtb_Switch9_g;
  int32_T tmp;
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  boolean_T guard3 = false;
  boolean_T guard4 = false;
  rtb_RelationalOperator = (DSMR_stFaultRank == 4);
  if (rtb_RelationalOperator) {
    rtb_Product_ai = 0.1F;
  } else {
    rtb_Product_ai = 0.0F;
  }

  rtb_Product_ai = (rtb_Product_ai + fminf(0.5F, HVSR_IsoChk_DW.Delay_DSTATE_p))
    * (real32_T)rtb_RelationalOperator;
  HVSR_IsoChk_DW.Delay_DSTATE_p = rtb_Product_ai;
  HVSR_bIsoResCalShieldCmd = (COMR_bIsoResCalShieldCmd || BCMR_bDChrgIsoStopCmd ||
    (rtb_Product_ai > 0.5F) || ((COMR_uBattVolt > HVSR_uBattVoltRngHi_C) ||
    (COMR_uBattVolt < HVSR_uBattVoltRngLo_C)) || ((BCCR_stBmsCtrMode == 1) ||
    (BCCR_stBmsCtrMode == 3) || (BCCR_stBmsCtrMode == 5) || (BCCR_stBmsCtrMode ==
    6)) || ((BCCR_stBmsDChrgCtrMode == 1) || (BCCR_stBmsDChrgCtrMode == 2) ||
            (BCCR_stBmsDChrgCtrMode == 5) || (BCCR_stBmsDChrgCtrMode == 7)));
  rtb_RelationalOperator = (HVSR_bIsoResShieldCal || HVSR_bIsoResCalShieldCmd);
  HVSR_flgBattInsResVald = HVSR_IsoChk_DW.Delay1_DSTATE_k;
  if (HVSR_IsoChk_DW.is_active_c3_HVSR_IsoChk == 0U) {
    HVSR_IsoChk_DW.is_active_c3_HVSR_IsoChk = 1U;
    HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_init;
    HVSR_flgIsoChkStart = false;
    HVSR_stIsoStateObsr = 0U;
    HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_DEFAULT;
    HVSR_IsoChk_DW.CctTotalTime = 0.0F;
  } else {
    switch (HVSR_IsoChk_DW.is_c3_HVSR_IsoChk) {
     case HVSR_IsoChk_IN_Stt_CctChk:
      HVSR_IsoChk_Stt_CctChk();
      break;

     case HVSR_IsoChk_IN_Stt_begin:
      if (HVSR_IsoChk_DW.Delay3_DSTATE_kl) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_standby;
        HVSR_IsoChk_B.init_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkFault = false;
        HVSR_flgIsoChkStart = false;
        HVSR_stIsoStateObsr = 1U;
      } else if ((HVSR_IsoChk_DW.counter > HVSR_numBgnTimeCnt_C) &&
                 HVSR_flgFrstRsVlotVld) {
        HVSR_IsoChk_DW.HVSR_cntPwrDown = 0U;
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_work;
        HVSR_IsoChk_B.init_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_ACTIVE;
        HVSR_stIsoStateObsr = 3U;
      } else {
        tmp = HVSR_IsoChk_DW.counter + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        HVSR_IsoChk_DW.counter = (uint16_T)tmp;
      }
      break;

     case HVSR_IsoChk_IN_Stt_cycle:
      if (BMCR_stBmsModeCtrl > HVSR_stBMSModeLvl_C) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_end;
        HVSR_IsoChk_B.init_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkStart = false;
        HVSR_stIsoStateObsr = 6U;
      } else if (HVSR_IsoChk_DW.Delay3_DSTATE_kl) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_standby;
        HVSR_IsoChk_B.init_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkFault = false;
        HVSR_flgIsoChkStart = false;
        HVSR_stIsoStateObsr = 1U;
      } else if ((BMCR_stBmsModeCtrl <= HVSR_stBMSModeLvl_C) &&
                 (HVSR_IsoChk_DW.count > HVSR_numCycleTimeCnt_C)) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_begin;
        HVSR_IsoChk_B.init_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkStart = true;
        HVSR_flgInsResUpd = false;
        HVSR_stIsoStateObsr = 2U;
        HVSR_IsoChk_DW.counter = 1U;
      } else {
        tmp = HVSR_IsoChk_DW.count + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        HVSR_IsoChk_DW.count = (uint16_T)tmp;
      }
      break;

     case HVSR_IsoChk_IN_Stt_end:
      break;

     case HVSR_IsoChk_IN_Stt_fastchk:
      HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_standby;
      HVSR_IsoChk_B.init_enable = enmActv_ACTIVE;
      HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
      HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
      HVSR_flgIsoChkFault = false;
      HVSR_flgIsoChkStart = false;
      HVSR_stIsoStateObsr = 1U;
      break;

     case HVSR_IsoChk_IN_Stt_fault:
      if (BMCR_stBmsModeCtrl <= HVSR_stBMSModeLvl_C) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_begin;
        HVSR_IsoChk_B.init_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkStart = true;
        HVSR_flgInsResUpd = false;
        HVSR_stIsoStateObsr = 2U;
        HVSR_IsoChk_DW.counter = 1U;
      } else {
        if (BMCR_stBmsModeCtrl > HVSR_stBMSModeLvl_C) {
          HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_end;
          HVSR_IsoChk_B.init_enable = enmActv_ACTIVE;
          HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
          HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
          HVSR_flgIsoChkStart = false;
          HVSR_stIsoStateObsr = 6U;
        }
      }
      break;

     case HVSR_IsoChk_IN_Stt_init:
      if ((BMCR_stBmsModeCtrl >= 2) && (BMCR_stBmsModeCtrl <=
           HVSR_stBMSModeLvl_C)) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_CctChk;
        HVSR_flgIsoChkStart = false;
        HVSR_stIsoStateObsr = 8U;
        HVSR_IsoChk_DW.CctTotalTime += 0.1F;
        HVSR_IsoChk_DW.is_Stt_CctChk = HVSR_IsoChk_IN_Stt_CctChkInit;
        HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_INIT;
        HVSR_numA1Val = 0.0F;
        HVSR_numA2Val = 0.0F;
        HVSR_numA3Val = 0.0F;
        HVSR_numA4Val = 0.0F;
        HVSR_numA5Val = 0.0F;
        HVSR_flgIsoCctChkOK = false;
        HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n = enmCctErr_DEFAULT;
        HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
        HVSR_IsoChk_DW.CctCount = 0.0F;
      }
      break;

     case HVSR_IsoChk_IN_Stt_standby:
      if (!HVSR_IsoChk_DW.Delay3_DSTATE_kl) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_begin;
        HVSR_IsoChk_B.init_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkStart = true;
        HVSR_flgInsResUpd = false;
        HVSR_stIsoStateObsr = 2U;
        HVSR_IsoChk_DW.counter = 1U;
      }
      break;

     default:
      if (HVSR_IsoChk_DW.Delay3_DSTATE_kl) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_standby;
        HVSR_IsoChk_B.init_enable = enmActv_ACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
        HVSR_flgIsoChkFault = false;
        HVSR_flgIsoChkStart = false;
        HVSR_stIsoStateObsr = 1U;
      } else if (HVSR_flgBattInsResVald) {
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_cycle;
        HVSR_flgInsResUpd = true;
        HVSR_flgIsoChkFault = false;
        HVSR_stIsoStateObsr = 4U;
        HVSR_IsoChk_DW.count = 0U;
      } else if ((!HVSR_flgBattInsResVald) && (HVSR_IsoChk_DW.HVSR_cntPwrDown <=
                  HVSR_cntPwrDown_C)) {
        tmp = HVSR_IsoChk_DW.HVSR_cntPwrDown + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        HVSR_IsoChk_DW.HVSR_cntPwrDown = (uint16_T)tmp;
        HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_work;
        HVSR_IsoChk_B.init_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
        HVSR_IsoChk_B.control_enable = enmActv_ACTIVE;
        HVSR_stIsoStateObsr = 3U;
      } else {
        if ((!HVSR_flgBattInsResVald) && (HVSR_IsoChk_DW.HVSR_cntPwrDown >
             HVSR_cntPwrDown_C)) {
          HVSR_IsoChk_DW.is_c3_HVSR_IsoChk = HVSR_IsoChk_IN_Stt_fault;
          HVSR_flgIsoChkFault = true;
          HVSR_stIsoStateObsr = 5U;
        }
      }
      break;
    }
  }

  HVSR_tsinit_enable = (HVSR_IsoChk_B.init_enable != 0U);
  if (HVSR_tsinit_enable) {
    HVSR_IsoChk_B.DataTypeConversion2_a = enmSWSta_SWOFF;
    HVSR_IsoChk_B.DataTypeConversion1_c = enmSWSta_SWOFF;
    HVSR_IsoChk_B.DataTypeConversion_i = enmSWSta_SWOFF;
  }

  HVSR_tsbegin_enable = (HVSR_IsoChk_B.begin_enable != 0U);
  if (HVSR_tsbegin_enable) {
    HVSR_IsoChk_B.DataTypeConversion2_l = enmSWSta_SWOFF;
    HVSR_IsoChk_B.DataTypeConversion3_j = enmSWSta_SWON;
    HVSR_IsoChk_B.DataTypeConversion1_j = enmSWSta_SWON;
    HVSR_IsoChk_B.DataTypeConversion = enmSWSta_SWOFF;
  }

  HVSR_tscontrol_enable = (HVSR_IsoChk_B.control_enable != 0U);
  if (HVSR_tscontrol_enable) {
    HVSR_IsoChk_B.DataTypeConversion1 = enmSWSta_SWON;
    HVSR_IsoChk_B.DataTypeConversion2 = enmSWSta_SWOFF;
    HVSR_IsoChk_B.DataTypeConversion3 = enmSWSta_SWON;
  }

  rtb_Compare = (HVSR_stIsoStateObsr == 8);
  if (HVSR_tsinit_enable) {
    HVSR_tsIIsoSw1Ena = HVSR_IsoChk_B.DataTypeConversion2_a;
    HVSR_tsIIsoSw2Ena = HVSR_IsoChk_B.DataTypeConversion1_c;
  } else {
    if (HVSR_tsbegin_enable) {
      HVSR_tsIIsoSw1Ena = HVSR_IsoChk_B.DataTypeConversion2_l;
    } else if (HVSR_tscontrol_enable) {
      HVSR_tsIIsoSw1Ena = HVSR_IsoChk_B.DataTypeConversion1;
    } else if (rtb_Compare) {
      HVSR_tsIIsoSw1Ena = (HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta != 0U);
    } else {
      HVSR_tsIIsoSw1Ena = false;
    }

    if (HVSR_tsbegin_enable) {
      HVSR_tsIIsoSw2Ena = HVSR_IsoChk_B.DataTypeConversion3_j;
    } else if (HVSR_tscontrol_enable) {
      HVSR_tsIIsoSw2Ena = HVSR_IsoChk_B.DataTypeConversion2;
    } else if (rtb_Compare) {
      HVSR_tsIIsoSw2Ena = (HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta != 0U);
    } else {
      HVSR_tsIIsoSw2Ena = false;
    }
  }

  if (rtb_RelationalOperator) {
    HVSR_bIsoSwt1Ena = HVSR_IsoChk_ConstB.DataTypeConversion3_f;
  } else if (HVSR_bSwEnaByMnl_C) {
    HVSR_bIsoSwt1Ena = HVSR_bSw1EnaByMnl_C;
  } else {
    HVSR_bIsoSwt1Ena = HVSR_tsIIsoSw1Ena;
  }

  if (HVSR_tsinit_enable) {
    HVSR_tsIIsoSw3Ena = HVSR_IsoChk_B.DataTypeConversion_i;
  } else {
    if (HVSR_tsbegin_enable) {
      rtb_Compare = HVSR_IsoChk_B.DataTypeConversion1_j;
    } else if (HVSR_tscontrol_enable) {
      rtb_Compare = HVSR_IsoChk_B.DataTypeConversion3;
    } else {
      if (rtb_Compare) {
        rtb_Compare = (HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta != 0U);
      }
    }

    HVSR_tsIIsoSw3Ena = rtb_Compare;
  }

  if (rtb_RelationalOperator) {
    HVSR_bIsoSwt2Ena = HVSR_IsoChk_ConstB.DataTypeConversion2_f;
    HVSR_bIsoSwt3Ena = HVSR_IsoChk_ConstB.DataTypeConversion5;
  } else {
    if (HVSR_bSwEnaByMnl_C) {
      HVSR_bIsoSwt2Ena = HVSR_bSw2EnaByMnl_C;
    } else {
      HVSR_bIsoSwt2Ena = HVSR_tsIIsoSw2Ena;
    }

    if (HVSR_bSwEnaByMnl_C) {
      HVSR_bIsoSwt3Ena = HVSR_bSw3EnaByMnl_C;
    } else {
      HVSR_bIsoSwt3Ena = HVSR_tsIIsoSw3Ena;
    }
  }

  HVSR_bIsoSwt4Ena = (boolean_T)enmSWSta_SWOFF;
  rtb_Delay = HVSR_IsoChk_B.MinMax;
  rtb_Product_ai = HVSR_IsoChk_B.OutportBufferForHVSR_resIsoTheo;
  if (HVSR_IsoChk_DW.Delay_DSTATE_iz) {
    rtb_Switch1_p = BSPR_uIsoPosVolt;
  } else {
    rtb_Switch1_p = (BSPR_uIsoPosVolt - HVSR_IsoChk_DW.UnitDelay_DSTATE_j) *
      HVSR_uIsoPosVoltFilter_C + HVSR_IsoChk_DW.UnitDelay_DSTATE_j;
  }

  HVSR_IsoChk_DW.UnitDelay_DSTATE_j = rtb_Switch1_p;
  HVSR_IsoChk_DW.Delay_DSTATE_iz = false;
  rtPrevAction = HVSR_IsoChk_DW.If_ActiveSubsystem;
  if (HVSR_tsbegin_enable && (!HVSR_tscontrol_enable)) {
    rtAction = 0;
  } else if ((!HVSR_tsbegin_enable) && HVSR_tscontrol_enable) {
    rtAction = 1;
  } else {
    rtAction = 2;
  }

  HVSR_IsoChk_DW.If_ActiveSubsystem = rtAction;
  switch (rtAction) {
   case 0:
    if (rtAction != rtPrevAction) {
      HVSR_IsoChk_DW.UnitDelay_DSTATE_k = 0.0F;
      HVSR_IsoChk_DW.Delay_DSTATE_ia = true;
      HVSR_IsoChk_DW.Delay_DSTATE_lk = 0.0F;
      HVSR_IsoChk_DW.is_active_c4_HVSR_IsoChk = 0U;
      HVSR_IsoChk_DW.is_c4_HVSR_IsoChk = HVSR_IsoChk_IN_NO_ACTIVE_CHILD;
      HVSR_IsoChk_DW.Slope_RS_c = 0.0F;
      HVSR_IsoChk_DW.V1_k = 0.0F;
      HVSR_IsoChk_DW.KIRS_filter_slope_f = 0U;
      HVSR_IsoChk_DW.cnt_c = 0U;
      HVSR_IsoChk_DW.tc_j = 0.0F;
      HVSR_bFrstSlopeVld = false;
    }

    HVSR_uIsoFrstRsVolt = rtb_Switch1_p;
    if (!HVSR_IsoChk_DW.Delay_DSTATE_ia) {
      rtb_Switch1_p = (HVSR_uIsoFrstRsVolt - HVSR_IsoChk_DW.UnitDelay_DSTATE_k) *
        HVSR_cofPosVoltfilter_C + HVSR_IsoChk_DW.UnitDelay_DSTATE_k;
    }

    HVSR_IsoChk_DW.UnitDelay_DSTATE_k = rtb_Switch1_p;
    HVSR_IsoChk_DW.Delay_DSTATE_ia = false;
    rtb_Compare = (fabsf(rtb_Switch1_p - HVSR_uIsoFrstRsVolt) <=
                   HVSR_uIsoKVoltThres_C);
    if (rtb_Compare) {
      rtb_Switch1_p = HVSR_tiTaskTime_C;
    } else {
      rtb_Switch1_p = 0.0F;
    }

    rtb_Switch1_p = (rtb_Switch1_p + fminf(HVSR_tiChkFilteTime_C,
      HVSR_IsoChk_DW.Delay_DSTATE_lk)) * (real32_T)rtb_Compare;
    HVSR_flgFrstRsKVld = (rtb_Switch1_p > HVSR_tiChkFilteTime_C);
    HVSR_IsoChk_DW.Delay_DSTATE_lk = rtb_Switch1_p;
    if (HVSR_flgFrstRsKVld) {
      HVSR_uFrstRsVlot = HVSR_uIsoFrstRsVolt;
    } else {
      HVSR_uFrstRsVlot = 0.0F;
    }

    if (HVSR_IsoChk_DW.is_active_c4_HVSR_IsoChk == 0U) {
      HVSR_IsoChk_DW.is_active_c4_HVSR_IsoChk = 1U;
      HVSR_IsoChk_DW.is_c4_HVSR_IsoChk = HVSR_IsoChk_IN_Fast_mode_init;
      HVSR_IsoChk_DW.Slope_RS_c = 100.0F;
      HVSR_IsoChk_DW.cnt_c = 0U;
      HVSR_IsoChk_DW.tc_j = HVSR_tiIsoChkCycl_T;
      HVSR_bFrstSlopeVld = false;
    } else {
      guard3 = false;
      guard4 = false;
      switch (HVSR_IsoChk_DW.is_c4_HVSR_IsoChk) {
       case HVSR_IsoChk_IN_Fast_mode_end:
        break;

       case HVSR_IsoChk_IN_Fast_mode_filter:
        if (HVSR_bFrstSlopeVld) {
          HVSR_IsoChk_DW.cnt_c = 0U;
          HVSR_IsoChk_DW.is_c4_HVSR_IsoChk = HVSR_IsoChk_IN_Fast_mode_end;
        } else {
          rtb_Switch1_p = HVSR_IsoChk_DW.V1_k;
          if (fabsf(HVSR_IsoChk_DW.Slope_RS_c) < HVSR_kSlopeVal_C) {
            tmp = HVSR_IsoChk_DW.KIRS_filter_slope_f + 1;
            if (tmp > 255) {
              tmp = 255;
            }

            HVSR_IsoChk_DW.KIRS_filter_slope_f = (uint8_T)tmp;
            guard4 = true;
          } else {
            HVSR_IsoChk_DW.V1_k = HVSR_uIsoFrstRsVolt;
            HVSR_IsoChk_DW.KIRS_filter_slope_f = 0U;
            if (HVSR_IsoChk_DW.cnt_c > 0) {
              guard4 = true;
            } else {
              tmp = HVSR_IsoChk_DW.cnt_c + 1;
              if (tmp > 255) {
                tmp = 255;
              }

              HVSR_IsoChk_DW.cnt_c = (uint8_T)tmp;
            }
          }
        }
        break;

       default:
        HVSR_IsoChk_DW.is_c4_HVSR_IsoChk = HVSR_IsoChk_IN_Fast_mode_filter;
        HVSR_IsoChk_DW.Slope_RS_c = 100.0F;
        HVSR_IsoChk_DW.cnt_c = 0U;
        HVSR_bFrstSlopeVld = false;
        HVSR_IsoChk_DW.KIRS_filter_slope_f = 0U;
        if (fabsf(HVSR_IsoChk_DW.Slope_RS_c) < HVSR_kSlopeVal_C) {
          tmp = HVSR_IsoChk_DW.KIRS_filter_slope_f + 1;
          if (tmp > 255) {
            tmp = 255;
          }

          HVSR_IsoChk_DW.KIRS_filter_slope_f = (uint8_T)tmp;
          guard3 = true;
        } else {
          HVSR_IsoChk_DW.V1_k = HVSR_uIsoFrstRsVolt;
          HVSR_IsoChk_DW.KIRS_filter_slope_f = 0U;
          if (HVSR_IsoChk_DW.cnt_c > 0) {
            guard3 = true;
          } else {
            tmp = HVSR_IsoChk_DW.cnt_c + 1;
            if (tmp > 255) {
              tmp = 255;
            }

            HVSR_IsoChk_DW.cnt_c = (uint8_T)tmp;
          }
        }
        break;
      }

      if (guard4) {
        if (HVSR_IsoChk_DW.KIRS_filter_slope_f > HVSR_numSlopeCnfrm_C) {
          HVSR_bFrstSlopeVld = true;
        } else {
          HVSR_IsoChk_DW.V1_k = HVSR_uIsoFrstRsVolt;
          HVSR_IsoChk_DW.Slope_RS_c = (HVSR_IsoChk_DW.V1_k - rtb_Switch1_p) /
            HVSR_IsoChk_DW.tc_j;
          tmp = HVSR_IsoChk_DW.cnt_c + 1;
          if (tmp > 255) {
            tmp = 255;
          }

          HVSR_IsoChk_DW.cnt_c = (uint8_T)tmp;
        }
      }

      if (guard3) {
        if (HVSR_IsoChk_DW.KIRS_filter_slope_f > HVSR_numSlopeCnfrm_C) {
          HVSR_bFrstSlopeVld = true;
        } else {
          HVSR_IsoChk_DW.V1_k = HVSR_uIsoFrstRsVolt;
          HVSR_IsoChk_DW.Slope_RS_c = HVSR_IsoChk_DW.V1_k / HVSR_IsoChk_DW.tc_j;
          tmp = HVSR_IsoChk_DW.cnt_c + 1;
          if (tmp > 255) {
            tmp = 255;
          }

          HVSR_IsoChk_DW.cnt_c = (uint8_T)tmp;
        }
      }
    }

    HVSR_flgFrstRsVlotVld = (HVSR_flgFrstRsKVld && HVSR_bFrstSlopeVld);
    if (HVSR_flgFrstRsVlotVld && (HVSR_IsoChk_PrevZCX.HVSR_IsoParCalc_Trig_ZCE_k
         != POS_ZCSIG)) {
      if (HVSR_uFrstRsVlot > 0.0F) {
        rtb_Product_ih = HVSR_uFrstRsVlot;
      } else {
        rtb_Product_ih = COMR_uBattVolt;
      }

      HVSR_numIsoFrstVal = (COMR_uBattVolt - HVSR_uFrstRsVlot) / rtb_Product_ih;
    }

    HVSR_IsoChk_PrevZCX.HVSR_IsoParCalc_Trig_ZCE_k = HVSR_flgFrstRsVlotVld;
    break;

   case 1:
    if (rtAction != rtPrevAction) {
      HVSR_IsoChk_DW.UnitDelay_DSTATE_l = 0.0F;
      HVSR_IsoChk_DW.Delay_DSTATE_m = true;
      HVSR_IsoChk_DW.Delay_DSTATE_ht = 0.0F;
      HVSR_IsoChk_DW.is_active_c5_HVSR_IsoChk = 0U;
      HVSR_IsoChk_DW.is_c5_HVSR_IsoChk = HVSR_IsoChk_IN_NO_ACTIVE_CHILD;
      HVSR_IsoChk_DW.Slope_RS = 0.0F;
      HVSR_IsoChk_DW.V1 = 0.0F;
      HVSR_IsoChk_DW.KIRS_filter_slope = 0U;
      HVSR_IsoChk_DW.cnt = 0U;
      HVSR_IsoChk_DW.tc = 0.0F;
      HVSR_bScndSlopeVld = false;
    }

    HVSR_uIsoScndRsVolt = rtb_Switch1_p;
    if (!HVSR_IsoChk_DW.Delay_DSTATE_m) {
      rtb_Switch1_p = (HVSR_uIsoScndRsVolt - HVSR_IsoChk_DW.UnitDelay_DSTATE_l) *
        HVSR_cofPosVoltfilter_C + HVSR_IsoChk_DW.UnitDelay_DSTATE_l;
    }

    HVSR_IsoChk_DW.UnitDelay_DSTATE_l = rtb_Switch1_p;
    HVSR_IsoChk_DW.Delay_DSTATE_m = false;
    rtb_Compare = (fabsf(rtb_Switch1_p - HVSR_uIsoScndRsVolt) <=
                   HVSR_uIsoKVoltThres_C);
    if (rtb_Compare) {
      rtb_Switch1_p = HVSR_tiTaskTime_C;
    } else {
      rtb_Switch1_p = 0.0F;
    }

    rtb_Switch1_p = (rtb_Switch1_p + fminf(HVSR_tiChkFilteTime_C,
      HVSR_IsoChk_DW.Delay_DSTATE_ht)) * (real32_T)rtb_Compare;
    HVSR_flgScndRsKVld = (rtb_Switch1_p > HVSR_tiChkFilteTime_C);
    HVSR_IsoChk_DW.Delay_DSTATE_ht = rtb_Switch1_p;
    if (HVSR_flgScndRsKVld) {
      HVSR_uScndRsVlot = HVSR_uIsoScndRsVolt;
    } else {
      HVSR_uScndRsVlot = 0.0F;
    }

    if (HVSR_IsoChk_DW.is_active_c5_HVSR_IsoChk == 0U) {
      HVSR_IsoChk_DW.is_active_c5_HVSR_IsoChk = 1U;
      HVSR_IsoChk_DW.is_c5_HVSR_IsoChk = HVSR_IsoChk_IN_Fast_mode_init;
      HVSR_IsoChk_DW.Slope_RS = 100.0F;
      HVSR_IsoChk_DW.cnt = 0U;
      HVSR_IsoChk_DW.tc = HVSR_tiIsoChkCycl_T;
      HVSR_bScndSlopeVld = false;
    } else {
      guard1 = false;
      guard2 = false;
      switch (HVSR_IsoChk_DW.is_c5_HVSR_IsoChk) {
       case HVSR_IsoChk_IN_Fast_mode_end:
        break;

       case HVSR_IsoChk_IN_Fast_mode_filter:
        if (HVSR_bScndSlopeVld) {
          HVSR_IsoChk_DW.cnt = 0U;
          HVSR_IsoChk_DW.is_c5_HVSR_IsoChk = HVSR_IsoChk_IN_Fast_mode_end;
        } else {
          rtb_Switch1_p = HVSR_IsoChk_DW.V1;
          if (fabsf(HVSR_IsoChk_DW.Slope_RS) < HVSR_kSlopeVal_C) {
            tmp = HVSR_IsoChk_DW.KIRS_filter_slope + 1;
            if (tmp > 255) {
              tmp = 255;
            }

            HVSR_IsoChk_DW.KIRS_filter_slope = (uint8_T)tmp;
            guard2 = true;
          } else {
            HVSR_IsoChk_DW.V1 = HVSR_uIsoScndRsVolt;
            HVSR_IsoChk_DW.KIRS_filter_slope = 0U;
            if (HVSR_IsoChk_DW.cnt > 0) {
              guard2 = true;
            } else {
              tmp = HVSR_IsoChk_DW.cnt + 1;
              if (tmp > 255) {
                tmp = 255;
              }

              HVSR_IsoChk_DW.cnt = (uint8_T)tmp;
            }
          }
        }
        break;

       default:
        HVSR_IsoChk_DW.is_c5_HVSR_IsoChk = HVSR_IsoChk_IN_Fast_mode_filter;
        HVSR_IsoChk_DW.Slope_RS = 100.0F;
        HVSR_IsoChk_DW.cnt = 0U;
        HVSR_bScndSlopeVld = false;
        HVSR_IsoChk_DW.KIRS_filter_slope = 0U;
        if (fabsf(HVSR_IsoChk_DW.Slope_RS) < HVSR_kSlopeVal_C) {
          tmp = HVSR_IsoChk_DW.KIRS_filter_slope + 1;
          if (tmp > 255) {
            tmp = 255;
          }

          HVSR_IsoChk_DW.KIRS_filter_slope = (uint8_T)tmp;
          guard1 = true;
        } else {
          HVSR_IsoChk_DW.V1 = HVSR_uIsoScndRsVolt;
          HVSR_IsoChk_DW.KIRS_filter_slope = 0U;
          if (HVSR_IsoChk_DW.cnt > 0) {
            guard1 = true;
          } else {
            tmp = HVSR_IsoChk_DW.cnt + 1;
            if (tmp > 255) {
              tmp = 255;
            }

            HVSR_IsoChk_DW.cnt = (uint8_T)tmp;
          }
        }
        break;
      }

      if (guard2) {
        if (HVSR_IsoChk_DW.KIRS_filter_slope > HVSR_numSlopeCnfrm_C) {
          HVSR_bScndSlopeVld = true;
        } else {
          HVSR_IsoChk_DW.V1 = HVSR_uIsoScndRsVolt;
          HVSR_IsoChk_DW.Slope_RS = (HVSR_IsoChk_DW.V1 - rtb_Switch1_p) /
            HVSR_IsoChk_DW.tc;
          tmp = HVSR_IsoChk_DW.cnt + 1;
          if (tmp > 255) {
            tmp = 255;
          }

          HVSR_IsoChk_DW.cnt = (uint8_T)tmp;
        }
      }

      if (guard1) {
        if (HVSR_IsoChk_DW.KIRS_filter_slope > HVSR_numSlopeCnfrm_C) {
          HVSR_bScndSlopeVld = true;
        } else {
          HVSR_IsoChk_DW.V1 = HVSR_uIsoScndRsVolt;
          HVSR_IsoChk_DW.Slope_RS = HVSR_IsoChk_DW.V1 / HVSR_IsoChk_DW.tc;
          tmp = HVSR_IsoChk_DW.cnt + 1;
          if (tmp > 255) {
            tmp = 255;
          }

          HVSR_IsoChk_DW.cnt = (uint8_T)tmp;
        }
      }
    }

    HVSR_flgScndRsVlotVld = (HVSR_flgScndRsKVld && HVSR_bScndSlopeVld);
    if (HVSR_flgScndRsVlotVld && (HVSR_IsoChk_PrevZCX.HVSR_IsoParCalc_Trig_ZCE
         != POS_ZCSIG)) {
      if (HVSR_uScndRsVlot > 0.0F) {
        rtb_Product_ih = HVSR_uScndRsVlot;
      } else {
        rtb_Product_ih = COMR_uBattVolt;
      }

      HVSR_numIsoScndVal = (COMR_uBattVolt - HVSR_uScndRsVlot) / rtb_Product_ih;
    }

    HVSR_IsoChk_PrevZCX.HVSR_IsoParCalc_Trig_ZCE = HVSR_flgScndRsVlotVld;
    break;

   case 2:
    break;
  }

  HVSR_bIsoFlgResVld1 = ((!HVSR_tsbegin_enable) && (!HVSR_tscontrol_enable));
  HVSR_bIsoFlgResVld2 = (HVSR_flgScndRsVlotVld && HVSR_flgFrstRsVlotVld);
  rtb_Compare = !HVSR_bIsoFlgResVld1;
  if (rtb_Compare) {
    rtb_Switch1_p = HVSR_tiTaskTime_C;
  } else {
    rtb_Switch1_p = 0.0F;
  }

  rtb_Switch1_p = (rtb_Switch1_p + fminf(HVSR_tiVoltDiffThres_C,
    HVSR_IsoChk_DW.Delay_DSTATE_oc)) * (real32_T)rtb_Compare;
  HVSR_IsoChk_DW.Delay_DSTATE_oc = rtb_Switch1_p;
  HVSR_bIsoFlgResVld5 = (HVSR_bVldEnaByMnl_C || HVSR_bIsoFlgResVld2);
  if (HVSR_bIsoFlgResVld5) {
    rtb_Product_ih = HVSR_tiTaskTime_C;
  } else {
    rtb_Product_ih = 0.0F;
  }

  rtb_Product_ih = (rtb_Product_ih + fminf(HVSR_tiVoltDiffThres_C,
    HVSR_IsoChk_DW.Delay_DSTATE_g1)) * (real32_T)HVSR_bIsoFlgResVld5;
  HVSR_IsoChk_DW.Delay_DSTATE_g1 = rtb_Product_ih;
  HVSR_bIsoFlgResVld = ((rtb_Switch1_p > HVSR_tiVoltDiffThres_C) &&
                        (rtb_Product_ih > HVSR_tiVoltDiffThres_C));
  HVSR_bIsoFlgResVld3 = ((HVSR_uIsoFrstRsVolt != 0.0F) && HVSR_flgFrstRsVlotVld &&
    (HVSR_uScndRsVlot != 0.0F) && HVSR_flgScndRsVlotVld);
  HVSR_BattInsResVald = (HVSR_bIsoFlgResVld3 && HVSR_bIsoFlgResVld);
  rtb_Compare = ((!HVSR_IsoChk_DW.Delay1_DSTATE_b) && HVSR_BattInsResVald);
  HVSR_IsoChk_DW.Delay1_DSTATE_b = HVSR_BattInsResVald;
  if (HVSR_IsoChk_DW.is_active_c2_HVSR_IsoChk == 0U) {
    HVSR_IsoChk_DW.is_active_c2_HVSR_IsoChk = 1U;
    HVSR_enter_internal_RS_FlipFlop(&rtb_Compare);
  } else {
    HVSR_IsoChk_RS_FlipFlop(&rtb_Compare);
  }

  HVSR_flgIFlipFlopVal = ((!HVSR_IsoChk_DW.Delay1_DSTATE_h) && HVSR_IsoChk_B.Q);
  HVSR_IsoChk_DW.Delay1_DSTATE_h = HVSR_IsoChk_B.Q;
  if (HVSR_BattInsResVald) {
    rtb_Switch1_p = fabsf(HVSR_numIsoFrstVal);
    rtb_Product_ih = fabsf(HVSR_numIsoScndVal);
    rtb_Switch_p = fabsf(rtb_Switch1_p * rtb_Product_ih *
                         HVSR_IsoChk_ConstB.DataTypeConversion3_k + (fabsf
      (HVSR_numIsoScndVal) * HVSR_IsoChk_ConstB.Abs4_c - HVSR_numIsoFrstVal));
    if (!(rtb_Switch_p > 0.0F)) {
      rtb_Switch_p = HVSR_IsoChk_ConstB.DataTypeConversion2_n;
    }

    rtb_Switch1_p = fabsf(fabsf(rtb_Switch1_p - rtb_Product_ih) / rtb_Switch_p *
                          fabsf(HVSR_numIsoCnst_C));
    if (rtb_Switch1_p > 6.0E+7F) {
      HVSR_resBattInsRes1 = 6.0E+7F;
    } else {
      HVSR_resBattInsRes1 = rtb_Switch1_p;
    }

    rtb_Switch1_p = fabsf((fabsf(HVSR_numIsoScndVal) * HVSR_IsoChk_ConstB.Abs4 -
      HVSR_numIsoFrstVal) + HVSR_IsoChk_ConstB.DataTypeConversion3);
    if (!(rtb_Switch1_p > 0.0F)) {
      rtb_Switch1_p = HVSR_IsoChk_ConstB.DataTypeConversion2;
    }

    rtb_Switch1_p = fabsf(fabsf(fabsf(HVSR_numIsoFrstVal) - fabsf
      (HVSR_numIsoScndVal)) / rtb_Switch1_p * fabsf(HVSR_numIsoCnst_C));
    if (rtb_Switch1_p > 6.0E+7F) {
      HVSR_resBattInsRes2 = 6.0E+7F;
    } else {
      HVSR_resBattInsRes2 = rtb_Switch1_p;
    }

    HVSR_IsoChk_B.MinMax = fminf(HVSR_resBattInsRes1, HVSR_resBattInsRes2);
    HVSR_IsoChk_B.OutportBufferForHVSR_resIsoTheo = HVSR_IsoChk_B.MinMax;
  }

  rtb_Compare = !HVSR_IsoChk_DW.Delay1_DSTATE_o;
  HVSR_IsoChk_DW.Delay1_DSTATE_o = HVSR_BattInsResVald;
  if (rtb_Compare && HVSR_BattInsResVald) {
    HVSR_IsoChk_B.In1 = HVSR_IsoChk_B.MinMax;
  }

  rtb_Compare = ((HVSR_IsoChk_DW.Delay_DSTATE_i2 || (fabsf(HVSR_IsoChk_B.In1 -
    HVSR_IsoChk_DW.Delay3_DSTATE) >= 1000.0F * HVSR_deltInsRes_C)) &&
                 (!HVSR_IsoChk_DW.Delay2_DSTATE_a));
  HVSR_flgInsResChngVld = (HVSR_flgIFlipFlopVal || (!rtb_Compare));
  HVSR_flgIsoVldLmt = (HVSR_BattInsResVald && HVSR_flgInsResChngVld);
  if ((!HVSR_flgIsoVldLmt) && (HVSR_IsoChk_PrevZCX.Subsystem1_Trig_ZCE !=
       ZERO_ZCSIG)) {
    HVSR_flgIsoUpdtVld = (rtb_Delay > HVSR_rIsoCnfHysDiag_C);
    rtb_Switch9_g = (rtb_Delay > HVSR_rIsoCnfHysLv1Diag_C);
    rtb_Switch_cd = (uint8_T)!HVSR_flgIsoUpdtVld;
    rtb_Switch1_p = ((real32_T)rtb_Switch_cd + fminf(HVSR_cntIsoChkCnfDiag_C,
      HVSR_IsoChk_DW.Delay_DSTATE_p33)) * (real32_T)rtb_Switch_cd;
    HVSR_IsoChk_DW.Delay_DSTATE_p33 = rtb_Switch1_p;
    rtb_Switch_cd = (uint8_T)(HVSR_flgIsoUpdtVld && (!rtb_Switch9_g));
    rtb_Product_ih = ((real32_T)rtb_Switch_cd + fminf(HVSR_cntIsoChkCnfLv1Diag_C,
      HVSR_IsoChk_DW.Delay_DSTATE_lg)) * (real32_T)rtb_Switch_cd;
    HVSR_IsoChk_DW.Delay_DSTATE_lg = rtb_Product_ih;
    if ((rtb_Switch1_p > HVSR_cntIsoChkCnfDiag_C) || rtb_Switch9_g ||
        (rtb_Product_ih > HVSR_cntIsoChkCnfLv1Diag_C)) {
      HVSR_IsoChk_B.Switch = rtb_Delay;
    }

    rtb_Switch9_g = (rtb_Product_ai > HVSR_rIsoCnfHysDiag_C);
    rtb_RelationalOperator3_m = (rtb_Product_ai > HVSR_rIsoCnfHysLv1Diag_C);
    rtb_Switch_cd = (uint8_T)!rtb_Switch9_g;
    rtb_Delay = ((real32_T)rtb_Switch_cd + fminf(HVSR_cntIsoChkCnfDiag_C,
      HVSR_IsoChk_DW.Delay_DSTATE_d)) * (real32_T)rtb_Switch_cd;
    HVSR_IsoChk_DW.Delay_DSTATE_d = rtb_Delay;
    rtb_Switch_cd = (uint8_T)(rtb_Switch9_g && (!rtb_RelationalOperator3_m));
    rtb_Switch1_p = ((real32_T)rtb_Switch_cd + fminf(HVSR_cntIsoChkCnfLv1Diag_C,
      HVSR_IsoChk_DW.Delay_DSTATE_le)) * (real32_T)rtb_Switch_cd;
    HVSR_IsoChk_DW.Delay_DSTATE_le = rtb_Switch1_p;
    if ((rtb_Delay > HVSR_cntIsoChkCnfDiag_C) || rtb_RelationalOperator3_m ||
        (rtb_Switch1_p > HVSR_cntIsoChkCnfLv1Diag_C)) {
      HVSR_IsoChk_B.Switch1 = rtb_Product_ai;
    }
  }

  HVSR_IsoChk_PrevZCX.Subsystem1_Trig_ZCE = HVSR_flgIsoVldLmt;
  if (HVSR_InsResCtrlSw_C) {
    rtb_Product_ai = HVSR_IsoChk_B.Switch;
  } else {
    rtb_Product_ai = HVSR_IsoChk_B.MinMax;
  }

  rtb_Switch1_p = HVSR_cofResGain_C * rtb_Product_ai * 0.001F;
  if (rtb_Switch1_p > HVSR_resRstnUpLim_C) {
    HVSR_rInsResVal = HVSR_resRstnUpLim_C;
  } else if (rtb_Switch1_p < 0.0F) {
    HVSR_rInsResVal = 0.0F;
  } else {
    HVSR_rInsResVal = rtb_Switch1_p;
  }

  HVSR_bInsResValZero = (HVSR_rInsResVal == 0.0F);
  if (HVSR_flgBattInsResVald) {
    rtb_Product_ih = HVSR_tiTaskTime_C;
  } else {
    rtb_Product_ih = 0.0F;
  }

  HVSR_tiIsoChkTimer = rtb_Product_ih + HVSR_tiIsoChkTimer;
  if (HVSR_ResFirstCtrlSw_C) {
    if (HVSR_tiIsoChkTimer == 0.0F) {
      if (HVSR_bInsResValZero) {
        HVSR_resIso = 7777.0F;
      } else {
        HVSR_resIso = HVSR_rInsResVal;
      }
    } else {
      HVSR_resIso = HVSR_rInsResVal;
    }
  } else {
    HVSR_resIso = HVSR_rInsResVal;
  }

  if (HVSR_InsResCtrlSw_C) {
    rtb_Product_ih = HVSR_IsoChk_B.Switch1;
  } else {
    rtb_Product_ih = HVSR_IsoChk_B.OutportBufferForHVSR_resIsoTheo;
  }

  HVSR_resIsoTheory = HVSR_cofResGain_C * rtb_Product_ih * 0.001F;
  if (HVSR_tsbegin_enable) {
    HVSR_uIsoVoltPos = HVSR_uIsoFrstRsVolt;
  } else if (HVSR_tscontrol_enable) {
    HVSR_uIsoVoltPos = HVSR_uIsoScndRsVolt;
  } else {
    HVSR_uIsoVoltPos = (real32_T)HVSR_tsinit_enable;
  }

  HVSR_uIsoVoltNeg = 0.0F;
  rtb_RelationalOperator3_m = ((HVSR_resIsoFaultLvl2Thres_C <
    HVSR_IsoChk_DW.Delay2_DSTATE) && (HVSR_resIsoFaultLvl1Thres_C >=
    HVSR_IsoChk_DW.Delay2_DSTATE));
  rtb_Switch9_g = ((HVSR_resIsoFaultLvl2Thres_C >= HVSR_IsoChk_DW.Delay_DSTATE_l)
                   && (HVSR_IsoChk_DW.Delay_DSTATE_l != 0.0F));
  HVSR_stIsoCctChkErr = HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n;
  if ((BMCR_stBmsModeCtrl >= HVSR_IsoChk_ConstB.DataTypeConversion) &&
      (BMCR_stBmsModeCtrl <= HVSR_stBMSModeLvl_C)) {
    HVSR_bISOHVOffFlg = ((BCCR_stBmsCtrMode == 90) || (BCCR_stBmsCtrMode == 0) ||
                         (BCCR_stBmsCtrMode == 17) || (BCCR_stBmsCtrMode == 14) ||
                         (BCCR_stBmsCtrMode == 7));
    rtb_LogicalOperator9 = ((!HVSR_bISOHVOffFlg) && (!BCMR_bDChrgCnnt) &&
      rtb_Switch9_g);
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_gf)) * (real32_T)rtb_LogicalOperator9;
    rtb_LogicalOperator9 = (rtb_Delay > HVSR_tiIsoChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_gf = rtb_Delay;
    rtb_BitwiseOperator4 = (uint8_T)(HVSR_cntIsoChkDiag_CW & 1);
    HVSR_flgIsoFaultLvl2 = ((rtb_BitwiseOperator4 != 0) && rtb_LogicalOperator9);
    rtb_LogicalOperator9 = !rtb_LogicalOperator9;
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_p3)) * (real32_T)rtb_LogicalOperator9;
    HVSR_IsoChk_DW.Delay_DSTATE_p3 = rtb_Delay;
    HVSR_flgIsoFaultLvl2Heal = ((!(rtb_BitwiseOperator4 != 0)) || (rtb_Delay >
      HVSR_tiIsoChkDebounce_C));
    if (HVSR_IsoChk_DW.Delay2_DSTATE_jz) {
      rtb_Switch_cd = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoChkLv2_ASW | 8U);
    } else if (HVSR_flgIsoFaultLvl2) {
      rtb_Switch_cd = (uint8_T)(DFC_IsoChkLv2_ASW | 152U);
    } else if (HVSR_flgIsoFaultLvl2Heal) {
      rtb_Switch_cd = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_IsoChkLv2_ASW |
        16U) | 8U);
    } else {
      rtb_Switch_cd = HVSR_IsoChk_DW.Delay3_DSTATE_b;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_jz = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_b = rtb_Switch_cd;
    DFC_IsoChkLv2_ASW = rtb_Switch_cd;
    rtb_LogicalOperator9 = (HVSR_stIsoCctChkErr ==
      HVSR_IsoChk_ConstB.DataTypeConversion3_h);
    rtb_BitwiseOperator7 = (uint8_T)(HVSR_cntIsoChkDiag_CW & 8);
    if (HVSR_IsoChk_DW.Delay2_DSTATE_iz) {
      rtb_Switch4_e = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoS3SwStuckClsd_ASW | 8U);
    } else if ((rtb_BitwiseOperator7 != 0) && rtb_LogicalOperator9) {
      rtb_Switch4_e = (uint8_T)(DFC_IsoS3SwStuckClsd_ASW | 152U);
    } else {
      if (rtb_BitwiseOperator7 != 0) {
        rtb_LogicalOperator9 = !rtb_LogicalOperator9;
      } else {
        rtb_LogicalOperator9 = true;
      }

      if (rtb_LogicalOperator9) {
        rtb_Switch4_e = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_IsoS3SwStuckClsd_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_e = HVSR_IsoChk_DW.Delay3_DSTATE_h;
      }
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_iz = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_h = rtb_Switch4_e;
    DFC_IsoS3SwStuckClsd_ASW = rtb_Switch4_e;
    if (HVSR_IsoChk_DW.Delay2_DSTATE_e) {
      rtb_Switch4_e = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoS2SwStuckClsd_ASW | 8U);
    } else if ((!(rtb_BitwiseOperator7 != 0)) ||
               HVSR_IsoChk_ConstB.LogicalOperator5) {
      rtb_Switch4_e = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_IsoS2SwStuckClsd_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_e = HVSR_IsoChk_DW.Delay3_DSTATE_f;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_e = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_f = rtb_Switch4_e;
    DFC_IsoS2SwStuckClsd_ASW = rtb_Switch4_e;
    rtb_LogicalOperator9 = (BCMR_bDChrgCnnt && rtb_RelationalOperator3_m);
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_b)) * (real32_T)rtb_LogicalOperator9;
    rtb_LogicalOperator9 = (rtb_Delay > HVSR_tiIsoChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_b = rtb_Delay;
    rtb_BitwiseOperator6 = (uint8_T)(HVSR_cntIsoChkDiag_CW & 2);
    HVSR_flgDCIsoFaultLvl1 = ((rtb_BitwiseOperator6 != 0) &&
      rtb_LogicalOperator9);
    rtb_LogicalOperator9 = !rtb_LogicalOperator9;
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_g)) * (real32_T)rtb_LogicalOperator9;
    HVSR_IsoChk_DW.Delay_DSTATE_g = rtb_Delay;
    HVSR_flgDCIsoFaultLvl1Heal = ((!(rtb_BitwiseOperator6 != 0)) || (rtb_Delay >
      HVSR_tiIsoChkDebounce_C));
    if (HVSR_IsoChk_DW.Delay2_DSTATE_mu) {
      rtb_Switch4_e = (uint8_T)~(uint8_T)((uint8_T)~DFC_DchrgIsoChkLv1_ASW | 8U);
    } else if (HVSR_flgDCIsoFaultLvl1) {
      rtb_Switch4_e = (uint8_T)(DFC_DchrgIsoChkLv1_ASW | 152U);
    } else if (HVSR_flgDCIsoFaultLvl1Heal) {
      rtb_Switch4_e = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_DchrgIsoChkLv1_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_e = HVSR_IsoChk_DW.Delay3_DSTATE_d;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_mu = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_d = rtb_Switch4_e;
    DFC_DchrgIsoChkLv1_ASW = rtb_Switch4_e;
    rtb_LogicalOperator9 = (HVSR_bISOHVOffFlg && (!BCMR_bDChrgCnnt) &&
      rtb_RelationalOperator3_m);
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_nz)) * (real32_T)rtb_LogicalOperator9;
    rtb_LogicalOperator9 = (rtb_Delay > HVSR_tiIsoChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_nz = rtb_Delay;
    HVSR_flgHVOffIsoFaultLvl1 = ((rtb_BitwiseOperator6 != 0) &&
      rtb_LogicalOperator9);
    rtb_LogicalOperator9 = !rtb_LogicalOperator9;
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_f)) * (real32_T)rtb_LogicalOperator9;
    HVSR_IsoChk_DW.Delay_DSTATE_f = rtb_Delay;
    HVSR_flgHVOffIsoFaultLvl1Heal = ((!(rtb_BitwiseOperator6 != 0)) ||
      (rtb_Delay > HVSR_tiIsoChkDebounce_C));
    if (HVSR_IsoChk_DW.Delay2_DSTATE_az) {
      rtb_Switch4_l = (uint8_T)~(uint8_T)((uint8_T)~DFC_HVOffIsoChkLv1_ASW | 8U);
    } else if (HVSR_flgHVOffIsoFaultLvl1) {
      rtb_Switch4_l = (uint8_T)(DFC_HVOffIsoChkLv1_ASW | 152U);
    } else if (HVSR_flgHVOffIsoFaultLvl1Heal) {
      rtb_Switch4_l = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_HVOffIsoChkLv1_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_l = HVSR_IsoChk_DW.Delay3_DSTATE_ew;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_az = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_ew = rtb_Switch4_l;
    DFC_HVOffIsoChkLv1_ASW = rtb_Switch4_l;
    rtb_LogicalOperator9 = (HVSR_bISOHVOffFlg && (!BCMR_bDChrgCnnt) &&
      rtb_Switch9_g);
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_pb)) * (real32_T)rtb_LogicalOperator9;
    rtb_LogicalOperator9 = (rtb_Delay > HVSR_tiIsoChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_pb = rtb_Delay;
    HVSR_flgHVOffIsoFaultLvl2 = ((rtb_BitwiseOperator4 != 0) &&
      rtb_LogicalOperator9);
    rtb_LogicalOperator9 = !rtb_LogicalOperator9;
    if (rtb_LogicalOperator9) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_n)) * (real32_T)rtb_LogicalOperator9;
    HVSR_IsoChk_DW.Delay_DSTATE_n = rtb_Delay;
    HVSR_flgHVOffIsoFaultLvl2Heal = ((!(rtb_BitwiseOperator4 != 0)) ||
      (rtb_Delay > HVSR_tiIsoChkDebounce_C));
    if (HVSR_IsoChk_DW.Delay2_DSTATE_j) {
      rtb_Switch4_o1 = (uint8_T)~(uint8_T)((uint8_T)~DFC_HVOffIsoChkLv2_ASW | 8U);
    } else if (HVSR_flgHVOffIsoFaultLvl2) {
      rtb_Switch4_o1 = (uint8_T)(DFC_HVOffIsoChkLv2_ASW | 152U);
    } else if (HVSR_flgHVOffIsoFaultLvl2Heal) {
      rtb_Switch4_o1 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_HVOffIsoChkLv2_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_o1 = HVSR_IsoChk_DW.Delay3_DSTATE_c;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_j = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_c = rtb_Switch4_o1;
    DFC_HVOffIsoChkLv2_ASW = rtb_Switch4_o1;
    rtb_RelationalOperator3_m = ((!HVSR_bISOHVOffFlg) && (!BCMR_bDChrgCnnt) &&
      rtb_RelationalOperator3_m);
    if (rtb_RelationalOperator3_m) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_km)) * (real32_T)rtb_RelationalOperator3_m;
    rtb_RelationalOperator3_m = (rtb_Delay > HVSR_tiIsoChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_km = rtb_Delay;
    HVSR_flgIsoFaultLvl1 = ((rtb_BitwiseOperator6 != 0) &&
      rtb_RelationalOperator3_m);
    rtb_RelationalOperator3_m = !rtb_RelationalOperator3_m;
    if (rtb_RelationalOperator3_m) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_h)) * (real32_T)rtb_RelationalOperator3_m;
    HVSR_IsoChk_DW.Delay_DSTATE_h = rtb_Delay;
    HVSR_flgIsoFaultLvl1Heal = ((!(rtb_BitwiseOperator6 != 0)) || (rtb_Delay >
      HVSR_tiIsoChkDebounce_C));
    if (HVSR_IsoChk_DW.Delay2_DSTATE_d) {
      rtb_Switch4_lr = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoChkLv1_ASW | 8U);
    } else if (HVSR_flgIsoFaultLvl1) {
      rtb_Switch4_lr = (uint8_T)(DFC_IsoChkLv1_ASW | 152U);
    } else if (HVSR_flgIsoFaultLvl1Heal) {
      rtb_Switch4_lr = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_IsoChkLv1_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_lr = HVSR_IsoChk_DW.Delay3_DSTATE_o;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_d = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_o = rtb_Switch4_lr;
    DFC_IsoChkLv1_ASW = rtb_Switch4_lr;
    rtb_RelationalOperator3_m = ((!(HVSR_flgBattInsResVald &&
      (!rtb_RelationalOperator))) && (!rtb_RelationalOperator) &&
      (!BSER_bDisFloorFlg));
    if (rtb_RelationalOperator3_m) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoVldChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_o)) * (real32_T)rtb_RelationalOperator3_m;
    rtb_RelationalOperator3_m = (rtb_Delay > HVSR_tiIsoVldChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_o = rtb_Delay;
    rtb_BitwiseOperator6 = (uint8_T)(HVSR_cntIsoChkDiag_CW & 4);
    HVSR_InsResValdFault = ((rtb_BitwiseOperator6 != 0) &&
      rtb_RelationalOperator3_m);
    if (rtb_BitwiseOperator6 != 0) {
      HVSR_InsResValdFaultHeal = !rtb_RelationalOperator3_m;
    } else {
      HVSR_InsResValdFaultHeal = true;
    }

    if (HVSR_IsoChk_DW.Delay2_DSTATE_g) {
      rtb_BitwiseOperator6 = (uint8_T)~(uint8_T)((uint8_T)~DFC_InsResValdFault_ASW |
        8U);
    } else if (HVSR_InsResValdFault) {
      rtb_BitwiseOperator6 = (uint8_T)(DFC_InsResValdFault_ASW | 152U);
    } else if (HVSR_InsResValdFaultHeal) {
      rtb_BitwiseOperator6 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_InsResValdFault_ASW | 16U) | 8U);
    } else {
      rtb_BitwiseOperator6 = HVSR_IsoChk_DW.Delay3_DSTATE_ho;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_g = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_ho = rtb_BitwiseOperator6;
    DFC_InsResValdFault_ASW = rtb_BitwiseOperator6;
    if (HVSR_IsoChk_DW.Delay2_DSTATE_mk) {
      rtb_BitwiseOperator6 = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoS1SwStuckClsd_ASW |
        8U);
    } else if ((!(rtb_BitwiseOperator7 != 0)) ||
               HVSR_IsoChk_ConstB.LogicalOperator4) {
      rtb_BitwiseOperator6 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_IsoS1SwStuckClsd_ASW | 16U) | 8U);
    } else {
      rtb_BitwiseOperator6 = HVSR_IsoChk_DW.Delay3_DSTATE_g;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_mk = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_g = rtb_BitwiseOperator6;
    DFC_IsoS1SwStuckClsd_ASW = rtb_BitwiseOperator6;
    rtb_RelationalOperator3_m = (HVSR_stIsoCctChkErr ==
      HVSR_IsoChk_ConstB.DataTypeConversion_g);
    if (HVSR_IsoChk_DW.Delay2_DSTATE_ih) {
      rtb_BitwiseOperator6 = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoS1SwStuckOpen_ASW |
        8U);
    } else if ((rtb_BitwiseOperator7 != 0) && rtb_RelationalOperator3_m) {
      rtb_BitwiseOperator6 = (uint8_T)(DFC_IsoS1SwStuckOpen_ASW | 152U);
    } else {
      if (rtb_BitwiseOperator7 != 0) {
        rtb_RelationalOperator3_m = !rtb_RelationalOperator3_m;
      } else {
        rtb_RelationalOperator3_m = true;
      }

      if (rtb_RelationalOperator3_m) {
        rtb_BitwiseOperator6 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_IsoS1SwStuckOpen_ASW | 16U) | 8U);
      } else {
        rtb_BitwiseOperator6 = HVSR_IsoChk_DW.Delay3_DSTATE_k;
      }
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_ih = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_k = rtb_BitwiseOperator6;
    DFC_IsoS1SwStuckOpen_ASW = rtb_BitwiseOperator6;
    rtb_Switch9_g = (BCMR_bDChrgCnnt && rtb_Switch9_g);
    if (rtb_Switch9_g) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_k)) * (real32_T)rtb_Switch9_g;
    rtb_Switch9_g = (rtb_Delay > HVSR_tiIsoChkDebounce_C);
    HVSR_IsoChk_DW.Delay_DSTATE_k = rtb_Delay;
    HVSR_flgDCIsoFaultLvl2 = ((rtb_BitwiseOperator4 != 0) && rtb_Switch9_g);
    rtb_Switch9_g = !rtb_Switch9_g;
    if (rtb_Switch9_g) {
      rtb_Delay = HVSR_tiTaskTime_C;
    } else {
      rtb_Delay = 0.0F;
    }

    rtb_Delay = (rtb_Delay + fminf(HVSR_tiIsoChkDebounce_C,
      HVSR_IsoChk_DW.Delay_DSTATE_i)) * (real32_T)rtb_Switch9_g;
    HVSR_IsoChk_DW.Delay_DSTATE_i = rtb_Delay;
    HVSR_flgDCIsoFaultLvl2Heal = ((!(rtb_BitwiseOperator4 != 0)) || (rtb_Delay >
      HVSR_tiIsoChkDebounce_C));
    if (HVSR_IsoChk_DW.Delay2_DSTATE_p) {
      rtb_BitwiseOperator4 = (uint8_T)~(uint8_T)((uint8_T)~DFC_DchrgIsoChkLv2_ASW |
        8U);
    } else if (HVSR_flgDCIsoFaultLvl2) {
      rtb_BitwiseOperator4 = (uint8_T)(DFC_DchrgIsoChkLv2_ASW | 152U);
    } else if (HVSR_flgDCIsoFaultLvl2Heal) {
      rtb_BitwiseOperator4 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DchrgIsoChkLv2_ASW | 16U) | 8U);
    } else {
      rtb_BitwiseOperator4 = HVSR_IsoChk_DW.Delay3_DSTATE_di;
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_p = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_di = rtb_BitwiseOperator4;
    DFC_DchrgIsoChkLv2_ASW = rtb_BitwiseOperator4;
    rtb_Switch9_g = (HVSR_stIsoCctChkErr ==
                     HVSR_IsoChk_ConstB.DataTypeConversion1);
    if (HVSR_IsoChk_DW.Delay2_DSTATE_n) {
      rtb_BitwiseOperator6 = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoS2SwStuckOpen_ASW |
        8U);
    } else if ((rtb_BitwiseOperator7 != 0) && rtb_Switch9_g) {
      rtb_BitwiseOperator6 = (uint8_T)(DFC_IsoS2SwStuckOpen_ASW | 152U);
    } else {
      if (rtb_BitwiseOperator7 != 0) {
        rtb_Switch9_g = !rtb_Switch9_g;
      } else {
        rtb_Switch9_g = true;
      }

      if (rtb_Switch9_g) {
        rtb_BitwiseOperator6 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_IsoS2SwStuckOpen_ASW | 16U) | 8U);
      } else {
        rtb_BitwiseOperator6 = HVSR_IsoChk_DW.Delay3_DSTATE_e;
      }
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_n = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_e = rtb_BitwiseOperator6;
    DFC_IsoS2SwStuckOpen_ASW = rtb_BitwiseOperator6;
    rtb_Switch9_g = (HVSR_stIsoCctChkErr ==
                     HVSR_IsoChk_ConstB.DataTypeConversion2_e);
    if (HVSR_IsoChk_DW.Delay2_DSTATE_ed) {
      rtb_BitwiseOperator7 = (uint8_T)~(uint8_T)((uint8_T)~DFC_IsoS3SwStuckOpen_ASW |
        8U);
    } else if ((rtb_BitwiseOperator7 != 0) && rtb_Switch9_g) {
      rtb_BitwiseOperator7 = (uint8_T)(DFC_IsoS3SwStuckOpen_ASW | 152U);
    } else {
      if (rtb_BitwiseOperator7 != 0) {
        rtb_Switch9_g = !rtb_Switch9_g;
      } else {
        rtb_Switch9_g = true;
      }

      if (rtb_Switch9_g) {
        rtb_BitwiseOperator7 = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_IsoS3SwStuckOpen_ASW | 16U) | 8U);
      } else {
        rtb_BitwiseOperator7 = HVSR_IsoChk_DW.Delay3_DSTATE_a;
      }
    }

    HVSR_IsoChk_DW.Delay2_DSTATE_ed = false;
    HVSR_IsoChk_DW.Delay3_DSTATE_a = rtb_BitwiseOperator7;
    DFC_IsoS3SwStuckOpen_ASW = rtb_BitwiseOperator7;
    rtb_Switch9_g = (HVSR_IsoChk_DW.Delay3_DSTATE_dv || ((rtb_Switch_cd & 24) ==
      24));
    rtb_RelationalOperator3_m = (HVSR_IsoChk_DW.Delay1_DSTATE_e ||
      ((rtb_Switch4_o1 & 24) == 24));
    if (rtb_Switch9_g || ((rtb_BitwiseOperator4 & 24) == 24) ||
        rtb_RelationalOperator3_m) {
      HVSR_flgIsoFault = 3U;
    } else if (((rtb_Switch4_lr & 24) == 24) || ((rtb_Switch4_e & 24) == 24) ||
               ((rtb_Switch4_l & 24) == 24)) {
      HVSR_flgIsoFault = 2U;
    } else {
      HVSR_flgIsoFault = 0U;
    }

    HVSR_IsoChk_DW.Delay1_DSTATE_e = rtb_RelationalOperator3_m;
    HVSR_IsoChk_DW.Delay3_DSTATE_dv = rtb_Switch9_g;
  }

  if (rtb_RelationalOperator) {
    HVSR_bIsoChkStatus = HVSR_IsoChk_ConstB.DataTypeConversion_a;
  } else {
    HVSR_bIsoChkStatus = HVSR_IsoChk_ConstB.DataTypeConversion1_j;
  }

  rtb_Switch9_g = !HVSR_IsoChk_DW.Delay1_DSTATE_g;
  HVSR_IsoChk_DW.Delay1_DSTATE_g = HVSR_IsoChk_DW.Delay2_DSTATE_a;
  if (rtb_Switch9_g && HVSR_IsoChk_DW.Delay2_DSTATE_a) {
    rtb_Delay = 0.0F;
  } else {
    if (rtb_Compare) {
      rtb_Switch1_p = HVSR_tiTaskTime_C;
    } else {
      rtb_Switch1_p = 0.0F;
    }

    rtb_Delay = rtb_Switch1_p + HVSR_IsoChk_DW.UnitDelay_DSTATE_o;
  }

  HVSR_uBattFltDiff = ((HVSR_IsoChk_DW.Delay_DSTATE_nd +
                        HVSR_IsoChk_DW.Delay1_DSTATE_j[0]) + COMR_uBattVolt) /
    3.0F - ((HVSR_IsoChk_DW.Delay2_DSTATE_i[0] + HVSR_IsoChk_DW.Delay6_DSTATE[0])
            + HVSR_IsoChk_DW.Delay7_DSTATE[0]) / 3.0F;
  HVSR_flgBattFilterEnd = (HVSR_uBattFltDiff <= HVSR_uIsoVoltThres_C);
  if (HVSR_flgBattFilterEnd) {
    HVSR_uBattFilterEnd = COMR_uBattVolt;
  } else {
    HVSR_uBattFilterEnd = 0.0F;
  }

  HVSR_IsoChk_DW.Delay_DSTATE_nd = COMR_uBattVolt;
  HVSR_IsoChk_DW.Delay1_DSTATE_j[0] = HVSR_IsoChk_DW.Delay1_DSTATE_j[1];
  HVSR_IsoChk_DW.Delay1_DSTATE_j[1] = COMR_uBattVolt;
  HVSR_IsoChk_DW.Delay2_DSTATE_i[0] = HVSR_IsoChk_DW.Delay2_DSTATE_i[1];
  HVSR_IsoChk_DW.Delay2_DSTATE_i[1] = HVSR_IsoChk_DW.Delay2_DSTATE_i[2];
  HVSR_IsoChk_DW.Delay2_DSTATE_i[2] = COMR_uBattVolt;
  HVSR_IsoChk_DW.Delay6_DSTATE[0] = HVSR_IsoChk_DW.Delay6_DSTATE[1];
  HVSR_IsoChk_DW.Delay6_DSTATE[1] = HVSR_IsoChk_DW.Delay6_DSTATE[2];
  HVSR_IsoChk_DW.Delay6_DSTATE[2] = HVSR_IsoChk_DW.Delay6_DSTATE[3];
  HVSR_IsoChk_DW.Delay6_DSTATE[3] = COMR_uBattVolt;
  HVSR_IsoChk_DW.Delay7_DSTATE[0] = HVSR_IsoChk_DW.Delay7_DSTATE[1];
  HVSR_IsoChk_DW.Delay7_DSTATE[1] = HVSR_IsoChk_DW.Delay7_DSTATE[2];
  HVSR_IsoChk_DW.Delay7_DSTATE[2] = HVSR_IsoChk_DW.Delay7_DSTATE[3];
  HVSR_IsoChk_DW.Delay7_DSTATE[3] = HVSR_IsoChk_DW.Delay7_DSTATE[4];
  HVSR_IsoChk_DW.Delay7_DSTATE[4] = COMR_uBattVolt;
  HVSR_stIsoCctChkSta = HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l;
  if (HVSR_tsbegin_enable) {
    HVSR_IsoChk_DW.Delay1_DSTATE_k = HVSR_IsoChk_B.DataTypeConversion;
  } else {
    HVSR_IsoChk_DW.Delay1_DSTATE_k = HVSR_BattInsResVald;
  }

  HVSR_IsoChk_DW.Delay3_DSTATE_kl = rtb_RelationalOperator;
  HVSR_IsoChk_DW.Delay_DSTATE_i2 = rtb_Compare;
  HVSR_IsoChk_DW.Delay3_DSTATE = HVSR_IsoChk_B.In1;
  HVSR_IsoChk_DW.Delay2_DSTATE_a = (rtb_Delay > (real32_T)HVSR_numCycleTimeCnt_C
    - 0.01F);
  HVSR_IsoChk_DW.Delay2_DSTATE = rtb_Product_ai;
  HVSR_IsoChk_DW.Delay_DSTATE_l = rtb_Product_ai;
  HVSR_IsoChk_DW.UnitDelay_DSTATE_o = rtb_Delay;
}

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

  /* block I/O */

  /* custom signals */
  HVSR_resIso = 7777.0F;
  HVSR_resIsoTheory = 7777.0F;
  HVSR_uIsoVoltPos = 0.0F;
  HVSR_uIsoVoltNeg = 0.0F;
  HVSR_stIsoStateObsr = ((uint8_T)0U);
  HVSR_flgIsoFault = ((uint8_T)0U);
  HVSR_flgBattInsResVald = false;
  HVSR_bIsoSwt1Ena = false;
  HVSR_bIsoSwt2Ena = false;
  HVSR_bIsoSwt3Ena = false;
  HVSR_bIsoSwt4Ena = false;
  HVSR_bIsoChkStatus = false;
  HVSR_flgIsoChkStart = false;
  HVSR_flgIsoChkFault = false;
  HVSR_flgInsResUpd = false;
  HVSR_flgIsoFaultLvl2 = false;
  HVSR_flgIsoFaultLvl2Heal = false;
  HVSR_flgDCIsoFaultLvl1 = false;
  HVSR_flgDCIsoFaultLvl1Heal = false;
  HVSR_flgHVOffIsoFaultLvl1 = false;
  HVSR_flgHVOffIsoFaultLvl1Heal = false;
  HVSR_flgHVOffIsoFaultLvl2 = false;
  HVSR_flgHVOffIsoFaultLvl2Heal = false;
  HVSR_flgIsoFaultLvl1 = false;
  HVSR_flgIsoFaultLvl1Heal = false;
  HVSR_InsResValdFault = false;
  HVSR_InsResValdFaultHeal = false;
  HVSR_flgDCIsoFaultLvl2 = false;
  HVSR_flgDCIsoFaultLvl2Heal = false;
  HVSR_IsoChk_DW.If_ActiveSubsystem = -1;
  HVSR_IsoChk_PrevZCX.Subsystem1_Trig_ZCE = ZERO_ZCSIG;
  HVSR_IsoChk_PrevZCX.HVSR_IsoParCalc_Trig_ZCE_k = POS_ZCSIG;
  HVSR_IsoChk_PrevZCX.HVSR_IsoParCalc_Trig_ZCE = POS_ZCSIG;
  HVSR_IsoChk_B.HVSR_stIsoCctChkErr_n = enmCctErr_DEFAULT;
  HVSR_IsoChk_B.HVSR_stIsoCctChkSta_l = enmCctDiagSta_DEFAULT;
  HVSR_IsoChk_B.control_enable = enmActv_INACTIVE;
  HVSR_IsoChk_B.init_enable = enmActv_INACTIVE;
  HVSR_IsoChk_B.begin_enable = enmActv_INACTIVE;
  HVSR_IsoChk_B.HVSR_bIsoChkSW1Sta = enmSWSta_SWOFF;
  HVSR_IsoChk_B.HVSR_bIsoChkSW2Sta = enmSWSta_SWOFF;
  HVSR_IsoChk_B.HVSR_bIsoChkSW3Sta = enmSWSta_SWOFF;
  HVSR_IsoChk_DW.Delay_DSTATE_iz = true;
  HVSR_IsoChk_DW.Delay_DSTATE_ia = true;
  HVSR_IsoChk_DW.Delay_DSTATE_m = true;
  HVSR_IsoChk_DW.Delay1_DSTATE_b = true;
  HVSR_IsoChk_DW.Delay1_DSTATE_h = true;
  HVSR_IsoChk_DW.Delay1_DSTATE_o = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_jz = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_iz = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_e = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_mu = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_az = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_j = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_d = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_g = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_mk = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_ih = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_p = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_n = true;
  HVSR_IsoChk_DW.Delay2_DSTATE_ed = true;
  HVSR_IsoChk_DW.Delay1_DSTATE_g = true;
}

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