/*
 * File: BTMR_ThmRnwyChk.c
 *
 * Code generated for Simulink model 'BTMR_ThmRnwyChk'.
 *
 * Model version                  : sd
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Wed Aug 25 11:28:21 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 "BTMR_ThmRnwyChk.h"
#include "BTMR_ThmRnwyChk_private.h"

/* Exported data definition */

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

/* Definition for custom storage class: Volatile */
volatile uint8_T DFC_ThmRnwy_ASW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM0_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_RAM0_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BTMR_bBusbarRnwyHighTempDet;
volatile boolean_T BTMR_bBusbarRnwyMaxTGDet;
volatile boolean_T BTMR_bBusbarRnwyTempDiffDet;
volatile boolean_T BTMR_bCellVoltGradAbnrDet;
volatile boolean_T BTMR_bLowVoltAlrm;
volatile boolean_T BTMR_bMaxVoltDiff;
volatile boolean_T BTMR_bMinVoltMdulFit;
volatile boolean_T BTMR_bModuleFit;
volatile boolean_T BTMR_bNewShrtVoltVld;
volatile boolean_T BTMR_bRnwyCellMdulVoltDet;
volatile boolean_T BTMR_bRnwyChkSleepPmt;
volatile boolean_T BTMR_bRnwyHighTempDet;
volatile boolean_T BTMR_bRnwyLowMdulVoltDet;
volatile boolean_T BTMR_bRnwyLowVoltDet;
volatile boolean_T BTMR_bRnwyMaxTGDet;
volatile boolean_T BTMR_bRnwyTempDiffDet;
volatile boolean_T BTMR_bRnwyVoltAbnrDet;
volatile boolean_T BTMR_bRnwyVoltDiagTGDet;
volatile boolean_T BTMR_bShrtLowVoltIDFitWrt;
volatile boolean_T BTMR_bStopTimeInvld;
volatile boolean_T BTMR_bTPLTmtThmRunAway;
volatile boolean_T BTMR_bTPLWkupRnwyDiagEna;
volatile boolean_T BTMR_bTSnsrTmt;
volatile boolean_T BTMR_bThmRnwyAlrm;
volatile boolean_T BTMR_bThmRnwyWarn;
volatile boolean_T BTMR_bThmRunAway;
volatile boolean_T BTMR_bThmRunAwayCond1;
volatile boolean_T BTMR_bThmRunAwayCond2;
volatile boolean_T BTMR_bThmRunAwayCond3;
volatile boolean_T BTMR_bThmRunAwayCond4;
volatile boolean_T BTMR_bVSnsrTmt;
volatile boolean_T BTMR_bVoltDiffAlrm;
volatile uint8_T BTMR_cntBattTGRnwy;
volatile uint8_T BTMR_cntBusbarTGRnwy;
volatile uint8_T BTMR_cntCellVoltGradAbnr;
volatile uint8_T BTMR_cntRnwyCellVoltAbnr;
volatile uint8_T BTMR_cntTPLTmtBattTDiffRnwy;
volatile uint8_T BTMR_cntTPLTmtBattTGRnwy;
volatile uint8_T BTMR_cntTPLTmtBattTRnwy;
volatile boolean_T BTMR_flgBusbarTGRunAwayLv2;
volatile boolean_T BTMR_flgBusbarTRunAwayLv3;
volatile boolean_T BTMR_flgDSMBattRunAway;
volatile boolean_T BTMR_flgNewCellVoltVld;
volatile boolean_T BTMR_flgTGRunAwayLv2;
volatile boolean_T BTMR_flgTPLWkupRnwyDiag;
volatile boolean_T BTMR_flgTRunAwayLv3;
volatile uint8_T BTMR_idxAbnrVoltGradID;
volatile uint8_T BTMR_idxBusbarMaxTempGradID;
volatile uint8_T BTMR_idxBusbarMaxTempID;
volatile uint8_T BTMR_idxBusbarTempDiffMaxID;
volatile uint8_T BTMR_idxMaxTempGradID;
volatile uint8_T BTMR_idxMaxTempGradVoltDiagID;
volatile uint8_T BTMR_idxMaxTempID;
volatile uint8_T BTMR_idxMaxVoltID;
volatile uint8_T BTMR_idxMinMdulVoltID;
volatile uint8_T BTMR_idxMinVoltID;
volatile uint8_T BTMR_idxShrtLowVoltIDWrt;
volatile uint8_T BTMR_idxTempDiffMaxID;
volatile real32_T BTMR_tBusbarMaxTemp;
volatile real32_T BTMR_tBusbarMaxTempGrad;
volatile real32_T BTMR_tBusbarTempDiffMax;
volatile real32_T BTMR_tBusbarTempGrad[48];
volatile real32_T BTMR_tBusbarTempMax;
volatile real32_T BTMR_tBusbarTempMin;
volatile real32_T BTMR_tBusbarTemp_A[48];
volatile real32_T BTMR_tCellTempGrad[48];
volatile real32_T BTMR_tCellTempMax;
volatile real32_T BTMR_tCellTempMin;
volatile real32_T BTMR_tCellTemp_A[48];
volatile real32_T BTMR_tMaxTemp;
volatile real32_T BTMR_tMaxTempGrad;
volatile real32_T BTMR_tMaxTempGradVoltDiag;
volatile real32_T BTMR_tTempDiffMax;
volatile uint16_T BTMR_tiRuntimeCalWrt;
volatile uint32_T BTMR_tiShortRuntimeSumWrt;
volatile real32_T BTMR_uAbnrVoltGrad;
volatile real32_T BTMR_uMaxVolt;
volatile real32_T BTMR_uMinMdulVolt;
volatile real32_T BTMR_uMinStrtVolt;
volatile real32_T BTMR_uMinVolt;
volatile real32_T BTMR_uShrtCellVoltDiffWrt;
volatile real32_T BTMR_uStrtCellVoltAvrg;
volatile real32_T Local_uShrtLowVoltDiff;

/* Block signals (auto storage) */
B_BTMR_ThmRnwyChk_T BTMR_ThmRnwyChk_B;

/* Block states (auto storage) */
DW_BTMR_ThmRnwyChk_T BTMR_ThmRnwyChk_DW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM0_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Previous zero-crossings (trigger) states */
PrevZCX_BTMR_ThmRnwyChk_T BTMR_ThmRnwyChk_PrevZCX;

/* Model step function */
void BTMR_ThmRnwyChk_step(void)
{
  int32_T in;
  boolean_T rtb_Compare_gf;
  boolean_T rtb_LogicalOperator1;
  real32_T rtb_Product_dy;
  real32_T rtb_Product_k2f;
  uint8_T rtb_DataTypeConversion4;
  boolean_T rtb_Compare_jj;
  boolean_T rtb_Compare_f;
  boolean_T rtb_LogicalOperator4_kf;
  real32_T rtb_Switch1_aj;
  boolean_T rtb_Compare_ns;
  boolean_T rtb_LogicalOperator4_eu;
  real32_T rtb_Switch1_lw;
  real32_T rtb_Switch1_dc;
  real32_T rtb_Switch1_fk;
  real32_T rtb_Switch1_cr;
  boolean_T rtb_RelationalOperator6_a2;
  uint32_T tmp;
  boolean_T rtb_LogicalOperator4_l0;
  boolean_T rtb_LogicalOperator4_b5;
  int32_T rtb_uDMaximum_o2_n;
  real32_T rtb_Product_e4;
  real32_T rtb_Product_cr;
  real32_T rtb_Product_ko;
  real32_T rtb_Divide1_h;
  real32_T rtb_Divide1_f;
  real32_T rtb_Divide1_k;
  real32_T rtb_Product_b5j;
  boolean_T rtb_RelationalOperator_i;
  boolean_T rtb_LogicalOperator3_c;
  real32_T rtb_Init[48];
  real32_T rtb_Init_l[48];
  real32_T rtb_Init_c[48];
  real32_T rtb_Init_k[48];
  real32_T rtb_Init_f[48];
  real32_T rtb_Init_n[48];
  real32_T rtb_Init_fe[48];
  real32_T rtb_Init_d[48];
  boolean_T rtb_RelationalOperator_br[48];
  real32_T rtb_Gain[150];
  boolean_T rtb_Compare_nd[150];
  real32_T rtb_Abs1[150];
  int32_T i;
  real32_T BTMR_bMinVoltMdulFit_tmp;
  for (i = 0; i < 48; i++) {
    if (BTMR_ThmRnwyChk_DW.StateName_ki != 0) {
      rtb_Product_dy = BSPR_tCellTemp_A[i];
    } else {
      rtb_Product_dy = BTMR_ThmRnwyChk_DW.StateName[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_j != 0) {
      rtb_Product_k2f = rtb_Product_dy;
    } else {
      rtb_Product_k2f = BTMR_ThmRnwyChk_DW.StateName_l[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_o != 0) {
      rtb_Switch1_aj = rtb_Product_k2f;
    } else {
      rtb_Switch1_aj = BTMR_ThmRnwyChk_DW.StateName_p[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_ef != 0) {
      rtb_Product_e4 = rtb_Switch1_aj;
    } else {
      rtb_Product_e4 = BTMR_ThmRnwyChk_DW.StateName_k[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_d != 0) {
      rtb_Product_b5j = rtb_Product_e4;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.StateName_b[i];
    }

    BTMR_tCellTempGrad[i] = BSPR_tCellTemp_A[i] - rtb_Product_b5j;
    if (BTMR_ThmRnwyChk_DW.StateName_bx != 0) {
      rtb_Switch1_lw = BSPR_tBattTemp_A[i];
    } else {
      rtb_Switch1_lw = BTMR_ThmRnwyChk_DW.StateName_be[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_jx != 0) {
      rtb_Switch1_dc = rtb_Switch1_lw;
    } else {
      rtb_Switch1_dc = BTMR_ThmRnwyChk_DW.StateName_g[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_k1 != 0) {
      rtb_Switch1_fk = rtb_Switch1_dc;
    } else {
      rtb_Switch1_fk = BTMR_ThmRnwyChk_DW.StateName_e[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_ey != 0) {
      rtb_Divide1_f = rtb_Switch1_fk;
    } else {
      rtb_Divide1_f = BTMR_ThmRnwyChk_DW.StateName_bl[i];
    }

    if (BTMR_ThmRnwyChk_DW.StateName_i != 0) {
      rtb_Product_b5j = rtb_Divide1_f;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.StateName_h[i];
    }

    BTMR_tBusbarTempGrad[i] = BSPR_tBattTemp_A[i] - rtb_Product_b5j;
    rtb_Init[i] = rtb_Product_dy;
    rtb_Init_l[i] = rtb_Product_k2f;
    rtb_Init_c[i] = rtb_Switch1_aj;
    rtb_Init_k[i] = rtb_Product_e4;
    rtb_Init_f[i] = rtb_Switch1_lw;
    rtb_Init_n[i] = rtb_Switch1_dc;
    rtb_Init_fe[i] = rtb_Switch1_fk;
    rtb_Init_d[i] = rtb_Divide1_f;
  }

  if (BTMR_bRnwyDiagEna_C) {
    rtb_Product_b5j = 0.1F;
  } else {
    rtb_Product_b5j = 0.0F;
  }

  if (BTMR_tiRnwyDiagEna_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_i) {
    rtb_Switch1_dc = BTMR_tiRnwyDiagEna_C;
  } else {
    rtb_Switch1_dc = BTMR_ThmRnwyChk_DW.Delay_DSTATE_i;
  }

  rtb_Product_dy = (rtb_Product_b5j + rtb_Switch1_dc) * (real32_T)
    BTMR_bRnwyDiagEna_C;
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_i = rtb_Product_dy;
  in = 1;
  rtb_Compare_gf = ((IoExtMc33771_ChkCIDCycSt == 0) || ((uint8_T)((uint32_T)
    COMR_bBattTempWireStt_A[0] + COMR_bBattTempWireStt_A[1]) > 0) || ((uint8_T)
    ((uint32_T)COMR_bCellVoltWireStt_A[0] + COMR_bCellVoltWireStt_A[1]) > 0) ||
                    ((DFC_CellTempTmt_ASW & 16) == 16) || ((DFC_CellVoltTmt_ASW & 16) ==
    16));
  rtb_LogicalOperator1 = !rtb_Compare_gf;
  if (rtb_LogicalOperator1) {
    rtb_Switch1_aj = 0.1F;
  } else {
    rtb_Switch1_aj = 0.0F;
  }

  if (BTMR_tiRnwyDiagIni_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_n) {
    rtb_Product_b5j = BTMR_tiRnwyDiagIni_C;
  } else {
    rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_n;
  }

  rtb_Product_k2f = (rtb_Switch1_aj + rtb_Product_b5j) * (real32_T)
    rtb_LogicalOperator1;
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_n = rtb_Product_k2f;
  if (BTMR_flgRnwyDiagSwitch_C) {
    BTMR_flgDSMBattRunAway = (rtb_Product_dy > BTMR_tiRnwyDiagEna_C);
  } else {
    BTMR_flgDSMBattRunAway = (rtb_Product_k2f > BTMR_tiRnwyDiagIni_C);
  }

  if (BTMR_flgDSMBattRunAway) {
    if (!BTMR_ThmRnwyChk_DW.Rnwy_Chk_MODE) {
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_hs = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h2 = false;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_gr = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_n = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_fk = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_d = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_k4 = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_dr = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_p = false;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_p5 = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hs = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_hj = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_a = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_f1 = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_f = false;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_cf = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_at = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_i = false;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_jn = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_n = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_er = false;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_j3 = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_dt = 0.0F;
      for (i = 0; i < 150; i++) {
        BTMR_ThmRnwyChk_DW.Delay4_DSTATE[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay3_DSTATE[i] = 0.0F;
      }

      BTMR_ThmRnwyChk_DW.Delay_DSTATE_lq = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_ka = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_d2 = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_ib = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e3 = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_cr = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_ar = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_ka = false;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_jf = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_j = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ez = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_dl = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_cj = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_fk = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_ez = 0.0F;
      for (i = 0; i < 48; i++) {
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_hn[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4x[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_l[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_g[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_c3[i] = 0.0F;
      }

      BTMR_ThmRnwyChk_DW.Delay_DSTATE_lc = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m0 = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e1 = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d1 = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_c = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_p = true;
      for (i = 0; i < 150; i++) {
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_f[i] = 0.0F;
      }

      BTMR_ThmRnwyChk_DW.Delay_DSTATE_mr = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ky = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_iz = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_m = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_md = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ka = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ha = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_hx = 0.0F;
      BTMR_ThmRnwyChk_DW.Rnwy_Chk_MODE = true;
    }

    rtb_LogicalOperator1 = (BSPR_tBattTempMax - BSPR_tBattTempMin >=
      BTMR_tBusbarTDiffRunAway_C);
    if (rtb_LogicalOperator1) {
      rtb_Switch1_aj = 0.1F;
    } else {
      rtb_Switch1_aj = 0.0F;
    }

    if (BTMR_tiBusbarRunAwayTempDiffDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_jf) {
      rtb_Product_b5j = BTMR_tiBusbarRunAwayTempDiffDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_jf;
    }

    rtb_Product_dy = (rtb_Switch1_aj + rtb_Product_b5j) * (real32_T)
      rtb_LogicalOperator1;
    BTMR_bBusbarRnwyTempDiffDet = (rtb_Product_dy >
      BTMR_tiBusbarRunAwayTempDiffDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_jf = rtb_Product_dy;
    if (BTMR_bBusbarRnwyTempDiffDet &&
        (BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_lt != POS_ZCSIG)) {
      BTMR_tBusbarTempDiffMax = BSPR_tBattTemp_A[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BSPR_tBattTemp_A[in] > BTMR_tBusbarTempDiffMax) {
          BTMR_tBusbarTempDiffMax = BSPR_tBattTemp_A[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_idxBusbarTempDiffMaxID = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_lt =
      BTMR_bBusbarRnwyTempDiffDet;
    in = 1;
    tmp = 0U;
    for (i = 0; i < 48; i++) {
      rtb_Compare_jj = (BTMR_tBusbarTempGrad[i] >= BTMR_tBusbarTGRunAway_C);
      if (rtb_Compare_jj) {
        rtb_Product_e4 = 0.1F;
      } else {
        rtb_Product_e4 = 0.0F;
      }

      if (BTMR_tiRunAwayBusbarTGDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_hn[i]) {
        rtb_Product_b5j = BTMR_tiRunAwayBusbarTGDe_C;
      } else {
        rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_hn[i];
      }

      rtb_Product_b5j = (rtb_Product_e4 + rtb_Product_b5j) * (real32_T)
        rtb_Compare_jj;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_hn[i] = rtb_Product_b5j;
      tmp += (rtb_Product_b5j > BTMR_tiRunAwayBusbarTGDe_C);
      rtb_Compare_jj = (BTMR_tBusbarTempGrad[i] >= BTMR_tBusbarTGRunAwayLv2_C);
      if (rtb_Compare_jj) {
        rtb_Product_e4 = 0.1F;
      } else {
        rtb_Product_e4 = 0.0F;
      }

      if (BTMR_tiRunAwayBusbarTGLv2De_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4x[i])
      {
        rtb_Product_b5j = BTMR_tiRunAwayBusbarTGLv2De_C;
      } else {
        rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4x[i];
      }

      rtb_Product_b5j = (rtb_Product_e4 + rtb_Product_b5j) * (real32_T)
        rtb_Compare_jj;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4x[i] = rtb_Product_b5j;
      rtb_RelationalOperator_br[i] = (rtb_Product_b5j >
        BTMR_tiRunAwayBusbarTGLv2De_C);
    }

    rtb_Compare_jj = ((uint8_T)tmp > 0);
    tmp = rtb_RelationalOperator_br[0];
    rtb_RelationalOperator_br[0] = (BSPR_tBattTemp_A[0] >=
      BTMR_tBusbarTRunAwayLv3_C);
    for (i = 0; i < 47; i++) {
      tmp += rtb_RelationalOperator_br[i + 1];
      rtb_RelationalOperator_br[i + 1] = (BSPR_tBattTemp_A[i + 1] >=
        BTMR_tBusbarTRunAwayLv3_C);
    }

    rtb_Compare_f = ((uint8_T)tmp > 0);
    tmp = rtb_RelationalOperator_br[0];
    for (i = 0; i < 47; i++) {
      tmp += rtb_RelationalOperator_br[i + 1];
    }

    rtb_LogicalOperator1 = ((uint8_T)tmp > 0);
    if (rtb_LogicalOperator1) {
      rtb_Switch1_aj = 0.1F;
    } else {
      rtb_Switch1_aj = 0.0F;
    }

    if (BTMR_tiBusbarRunAwayLv3De_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_j) {
      rtb_Product_b5j = BTMR_tiBusbarRunAwayLv3De_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_j;
    }

    rtb_Product_dy = (rtb_Switch1_aj + rtb_Product_b5j) * (real32_T)
      rtb_LogicalOperator1;
    BTMR_flgBusbarTRunAwayLv3 = (rtb_Product_dy > BTMR_tiBusbarRunAwayLv3De_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_j = rtb_Product_dy;
    BTMR_flgBusbarTGRunAwayLv2 = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_hs ||
      rtb_Compare_f) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h2));
    rtb_LogicalOperator4_kf = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ez) &&
      rtb_Compare_jj);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ez = rtb_Compare_jj;
    rtb_LogicalOperator1 = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_gr ||
      rtb_LogicalOperator4_kf) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_n));
    if (!rtb_LogicalOperator1) {
      rtb_Product_dy = 0.0F;
    } else {
      rtb_Product_dy = (real32_T)rtb_LogicalOperator4_kf +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_fk;
    }

    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Product_dy), 256.0F);
    BTMR_cntBusbarTGRnwy = (uint8_T)(rtb_Product_b5j < 0.0F ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)rtb_Product_b5j);
    BTMR_bBusbarRnwyMaxTGDet = ((BTMR_flgBusbarTRunAwayLv3 &&
      BTMR_flgBusbarTGRunAwayLv2) || (BTMR_cntBusbarTGRnwy >=
      BTMR_cntBusbarTGradThres_C));
    rtb_Compare_jj = (rtb_Compare_f || rtb_Compare_jj);
    if (rtb_Compare_jj && (BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal_Trig_ZCE_l
                           != POS_ZCSIG)) {
      BTMR_tBusbarMaxTempGrad = BTMR_tBusbarTempGrad[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BTMR_tBusbarTempGrad[in] > BTMR_tBusbarMaxTempGrad) {
          BTMR_tBusbarMaxTempGrad = BTMR_tBusbarTempGrad[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_idxBusbarMaxTempGradID = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal_Trig_ZCE_l = rtb_Compare_jj;
    rtb_Compare_jj = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_dl;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_dl = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_n;
    if (rtb_Compare_jj && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_n) {
      rtb_Product_k2f = 0.0F;
    } else {
      if (rtb_LogicalOperator1) {
        rtb_Switch1_aj = 0.1F;
      } else {
        rtb_Switch1_aj = 0.0F;
      }

      rtb_Product_k2f = rtb_Switch1_aj + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_d;
    }

    rtb_Compare_jj = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_cj;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_cj = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h2;
    if (rtb_Compare_jj && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h2) {
      rtb_Switch1_aj = 0.0F;
    } else {
      if (BTMR_flgBusbarTGRunAwayLv2) {
        rtb_Product_b5j = 0.1F;
      } else {
        rtb_Product_b5j = 0.0F;
      }

      rtb_Switch1_aj = rtb_Product_b5j + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_k4;
    }

    rtb_Compare_jj = (BSPR_tBattTempMax >= BTMR_tBusbarTRunAway_C);
    if (rtb_Compare_jj) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    if (BTMR_tiBusbarRunAwayTempDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_fk) {
      rtb_Product_b5j = BTMR_tiBusbarRunAwayTempDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_fk;
    }

    rtb_Product_e4 = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)
      rtb_Compare_jj;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_fk = rtb_Product_e4;
    BTMR_bBusbarRnwyHighTempDet = (rtb_Product_e4 > BTMR_tiBusbarRunAwayTempDe_C);
    if (BTMR_bBusbarRnwyHighTempDet &&
        (BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_l != POS_ZCSIG)) {
      in = 1;
      BTMR_tBusbarMaxTemp = BSPR_tBattTemp_A[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BSPR_tBattTemp_A[in] > BTMR_tBusbarMaxTemp) {
          BTMR_tBusbarMaxTemp = BSPR_tBattTemp_A[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_idxBusbarMaxTempID = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_l =
      BTMR_bBusbarRnwyHighTempDet;
    rtb_Compare_jj = (BSPR_tCellTempMax - BSPR_tCellTempMin >=
                      BTMR_tBattTDiffRunAway_C);
    if (rtb_Compare_jj) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    if (BTMR_tiRunAwayTempDiffDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_ez) {
      rtb_Product_b5j = BTMR_tiRunAwayTempDiffDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_ez;
    }

    rtb_Product_e4 = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)
      rtb_Compare_jj;
    BTMR_ThmRnwyChk_B.RelationalOperator_d = (rtb_Product_e4 >
      BTMR_tiRunAwayTempDiffDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_ez = rtb_Product_e4;
    if (BTMR_ThmRnwyChk_B.RelationalOperator_d &&
        (BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_f != POS_ZCSIG)) {
      in = 1;
      BTMR_ThmRnwyChk_B.uDMaximum_o1_f = BSPR_tCellTemp_A[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BSPR_tCellTemp_A[in] > BTMR_ThmRnwyChk_B.uDMaximum_o1_f) {
          BTMR_ThmRnwyChk_B.uDMaximum_o1_f = BSPR_tCellTemp_A[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_dk = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_f =
      BTMR_ThmRnwyChk_B.RelationalOperator_d;
    in = 1;
    tmp = 0U;
    for (i = 0; i < 48; i++) {
      rtb_Compare_jj = (BTMR_tCellTempGrad[i] >= BTMR_tBattTGRunAway_C);
      if (rtb_Compare_jj) {
        rtb_Product_e4 = 0.1F;
      } else {
        rtb_Product_e4 = 0.0F;
      }

      if (BTMR_tiRunAwayTempGradDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_l[i]) {
        rtb_Product_b5j = BTMR_tiRunAwayTempGradDe_C;
      } else {
        rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_l[i];
      }

      rtb_Product_b5j = (rtb_Product_e4 + rtb_Product_b5j) * (real32_T)
        rtb_Compare_jj;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_l[i] = rtb_Product_b5j;
      tmp += (rtb_Product_b5j > BTMR_tiRunAwayTempGradDe_C);
      rtb_Compare_jj = (BTMR_tCellTempGrad[i] >= BTMR_tBattTGRunAwayLv2_C);
      if (rtb_Compare_jj) {
        rtb_Product_e4 = 0.1F;
      } else {
        rtb_Product_e4 = 0.0F;
      }

      if (BTMR_tiRunAwayTempGradLv2De_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_g[i])
      {
        rtb_Product_b5j = BTMR_tiRunAwayTempGradLv2De_C;
      } else {
        rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_g[i];
      }

      rtb_Product_b5j = (rtb_Product_e4 + rtb_Product_b5j) * (real32_T)
        rtb_Compare_jj;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_g[i] = rtb_Product_b5j;
      rtb_RelationalOperator_br[i] = (rtb_Product_b5j >
        BTMR_tiRunAwayTempGradLv2De_C);
    }

    rtb_Compare_ns = ((uint8_T)tmp > 0);
    tmp = rtb_RelationalOperator_br[0];
    rtb_RelationalOperator_br[0] = (BSPR_tCellTemp_A[0] >=
      BTMR_tBattTRunAwayLv3_C);
    for (i = 0; i < 47; i++) {
      tmp += rtb_RelationalOperator_br[i + 1];
      rtb_RelationalOperator_br[i + 1] = (BSPR_tCellTemp_A[i + 1] >=
        BTMR_tBattTRunAwayLv3_C);
    }

    rtb_Compare_f = ((uint8_T)tmp > 0);
    tmp = 0U;
    for (i = 0; i < 48; i++) {
      tmp += rtb_RelationalOperator_br[i];
      rtb_Compare_jj = (BTMR_tCellTempGrad[i] >= BTMR_tBattTGRunAwayVoltDiag_C);
      if (rtb_Compare_jj) {
        rtb_Product_e4 = 0.1F;
      } else {
        rtb_Product_e4 = 0.0F;
      }

      if (BTMR_tiRunAwayVoltTempGradDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_c3[i])
      {
        rtb_Product_b5j = BTMR_tiRunAwayVoltTempGradDe_C;
      } else {
        rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_c3[i];
      }

      rtb_Product_b5j = (rtb_Product_e4 + rtb_Product_b5j) * (real32_T)
        rtb_Compare_jj;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_c3[i] = rtb_Product_b5j;
      rtb_RelationalOperator_br[i] = (rtb_Product_b5j >
        BTMR_tiRunAwayVoltTempGradDe_C);
    }

    rtb_Compare_jj = ((uint8_T)tmp > 0);
    tmp = rtb_RelationalOperator_br[0];
    for (i = 0; i < 47; i++) {
      tmp += rtb_RelationalOperator_br[i + 1];
    }

    rtb_LogicalOperator4_kf = ((uint8_T)tmp > 0);
    if (rtb_Compare_jj) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    if (BTMR_tiBattRunAwayLv3De_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_lc) {
      rtb_Product_b5j = BTMR_tiBattRunAwayLv3De_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_lc;
    }

    rtb_Product_e4 = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)
      rtb_Compare_jj;
    BTMR_flgTRunAwayLv3 = (rtb_Product_e4 > BTMR_tiBattRunAwayLv3De_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_lc = rtb_Product_e4;
    BTMR_flgTGRunAwayLv2 = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_dr || rtb_Compare_f)
      && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_p));
    rtb_LogicalOperator4_eu = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m0) &&
      rtb_Compare_ns);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m0 = rtb_Compare_ns;
    rtb_Compare_jj = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_p5 ||
                       rtb_LogicalOperator4_eu) &&
                      (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hs));
    if (!rtb_Compare_jj) {
      rtb_Product_e4 = 0.0F;
    } else {
      rtb_Product_e4 = (real32_T)rtb_LogicalOperator4_eu +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_hj;
    }

    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Product_e4), 256.0F);
    BTMR_ThmRnwyChk_B.DataTypeConversion_g = (uint8_T)(rtb_Product_b5j < 0.0F ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)
      rtb_Product_b5j);
    BTMR_ThmRnwyChk_B.BTMR_bRnwyMaxTGDet_i = ((BTMR_flgTRunAwayLv3 &&
      BTMR_flgTGRunAwayLv2) || (BTMR_ThmRnwyChk_B.DataTypeConversion_g >=
      BTMR_cntBattTGradThres_C));
    rtb_Compare_ns = (rtb_Compare_f || rtb_Compare_ns);
    if (rtb_Compare_ns && (BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal_Trig_ZCE !=
                           POS_ZCSIG)) {
      BTMR_ThmRnwyChk_B.uDMaximum_o1_j = BTMR_tCellTempGrad[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BTMR_tCellTempGrad[in] > BTMR_ThmRnwyChk_B.uDMaximum_o1_j) {
          BTMR_ThmRnwyChk_B.uDMaximum_o1_j = BTMR_tCellTempGrad[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_c = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal_Trig_ZCE = rtb_Compare_ns;
    if (rtb_LogicalOperator4_kf &&
        (BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal1_Trig_ZCE != POS_ZCSIG)) {
      in = 1;
      BTMR_ThmRnwyChk_B.uDMaximum_o1_h = BTMR_tCellTempGrad[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BTMR_tCellTempGrad[in] > BTMR_ThmRnwyChk_B.uDMaximum_o1_h) {
          BTMR_ThmRnwyChk_B.uDMaximum_o1_h = BTMR_tCellTempGrad[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_l = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal1_Trig_ZCE = rtb_LogicalOperator4_kf;
    rtb_Compare_ns = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e1;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e1 = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hs;
    if (rtb_Compare_ns && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hs) {
      rtb_Switch1_lw = 0.0F;
    } else {
      if (rtb_Compare_jj) {
        rtb_Product_ko = 0.1F;
      } else {
        rtb_Product_ko = 0.0F;
      }

      rtb_Switch1_lw = rtb_Product_ko + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_a;
    }

    rtb_Compare_ns = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d1;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d1 = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_p;
    if (rtb_Compare_ns && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_p) {
      rtb_Switch1_dc = 0.0F;
    } else {
      if (BTMR_flgTGRunAwayLv2) {
        rtb_Product_b5j = 0.1F;
      } else {
        rtb_Product_b5j = 0.0F;
      }

      rtb_Switch1_dc = rtb_Product_b5j + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_f1;
    }

    rtb_Compare_ns = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_f;
    BTMR_ThmRnwyChk_B.LogicalOperator4_m = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_cf ||
      rtb_LogicalOperator4_kf) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_f));
    if (rtb_Compare_ns && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_f) {
      rtb_Switch1_fk = 0.0F;
    } else {
      if (BTMR_ThmRnwyChk_B.LogicalOperator4_m) {
        rtb_Product_b5j = 0.1F;
      } else {
        rtb_Product_b5j = 0.0F;
      }

      rtb_Switch1_fk = rtb_Product_b5j + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_at;
    }

    rtb_LogicalOperator4_kf = (BSPR_tCellTempMax >= BTMR_tBattTRunAway_C);
    if (rtb_LogicalOperator4_kf) {
      rtb_Product_cr = 0.1F;
    } else {
      rtb_Product_cr = 0.0F;
    }

    if (BTMR_tiRunAwayTempDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_c) {
      rtb_Product_b5j = BTMR_tiRunAwayTempDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_c;
    }

    rtb_Product_cr = (rtb_Product_cr + rtb_Product_b5j) * (real32_T)
      rtb_LogicalOperator4_kf;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_c = rtb_Product_cr;
    BTMR_ThmRnwyChk_B.LogicalOperator1 = (rtb_Product_cr >
      BTMR_tiRunAwayTempDe_C);
    if (BTMR_ThmRnwyChk_B.LogicalOperator1 &&
        (BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE != POS_ZCSIG)) {
      in = 1;
      BTMR_ThmRnwyChk_B.uDMaximum_o1 = BSPR_tCellTemp_A[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 47; i++) {
        if (BSPR_tCellTemp_A[in] > BTMR_ThmRnwyChk_B.uDMaximum_o1) {
          BTMR_ThmRnwyChk_B.uDMaximum_o1 = BSPR_tCellTemp_A[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_d = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE =
      BTMR_ThmRnwyChk_B.LogicalOperator1;
    rtb_Compare_ns = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_p;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_p = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_i;
    in = 1;
    tmp = 0U;
    for (i = 0; i < 150; i++) {
      rtb_Divide1_f = 1000.0F * BSPR_uCellVolt_A[i];
      tmp += (rtb_Divide1_f == 0.0F);
      rtb_Divide1_k = (real32_T)fabs(BTMR_ThmRnwyChk_DW.Delay4_DSTATE[i] -
        rtb_Divide1_f);
      rtb_LogicalOperator4_kf = (rtb_Divide1_k > BTMR_uCellVoltGradThre_C);
      if (rtb_LogicalOperator4_kf) {
        rtb_Product_cr = 0.1F;
      } else {
        rtb_Product_cr = 0.0F;
      }

      if (BTMR_tiCellVoltAbnrDeb_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_f[i]) {
        rtb_Product_b5j = BTMR_tiCellVoltAbnrDeb_C;
      } else {
        rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_f[i];
      }

      rtb_Product_b5j = (rtb_Product_cr + rtb_Product_b5j) * (real32_T)
        rtb_LogicalOperator4_kf;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_f[i] = rtb_Product_b5j;
      rtb_Compare_nd[i] = (rtb_Product_b5j > BTMR_tiCellVoltAbnrDeb_C);
      rtb_Gain[i] = rtb_Divide1_f;
      rtb_Abs1[i] = rtb_Divide1_k;
    }

    rtb_DataTypeConversion4 = (uint8_T)tmp;
    tmp = rtb_Compare_nd[0];
    for (i = 0; i < 149; i++) {
      tmp += rtb_Compare_nd[i + 1];
    }

    BTMR_ThmRnwyChk_B.SumofElements4 = (uint8_T)tmp;
    rtb_LogicalOperator4_kf = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_jn ||
      ((rtb_DataTypeConversion4 == 0) && (BTMR_ThmRnwyChk_B.SumofElements4 <=
      BTMR_cntCellVoltGradAbnrUpLim_C) && (BTMR_ThmRnwyChk_B.SumofElements4 >=
      BTMR_cntCellVoltGradAbnrLoLim_C))) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_i));
    if (rtb_Compare_ns && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_i) {
      rtb_Product_cr = 0.0F;
    } else {
      if (rtb_LogicalOperator4_kf) {
        rtb_Product_cr = 0.1F;
      } else {
        rtb_Product_cr = 0.0F;
      }

      rtb_Product_cr += BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_n;
    }

    rtb_Compare_ns = ((real32_T)fabs(BSPR_iBattCurr) <=
                      BTMR_iCellVoltGradDiagThre_C);
    if (rtb_Compare_ns) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiCurrLimDeb_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_mr) {
      rtb_Product_b5j = BTMR_tiCurrLimDeb_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_mr;
    }

    rtb_Product_ko = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)
      rtb_Compare_ns;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_mr = rtb_Product_ko;
    BTMR_ThmRnwyChk_B.LogicalOperator4_o = (rtb_LogicalOperator4_kf &&
      (rtb_Product_ko > BTMR_tiCurrLimDeb_C));
    if (BTMR_ThmRnwyChk_B.LogicalOperator4_o &&
        (BTMR_ThmRnwyChk_PrevZCX.AbnrVoltGradIdCal_Trig_ZCE != POS_ZCSIG)) {
      rtb_Divide1_h = rtb_Abs1[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 149; i++) {
        if (rtb_Abs1[in] > rtb_Divide1_h) {
          rtb_Divide1_h = rtb_Abs1[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_h = (uint8_T)rtb_uDMaximum_o2_n;
      BTMR_ThmRnwyChk_B.DataTypeConversion3_d = rtb_Divide1_h / 1000.0F;
    }

    BTMR_ThmRnwyChk_PrevZCX.AbnrVoltGradIdCal_Trig_ZCE =
      BTMR_ThmRnwyChk_B.LogicalOperator4_o;
    rtb_Divide1_h = BSPR_uCellVoltAvrg * (real32_T)BTMR_cntMdulCellNum_C;
    rtb_Compare_f = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ky;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ky = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_er;
    in = 1;
    tmp = (uint32_T)(rtb_Gain[0] > BTMR_uBattTRunAwayMax_C);
    for (i = 0; i < 149; i++) {
      tmp += (rtb_Gain[i + 1] > BTMR_uBattTRunAwayMax_C);
    }

    rtb_Compare_ns = ((uint8_T)tmp > 0);
    if (rtb_Compare_ns) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiRunAwayMaxVoltDeb_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_iz) {
      rtb_Product_b5j = BTMR_tiRunAwayMaxVoltDeb_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_iz;
    }

    rtb_Product_ko = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)
      rtb_Compare_ns;
    rtb_Compare_ns = (rtb_Product_ko > BTMR_tiRunAwayMaxVoltDeb_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_iz = rtb_Product_ko;
    tmp = (uint32_T)(rtb_Gain[0] < BTMR_uBattTRunAwayMin_C);
    for (i = 0; i < 149; i++) {
      tmp += (rtb_Gain[i + 1] < BTMR_uBattTRunAwayMin_C);
    }

    rtb_LogicalOperator4_eu = ((uint8_T)tmp > 0);
    if (rtb_LogicalOperator4_eu) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    if (BTMR_tiRunAwayMinVoltDeb_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_m) {
      rtb_Product_b5j = BTMR_tiRunAwayMinVoltDeb_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_m;
    }

    rtb_Product_ko = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)
      rtb_LogicalOperator4_eu;
    rtb_LogicalOperator4_eu = (rtb_Product_ko > BTMR_tiRunAwayMinVoltDeb_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_m = rtb_Product_ko;
    BTMR_ThmRnwyChk_B.LogicalOperator4_f = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_j3 ||
      (rtb_Compare_ns || rtb_LogicalOperator4_eu)) &&
      (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_er));
    if (rtb_Compare_f && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_er) {
      rtb_Product_ko = 0.0F;
    } else {
      if (BTMR_ThmRnwyChk_B.LogicalOperator4_f) {
        rtb_Product_b5j = 0.1F;
      } else {
        rtb_Product_b5j = 0.0F;
      }

      rtb_Product_ko = rtb_Product_b5j + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_dt;
    }

    tmp = (uint32_T)((real32_T)fabs(rtb_Divide1_h - COMR_uMdulVolt_A[0]) >
                     BTMR_uMdulLowVoltDiag_C);
    for (i = 0; i < 7; i++) {
      tmp += ((real32_T)fabs(rtb_Divide1_h - COMR_uMdulVolt_A[i + 1]) >
              BTMR_uMdulLowVoltDiag_C);
    }

    rtb_Compare_f = ((uint8_T)tmp > 0);
    for (i = 0; i < 150; i++) {
      rtb_Abs1[i] = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e[i];
    }

    if (rtb_Compare_f) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiRunAwayMdulVoltDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_md) {
      rtb_Product_b5j = BTMR_tiRunAwayMdulVoltDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_md;
    }

    rtb_Divide1_h = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)rtb_Compare_f;
    rtb_Compare_f = (rtb_Divide1_h > BTMR_tiRunAwayMdulVoltDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_md = rtb_Divide1_h;
    BTMR_ThmRnwyChk_B.LogicalOperator4_d = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_lq ||
      rtb_Compare_f) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_ka));
    if (rtb_LogicalOperator4_eu &&
        (BTMR_ThmRnwyChk_PrevZCX.MinVoltIdCal_Trig_ZCE != POS_ZCSIG)) {
      rtb_Divide1_f = rtb_Gain[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 149; i++) {
        if (rtb_Gain[in] < rtb_Divide1_f) {
          rtb_Divide1_f = rtb_Gain[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_e = (uint8_T)rtb_uDMaximum_o2_n;
      BTMR_ThmRnwyChk_B.DataTypeConversion3_n = rtb_Divide1_f / 1000.0F;
    }

    BTMR_ThmRnwyChk_PrevZCX.MinVoltIdCal_Trig_ZCE = rtb_LogicalOperator4_eu;
    if (rtb_Compare_f && (BTMR_ThmRnwyChk_PrevZCX.MinMdulVoltIdCal_Trig_ZCE !=
                          POS_ZCSIG)) {
      in = 1;
      BTMR_ThmRnwyChk_B.uDMinimum_o1 = COMR_uMdulVolt_A[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 7; i++) {
        if (COMR_uMdulVolt_A[in] < BTMR_ThmRnwyChk_B.uDMinimum_o1) {
          BTMR_ThmRnwyChk_B.uDMinimum_o1 = COMR_uMdulVolt_A[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_idxMinMdulVoltID = (uint8_T)rtb_uDMaximum_o2_n;
    }

    BTMR_ThmRnwyChk_PrevZCX.MinMdulVoltIdCal_Trig_ZCE = rtb_Compare_f;
    if (rtb_Compare_ns && (BTMR_ThmRnwyChk_PrevZCX.MaxVoltIdCal_Trig_ZCE !=
                           POS_ZCSIG)) {
      in = 1;
      rtb_Divide1_k = rtb_Gain[0];
      rtb_uDMaximum_o2_n = 1;
      for (i = 0; i < 149; i++) {
        if (rtb_Gain[in] > rtb_Divide1_k) {
          rtb_Divide1_k = rtb_Gain[in];
          rtb_uDMaximum_o2_n = i + 2;
        }

        in++;
      }

      BTMR_ThmRnwyChk_B.DataTypeConversion_j = (uint8_T)rtb_uDMaximum_o2_n;
      BTMR_ThmRnwyChk_B.DataTypeConversion3_m = rtb_Divide1_k / 1000.0F;
    }

    BTMR_ThmRnwyChk_PrevZCX.MaxVoltIdCal_Trig_ZCE = rtb_Compare_ns;
    BTMR_bMinVoltMdulFit_tmp = (uint8_T)(BTMR_ThmRnwyChk_B.DataTypeConversion_e
      - 1);
    rtb_Divide1_h = (uint8_T)(BTMR_ThmRnwyChk_B.DataTypeConversion_j - 1);
    BTMR_bMinVoltMdulFit = (((int32_T)(real32_T)floor(BTMR_bMinVoltMdulFit_tmp /
      12.0F) + 1 == BTMR_idxMinMdulVoltID) || ((int32_T)(real32_T)floor
      (rtb_Divide1_h / 12.0F) + 1 == BTMR_idxMinMdulVoltID));
    BTMR_ThmRnwyChk_B.LogicalOperator2_j = (BTMR_ThmRnwyChk_B.LogicalOperator4_d
      && BTMR_bMinVoltMdulFit && BTMR_ThmRnwyChk_B.LogicalOperator4_f);
    rtb_Compare_ns = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ka;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ka = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_ka;
    if (rtb_Compare_ns && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_ka) {
      rtb_Divide1_f = 0.0F;
    } else {
      if (BTMR_ThmRnwyChk_B.LogicalOperator4_d) {
        rtb_Product_b5j = 0.1F;
      } else {
        rtb_Product_b5j = 0.0F;
      }

      rtb_Divide1_f = rtb_Product_b5j + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_d2;
    }

    if (BTMR_flgMdulFitDiagSwitch_C) {
      rtb_Compare_f = BTMR_ThmRnwyChk_B.LogicalOperator2_j;
    } else {
      rtb_Compare_f = BTMR_ThmRnwyChk_B.LogicalOperator4_f;
    }

    rtb_Compare_ns = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_ib || rtb_Compare_f) && (
      !BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e3));
    if (!rtb_Compare_ns) {
      rtb_Divide1_k = 0.0F;
    } else {
      rtb_Divide1_k = (real32_T)rtb_Compare_f +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_cr;
    }

    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Divide1_k), 256.0F);
    BTMR_ThmRnwyChk_B.DataTypeConversion_b = (uint8_T)(rtb_Product_b5j < 0.0F ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)
      rtb_Product_b5j);
    BTMR_ThmRnwyChk_B.RelationalOperator5 =
      (BTMR_ThmRnwyChk_B.DataTypeConversion_b >= BTMR_cntCellVoltThres_C);
    rtb_Compare_f = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ha;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ha = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e3;
    if (rtb_Compare_f && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e3) {
      rtb_Switch1_cr = 0.0F;
    } else {
      if (rtb_Compare_ns) {
        rtb_Switch1_cr = 0.1F;
      } else {
        rtb_Switch1_cr = 0.0F;
      }

      rtb_Switch1_cr += BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_ar;
    }

    rtb_LogicalOperator4_eu = (BTMR_ThmRnwyChk_B.DataTypeConversion_e != 0);
    BTMR_bMinVoltMdulFit_tmp = (real32_T)floor(BTMR_bMinVoltMdulFit_tmp / 4.0F);
    rtb_Compare_f = (BTMR_ThmRnwyChk_B.DataTypeConversion_j != 0);
    in = (int32_T)(real32_T)floor(rtb_Divide1_h / 4.0F) + 1;
    if (GeRTE_CapEdition_enum == enmBattType_SWD75) {
      rtb_Product_b5j = BTMR_tCellTempUpLimSWD_C;
    } else {
      rtb_Product_b5j = BTMR_tCellTempUpLimCATL_C;
    }

    rtb_RelationalOperator6_a2 = (BSPR_tCellTempMax == rtb_Product_b5j);
    if (rtb_RelationalOperator6_a2) {
      rtb_Divide1_h = 0.1F;
    } else {
      rtb_Divide1_h = 0.0F;
    }

    if (BTMR_tiRunAwayTempUpLimDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_hx) {
      rtb_Product_b5j = BTMR_tiRunAwayTempUpLimDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_hx;
    }

    rtb_Product_b5j = (rtb_Divide1_h + rtb_Product_b5j) * (real32_T)
      rtb_RelationalOperator6_a2;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_hx = rtb_Product_b5j;
    BTMR_bModuleFit = ((rtb_LogicalOperator4_eu && ((int32_T)
      (BTMR_bMinVoltMdulFit_tmp + 1.0F) ==
      BTMR_ThmRnwyChk_B.DataTypeConversion_c)) ||
                       ((BTMR_ThmRnwyChk_B.DataTypeConversion_c ==
                         BTMR_ThmRnwyChk_B.DataTypeConversion_d) &&
                        (BTMR_ThmRnwyChk_B.DataTypeConversion_d != 0)) ||
                       (rtb_Compare_f && (in ==
      BTMR_ThmRnwyChk_B.DataTypeConversion_c)) || (rtb_Compare_f && (in ==
      BTMR_ThmRnwyChk_B.DataTypeConversion_d)) || (rtb_LogicalOperator4_eu &&
      ((int32_T)(BTMR_bMinVoltMdulFit_tmp + 1.0F) ==
       BTMR_ThmRnwyChk_B.DataTypeConversion_d)) || (rtb_Product_b5j >
      BTMR_tiRunAwayTempUpLimDe_C));
    if (BTMR_flgIDDiagSwitch_C) {
      rtb_Compare_f = BTMR_bIDDiagEna_C;
    } else if (BTMR_flgModlFitDiagSwitch_C) {
      rtb_Compare_f = BTMR_bModuleFit;
    } else {
      rtb_Compare_f = BTMR_ThmRnwyChk_B.LogicalOperator4_f;
    }

    BTMR_ThmRnwyChk_B.LogicalOperator5 = (BTMR_ThmRnwyChk_B.RelationalOperator_d
      && BTMR_ThmRnwyChk_B.BTMR_bRnwyMaxTGDet_i &&
      BTMR_ThmRnwyChk_B.LogicalOperator1 && rtb_Compare_f);
    if (BTMR_flgThmRnwyCon2Switch_C) {
      if (BTMR_flgIDDiagSwitch_C) {
        rtb_Compare_f = BTMR_bIDDiagEna_C;
        rtb_LogicalOperator4_eu = BTMR_bIDDiagEna_C;
        rtb_RelationalOperator6_a2 = BTMR_bIDDiagEna_C;
      } else {
        i = (int32_T)BTMR_bMinVoltMdulFit_tmp + 1;
        rtb_Compare_f = (((BTMR_ThmRnwyChk_B.DataTypeConversion_e != 0) && (i ==
          BTMR_ThmRnwyChk_B.DataTypeConversion_dk)) || ((in ==
          BTMR_ThmRnwyChk_B.DataTypeConversion_dk) &&
          (BTMR_ThmRnwyChk_B.DataTypeConversion_j != 0)));
        rtb_LogicalOperator4_eu = (((BTMR_ThmRnwyChk_B.DataTypeConversion_e != 0)
          && (i == BTMR_ThmRnwyChk_B.DataTypeConversion_c)) || ((in ==
          BTMR_ThmRnwyChk_B.DataTypeConversion_c) &&
          (BTMR_ThmRnwyChk_B.DataTypeConversion_j != 0)));
        rtb_RelationalOperator6_a2 = (((BTMR_ThmRnwyChk_B.DataTypeConversion_e
          != 0) && (i == BTMR_ThmRnwyChk_B.DataTypeConversion_d)) || ((in ==
          BTMR_ThmRnwyChk_B.DataTypeConversion_d) &&
          (BTMR_ThmRnwyChk_B.DataTypeConversion_j != 0)));
      }

      BTMR_ThmRnwyChk_B.Switch4 = ((BTMR_ThmRnwyChk_B.RelationalOperator_d &&
        BTMR_ThmRnwyChk_B.RelationalOperator5 && rtb_Compare_f) ||
        (BTMR_ThmRnwyChk_B.BTMR_bRnwyMaxTGDet_i &&
         BTMR_ThmRnwyChk_B.RelationalOperator5 && rtb_LogicalOperator4_eu) ||
        (BTMR_ThmRnwyChk_B.LogicalOperator1 &&
         BTMR_ThmRnwyChk_B.RelationalOperator5 && rtb_RelationalOperator6_a2) ||
        (BTMR_bBusbarRnwyMaxTGDet && BTMR_ThmRnwyChk_B.RelationalOperator5) ||
        (BTMR_bBusbarRnwyHighTempDet && BTMR_ThmRnwyChk_B.RelationalOperator5) ||
        (BTMR_bBusbarRnwyTempDiffDet && BTMR_ThmRnwyChk_B.RelationalOperator5));
    } else {
      BTMR_ThmRnwyChk_B.Switch4 = BTMR_bThmRnwyCon2Ena_C;
    }

    if (BTMR_flgThmRnwyCon3Switch_C) {
      BTMR_ThmRnwyChk_B.Switch3 = BTMR_ThmRnwyChk_B.LogicalOperator4_o;
    } else {
      BTMR_ThmRnwyChk_B.Switch3 = BTMR_bThmRnwyCon3Ena_C;
    }

    BTMR_bThmRunAwayCond4 = (BTMR_bBusbarRnwyMaxTGDet &&
      BTMR_bBusbarRnwyHighTempDet && BTMR_bBusbarRnwyTempDiffDet);
    if ((BTMR_cntBattRunAwayDiag_CW & 1) == 1) {
      if (BTMR_flgThmRnwyCon4Switch_C) {
        rtb_Compare_f = ((GcRTE_BusbarTempNumb_numb > 0) &&
                         BTMR_bThmRunAwayCond4);
      } else {
        rtb_Compare_f = BTMR_bThmRnwyCon4Ena_C;
      }

      rtb_Compare_f = (BTMR_ThmRnwyChk_B.LogicalOperator5 ||
                       BTMR_ThmRnwyChk_B.Switch4 || BTMR_ThmRnwyChk_B.Switch3 ||
                       rtb_Compare_f);
    } else {
      rtb_Compare_f = false;
    }

    rtb_Compare_f = (BTMR_ThmRnwyChk_DW.Delay_DSTATE_ka || rtb_Compare_f);
    if (BTMR_bThmRunAwayFltSwitch_C) {
      BTMR_ThmRnwyChk_B.Switch5 = BTMR_bThmRunAwayFltEna_C;
    } else {
      BTMR_ThmRnwyChk_B.Switch5 = rtb_Compare_f;
    }

    BTMR_ThmRnwyChk_DW.Delay_DSTATE_hs = BTMR_flgBusbarTGRunAwayLv2;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h2 = (rtb_Switch1_aj >
      BTMR_tiBusbarTGRunAwayLv2CondRes_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_gr = rtb_LogicalOperator1;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_n = (rtb_Product_k2f >
      BTMR_tiBusbarThmRnwyCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_fk = rtb_Product_dy;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_d = rtb_Product_k2f;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_k4 = rtb_Switch1_aj;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_dr = BTMR_flgTGRunAwayLv2;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_p = (rtb_Switch1_dc >
      BTMR_tiTGRunAwayLv2CondRes_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_p5 = rtb_Compare_jj;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hs = (rtb_Switch1_lw >
      BTMR_tiThmRnwyCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_hj = rtb_Product_e4;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_a = rtb_Switch1_lw;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_f1 = rtb_Switch1_dc;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_f = (rtb_Switch1_fk >
      BTMR_tiVGTGRunAwayCondRes_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_cf = BTMR_ThmRnwyChk_B.LogicalOperator4_m;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_at = rtb_Switch1_fk;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_i = (rtb_Product_cr >
      BTMR_tiCellVoltCondRes_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_jn = rtb_LogicalOperator4_kf;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_n = rtb_Product_cr;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_er = (rtb_Product_ko >
      BTMR_tiCellVoltCondRes_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_j3 = BTMR_ThmRnwyChk_B.LogicalOperator4_f;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_dt = rtb_Product_ko;
    for (i = 0; i < 150; i++) {
      BTMR_ThmRnwyChk_DW.Delay4_DSTATE[i] = BTMR_ThmRnwyChk_DW.Delay3_DSTATE[i];
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e[i] = rtb_Gain[i];
      BTMR_ThmRnwyChk_DW.Delay3_DSTATE[i] = rtb_Abs1[i];
    }

    BTMR_ThmRnwyChk_DW.Delay_DSTATE_lq = BTMR_ThmRnwyChk_B.LogicalOperator4_d;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_ka = (rtb_Divide1_f >
      BTMR_tiMudlVoltCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_d2 = rtb_Divide1_f;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_ib = rtb_Compare_ns;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_e3 = (rtb_Switch1_cr >
      BTMR_tiThmRnwyCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_cr = rtb_Divide1_k;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_ar = rtb_Switch1_cr;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_ka = rtb_Compare_f;
  } else {
    if (BTMR_ThmRnwyChk_DW.Rnwy_Chk_MODE) {
      BTMR_ThmRnwyChk_DW.Rnwy_Chk_MODE = false;
    }
  }

  BTMR_bThmRunAway = BTMR_ThmRnwyChk_B.Switch5;
  if (BTMR_ThmRnwyChk_DW.Delay2_DSTATE_bb) {
    DFC_ThmRnwy_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_ThmRnwy_ASW | 8U);
  } else if (BTMR_bThmRunAway) {
    DFC_ThmRnwy_ASW = (uint8_T)(DFC_ThmRnwy_ASW | 152U);
  } else {
    DFC_ThmRnwy_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_ThmRnwy_ASW | 16U) |
      8U);
  }

  BTMR_ThmRnwyChk_DW.Delay2_DSTATE_bb = false;
  rtb_LogicalOperator1 = ((BSW_stSysWkUpSrc & 256) != 0);
  rtb_Compare_jj = (BMCR_stBmsModeCtrl >= 1);
  if (rtb_Compare_jj) {
    rtb_Product_ko = 0.1F;
  } else {
    rtb_Product_ko = 0.0F;
  }

  if (BTMR_tiTPLTmtRnwyDiagIni_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_e) {
    rtb_Product_b5j = BTMR_tiTPLTmtRnwyDiagIni_C;
  } else {
    rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_e;
  }

  rtb_Product_dy = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)rtb_Compare_jj;
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_e = rtb_Product_dy;
  if (BTMR_flgTPLTmtRnwyDiagSwitch_C) {
    rtb_Compare_f = BTMR_bTPLTmtRnwyDiagEna_C;
  } else {
    rtb_Compare_f = (rtb_Product_dy > BTMR_tiTPLTmtRnwyDiagIni_C);
  }

  if (rtb_Compare_f) {
    if (!BTMR_ThmRnwyChk_DW.Rnwy_Chk_TPLTmt_MODE) {
      for (i = 0; i < 240; i++) {
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_d[i] = 0.0F;
        BTMR_ThmRnwyChk_DW.Delay1_DSTATE[i] = 0.0F;
      }

      BTMR_ThmRnwyChk_DW.Delay_DSTATE_nz = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_h = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_mf = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_m = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_b = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_pm = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hj = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_g = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_c5 = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_l = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_j = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_cw = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_k = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_i = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_c1 = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_kh = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_c = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_p = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_k = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_i0 = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_f = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_m = 0.0F;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_ks = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_ax = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_c = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4 = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_n = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_k = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i3 = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_ig = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_j = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_h = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_op = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_nl = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_gb = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_o = true;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_a = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_pn = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_hd = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_my = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_hb = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_oe = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_du = true;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_g = true;
      BTMR_ThmRnwyChk_DW.Rnwy_Chk_TPLTmt_MODE = true;
    }

    tmp = (uint32_T)(BSPR_tCellTemp_A[0] - BTMR_ThmRnwyChk_DW.Delay_DSTATE_d[0] >=
                     BTMR_tTPLTmtBattTGRunAway_C);
    rtb_RelationalOperator_br[0] = (BSPR_tCellTemp_A[0] == BTMR_tBattTSnsrAbnm_C);
    for (i = 0; i < 47; i++) {
      tmp += (BSPR_tCellTemp_A[i + 1] - BTMR_ThmRnwyChk_DW.Delay_DSTATE_d[i + 1]
              >= BTMR_tTPLTmtBattTGRunAway_C);
      rtb_RelationalOperator_br[i + 1] = (BSPR_tCellTemp_A[i + 1] ==
        BTMR_tBattTSnsrAbnm_C);
    }

    rtb_Compare_f = ((uint8_T)tmp > 0);
    rtb_Compare_jj = (IoExtMc33771_ChkCIDCycSt == 0);
    tmp = rtb_RelationalOperator_br[0];
    for (i = 0; i < 47; i++) {
      tmp += rtb_RelationalOperator_br[i + 1];
    }

    rtb_LogicalOperator4_kf = ((uint8_T)tmp > 0);
    for (i = 0; i < 150; i++) {
      rtb_Compare_nd[i] = (BSPR_uCellVolt_A[i] == 0.0F);
    }

    tmp = (uint32_T)(BSPR_tBattTemp_A[0] - BTMR_ThmRnwyChk_DW.Delay1_DSTATE[0] >=
                     BTMR_tTPLTmtBusbarTGRunAway_C);
    for (i = 0; i < 47; i++) {
      tmp += (BSPR_tBattTemp_A[i + 1] - BTMR_ThmRnwyChk_DW.Delay1_DSTATE[i + 1] >=
              BTMR_tTPLTmtBusbarTGRunAway_C);
    }

    rtb_Compare_ns = ((uint8_T)tmp > 0);
    if (rtb_Compare_f) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiTPLTmtRunAwayTempGradDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_ax) {
      rtb_Product_b5j = BTMR_tiTPLTmtRunAwayTempGradDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_ax;
    }

    rtb_Product_dy = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)
      rtb_Compare_f;
    rtb_LogicalOperator4_eu = (rtb_Product_dy > BTMR_tiTPLTmtRunAwayTempGradDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_ax = rtb_Product_dy;
    rtb_Compare_f = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_c) &&
                     rtb_LogicalOperator4_eu);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_c = rtb_LogicalOperator4_eu;
    rtb_LogicalOperator4_eu = (BSPR_tCellTempMax >= BTMR_tTPLTmtBattTRunAway_C);
    if (rtb_LogicalOperator4_eu) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    if (BTMR_tiTPLTmtRunAwayTempDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4) {
      rtb_Product_b5j = BTMR_tiTPLTmtRunAwayTempDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4;
    }

    rtb_Product_dy = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)
      rtb_LogicalOperator4_eu;
    rtb_RelationalOperator6_a2 = (rtb_Product_dy > BTMR_tiTPLTmtRunAwayTempDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_h4 = rtb_Product_dy;
    rtb_LogicalOperator4_eu = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_n) &&
      rtb_RelationalOperator6_a2);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_n = rtb_RelationalOperator6_a2;
    rtb_RelationalOperator6_a2 = ((BSPR_tCellTempMax - BSPR_tCellTempMin >=
      BTMR_tTPLTmtBattTDiffRunAway_C) && (BSPR_tCellTempMin !=
      BTMR_tTsnsrTmtThre_C));
    if (rtb_RelationalOperator6_a2) {
      rtb_Divide1_h = 0.1F;
    } else {
      rtb_Divide1_h = 0.0F;
    }

    if (BTMR_tiTPLTmtRunAwayTempDiffDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_k) {
      rtb_Product_b5j = BTMR_tiTPLTmtRunAwayTempDiffDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_k;
    }

    rtb_Product_dy = (rtb_Divide1_h + rtb_Product_b5j) * (real32_T)
      rtb_RelationalOperator6_a2;
    rtb_RelationalOperator_i = (rtb_Product_dy >
      BTMR_tiTPLTmtRunAwayTempDiffDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_k = rtb_Product_dy;
    rtb_RelationalOperator6_a2 = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i3) &&
      rtb_RelationalOperator_i);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i3 = rtb_RelationalOperator_i;
    if (rtb_Compare_ns) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiTPLTmtRunAwayBusbarTG_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_ig) {
      rtb_Product_b5j = BTMR_tiTPLTmtRunAwayBusbarTG_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_ig;
    }

    rtb_Product_dy = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)
      rtb_Compare_ns;
    rtb_Compare_ns = (rtb_Product_dy > BTMR_tiTPLTmtRunAwayBusbarTG_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_ig = rtb_Product_dy;
    rtb_RelationalOperator_i = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_j) &&
      rtb_Compare_ns);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_j = rtb_Compare_ns;
    rtb_Compare_ns = (BSPR_tBattTempMax >= BTMR_tTPLTmtBusbarTRunAway_C);
    if (rtb_Compare_ns) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiTPLTmtRnwyBusbarTemp_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_h) {
      rtb_Product_b5j = BTMR_tiTPLTmtRnwyBusbarTemp_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_h;
    }

    rtb_Product_dy = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)
      rtb_Compare_ns;
    rtb_Compare_ns = (rtb_Product_dy > BTMR_tiTPLTmtRnwyBusbarTemp_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_h = rtb_Product_dy;
    rtb_LogicalOperator4_l0 = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_op) &&
      rtb_Compare_ns);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_op = rtb_Compare_ns;
    rtb_Compare_ns = ((BSPR_tBattTempMax - BSPR_tBattTempMin >=
                       BTMR_tTPLTmtBusbarTDiffRunAway_C) && (BSPR_tBattTempMin
      != BTMR_tTsnsrTmtThre_C));
    if (rtb_Compare_ns) {
      rtb_Switch1_cr = 0.1F;
    } else {
      rtb_Switch1_cr = 0.0F;
    }

    if (BTMR_tiTPLTmtRunAwayTempDiffDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_nl) {
      rtb_Product_b5j = BTMR_tiTPLTmtRunAwayTempDiffDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_nl;
    }

    rtb_Product_dy = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)
      rtb_Compare_ns;
    rtb_Compare_ns = (rtb_Product_dy > BTMR_tiTPLTmtRunAwayTempDiffDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_nl = rtb_Product_dy;
    rtb_LogicalOperator4_b5 = ((!BTMR_ThmRnwyChk_DW.Delay1_DSTATE_gb) &&
      rtb_Compare_ns);
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_gb = rtb_Compare_ns;
    rtb_Compare_ns = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_nz || rtb_Compare_f) && (
      !BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h));
    if (!rtb_Compare_ns) {
      rtb_Product_dy = 0.0F;
    } else {
      rtb_Product_dy = (real32_T)rtb_Compare_f +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_h;
    }

    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Product_dy), 256.0F);
    BTMR_ThmRnwyChk_B.DataTypeConversion = (uint8_T)(rtb_Product_b5j < 0.0F ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)
      rtb_Product_b5j);
    rtb_Compare_f = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_mf ||
                      rtb_LogicalOperator4_eu) &&
                     (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_m));
    if (!rtb_Compare_f) {
      rtb_Product_k2f = 0.0F;
    } else {
      rtb_Product_k2f = (real32_T)rtb_LogicalOperator4_eu +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_b;
    }

    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Product_k2f), 256.0F);
    BTMR_ThmRnwyChk_B.DataTypeConversion_f = (uint8_T)(rtb_Product_b5j < 0.0F ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)
      rtb_Product_b5j);
    rtb_LogicalOperator4_eu = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_pm ||
      rtb_RelationalOperator6_a2) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hj));
    rtb_LogicalOperator3_c = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_o;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_o = rtb_RelationalOperator6_a2;
    if (!rtb_LogicalOperator4_eu) {
      rtb_Switch1_aj = 0.0F;
    } else {
      rtb_Switch1_aj = (real32_T)(rtb_LogicalOperator3_c &&
        rtb_RelationalOperator6_a2) + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_g;
    }

    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Switch1_aj), 256.0F);
    BTMR_ThmRnwyChk_B.DataTypeConversion_fs = (uint8_T)(rtb_Product_b5j < 0.0F ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)
      rtb_Product_b5j);
    tmp = rtb_Compare_nd[0];
    for (i = 0; i < 149; i++) {
      tmp += rtb_Compare_nd[i + 1];
    }

    rtb_RelationalOperator6_a2 = ((uint8_T)tmp >= BTMR_cntVSnsrTmtRnwy_C);
    if (rtb_RelationalOperator6_a2) {
      rtb_Divide1_h = 0.1F;
    } else {
      rtb_Divide1_h = 0.0F;
    }

    if (BTMR_tiVSnsrTmtRunAwayDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_a) {
      rtb_Product_b5j = BTMR_tiVSnsrTmtRunAwayDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_a;
    }

    rtb_Divide1_f = (rtb_Divide1_h + rtb_Product_b5j) * (real32_T)
      rtb_RelationalOperator6_a2;
    BTMR_ThmRnwyChk_B.RelationalOperator = (rtb_Divide1_f >
      BTMR_tiVSnsrTmtRunAwayDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_a = rtb_Divide1_f;
    if (rtb_Compare_jj) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    if (BTMR_tiRnwyTplTmtDeb_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_pn) {
      rtb_Product_b5j = BTMR_tiRnwyTplTmtDeb_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_pn;
    }

    rtb_Switch1_lw = (rtb_Product_ko + rtb_Product_b5j) * (real32_T)
      rtb_Compare_jj;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_pn = rtb_Switch1_lw;
    if (rtb_LogicalOperator4_kf) {
      rtb_Product_cr = 0.1F;
    } else {
      rtb_Product_cr = 0.0F;
    }

    if (BTMR_tiTSnsrTmtRunAwayDe_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_hd) {
      rtb_Product_b5j = BTMR_tiTSnsrTmtRunAwayDe_C;
    } else {
      rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_hd;
    }

    rtb_Divide1_f = (rtb_Product_cr + rtb_Product_b5j) * (real32_T)
      rtb_LogicalOperator4_kf;
    BTMR_ThmRnwyChk_B.RelationalOperator_j = (rtb_Divide1_f >
      BTMR_tiTSnsrTmtRunAwayDe_C);
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_hd = rtb_Divide1_f;
    rtb_Compare_jj = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_c5 ||
                       rtb_RelationalOperator_i) &&
                      (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_l));
    if (!rtb_Compare_jj) {
      rtb_Divide1_f = 0.0F;
    } else {
      rtb_Divide1_f = (real32_T)rtb_RelationalOperator_i +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_j;
    }

    rtb_LogicalOperator4_kf = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_cw ||
      rtb_LogicalOperator4_l0) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_k));
    if (!rtb_LogicalOperator4_kf) {
      rtb_Divide1_k = 0.0F;
    } else {
      rtb_Divide1_k = (real32_T)rtb_LogicalOperator4_l0 +
        BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_i;
    }

    rtb_RelationalOperator6_a2 = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_c1 ||
      rtb_LogicalOperator4_b5) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_kh));
    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m = rtb_LogicalOperator4_b5;
    if (!rtb_RelationalOperator6_a2) {
      rtb_Product_e4 = 0.0F;
    } else {
      rtb_Product_e4 = (real32_T)(rtb_RelationalOperator_i &&
        rtb_LogicalOperator4_b5) + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_c;
    }

    if ((BTMR_cntBattRunAwayDiag_CW & 2) == 2) {
      rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Divide1_f), 256.0F);
      rtb_Switch1_dc = (real32_T)fmod((real32_T)floor(rtb_Divide1_k), 256.0F);
      rtb_Switch1_fk = (real32_T)fmod((real32_T)floor(rtb_Product_e4), 256.0F);
      BTMR_ThmRnwyChk_B.Switch = ((BTMR_ThmRnwyChk_B.RelationalOperator ||
        (rtb_Switch1_lw > BTMR_tiRnwyTplTmtDeb_C) ||
        BTMR_ThmRnwyChk_B.RelationalOperator_j) &&
        ((BTMR_ThmRnwyChk_B.DataTypeConversion >= BTMR_cntTPLTmtBattTGradThres_C)
         || (BTMR_ThmRnwyChk_B.DataTypeConversion_f >=
             BTMR_cntTPLTmtBattTThres_C) ||
         (BTMR_ThmRnwyChk_B.DataTypeConversion_fs >=
          BTMR_cntTPLTmtBattTDiffThres_C)) && (((rtb_Product_b5j < 0.0F ?
        (int32_T)(uint8_T)-(int8_T)(uint8_T)-rtb_Product_b5j : (int32_T)(uint8_T)
        rtb_Product_b5j) >= BTMR_cntTPLTmtBusbarTGradThres_C) ||
        ((rtb_Switch1_dc < 0.0F ? (int32_T)(uint8_T)-(int8_T)(uint8_T)
          -rtb_Switch1_dc : (int32_T)(uint8_T)rtb_Switch1_dc) >=
         BTMR_cntTPLTmtBusbarTThres_C) || ((rtb_Switch1_fk < 0.0F ? (int32_T)
        (uint8_T)-(int8_T)(uint8_T)-rtb_Switch1_fk : (int32_T)(uint8_T)
        rtb_Switch1_fk) >= BTMR_cntTPLTmtBattTDiffThres_C)));
    } else {
      BTMR_ThmRnwyChk_B.Switch = BTMR_bTPLTmtBattRunAwayEna_C;
    }

    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_my;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_my = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_m;
    if (rtb_RelationalOperator_i && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_m) {
      rtb_Switch1_lw = 0.0F;
    } else {
      if (rtb_Compare_f) {
        rtb_Switch1_cr = 0.1F;
      } else {
        rtb_Switch1_cr = 0.0F;
      }

      rtb_Switch1_lw = rtb_Switch1_cr + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_p;
    }

    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_hb;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_hb = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_k;
    if (rtb_RelationalOperator_i && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_k) {
      rtb_Switch1_dc = 0.0F;
    } else {
      if (rtb_LogicalOperator4_kf) {
        rtb_Product_cr = 0.1F;
      } else {
        rtb_Product_cr = 0.0F;
      }

      rtb_Switch1_dc = rtb_Product_cr + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_k;
    }

    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_oe;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_oe = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hj;
    if (rtb_RelationalOperator_i && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hj) {
      rtb_Switch1_fk = 0.0F;
    } else {
      if (rtb_LogicalOperator4_eu) {
        rtb_Product_ko = 0.1F;
      } else {
        rtb_Product_ko = 0.0F;
      }

      rtb_Switch1_fk = rtb_Product_ko + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_i0;
    }

    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_kh;
    if (rtb_RelationalOperator_i && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_kh) {
      rtb_Product_cr = 0.0F;
    } else {
      if (rtb_RelationalOperator6_a2) {
        rtb_Divide1_h = 0.1F;
      } else {
        rtb_Divide1_h = 0.0F;
      }

      rtb_Product_cr = rtb_Divide1_h + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_f;
    }

    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_du;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_du = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h;
    if (rtb_RelationalOperator_i && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h) {
      rtb_Divide1_h = 0.0F;
    } else {
      if (rtb_Compare_ns) {
        rtb_Switch1_cr = 0.1F;
      } else {
        rtb_Switch1_cr = 0.0F;
      }

      rtb_Divide1_h = rtb_Switch1_cr + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_m;
    }

    rtb_RelationalOperator_i = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_g;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_g = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_l;
    if (rtb_RelationalOperator_i && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_l) {
      rtb_Product_ko = 0.0F;
    } else {
      if (rtb_Compare_jj) {
        rtb_Product_ko = 0.1F;
      } else {
        rtb_Product_ko = 0.0F;
      }

      rtb_Product_ko += BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_ks;
    }

    for (in = 0; in < 4; in++) {
      for (i = 0; i < 48; i++) {
        BTMR_ThmRnwyChk_DW.Delay_DSTATE_d[in * 48 + i] =
          BTMR_ThmRnwyChk_DW.Delay_DSTATE_d[(in + 1) * 48 + i];
      }
    }

    for (i = 0; i < 48; i++) {
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_d[i + 192] = BSPR_tCellTemp_A[i];
    }

    for (in = 0; in < 4; in++) {
      for (i = 0; i < 48; i++) {
        BTMR_ThmRnwyChk_DW.Delay1_DSTATE[in * 48 + i] =
          BTMR_ThmRnwyChk_DW.Delay1_DSTATE[(in + 1) * 48 + i];
      }
    }

    for (i = 0; i < 48; i++) {
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE[i + 192] = BSPR_tBattTemp_A[i];
    }

    BTMR_ThmRnwyChk_DW.Delay_DSTATE_nz = rtb_Compare_ns;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_h = (rtb_Divide1_h >
      BTMR_tiTPLTmtThmRnwyTGCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_h = rtb_Product_dy;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_mf = rtb_Compare_f;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_m = (rtb_Switch1_lw >
      BTMR_tiTPLTmtThmRnwyTCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_b = rtb_Product_k2f;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_pm = rtb_LogicalOperator4_eu;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_hj = (rtb_Switch1_fk >
      BTMR_tiTPLTmtThmRnwyTDiffCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_g = rtb_Switch1_aj;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_c5 = rtb_Compare_jj;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_l = (rtb_Product_ko >
      BTMR_tiTPLTmtbusbarTGCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_j = rtb_Divide1_f;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_cw = rtb_LogicalOperator4_kf;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_k = (rtb_Switch1_dc >
      BTMR_tiTPLTmtThmRnwyBusbarTRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_i = rtb_Divide1_k;
    BTMR_ThmRnwyChk_DW.Delay_DSTATE_c1 = rtb_RelationalOperator6_a2;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_kh = (rtb_Product_cr >
      BTMR_tiTPLTmtThmRnwyTDiffCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_c = rtb_Product_e4;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_p = rtb_Switch1_lw;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_k = rtb_Switch1_dc;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_i0 = rtb_Switch1_fk;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_f = rtb_Product_cr;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_m = rtb_Divide1_h;
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_ks = rtb_Product_ko;
  } else {
    if (BTMR_ThmRnwyChk_DW.Rnwy_Chk_TPLTmt_MODE) {
      BTMR_ThmRnwyChk_DW.Rnwy_Chk_TPLTmt_MODE = false;
    }
  }

  rtb_LogicalOperator4_kf = ((BMCR_stBmsModeCtrl == 2) &&
    (BTMR_ThmRnwyChk_DW.Delay_DSTATE_o == 1));
  rtb_Compare_jj = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_o5 ||
                     rtb_LogicalOperator4_kf) &&
                    (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_o));
  rtb_Compare_gf = (GbBSW_CellVoltVldAll_flg && (!rtb_Compare_gf));
  if (rtb_Compare_gf) {
    rtb_Product_dy = 0.1F;
  } else {
    rtb_Product_dy = 0.0F;
  }

  if (BTMR_tiRnwyPreChkDiagDebounce_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_ey) {
    rtb_Product_b5j = BTMR_tiRnwyPreChkDiagDebounce_C;
  } else {
    rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_ey;
  }

  rtb_Product_dy = (rtb_Product_dy + rtb_Product_b5j) * (real32_T)rtb_Compare_gf;
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_ey = rtb_Product_dy;
  if (BTMR_flgPreRnwyDiagSwitch_C) {
    rtb_Compare_gf = BTMR_bPreRnwyDiagEna_C;
  } else {
    rtb_Compare_gf = (rtb_Product_dy > BTMR_tiRnwyPreChkDiagDebounce_C);
  }

  rtb_Compare_ns = ((COMR_tiStopTime >= BTMR_tiThmRnwyPreChkStpTimeThreLv1_C) &&
                    rtb_Compare_jj && rtb_Compare_gf);
  if (rtb_Compare_ns) {
    rtb_Switch1_cr = 0.1F;
  } else {
    rtb_Switch1_cr = 0.0F;
  }

  if (BTMR_tiRnwyPreChkVoltDebounce_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_e3) {
    rtb_Product_b5j = BTMR_tiRnwyPreChkVoltDebounce_C;
  } else {
    rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_e3;
  }

  rtb_Product_dy = (rtb_Switch1_cr + rtb_Product_b5j) * (real32_T)rtb_Compare_ns;
  BTMR_bNewShrtVoltVld = (rtb_Product_dy > BTMR_tiRnwyPreChkVoltDebounce_C);
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_e3 = rtb_Product_dy;
  if (BTMR_bNewShrtVoltVld && (BTMR_ThmRnwyChk_PrevZCX.ShortCellVoltCal_Trig_ZCE
       != POS_ZCSIG)) {
    in = 1;
    rtb_Product_k2f = BSPR_uCellVolt_A[0];
    rtb_uDMaximum_o2_n = 1;
    for (i = 0; i < 149; i++) {
      if (BSPR_uCellVolt_A[in] < rtb_Product_k2f) {
        rtb_Product_k2f = BSPR_uCellVolt_A[in];
        rtb_uDMaximum_o2_n = i + 2;
      }

      in++;
    }

    BTMR_ThmRnwyChk_B.Add = BSPR_uCellVoltAvrg - rtb_Product_k2f / 1000.0F;
    BTMR_ThmRnwyChk_B.DataTypeConversion1 = (uint8_T)rtb_uDMaximum_o2_n;
  }

  BTMR_ThmRnwyChk_PrevZCX.ShortCellVoltCal_Trig_ZCE = BTMR_bNewShrtVoltVld;
  Local_uShrtLowVoltDiff = BTMR_ThmRnwyChk_B.Add;
  rtb_Compare_ns = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_a;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_a = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_o;
  if (rtb_Compare_ns && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_o) {
    rtb_Product_k2f = 0.0F;
  } else {
    if (rtb_Compare_jj) {
      rtb_Product_ko = 0.1F;
    } else {
      rtb_Product_ko = 0.0F;
    }

    rtb_Product_k2f = rtb_Product_ko + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE;
  }

  rtb_Compare_ns = (BTMR_ThmRnwyChk_DW.Delay1_DSTATE_k || BTMR_bNewShrtVoltVld);
  BTMR_bStopTimeInvld = (BTMR_bShrtLowVoltIDFitRd && (!rtb_Compare_ns));
  BTMR_bShrtLowVoltIDFitWrt = (BTMR_bStopTimeInvld || ((BTMR_idxShrtLowVoltIDRd ==
    BTMR_ThmRnwyChk_B.DataTypeConversion1) && (BTMR_idxShrtLowVoltIDRd != 0) &&
    (BTMR_ThmRnwyChk_B.DataTypeConversion1 != 0)));
  rtb_Compare_gf = (rtb_Compare_gf && rtb_Compare_jj && (COMR_tiStopTime >=
    BTMR_tiThmRnwyPreChkStpTimeThreLv2_C));
  if (rtb_Compare_gf) {
    rtb_Product_dy = 0.1F;
  } else {
    rtb_Product_dy = 0.0F;
  }

  if (BTMR_tiRnwyPreChkVoltDebounce_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE_p) {
    rtb_Product_b5j = BTMR_tiRnwyPreChkVoltDebounce_C;
  } else {
    rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE_p;
  }

  rtb_Product_dy = (rtb_Product_dy + rtb_Product_b5j) * (real32_T)rtb_Compare_gf;
  BTMR_flgNewCellVoltVld = (rtb_Product_dy > BTMR_tiRnwyPreChkVoltDebounce_C);
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_p = rtb_Product_dy;
  if (BTMR_flgNewCellVoltVld &&
      (BTMR_ThmRnwyChk_PrevZCX.LongCellVoltInit_Trig_ZCE != POS_ZCSIG)) {
    in = 1;
    rtb_Product_e4 = BSPR_uCellVolt_A[0];
    for (i = 0; i < 149; i++) {
      if (BSPR_uCellVolt_A[in] < rtb_Product_e4) {
        rtb_Product_e4 = BSPR_uCellVolt_A[in];
      }

      in++;
    }

    BTMR_ThmRnwyChk_B.DataTypeConversion3 = rtb_Product_e4 / 1000.0F;
    BTMR_ThmRnwyChk_B.BSPR_uCellVoltAvrg_d = BSPR_uCellVoltAvrg;
  }

  BTMR_ThmRnwyChk_PrevZCX.LongCellVoltInit_Trig_ZCE = BTMR_flgNewCellVoltVld;
  BTMR_uStrtCellVoltAvrg = BTMR_ThmRnwyChk_B.BSPR_uCellVoltAvrg_d;
  BTMR_uMinStrtVolt = BTMR_ThmRnwyChk_B.DataTypeConversion3;
  rtb_Product_e4 = BTMR_uStrtCellVoltAvrg - BTMR_uMinStrtVolt;
  rtb_Compare_gf = (BTMR_uMinStrtVolt != 0.0F);
  rtb_Compare_f = (BTMR_uStrtCellVoltAvrg != 0.0F);
  BTMR_bMaxVoltDiff = ((rtb_Product_e4 >= BTMR_uCellVoltLowWarn_C) &&
                       rtb_Compare_f && rtb_Compare_gf);
  BTMR_bLowVoltAlrm = (rtb_Compare_gf && rtb_Compare_f && (rtb_Product_e4 >=
    BTMR_uCellVoltLowAlrm_C));
  if (BTMR_bShrtLowVoltIDFitWrt) {
    rtb_Product_b5j = (real32_T)fmod((real32_T)floor(COMR_tiStopTime),
      4.294967296E+9F);
    BTMR_tiShortRuntimeSumWrt = ((rtb_Product_b5j < 0.0F ? (uint32_T)-(int32_T)
      (uint32_T)-rtb_Product_b5j : (uint32_T)rtb_Product_b5j) +
      BTMR_tiRuntimeCalRd) + BTMR_tiShortRuntimeSumRd;
  } else {
    BTMR_tiShortRuntimeSumWrt = 0U;
  }

  rtb_Compare_gf = (BTMR_ThmRnwyChk_DW.Delay1_DSTATE_h ||
                    rtb_LogicalOperator4_kf);
  BTMR_bVoltDiffAlrm = ((BTMR_tiShortRuntimeSumWrt != 0U) &&
                        (BTMR_tiShortRuntimeSumWrt <
    BTMR_tiLowCellVoltDiffShortTimeThre_C) && (Local_uShrtLowVoltDiff != 0.0F) &&
                        (Local_uShrtLowVoltDiff - BTMR_uShrtCellVoltDiffRd >
    BTMR_uDeltaVoltDiffThre_C));
  BTMR_bThmRnwyAlrm = (BTMR_bVoltDiffAlrm || BTMR_bLowVoltAlrm);
  BTMR_bThmRnwyWarn = ((BTMR_tiShortRuntimeSumWrt >=
                        BTMR_tiLowCellVoltShortTimeThre_C) || BTMR_bMaxVoltDiff);
  if (rtb_Compare_gf) {
    rtb_Product_dy = 0.1F;
  } else {
    rtb_Product_dy = 0.0F;
  }

  rtb_Product_e4 = (rtb_Product_dy + BTMR_ThmRnwyChk_DW.Delay2_DSTATE) *
    (real32_T)rtb_Compare_gf;
  rtb_Product_b5j = (real32_T)fmod((real32_T)floor(rtb_Product_e4 / 60.0F),
    65536.0F);
  BTMR_tiRuntimeCalWrt = (uint16_T)(rtb_Product_b5j < 0.0F ? (int32_T)(uint16_T)
    -(int16_T)(uint16_T)-rtb_Product_b5j : (int32_T)(uint16_T)rtb_Product_b5j);
  if (BTMR_bStopTimeInvld) {
    BTMR_idxShrtLowVoltIDWrt = BTMR_idxShrtLowVoltIDRd;
  } else {
    BTMR_idxShrtLowVoltIDWrt = BTMR_ThmRnwyChk_B.DataTypeConversion1;
  }

  if (BTMR_bShrtLowVoltIDFitWrt) {
    BTMR_uShrtCellVoltDiffWrt = BTMR_uShrtCellVoltDiffRd;
  } else {
    BTMR_uShrtCellVoltDiffWrt = Local_uShrtLowVoltDiff;
  }

  BTMR_bTPLTmtThmRunAway = BTMR_ThmRnwyChk_B.Switch;
  if (rtb_LogicalOperator1) {
    rtb_Switch1_aj = 0.1F;
  } else {
    rtb_Switch1_aj = 0.0F;
  }

  if (BTMR_tiRnwyDiagIni_C < BTMR_ThmRnwyChk_DW.Delay_DSTATE) {
    rtb_Product_b5j = BTMR_tiRnwyDiagIni_C;
  } else {
    rtb_Product_b5j = BTMR_ThmRnwyChk_DW.Delay_DSTATE;
  }

  rtb_Product_dy = (rtb_Switch1_aj + rtb_Product_b5j) * (real32_T)
    rtb_LogicalOperator1;
  BTMR_ThmRnwyChk_DW.Delay_DSTATE = rtb_Product_dy;
  if (BTMR_flgTPLWkupDiagSwitch_C) {
    BTMR_flgTPLWkupRnwyDiag = BTMR_bTPLWkupDiagEna_C;
  } else {
    BTMR_flgTPLWkupRnwyDiag = (rtb_Product_dy > BTMR_tiRnwyDiagIni_C);
  }

  if (BTMR_flgTPLWkupRnwyDiag) {
    if (!BTMR_ThmRnwyChk_DW.Subsystem_MODE) {
      BTMR_ThmRnwyChk_DW.Delay_DSTATE_axs = false;
      BTMR_ThmRnwyChk_DW.Delay2_DSTATE_b = false;
      BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_l = 0.0F;
      BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d = true;
      BTMR_ThmRnwyChk_DW.Subsystem_MODE = true;
    }

    BTMR_ThmRnwyChk_B.LogicalOperator4 = ((BTMR_ThmRnwyChk_DW.Delay_DSTATE_axs ||
      (BMCR_stBmsModeCtrl > 0)) && (!BTMR_ThmRnwyChk_DW.Delay2_DSTATE_b));
    BTMR_ThmRnwyChk_B.LogicalOperator2 = !(BTMR_ThmRnwyChk_B.LogicalOperator4 ||
      BTMR_bThmRunAway || BTMR_bTPLTmtThmRunAway);
    rtb_LogicalOperator1 = !BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d;
    BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d = BTMR_ThmRnwyChk_DW.Delay2_DSTATE_b;
    if (rtb_LogicalOperator1 && BTMR_ThmRnwyChk_DW.Delay2_DSTATE_b) {
      rtb_Product_dy = 0.0F;
    } else {
      if (BTMR_ThmRnwyChk_B.LogicalOperator4) {
        rtb_Product_b5j = 0.1F;
      } else {
        rtb_Product_b5j = 0.0F;
      }

      rtb_Product_dy = rtb_Product_b5j + BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_l;
    }

    BTMR_ThmRnwyChk_DW.Delay_DSTATE_axs = BTMR_ThmRnwyChk_B.LogicalOperator4;
    BTMR_ThmRnwyChk_DW.Delay2_DSTATE_b = (rtb_Product_dy >
      BTMR_tiTPLWkupCondRes_C);
    BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE_l = rtb_Product_dy;
  } else {
    if (BTMR_ThmRnwyChk_DW.Subsystem_MODE) {
      BTMR_ThmRnwyChk_DW.Subsystem_MODE = false;
    }
  }

  BTMR_cntBattTGRnwy = BTMR_ThmRnwyChk_B.DataTypeConversion_g;
  BTMR_uMinMdulVolt = BTMR_ThmRnwyChk_B.uDMinimum_o1;
  BTMR_bRnwyLowMdulVoltDet = BTMR_ThmRnwyChk_B.LogicalOperator4_d;
  BTMR_uMaxVolt = BTMR_ThmRnwyChk_B.DataTypeConversion3_m;
  BTMR_idxMaxVoltID = BTMR_ThmRnwyChk_B.DataTypeConversion_j;
  BTMR_bRnwyMaxTGDet = BTMR_ThmRnwyChk_B.BTMR_bRnwyMaxTGDet_i;
  BTMR_bRnwyVoltAbnrDet = BTMR_ThmRnwyChk_B.RelationalOperator5;
  BTMR_bRnwyCellMdulVoltDet = BTMR_ThmRnwyChk_B.LogicalOperator2_j;
  BTMR_cntRnwyCellVoltAbnr = BTMR_ThmRnwyChk_B.DataTypeConversion_b;
  BTMR_bRnwyTempDiffDet = BTMR_ThmRnwyChk_B.RelationalOperator_d;
  BTMR_tMaxTempGrad = BTMR_ThmRnwyChk_B.uDMaximum_o1_j;
  BTMR_tTempDiffMax = BTMR_ThmRnwyChk_B.uDMaximum_o1_f;
  BTMR_idxTempDiffMaxID = BTMR_ThmRnwyChk_B.DataTypeConversion_dk;
  BTMR_bThmRunAwayCond1 = BTMR_ThmRnwyChk_B.LogicalOperator5;
  BTMR_bThmRunAwayCond2 = BTMR_ThmRnwyChk_B.Switch4;
  BTMR_uAbnrVoltGrad = BTMR_ThmRnwyChk_B.DataTypeConversion3_d;
  BTMR_idxAbnrVoltGradID = BTMR_ThmRnwyChk_B.DataTypeConversion_h;
  BTMR_bCellVoltGradAbnrDet = BTMR_ThmRnwyChk_B.LogicalOperator4_o;
  BTMR_bThmRunAwayCond3 = BTMR_ThmRnwyChk_B.Switch3;
  BTMR_cntCellVoltGradAbnr = BTMR_ThmRnwyChk_B.SumofElements4;
  BTMR_tMaxTempGradVoltDiag = BTMR_ThmRnwyChk_B.uDMaximum_o1_h;
  BTMR_tMaxTemp = BTMR_ThmRnwyChk_B.uDMaximum_o1;
  BTMR_idxMaxTempGradVoltDiagID = BTMR_ThmRnwyChk_B.DataTypeConversion_l;
  BTMR_bRnwyVoltDiagTGDet = BTMR_ThmRnwyChk_B.LogicalOperator4_m;
  BTMR_uMinVolt = BTMR_ThmRnwyChk_B.DataTypeConversion3_n;
  BTMR_idxMaxTempGradID = BTMR_ThmRnwyChk_B.DataTypeConversion_c;
  BTMR_idxMaxTempID = BTMR_ThmRnwyChk_B.DataTypeConversion_d;
  BTMR_idxMinVoltID = BTMR_ThmRnwyChk_B.DataTypeConversion_e;
  BTMR_bRnwyLowVoltDet = BTMR_ThmRnwyChk_B.LogicalOperator4_f;
  BTMR_bRnwyHighTempDet = BTMR_ThmRnwyChk_B.LogicalOperator1;
  BTMR_cntTPLTmtBattTRnwy = BTMR_ThmRnwyChk_B.DataTypeConversion_f;
  BTMR_cntTPLTmtBattTDiffRnwy = BTMR_ThmRnwyChk_B.DataTypeConversion_fs;
  BTMR_cntTPLTmtBattTGRnwy = BTMR_ThmRnwyChk_B.DataTypeConversion;
  BTMR_bVSnsrTmt = BTMR_ThmRnwyChk_B.RelationalOperator;
  BTMR_bTSnsrTmt = BTMR_ThmRnwyChk_B.RelationalOperator_j;
  BTMR_bTPLWkupRnwyDiagEna = BTMR_ThmRnwyChk_B.LogicalOperator4;
  BTMR_bRnwyChkSleepPmt = BTMR_ThmRnwyChk_B.LogicalOperator2;
  BTMR_tBusbarTempMax = 0.0F;
  BTMR_tBusbarTempMin = 0.0F;
  BTMR_tCellTempMax = 0.0F;
  BTMR_tCellTempMin = 0.0F;
  BTMR_ThmRnwyChk_DW.StateName_ki = 0U;
  BTMR_ThmRnwyChk_DW.StateName_j = 0U;
  BTMR_ThmRnwyChk_DW.StateName_o = 0U;
  BTMR_ThmRnwyChk_DW.StateName_ef = 0U;
  BTMR_ThmRnwyChk_DW.StateName_d = 0U;
  BTMR_ThmRnwyChk_DW.StateName_bx = 0U;
  BTMR_ThmRnwyChk_DW.StateName_jx = 0U;
  BTMR_ThmRnwyChk_DW.StateName_k1 = 0U;
  BTMR_ThmRnwyChk_DW.StateName_ey = 0U;
  BTMR_ThmRnwyChk_DW.StateName_i = 0U;
  for (i = 0; i < 48; i++) {
    BTMR_tBusbarTemp_A[i] = 0.0F;
    BTMR_tCellTemp_A[i] = 0.0F;
    BTMR_ThmRnwyChk_DW.StateName[i] = BSPR_tCellTemp_A[i];
    BTMR_ThmRnwyChk_DW.StateName_l[i] = rtb_Init[i];
    BTMR_ThmRnwyChk_DW.StateName_p[i] = rtb_Init_l[i];
    BTMR_ThmRnwyChk_DW.StateName_k[i] = rtb_Init_c[i];
    BTMR_ThmRnwyChk_DW.StateName_b[i] = rtb_Init_k[i];
    BTMR_ThmRnwyChk_DW.StateName_be[i] = BSPR_tBattTemp_A[i];
    BTMR_ThmRnwyChk_DW.StateName_g[i] = rtb_Init_f[i];
    BTMR_ThmRnwyChk_DW.StateName_e[i] = rtb_Init_n[i];
    BTMR_ThmRnwyChk_DW.StateName_bl[i] = rtb_Init_fe[i];
    BTMR_ThmRnwyChk_DW.StateName_h[i] = rtb_Init_d[i];
  }

  BTMR_ThmRnwyChk_DW.Delay_DSTATE_o5 = rtb_Compare_jj;
  BTMR_ThmRnwyChk_DW.Delay_DSTATE_o = BMCR_stBmsModeCtrl;
  BTMR_ThmRnwyChk_DW.Delay2_DSTATE_o = (rtb_Product_k2f > BTMR_tiBMSStartDelay_C);
  BTMR_ThmRnwyChk_DW.UnitDelay_DSTATE = rtb_Product_k2f;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_k = rtb_Compare_ns;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_h = rtb_Compare_gf;
  BTMR_ThmRnwyChk_DW.Delay2_DSTATE = rtb_Product_e4;
}

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

  /* block I/O */

  /* custom signals */
  Local_uShrtLowVoltDiff = 0.0F;
  BTMR_uStrtCellVoltAvrg = 0.0F;
  BTMR_uMinStrtVolt = 0.0F;
  BTMR_uShrtCellVoltDiffWrt = 0.0F;
  BTMR_uMinMdulVolt = 0.0F;
  BTMR_uMaxVolt = 0.0F;
  BTMR_tMaxTempGrad = 0.0F;
  BTMR_tTempDiffMax = 0.0F;
  BTMR_uAbnrVoltGrad = 0.0F;
  BTMR_tMaxTempGradVoltDiag = 0.0F;
  BTMR_tMaxTemp = 0.0F;
  BTMR_uMinVolt = 0.0F;
  BTMR_tBusbarTempMax = 0.0F;
  BTMR_tBusbarTempMin = 0.0F;
  BTMR_tCellTempMax = 0.0F;
  BTMR_tCellTempMin = 0.0F;

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BTMR_tBusbarTemp_A[i] = 0.0F;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BTMR_tCellTemp_A[i] = 0.0F;
    }
  }

  BTMR_tiShortRuntimeSumWrt = 0U;
  BTMR_tiRuntimeCalWrt = ((uint16_T)0U);
  BTMR_idxShrtLowVoltIDWrt = ((uint8_T)0U);
  BTMR_cntBattTGRnwy = ((uint8_T)0U);
  BTMR_idxMaxVoltID = ((uint8_T)0U);
  BTMR_cntRnwyCellVoltAbnr = ((uint8_T)0U);
  BTMR_idxTempDiffMaxID = ((uint8_T)0U);
  BTMR_idxAbnrVoltGradID = ((uint8_T)0U);
  BTMR_cntCellVoltGradAbnr = ((uint8_T)0U);
  BTMR_idxMaxTempGradVoltDiagID = ((uint8_T)0U);
  BTMR_idxMaxTempGradID = ((uint8_T)0U);
  BTMR_idxMaxTempID = ((uint8_T)0U);
  BTMR_idxMinVoltID = ((uint8_T)0U);
  BTMR_cntTPLTmtBattTRnwy = ((uint8_T)0U);
  BTMR_cntTPLTmtBattTDiffRnwy = ((uint8_T)0U);
  BTMR_cntTPLTmtBattTGRnwy = ((uint8_T)0U);
  BTMR_bThmRunAway = false;
  BTMR_bStopTimeInvld = false;
  BTMR_bShrtLowVoltIDFitWrt = false;
  BTMR_bMaxVoltDiff = false;
  BTMR_bLowVoltAlrm = false;
  BTMR_bVoltDiffAlrm = false;
  BTMR_bThmRnwyAlrm = false;
  BTMR_bThmRnwyWarn = false;
  BTMR_bTPLTmtThmRunAway = false;
  BTMR_bRnwyLowMdulVoltDet = false;
  BTMR_bRnwyMaxTGDet = false;
  BTMR_bRnwyVoltAbnrDet = false;
  BTMR_bRnwyCellMdulVoltDet = false;
  BTMR_bRnwyTempDiffDet = false;
  BTMR_bThmRunAwayCond1 = false;
  BTMR_bThmRunAwayCond2 = false;
  BTMR_bCellVoltGradAbnrDet = false;
  BTMR_bThmRunAwayCond3 = false;
  BTMR_bRnwyVoltDiagTGDet = false;
  BTMR_bRnwyLowVoltDet = false;
  BTMR_bRnwyHighTempDet = false;
  BTMR_bVSnsrTmt = false;
  BTMR_bTSnsrTmt = false;
  BTMR_bTPLWkupRnwyDiagEna = false;
  BTMR_bRnwyChkSleepPmt = false;
  BTMR_flgNewCellVoltVld = false;
  BTMR_bNewShrtVoltVld = false;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_lt = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal_Trig_ZCE_l = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_l = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE_f = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempGradIDCal1_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxTempIDCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.AbnrVoltGradIdCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MaxVoltIdCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MinMdulVoltIdCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.MinVoltIdCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.LongCellVoltInit_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_PrevZCX.ShortCellVoltCal_Trig_ZCE = POS_ZCSIG;
  BTMR_ThmRnwyChk_DW.StateName_ki = 1U;
  BTMR_ThmRnwyChk_DW.StateName_j = 1U;
  BTMR_ThmRnwyChk_DW.StateName_o = 1U;
  BTMR_ThmRnwyChk_DW.StateName_ef = 1U;
  BTMR_ThmRnwyChk_DW.StateName_d = 1U;
  BTMR_ThmRnwyChk_DW.StateName_bx = 1U;
  BTMR_ThmRnwyChk_DW.StateName_jx = 1U;
  BTMR_ThmRnwyChk_DW.StateName_k1 = 1U;
  BTMR_ThmRnwyChk_DW.StateName_ey = 1U;
  BTMR_ThmRnwyChk_DW.StateName_i = 1U;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ez = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_dl = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_cj = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m0 = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e1 = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d1 = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_e = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_p = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ky = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ka = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_ha = true;
  BTMR_ThmRnwyChk_DW.Delay2_DSTATE_bb = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_c = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_n = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i3 = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_j = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_op = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_gb = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_o = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_m = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_my = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_hb = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_oe = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_i = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_du = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_g = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_a = true;
  BTMR_ThmRnwyChk_DW.Delay1_DSTATE_d = true;
}

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