/*
 * File: BTMR_ThmalReqCalc.c
 *
 * Code generated for Simulink model 'BTMR_ThmalReqCalc'.
 *
 * Model version                  : 1
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Wed Aug 11 10:45:02 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_ThmalReqCalc.h"
#include "BTMR_ThmalReqCalc_private.h"

/* Named constants for Chart: '<S11>/Chart' */
#define BTMR_ThmalRe_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define BTMR_ThmalReqC_IN_AddCourse_Stt ((uint8_T)1U)
#define BTMR_ThmalReqCal_IN_Default_Stt ((uint8_T)2U)

/* Named constants for Chart: '<S14>/Chart' */
#define BTMR_ThmalRe_IN_CoolChrgDefault ((uint8_T)1U)
#define BTMR_ThmalReq_IN_CoolChrgStage1 ((uint8_T)2U)
#define BTMR_ThmalReq_IN_CoolChrgStage2 ((uint8_T)3U)
#define BTMR_ThmalReq_IN_CoolChrgStage3 ((uint8_T)4U)
#define BTMR_Thmal_IN_NO_ACTIVE_CHILD_k ((uint8_T)0U)

/* Named constants for Chart: '<S15>/Chart' */
#define BTMR_ThmalRe_IN_CoolNormDefault ((uint8_T)1U)
#define BTMR_ThmalReq_IN_CoolNormStage1 ((uint8_T)2U)
#define BTMR_ThmalReq_IN_CoolNormStage2 ((uint8_T)3U)
#define BTMR_ThmalReq_IN_CoolNormStage3 ((uint8_T)4U)

/* Named constants for Chart: '<S7>/BTMR_ThmStsCalc' */
#define BTMR_ThmalReqC_IN_Default_Stt_j ((uint8_T)4U)
#define BTMR_ThmalReqCa_IN_CoolChrg_Stt ((uint8_T)2U)
#define BTMR_ThmalReqCa_IN_CoolNorm_Stt ((uint8_T)3U)
#define BTMR_ThmalReqCal_IN_Standby_Stt ((uint8_T)8U)
#define BTMR_ThmalReqCalc_IN_Brush_Stt ((uint8_T)1U)
#define BTMR_ThmalReqCalc_IN_HtgAC_Stt ((uint8_T)5U)
#define BTMR_ThmalReqCalc_IN_HtgDC_Stt ((uint8_T)6U)
#define BTMR_ThmalReqCalc_IN_HtgDrv_Stt ((uint8_T)7U)

/* Named constants for Chart: '<S477>/Chart' */
#define BTMR_Th_IN_CoolChrgStage1Reduce ((uint8_T)2U)
#define BTMR_Th_IN_CoolChrgStage2Reduce ((uint8_T)2U)
#define BTMR_Th_IN_CoolChrgStage3Reduce ((uint8_T)2U)
#define BTMR_Thma_IN_CoolChrgStage1Norm ((uint8_T)1U)
#define BTMR_Thma_IN_CoolChrgStage2Norm ((uint8_T)1U)
#define BTMR_Thma_IN_CoolChrgStage3Norm ((uint8_T)1U)

/* Named constants for Chart: '<S478>/Chart' */
#define BTMR_Thm_IN_CoolNormStage1Pause ((uint8_T)1U)
#define BTMR_Thm_IN_CoolNormStage1Start ((uint8_T)2U)
#define BTMR_Thm_IN_CoolNormStage2Pause ((uint8_T)1U)
#define BTMR_Thm_IN_CoolNormStage2Start ((uint8_T)2U)
#define BTMR_Thm_IN_CoolNormStage3Pause ((uint8_T)1U)
#define BTMR_Thm_IN_CoolNormStage3Start ((uint8_T)2U)

/* Named constants for Chart: '<S493>/Chart' */
#define BTMR_ThmalR_IN_HtgDCStage2Pause ((uint8_T)2U)
#define BTMR_ThmalReqCa_IN_HtgDCDefault ((uint8_T)1U)
#define BTMR_ThmalReqCal_IN_HtgDCStage1 ((uint8_T)2U)
#define BTMR_ThmalReqCal_IN_HtgDCStage2 ((uint8_T)3U)
#define BTMR_Thmal_IN_HtgDCStage2Curve1 ((uint8_T)1U)

/* Exported data definition */
#define ASW1_OEM_START_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile uint8_T BTMR_flgBrsPwrReq;
volatile uint8_T BTMR_flgBrsTempReq;
volatile uint8_T BTMR_flgClntPwrReq;
volatile uint8_T BTMR_flgClntTempReq;
volatile boolean_T BTMR_flgCoolNormEna;
volatile boolean_T BTMR_flgCoolNormEnaTemp;
volatile uint8_T BTMR_flgCoolReq;
volatile uint8_T BTMR_flgHeatReq;
volatile uint8_T BTMR_flgHtgPwrReq;
volatile uint8_T BTMR_flgHtgTempReq;
volatile boolean_T BTMR_flgTempDiff;
volatile real32_T BTMR_pClntPwrReq;
volatile real32_T BTMR_pHtgPwrReq;
volatile real32_T BTMR_tClntTempReq;
volatile real32_T BTMR_tHtgTempReq;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BTMR_ThmalReqCalc_T BTMR_ThmalReqCalc_B;

/* Block states (auto storage) */
DW_BTMR_ThmalReqCalc_T BTMR_ThmalReqCalc_DW;

/*
 * System reset for atomic system:
 *    '<S11>/Chart'
 *    '<S20>/Chart'
 *    '<S26>/Chart'
 *    '<S474>/Chart'
 *    '<S483>/Chart'
 *    '<S489>/Chart'
 *    '<S499>/Chart'
 */
void BTMR_ThmalReqCalc_Chart_Reset(B_Chart_BTMR_ThmalReqCalc_T *localB,
  DW_Chart_BTMR_ThmalReqCalc_T *localDW)
{
  localDW->is_active_c3_BTMR_ThmalReqCalc = 0U;
  localDW->is_c3_BTMR_ThmalReqCalc = BTMR_ThmalRe_IN_NO_ACTIVE_CHILD;
  localDW->i = 0U;
  localB->flg_out = false;
}

/*
 * Output and update for atomic system:
 *    '<S11>/Chart'
 *    '<S20>/Chart'
 *    '<S26>/Chart'
 *    '<S474>/Chart'
 *    '<S483>/Chart'
 *    '<S489>/Chart'
 *    '<S499>/Chart'
 */
void BTMR_ThmalReqCalc_Chart(boolean_T rtu_trigger_in, uint8_T rtu_cntStable,
  B_Chart_BTMR_ThmalReqCalc_T *localB, DW_Chart_BTMR_ThmalReqCalc_T *localDW)
{
  int32_T tmp;
  if (localDW->is_active_c3_BTMR_ThmalReqCalc == 0U) {
    localDW->is_active_c3_BTMR_ThmalReqCalc = 1U;
    localDW->is_c3_BTMR_ThmalReqCalc = BTMR_ThmalReqCal_IN_Default_Stt;
    localDW->i = 0U;
    localB->flg_out = false;
  } else if (localDW->is_c3_BTMR_ThmalReqCalc == BTMR_ThmalReqC_IN_AddCourse_Stt)
  {
    if (localDW->i > rtu_cntStable) {
      localDW->is_c3_BTMR_ThmalReqCalc = BTMR_ThmalReqCal_IN_Default_Stt;
      localDW->i = 0U;
      localB->flg_out = false;
    } else {
      tmp = localDW->i + 1;
      if (tmp > 255) {
        tmp = 255;
      }

      localDW->i = (uint8_T)tmp;
    }
  } else {
    if (rtu_trigger_in) {
      localDW->is_c3_BTMR_ThmalReqCalc = BTMR_ThmalReqC_IN_AddCourse_Stt;
      localB->flg_out = true;
    }
  }
}

/*
 * Output and update for atomic system:
 *    '<S63>/BMSDebounceStartZero'
 *    '<S64>/BMSDebounceStartZero'
 *    '<S65>/BMSDebounceStartZero'
 *    '<S66>/BMSDebounceStartZero'
 *    '<S67>/BMSDebounceStartZero'
 *    '<S68>/BMSDebounceStartZero'
 *    '<S69>/BMSDebounceStartZero'
 *    '<S70>/BMSDebounceStartZero'
 *    '<S71>/BMSDebounceStartZero'
 *    '<S173>/BMSDebounceStartZero'
 *    ...
 */
void BTMR_Thmal_BMSDebounceStartZero(boolean_T rtu_Signal, uint16_T
  rtu_Hearl2Fault, uint16_T rtu_FaultStep, B_BMSDebounceStartZero_BTMR_T_T
  *localB, DW_BMSDebounceStartZero_BTMR__T *localDW)
{
  boolean_T rtb_RelationalOperator_af;
  boolean_T rtb_RelationalOperator_awk;
  uint16_T rtb_Switch2_h;
  uint16_T rtb_Switch2_a4;
  if (localDW->StateName_m) {
    rtb_Switch2_h = 0U;
  } else {
    rtb_Switch2_h = localDW->StateName;
  }

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

  rtb_RelationalOperator_af = (rtb_Switch2_h > rtu_Hearl2Fault);
  if (localDW->StateName_l) {
    rtb_Switch2_a4 = 0U;
  } else {
    rtb_Switch2_a4 = localDW->StateName_k;
  }

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

  rtb_RelationalOperator_awk = (rtb_Switch2_a4 > rtu_Hearl2Fault);
  if (!localB->Switch) {
    localB->Switch = rtb_RelationalOperator_af;
  } else {
    localB->Switch = !rtb_RelationalOperator_awk;
  }

  localDW->StateName_m = rtb_RelationalOperator_af;
  localDW->StateName = rtb_Switch2_h;
  localDW->StateName_l = rtb_RelationalOperator_awk;
  localDW->StateName_k = rtb_Switch2_a4;
}

/* Model step function */
void BTMR_ThmalReqCalc_step(void)
{
  boolean_T rtb_BTMR_flgHtgDrvSOC;
  boolean_T rtb_BTMR_flgBrsEna1;
  boolean_T rtb_BTMR_flgBrsDrvOut;
  boolean_T rtb_BTMR_flgBrsEna2;
  boolean_T rtb_BTMR_flgBrsIntEna2;
  boolean_T rtb_BTMR_flgBrsEna3;
  boolean_T rtb_BTMR_flgBrsEna_p;
  boolean_T rtb_BTMR_flgBrsDCOut;
  boolean_T rtb_BTMR_flgHtgDCEna;
  boolean_T rtb_BTMR_flgHtgACEna;
  boolean_T rtb_BTMR_flgHtgDrvEna;
  boolean_T rtb_LogicalOperator10;
  boolean_T rtb_BTMR_flgHtgDCThmEnd;
  boolean_T rtb_BTMR_flgHtgACThmEnd;
  boolean_T rtb_BTMR_flgHtgDrvThmEnd;
  uint8_T rtb_DataTypeConversion1;
  uint8_T rtb_DataTypeConversion_b;
  uint8_T rtb_Switch_j;
  uint16_T rtb_Switch2_pt;
  uint16_T rtb_Switch2_m;
  int32_T tmp;
  rtb_BTMR_flgHtgDrvSOC = (BMCR_stBmsModeCtrl ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >=
    BTMR_t891HtgDCStartHiTemp_C) && (BSPR_tCellTempMax <
    BTMR_t891CoolChrgAcesTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero);
  rtb_BTMR_flgBrsEna1 = (rtb_BTMR_flgHtgDrvSOC &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tClntUsT >= BTMR_t891HtgDCStartHiTemp_C)
    && (BSPR_tClntUsT < BTMR_t891CoolChrgAcesTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_i,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_i);
  rtb_BTMR_flgBrsEna1 = (rtb_BTMR_flgBrsEna1 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_i.Switch);
  rtb_BTMR_flgBrsDrvOut = (BMCR_stBmsModeCtrl ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion1);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >=
    BTMR_t891HtgACStartHiTemp_C) && (BSPR_tCellTempMax <
    BTMR_t891CoolNormAcesTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_m,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_m);
  rtb_BTMR_flgBrsEna2 = (rtb_BTMR_flgBrsDrvOut &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_m.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tClntUsT >= BTMR_t891HtgACStartHiTemp_C)
    && (BSPR_tClntUsT < BTMR_t891CoolNormAcesTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_e,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_e);
  rtb_BTMR_flgBrsIntEna2 = (rtb_BTMR_flgBrsEna2 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_e.Switch);
  rtb_BTMR_flgBrsEna2 = ((BMCR_stBmsModeCtrl ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion2) && (!COMR_bLeadAcidChgHvOn));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >
    BTMR_t891HtgDrvStartHiTemp_C) && (BSPR_tCellTempMax <
    BTMR_t891CoolNormAcesTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_g);
  rtb_BTMR_flgBrsEna3 = (rtb_BTMR_flgBrsEna2 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tClntUsT > BTMR_t891HtgDrvStartHiTemp_C)
    && (BSPR_tClntUsT < BTMR_t891CoolNormAcesTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_j,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_j);
  rtb_BTMR_flgBrsEna3 = (rtb_BTMR_flgBrsEna3 && (BSER_rSoc >
    BTMR_r891BrsDrvSoc_C) && BTMR_ThmalReqCalc_B.BMSDebounceStartZero_j.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin - BSPR_tClntUsT <
    BTMR_tBrsCellClntDvtTemp_C) && (BSPR_tClntUsT - BSPR_tCellTempMax <
    BTMR_tBrsCellClntDvtTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_p,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_p);
  rtb_BTMR_flgBrsEna_p = ((rtb_BTMR_flgBrsEna1 || rtb_BTMR_flgBrsIntEna2 ||
    rtb_BTMR_flgBrsEna3) && BTMR_ThmalReqCalc_B.BMSDebounceStartZero_p.Switch);
  rtb_BTMR_flgBrsDCOut = (rtb_BTMR_flgHtgDrvSOC &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax <
    BTMR_t891HtgDCStopMaxTemp_C - BTMR_tHtgDCMaxTempDeb_C) && (BSPR_tCellTempMax
    - BSPR_tCellTempMin < BTMR_t891HtgDCEndDiffTemp_C -
    BTMR_t891HtgDCDiffDebTemp_C) && (BSPR_tCellTempMin >
    BTMR_t891HtgDCStartLoTemp_C) && (BSPR_tCellTempMin <
    BTMR_t891HtgDCStartHiTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_o,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_o);
  rtb_BTMR_flgHtgDCEna = (rtb_BTMR_flgBrsDCOut &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_o.Switch);
  rtb_BTMR_flgBrsEna3 = (rtb_BTMR_flgBrsDrvOut &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_m.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t891HtgACEndDiffTemp_C - BTMR_t891HtgACDiffDebTemp_C) &&
    (BSPR_tCellTempMin >= BTMR_t891HtgACStartLoTemp_C) && (BSPR_tCellTempMin <
    BTMR_t891HtgACStartHiTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_e4,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_e4);
  rtb_BTMR_flgHtgACEna = (rtb_BTMR_flgBrsEna3 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_e4.Switch);
  rtb_BTMR_flgBrsIntEna2 = (rtb_BTMR_flgBrsEna2 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t891HtgDrvEndDiffTemp_C - BTMR_t891HtgDrvDiffDebTemp_C) &&
    (BSPR_tCellTempMin <= BTMR_t891HtgDrvStartHiTemp_C) && (BSPR_tCellTempMin >=
    BTMR_t891HtgDrvStartLoTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ot,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ot);
  rtb_BTMR_flgHtgDrvEna = (rtb_BTMR_flgBrsIntEna2 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ot.Switch);
  rtb_BTMR_flgBrsEna1 = (BSER_rSoc > BTMR_r891HtgDrvSoc_C);
  rtb_BTMR_flgBrsEna3 = (rtb_BTMR_flgBrsEna3 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_e4.Switch));
  rtb_BTMR_flgBrsIntEna2 = (rtb_BTMR_flgBrsIntEna2 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ot.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax >=
    BTMR_t891CoolNormAcesTemp_C) && (BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t891CoolNormEndDiffTemp_C - BTMR_t891CoolNormDiffDebTemp_C),
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ik,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ik);
  rtb_BTMR_flgBrsIntEna2 = ((rtb_BTMR_flgBrsEna3 || rtb_BTMR_flgBrsIntEna2) &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ik.Switch);
  rtb_BTMR_flgBrsEna3 = !BTMR_ThmalReqCalc_B.BMSDebounceStartZero_o.Switch;
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax >=
    BTMR_t891CoolChrgAcesTemp_C) && (BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t891CoolChrgEndDiffTemp_C - BTMR_t891CoolChrgDiffDebTemp_C) &&
    (BSPR_tCellTempMin >= BTMR_t891HtgDCStopMinTemp_C + BTMR_t891CoolDCDebTemp_C),
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_b,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_b);
  rtb_BTMR_flgBrsEna3 = (rtb_BTMR_flgBrsDCOut && rtb_BTMR_flgBrsEna3 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_b.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin <=
    BTMR_t891BrsDiffLv0Temp_C) || (BSPR_tCellTempMin <=
    BTMR_tBrsMinCellTempThre_C - BTMR_tBrsMinCellTempDeb_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_c,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_c);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >=
    BTMR_t891HtgDCStopMinTemp_C) || (BSPR_tCellTempMax >=
    BTMR_t891HtgDCStopMaxTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jw,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_jw);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >= BTMR_t891HtgACStopTemp_C)
    || (BSPR_tCellTempMax >= BTMR_t891HtgACStopMxTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_co,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_co);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >=
    BTMR_t891HtgDrvStopTemp_C) || (BSPR_tCellTempMax >=
    BTMR_t891HtgDrvStopMxTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bz,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_bz);
  rtb_BTMR_flgBrsDCOut = (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bz.Switch ||
    (!rtb_BTMR_flgBrsEna1));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t891CoolNormExitTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_l,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_l);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t891CoolChrgExitTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_c4,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_c4);
  rtb_LogicalOperator10 = ((BMCR_stBmsModeCtrl !=
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE) || (DSMR_stFaultRank >=
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion_f) || COMR_bLeadAcidChgHvOn);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t891HtgDCEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_my,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_my);
  rtb_BTMR_flgHtgDCThmEnd = (rtb_LogicalOperator10 || (rtb_BTMR_flgHtgDrvSOC &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_my.Switch));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t891HtgACEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_pg,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_pg);
  rtb_BTMR_flgHtgACThmEnd = (rtb_LogicalOperator10 || (rtb_BTMR_flgBrsDrvOut &&
    (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_pg.Switch || BCMR_bAcChrgHeatFbd)));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t891HtgDrvEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cq,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_cq);
  rtb_BTMR_flgHtgDrvThmEnd = (rtb_LogicalOperator10 || (rtb_BTMR_flgBrsEna2 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cq.Switch));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t891CoolNormEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_n,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_n);
  rtb_BTMR_flgBrsDrvOut = (rtb_LogicalOperator10 || ((rtb_BTMR_flgBrsDrvOut ||
    rtb_BTMR_flgBrsEna2) && BTMR_ThmalReqCalc_B.BMSDebounceStartZero_n.Switch));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t891CoolChrgEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ge,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ge);
  rtb_BTMR_flgHtgDrvSOC = (rtb_LogicalOperator10 || (rtb_BTMR_flgHtgDrvSOC &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ge.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t891BrsDiffLv1Temp_C) && (BSPR_tCellTempMin >=
    BTMR_tBrsMinCellTempThre_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_f,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_f);
  if (BTMR_ThmalReqCalc_DW.is_active_c6_BTMR_ThmalReqCalc == 0U) {
    BTMR_ThmalReqCalc_DW.is_active_c6_BTMR_ThmalReqCalc = 1U;
    BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
      BTMR_ThmalReqC_IN_Default_Stt_j;
    BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
    BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
    BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
  } else {
    switch (BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc) {
     case BTMR_ThmalReqCalc_IN_Brush_Stt:
      if ((!rtb_BTMR_flgBrsEna_p) || (rtb_LogicalOperator10 ||
           BTMR_ThmalReqCalc_B.BMSDebounceStartZero_c.Switch)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCa_IN_CoolChrg_Stt:
      if (rtb_BTMR_flgHtgDrvSOC ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_c4.Switch) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCa_IN_CoolNorm_Stt:
      if (rtb_BTMR_flgBrsDrvOut ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_l.Switch) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
        }
      }
      break;

     case BTMR_ThmalReqC_IN_Default_Stt_j:
      BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
        BTMR_ThmalReqCal_IN_Standby_Stt;
      BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
      BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
      BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
      BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
      if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
        tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
      } else {
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
      }
      break;

     case BTMR_ThmalReqCalc_IN_HtgAC_Stt:
      if (rtb_BTMR_flgHtgACThmEnd ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_co.Switch) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCalc_IN_HtgDC_Stt:
      if (rtb_BTMR_flgHtgDCThmEnd ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jw.Switch) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCalc_IN_HtgDrv_Stt:
      if (rtb_BTMR_flgHtgDrvThmEnd || rtb_BTMR_flgBrsDCOut) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
        }
      }
      break;

     default:
      if (rtb_BTMR_flgBrsEna3 && (!rtb_BTMR_flgHtgDrvSOC) &&
          (BTMR_ThmalReqCalc_DW.Local_DebCnt_h >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCa_IN_CoolChrg_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_CoolChrg;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgBrsIntEna2 && (!rtb_BTMR_flgBrsDrvOut) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt_h >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCa_IN_CoolNorm_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_CoolNorm;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgHtgDCEna && (!rtb_BTMR_flgHtgDCThmEnd) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt_h >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_HtgDC_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_HeatDC;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgHtgACEna && (!rtb_BTMR_flgHtgACThmEnd) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt_h >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_HtgAC_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_HeatAC;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgHtgDrvEna && rtb_BTMR_flgBrsEna1 &&
                 (!rtb_BTMR_flgHtgDrvThmEnd) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt_h >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_HtgDrv_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_HeatDrv;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgBrsEna_p &&
                 BTMR_ThmalReqCalc_B.BMSDebounceStartZero_f.Switch &&
                 (!rtb_LogicalOperator10) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt_h >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c6_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_Brush_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_ACTIVE;
      } else if (BTMR_ThmalReqCalc_DW.Local_DebCnt_h <= 600) {
        tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt_h + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = (uint16_T)tmp;
      } else {
        BTMR_ThmalReqCalc_DW.Local_DebCnt_h = 600U;
      }
      break;
    }
  }

  rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.stHtgSts_g;
  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_bw)
  {
    BTMR_ThmalReqCalc_B.Merge_l = enmThmHeatFlg_ACTIVE;
    BTMR_ThmalReqCalc_B.Merge1_m = BTMR_tHtgACTempReq_C;
  }

  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_ov)
  {
    BTMR_ThmalReqCalc_B.Merge_l = enmThmHeatFlg_ACTIVE;
    BTMR_ThmalReqCalc_B.Merge1_m = BTMR_tHtgDCTempReq_C;
  }

  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion4_f)
  {
    BTMR_ThmalReqCalc_B.Merge_l = enmThmHeatFlg_ACTIVE;
    BTMR_ThmalReqCalc_B.Merge1_m = BTMR_tHtgDrvTempReq_C;
  }

  if (rtb_DataTypeConversion1 != 0) {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.Merge_l;
  } else {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_h;
  }

  if (BTMR_rHeatClbFlg_C > 10.0F) {
    BTMR_tHtgTempReq = BTMR_tHeatTempClbQnt_C;
    BTMR_flgHtgTempReq = 1U;
  } else if ((BCMR_stAChrgPreThmReq == 1) || (BCMR_stAChrgPreThmReq == 2)) {
    if (BCMR_pHeatPwrReq >= 100.0F) {
      BTMR_tHtgTempReq = BTMR_tPreHtgTemp_C;
    } else {
      BTMR_tHtgTempReq = 0.0F;
    }

    BTMR_flgHtgTempReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion8_m;
  } else {
    if (rtb_DataTypeConversion1 != 0) {
      BTMR_tHtgTempReq = BTMR_ThmalReqCalc_B.Merge1_m;
    } else {
      BTMR_tHtgTempReq = 0.0F;
    }

    BTMR_flgHtgTempReq = rtb_DataTypeConversion1;
  }

  rtb_BTMR_flgBrsDrvOut = (BTMR_ThmalReqCalc_B.stBrsSts_o ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion_gd);
  BTMR_ThmalReqCalc_Chart(rtb_BTMR_flgBrsDrvOut !=
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_f, BMS_cntThmStbNum_C,
    &BTMR_ThmalReqCalc_B.sf_Chart, &BTMR_ThmalReqCalc_DW.sf_Chart);
  if (BTMR_ThmalReqCalc_B.sf_Chart.flg_out) {
    rtb_BTMR_flgBrsEna2 = BTMR_ThmalReqCalc_DW.Delay1_DSTATE_e;
  } else {
    rtb_BTMR_flgBrsEna2 = rtb_BTMR_flgBrsDrvOut;
  }

  if (BTMR_rFlashClbFlg_C > 10.0F) {
    BTMR_flgBrsTempReq = 1U;
  } else if (rtb_BTMR_flgBrsEna2) {
    BTMR_flgBrsTempReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_a;
  } else {
    BTMR_flgBrsTempReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_m1;
  }

  BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_f = rtb_BTMR_flgBrsDrvOut;
  BTMR_ThmalReqCalc_DW.Delay1_DSTATE_e = rtb_BTMR_flgBrsEna2;
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t891CoolNormLv2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_d,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_d);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t891CoolNormLv3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_et,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_et);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t891CoolNormExitLv2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_eb,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_eb);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t891CoolNormExitLv3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bi,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_bi);
  rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.stCoolSts_m;
  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion_e)
  {
    if (!BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgTempCalc_MODE) {
      BTMR_ThmalReqCalc_DW.Delay1_DSTATE_b = 0U;
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_g = 0U;
      BTMR_ThmalReqCalc_DW.is_active_c8_BTMR_ThmalReqCalc = 0U;
      BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
        BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Default;
      BTMR_ThmalReqCalc_Chart_Reset(&BTMR_ThmalReqCalc_B.sf_Chart_i,
        &BTMR_ThmalReqCalc_DW.sf_Chart_i);
      BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgTempCalc_MODE = true;
    }

    if (BTMR_ThmalReqCalc_DW.is_active_c8_BTMR_ThmalReqCalc == 0U) {
      BTMR_ThmalReqCalc_DW.is_active_c8_BTMR_ThmalReqCalc = 1U;
      BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
        BTMR_ThmalRe_IN_CoolNormDefault;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Default;
    } else {
      switch (BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc) {
       case BTMR_ThmalRe_IN_CoolNormDefault:
        BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
          BTMR_ThmalReq_IN_CoolNormStage1;
        BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Stg_Lv1;
        break;

       case BTMR_ThmalReq_IN_CoolNormStage1:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_d.Switch) {
          BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage2;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Stg_Lv2;
        }
        break;

       case BTMR_ThmalReq_IN_CoolNormStage2:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_eb.Switch) {
          BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage1;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Stg_Lv1;
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_et.Switch) {
            BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
              BTMR_ThmalReq_IN_CoolNormStage3;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j =
              enmThmCoolNormStg_891_Stg_Lv3;
          }
        }
        break;

       default:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bi.Switch) {
          BTMR_ThmalReqCalc_DW.is_c8_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage2;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Stg_Lv2;
        }
        break;
      }
    }

    rtb_DataTypeConversion_b = BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j;
    BTMR_ThmalReqCalc_Chart(rtb_DataTypeConversion_b !=
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_g, BMS_cntThmStbNum_C,
      &BTMR_ThmalReqCalc_B.sf_Chart_i, &BTMR_ThmalReqCalc_DW.sf_Chart_i);
    if (BTMR_ThmalReqCalc_B.sf_Chart_i.flg_out) {
      rtb_Switch_j = BTMR_ThmalReqCalc_DW.Delay1_DSTATE_b;
    } else {
      rtb_Switch_j = rtb_DataTypeConversion_b;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_m) {
      if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion4_k) {
        if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion5_co) {
          BTMR_ThmalReqCalc_B.Merge1 = BTMR_tNormClntTempLv3_C;
        } else {
          BTMR_ThmalReqCalc_B.Merge1 = BTMR_tNormClntTempLv2_C;
        }
      } else {
        BTMR_ThmalReqCalc_B.Merge1 = BTMR_tNormClntTempLv1_C;
      }
    } else {
      BTMR_ThmalReqCalc_B.Merge1 = 0.0F;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_j) {
      BTMR_ThmalReqCalc_B.Merge = BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_n;
    } else {
      BTMR_ThmalReqCalc_B.Merge =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_jd;
    }

    BTMR_ThmalReqCalc_DW.Delay1_DSTATE_b = rtb_Switch_j;
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_g = rtb_DataTypeConversion_b;
  } else {
    if (BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgTempCalc_MODE) {
      BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgTempCalc_MODE = false;
    }
  }

  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t891CoolChrgAces2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_lr,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_lr);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t891CoolChrgAces3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jm,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_jm);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t891CoolChrgExitLv2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bia,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_bia);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t891CoolChrgExitLv3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ots,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ots);
  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_b)
  {
    if (!BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgTempCalc_MODE) {
      BTMR_ThmalReqCalc_DW.Delay1_DSTATE_c = 0U;
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_gv = 0U;
      BTMR_ThmalReqCalc_DW.is_active_c9_BTMR_ThmalReqCalc = 0U;
      BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
        BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Default;
      BTMR_ThmalReqCalc_Chart_Reset(&BTMR_ThmalReqCalc_B.sf_Chart_m,
        &BTMR_ThmalReqCalc_DW.sf_Chart_m);
      BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgTempCalc_MODE = true;
    }

    if (BTMR_ThmalReqCalc_DW.is_active_c9_BTMR_ThmalReqCalc == 0U) {
      BTMR_ThmalReqCalc_DW.is_active_c9_BTMR_ThmalReqCalc = 1U;
      BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
        BTMR_ThmalRe_IN_CoolChrgDefault;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Default;
    } else {
      switch (BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc) {
       case BTMR_ThmalRe_IN_CoolChrgDefault:
        BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
          BTMR_ThmalReq_IN_CoolChrgStage1;
        BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Stg_Lv1;
        break;

       case BTMR_ThmalReq_IN_CoolChrgStage1:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_lr.Switch) {
          BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage2;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Stg_Lv2;
        }
        break;

       case BTMR_ThmalReq_IN_CoolChrgStage2:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bia.Switch) {
          BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage1;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Stg_Lv1;
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jm.Switch) {
            BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
              BTMR_ThmalReq_IN_CoolChrgStage3;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Stg_Lv3;
          }
        }
        break;

       default:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ots.Switch) {
          BTMR_ThmalReqCalc_DW.is_c9_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage2;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Stg_Lv2;
        }
        break;
      }
    }

    rtb_DataTypeConversion_b = BTMR_ThmalReqCalc_B.BTMR_stsClntStg;
    BTMR_ThmalReqCalc_Chart(rtb_DataTypeConversion_b !=
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_gv, BMS_cntThmStbNum_C,
      &BTMR_ThmalReqCalc_B.sf_Chart_m, &BTMR_ThmalReqCalc_DW.sf_Chart_m);
    if (BTMR_ThmalReqCalc_B.sf_Chart_m.flg_out) {
      rtb_Switch_j = BTMR_ThmalReqCalc_DW.Delay1_DSTATE_c;
    } else {
      rtb_Switch_j = rtb_DataTypeConversion_b;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_ct) {
      if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion4_h) {
        if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion5_h) {
          BTMR_ThmalReqCalc_B.Merge1 = BTMR_tChrgClntTempLv3_C;
        } else {
          BTMR_ThmalReqCalc_B.Merge1 = BTMR_tChrgClntTempLv2_C;
        }
      } else {
        BTMR_ThmalReqCalc_B.Merge1 = BTMR_tChrgClntTempLv1_C;
      }
    } else {
      BTMR_ThmalReqCalc_B.Merge1 = 0.0F;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_f) {
      BTMR_ThmalReqCalc_B.Merge =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_hv;
    } else {
      BTMR_ThmalReqCalc_B.Merge = BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_a;
    }

    BTMR_ThmalReqCalc_DW.Delay1_DSTATE_c = rtb_Switch_j;
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_gv = rtb_DataTypeConversion_b;
  } else {
    if (BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgTempCalc_MODE) {
      BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgTempCalc_MODE = false;
    }
  }

  if (rtb_DataTypeConversion1 != 0) {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.Merge;
  } else {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_ConstB.DataTypeConversion5;
  }

  if (BTMR_rCoolClbFlg_C > 10.0F) {
    BTMR_tClntTempReq = BTMR_tCoolTempClbQnt_C;
    BTMR_flgClntTempReq = 1U;
  } else if (BTMR_flgBrsTempReq != 0) {
    BTMR_tClntTempReq = 0.0F;
    BTMR_flgClntTempReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_j;
  } else {
    if (rtb_DataTypeConversion1 != 0) {
      BTMR_tClntTempReq = BTMR_ThmalReqCalc_B.Merge1;
    } else {
      BTMR_tClntTempReq = 0.0F;
    }

    BTMR_flgClntTempReq = rtb_DataTypeConversion1;
  }

  rtb_BTMR_flgBrsEna1 = (BMCR_stBmsModeCtrl ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion_g);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >=
    BTMR_t861HtgDCStartHiTemp_C) && (BSPR_tCellTempMax <
    BTMR_t861CoolChrgAcesTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cw,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_cw);
  rtb_BTMR_flgHtgDrvSOC = (rtb_BTMR_flgBrsEna1 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cw.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tClntUsT >= BTMR_t861HtgDCStartHiTemp_C)
    && (BSPR_tClntUsT < BTMR_t861CoolChrgAcesTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_j4,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_j4);
  rtb_BTMR_flgHtgDrvSOC = (rtb_BTMR_flgHtgDrvSOC &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_j4.Switch);
  rtb_BTMR_flgBrsIntEna2 = (BMCR_stBmsModeCtrl ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_m);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >=
    BTMR_t861HtgACStartHiTemp_C) && (BSPR_tCellTempMax <
    BTMR_t861CoolNormAcesTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ox,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ox);
  rtb_BTMR_flgBrsDrvOut = (rtb_BTMR_flgBrsIntEna2 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ox.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tClntUsT >= BTMR_t861HtgACStartHiTemp_C)
    && (BSPR_tClntUsT < BTMR_t861CoolNormAcesTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jb,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_jb);
  rtb_BTMR_flgBrsDrvOut = (rtb_BTMR_flgBrsDrvOut &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jb.Switch);
  rtb_BTMR_flgBrsEna3 = ((BMCR_stBmsModeCtrl ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_jt) && (!COMR_bLeadAcidChgHvOn));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin >
    BTMR_t861HtgDrvStartHiTemp_C) && (BSPR_tCellTempMax <
    BTMR_t861CoolNormAcesTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_h,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_h);
  rtb_BTMR_flgBrsEna2 = (rtb_BTMR_flgBrsEna3 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_h.Switch && (BSER_rSoc >
    BTMR_r861BrsDrvSoc_C));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tClntUsT > BTMR_t861HtgDrvStartHiTemp_C)
    && (BSPR_tClntUsT < BTMR_t861CoolNormAcesTemp_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_dk,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_dk);
  rtb_BTMR_flgBrsEna_p = (rtb_BTMR_flgHtgDrvSOC || rtb_BTMR_flgBrsDrvOut ||
    (rtb_BTMR_flgBrsEna2 && BTMR_ThmalReqCalc_B.BMSDebounceStartZero_dk.Switch));
  rtb_BTMR_flgBrsDCOut = (rtb_BTMR_flgBrsEna1 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cw.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax < BTMR_t861HtgDCStopTemp2_C
    - BTMR_tHtgDCMaxTempDeb_C) && (BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t861HtgDCEndDiffTemp_C - BTMR_t861HtgDCDiffDebTemp_C) &&
    (BSPR_tCellTempMin > BTMR_t861HtgDCStartLoTemp_C) && (BSPR_tCellTempMin <
    BTMR_t861HtgDCStartHiTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_no,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_no);
  rtb_BTMR_flgHtgDCEna = (rtb_BTMR_flgBrsDCOut &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_no.Switch);
  rtb_BTMR_flgBrsEna2 = (rtb_BTMR_flgBrsIntEna2 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ox.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t861HtgACEndDiffTemp_C - BTMR_t861HtgACDiffDebTemp_C) &&
    (BSPR_tCellTempMin >= BTMR_t861HtgACStartLoTemp_C) && (BSPR_tCellTempMin <
    BTMR_t861HtgACStartHiTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jk,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_jk);
  rtb_BTMR_flgHtgACEna = (rtb_BTMR_flgBrsEna2 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jk.Switch);
  rtb_BTMR_flgBrsDrvOut = (rtb_BTMR_flgBrsEna3 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_h.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t861HtgDrvEndDiffTemp_C - BTMR_t861HtgDrvDiffDebTemp_C) &&
    (BSPR_tCellTempMin <= BTMR_t861HtgDrvStartHiTemp_C) && (BSPR_tCellTempMin >=
    BTMR_t861HtgDrvStartLoTemp_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_a,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_a);
  rtb_BTMR_flgHtgDrvEna = (rtb_BTMR_flgBrsDrvOut &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_a.Switch);
  rtb_BTMR_flgHtgDrvSOC = (BSER_rSoc > BTMR_r861HtgDrvSoc_C);
  BTMR_flgTempDiff = (BSPR_tCellTempMax - BSPR_tCellTempMin <
                      BTMR_t861CoolNormEndDiffTemp_C -
                      BTMR_t861CoolNormDiffDebTemp_C);
  rtb_BTMR_flgHtgACThmEnd = ((BSPR_tCellTempMax >= BTMR_t861CoolNormAcesTemp_C) &&
    BTMR_flgTempDiff);
  if (BTMR_ThmalReqCalc_DW.StateName_a) {
    rtb_Switch2_pt = 0U;
  } else {
    rtb_Switch2_pt = BTMR_ThmalReqCalc_DW.StateName;
  }

  if (rtb_BTMR_flgHtgACThmEnd) {
    rtb_Switch2_pt = (uint16_T)((uint32_T)BTMR_tiTempBase_C + rtb_Switch2_pt);
    if (!(rtb_Switch2_pt <= 60000)) {
      rtb_Switch2_pt = 60000U;
    }
  } else if (rtb_Switch2_pt >= BTMR_tiTempBase_C) {
    rtb_Switch2_pt = (uint16_T)((uint32_T)rtb_Switch2_pt - BTMR_tiTempBase_C);
  } else {
    rtb_Switch2_pt = 0U;
  }

  rtb_BTMR_flgHtgDCThmEnd = (rtb_Switch2_pt > BTMR_tiTempDebs_C);
  if (BTMR_ThmalReqCalc_DW.StateName_d) {
    rtb_Switch2_m = 0U;
  } else {
    rtb_Switch2_m = BTMR_ThmalReqCalc_DW.StateName_h;
  }

  if (!rtb_BTMR_flgHtgACThmEnd) {
    rtb_Switch2_m = (uint16_T)((uint32_T)BTMR_tiTempBase_C + rtb_Switch2_m);
    if (!(rtb_Switch2_m <= 60000)) {
      rtb_Switch2_m = 60000U;
    }
  } else if (rtb_Switch2_m >= BTMR_tiTempBase_C) {
    rtb_Switch2_m = (uint16_T)((uint32_T)rtb_Switch2_m - BTMR_tiTempBase_C);
  } else {
    rtb_Switch2_m = 0U;
  }

  rtb_BTMR_flgHtgACThmEnd = (rtb_Switch2_m > BTMR_tiTempDebs_C);
  if (!BTMR_flgCoolNormEnaTemp) {
    BTMR_flgCoolNormEnaTemp = rtb_BTMR_flgHtgDCThmEnd;
  } else {
    BTMR_flgCoolNormEnaTemp = !rtb_BTMR_flgHtgACThmEnd;
  }

  BTMR_ThmalReqCalc_DW.StateName_a = rtb_BTMR_flgHtgDCThmEnd;
  BTMR_ThmalReqCalc_DW.StateName = rtb_Switch2_pt;
  BTMR_ThmalReqCalc_DW.StateName_d = rtb_BTMR_flgHtgACThmEnd;
  BTMR_ThmalReqCalc_DW.StateName_h = rtb_Switch2_m;
  BTMR_flgCoolNormEna = (((rtb_BTMR_flgBrsEna2 &&
    (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jk.Switch)) ||
    (rtb_BTMR_flgBrsDrvOut &&
     (!BTMR_ThmalReqCalc_B.BMSDebounceStartZero_a.Switch))) &&
    BTMR_flgCoolNormEnaTemp);
  rtb_BTMR_flgBrsDrvOut = !BTMR_ThmalReqCalc_B.BMSDebounceStartZero_no.Switch;
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax >=
    BTMR_t861CoolChrgAcesTemp_C) && (BSPR_tCellTempMax - BSPR_tCellTempMin <
    BTMR_t861CoolChrgEndDiffTemp_C - BTMR_t861CoolChrgDiffDebTemp_C) &&
    (BSPR_tCellTempMin >= BTMR_t861HtgDCStopTemp_C + BTMR_t861CoolDCDebTemp_C),
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_hg,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_hg);
  rtb_BTMR_flgBrsDrvOut = (rtb_BTMR_flgBrsDCOut && rtb_BTMR_flgBrsDrvOut &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_hg.Switch);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin <=
    BTMR_t861BrsDiffLv0Temp_C) || (BSPR_tCellTempMin <=
    BTMR_tBrsMinCellTempThre_C - BTMR_tBrsMinCellTempDeb_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cd,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_cd);
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMin > BTMR_t861HtgDCStopTemp_C)
    || (BSPR_tCellTempMax > BTMR_t861HtgDCStopTemp2_C), BTMR_tiTempDebs_C,
    BTMR_tiTempBase_C, &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_nj,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_nj);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMin >= BTMR_t861HtgACStopTemp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_of,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_of);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMin >= BTMR_t861HtgDrvStopTemp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_b4,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_b4);
  rtb_BTMR_flgBrsEna2 = (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_b4.Switch || (
    !rtb_BTMR_flgHtgDrvSOC));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t861CoolNormExitTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_k,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_k);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t861CoolChrgExitTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_fg,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_fg);
  rtb_BTMR_flgBrsDCOut = ((BMCR_stBmsModeCtrl !=
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_p) || (DSMR_stFaultRank >=
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_ja) || COMR_bLeadAcidChgHvOn);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t861HtgDCEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ez,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ez);
  rtb_LogicalOperator10 = (rtb_BTMR_flgBrsDCOut || (rtb_BTMR_flgBrsEna1 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ez.Switch));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t861HtgACEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_k0,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_k0);
  rtb_BTMR_flgHtgDCThmEnd = (rtb_BTMR_flgBrsDCOut || (rtb_BTMR_flgBrsIntEna2 &&
    (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_k0.Switch || BCMR_bAcChrgHeatFbd)));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t861HtgDrvEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jz,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_jz);
  rtb_BTMR_flgHtgACThmEnd = (rtb_BTMR_flgBrsDCOut || (rtb_BTMR_flgBrsEna3 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_jz.Switch));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t861CoolNormEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_kc,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_kc);
  rtb_BTMR_flgBrsIntEna2 = (rtb_BTMR_flgBrsDCOut || ((rtb_BTMR_flgBrsIntEna2 ||
    rtb_BTMR_flgBrsEna3) && BTMR_ThmalReqCalc_B.BMSDebounceStartZero_kc.Switch));
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t861CoolChrgEndDiffTemp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_dn,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_dn);
  rtb_BTMR_flgBrsEna1 = (rtb_BTMR_flgBrsDCOut || (rtb_BTMR_flgBrsEna1 &&
    BTMR_ThmalReqCalc_B.BMSDebounceStartZero_dn.Switch));
  BTMR_Thmal_BMSDebounceStartZero((BSPR_tCellTempMax - BSPR_tCellTempMin >=
    BTMR_t861BrsDiffLv1Temp_C) && (BSPR_tCellTempMin - BSPR_tClntUsT <
    BTMR_tBrsCellClntDvtTemp_C) && (BSPR_tClntUsT - BSPR_tCellTempMax <
    BTMR_tBrsCellClntDvtTemp_C) && (BSPR_tCellTempMin >=
    BTMR_tBrsMinCellTempThre_C), BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_a0,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_a0);
  if (BTMR_ThmalReqCalc_DW.is_active_c16_BTMR_ThmalReqCalc == 0U) {
    BTMR_ThmalReqCalc_DW.is_active_c16_BTMR_ThmalReqCalc = 1U;
    BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
      BTMR_ThmalReqC_IN_Default_Stt_j;
    BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
    BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
    BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
  } else {
    switch (BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc) {
     case BTMR_ThmalReqCalc_IN_Brush_Stt:
      if ((!rtb_BTMR_flgBrsEna_p) || (rtb_BTMR_flgBrsDCOut ||
           BTMR_ThmalReqCalc_B.BMSDebounceStartZero_cd.Switch)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCa_IN_CoolChrg_Stt:
      if (rtb_BTMR_flgBrsEna1 ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_fg.Switch) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCa_IN_CoolNorm_Stt:
      if (rtb_BTMR_flgBrsIntEna2 ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_k.Switch) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
        }
      }
      break;

     case BTMR_ThmalReqC_IN_Default_Stt_j:
      BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
        BTMR_ThmalReqCal_IN_Standby_Stt;
      BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
      BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
      BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
      BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
      if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
        tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
      } else {
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
      }
      break;

     case BTMR_ThmalReqCalc_IN_HtgAC_Stt:
      if (rtb_BTMR_flgHtgDCThmEnd ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_of.Switch) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCalc_IN_HtgDC_Stt:
      if (rtb_LogicalOperator10 ||
          BTMR_ThmalReqCalc_B.BMSDebounceStartZero_nj.Switch) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
        }
      }
      break;

     case BTMR_ThmalReqCalc_IN_HtgDrv_Stt:
      if (rtb_BTMR_flgHtgACThmEnd || rtb_BTMR_flgBrsEna2) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_Standby_Stt;
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 0U;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
        if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
          tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
          if (tmp > 65535) {
            tmp = 65535;
          }

          BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
        } else {
          BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
        }
      }
      break;

     default:
      if (rtb_BTMR_flgBrsDrvOut && (!rtb_BTMR_flgBrsEna1) &&
          (BTMR_ThmalReqCalc_DW.Local_DebCnt >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCa_IN_CoolChrg_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_CoolChrg;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
      } else if (BTMR_flgCoolNormEna && (!rtb_BTMR_flgBrsIntEna2) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCa_IN_CoolNorm_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_CoolNorm;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgHtgDCEna && (!rtb_LogicalOperator10) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_HtgDC_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_HeatDC;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgHtgACEna && (!rtb_BTMR_flgHtgDCThmEnd) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_HtgAC_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_HeatAC;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgHtgDrvEna && rtb_BTMR_flgHtgDrvSOC &&
                 (!rtb_BTMR_flgHtgACThmEnd) &&
                 (BTMR_ThmalReqCalc_DW.Local_DebCnt >= 600)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_HtgDrv_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_HeatDrv;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
      } else if (rtb_BTMR_flgBrsEna_p &&
                 BTMR_ThmalReqCalc_B.BMSDebounceStartZero_a0.Switch &&
                 (!rtb_BTMR_flgBrsDCOut) && (BTMR_ThmalReqCalc_DW.Local_DebCnt >=
                  600)) {
        BTMR_ThmalReqCalc_DW.is_c16_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCalc_IN_Brush_Stt;
        BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
        BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
        BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_ACTIVE;
      } else if (BTMR_ThmalReqCalc_DW.Local_DebCnt <= 600) {
        tmp = BTMR_ThmalReqCalc_DW.Local_DebCnt + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        BTMR_ThmalReqCalc_DW.Local_DebCnt = (uint16_T)tmp;
      } else {
        BTMR_ThmalReqCalc_DW.Local_DebCnt = 600U;
      }
      break;
    }
  }

  rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.stHtgSts;
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT >= BTMR_t861HtgDCIntLv4Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g3,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_g3);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT >= BTMR_t861HtgDCIntLv3Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_pn,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_pn);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT <= BTMR_t861HtgDCIntLv2Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bc,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_bc);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT <= BTMR_t861HtgDCIntLv1Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_id,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_id);
  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion3) {
    BTMR_ThmalReqCalc_B.Merge_d = enmThmHeatFlg_ACTIVE;
    BTMR_ThmalReqCalc_B.Merge1_f = BTMR_pHtgACPwrReq_C;
  }

  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_o)
  {
    if (!BTMR_ThmalReqCalc_DW.BTMR_HtgDCCal_MODE) {
      BTMR_ThmalReqCalc_DW.Delay1_DSTATE = 0U;
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_i = 0U;
      BTMR_ThmalReqCalc_DW.is_HtgDCStage2 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_active_c14_BTMR_ThmalReqCalc = 0U;
      BTMR_ThmalReqCalc_DW.is_c14_BTMR_ThmalReqCalc =
        BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Default;
      BTMR_ThmalReqCalc_Chart_Reset(&BTMR_ThmalReqCalc_B.sf_Chart_mp,
        &BTMR_ThmalReqCalc_DW.sf_Chart_mp);
      BTMR_ThmalReqCalc_DW.BTMR_HtgDCCal_MODE = true;
    }

    if (BTMR_ThmalReqCalc_DW.is_active_c14_BTMR_ThmalReqCalc == 0U) {
      BTMR_ThmalReqCalc_DW.is_active_c14_BTMR_ThmalReqCalc = 1U;
      BTMR_ThmalReqCalc_DW.is_c14_BTMR_ThmalReqCalc =
        BTMR_ThmalReqCa_IN_HtgDCDefault;
      BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Default;
    } else {
      switch (BTMR_ThmalReqCalc_DW.is_c14_BTMR_ThmalReqCalc) {
       case BTMR_ThmalReqCa_IN_HtgDCDefault:
        BTMR_ThmalReqCalc_DW.is_c14_BTMR_ThmalReqCalc =
          BTMR_ThmalReqCal_IN_HtgDCStage1;
        BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Stg_Lv1;
        break;

       case BTMR_ThmalReqCal_IN_HtgDCStage1:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g3.Switch) {
          BTMR_ThmalReqCalc_DW.is_c14_BTMR_ThmalReqCalc =
            BTMR_ThmalReqCal_IN_HtgDCStage2;
          BTMR_ThmalReqCalc_DW.is_HtgDCStage2 = BTMR_ThmalR_IN_HtgDCStage2Pause;
          BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Stg_Lv2Red;
        }
        break;

       default:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_id.Switch) {
          BTMR_ThmalReqCalc_DW.is_HtgDCStage2 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c14_BTMR_ThmalReqCalc =
            BTMR_ThmalReqCal_IN_HtgDCStage1;
          BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Stg_Lv1;
        } else if (BTMR_ThmalReqCalc_DW.is_HtgDCStage2 ==
                   BTMR_Thmal_IN_HtgDCStage2Curve1) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_pn.Switch) {
            BTMR_ThmalReqCalc_DW.is_HtgDCStage2 =
              BTMR_ThmalR_IN_HtgDCStage2Pause;
            BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Stg_Lv2Red;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bc.Switch) {
            BTMR_ThmalReqCalc_DW.is_HtgDCStage2 =
              BTMR_Thmal_IN_HtgDCStage2Curve1;
            BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Stg_Lv2Res;
          }
        }
        break;
      }
    }

    rtb_DataTypeConversion_b = BTMR_ThmalReqCalc_B.BTMR_stsHeatStg;
    BTMR_ThmalReqCalc_Chart(rtb_DataTypeConversion_b !=
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_i, BTMR_cntThmalReqVal_C,
      &BTMR_ThmalReqCalc_B.sf_Chart_mp, &BTMR_ThmalReqCalc_DW.sf_Chart_mp);
    if (BTMR_ThmalReqCalc_B.sf_Chart_mp.flg_out) {
      rtb_Switch_j = BTMR_ThmalReqCalc_DW.Delay1_DSTATE;
    } else {
      rtb_Switch_j = rtb_DataTypeConversion_b;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_h) {
      if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion4_c) {
        if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion5_d) {
          if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion6) {
            if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion7_b)
            {
              BTMR_ThmalReqCalc_B.Merge1_f = look1_iflf_binlcapw(COMR_tEnvT, ((
                const real32_T *)&(BTMR_tEnvTStage2_A[0])), ((const real32_T *)
                &(BTMR_pHtgsStage2_CUR[0])), 5U);
            } else {
              BTMR_ThmalReqCalc_B.Merge1_f = 0.0F;
            }
          } else {
            BTMR_ThmalReqCalc_B.Merge1_f = look1_iflf_binlcapw(COMR_tEnvT, ((
              const real32_T *)&(BTMR_tEnvTStage1_A[0])), ((const real32_T *)
              &(BTMR_pHtgsStage1_CUR[0])), 5U);
          }
        } else {
          BTMR_ThmalReqCalc_B.Merge1_f = 0.0F;
        }
      } else {
        BTMR_ThmalReqCalc_B.Merge1_f = BTMR_pHtgDCPwrReq_C;
      }
    } else {
      BTMR_ThmalReqCalc_B.Merge1_f = 0.0F;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_g) {
      BTMR_ThmalReqCalc_B.Merge_d =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_p;
    } else {
      BTMR_ThmalReqCalc_B.Merge_d =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_k;
    }

    BTMR_ThmalReqCalc_DW.Delay1_DSTATE = rtb_Switch_j;
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_i = rtb_DataTypeConversion_b;
  } else {
    if (BTMR_ThmalReqCalc_DW.BTMR_HtgDCCal_MODE) {
      BTMR_ThmalReqCalc_DW.BTMR_HtgDCCal_MODE = false;
    }
  }

  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion4) {
    BTMR_ThmalReqCalc_B.Merge_d = enmThmHeatFlg_ACTIVE;
    BTMR_ThmalReqCalc_B.Merge1_f = BTMR_pHtgDrvPwrReq_C;
  }

  if (rtb_DataTypeConversion1 != 0) {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.Merge_d;
  } else {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_ConstB.DataTypeConversion7;
  }

  if ((BCMR_stAChrgPreThmReq == 1) || (BCMR_stAChrgPreThmReq == 2)) {
    BTMR_pHtgPwrReq = BCMR_pHeatPwrReq;
    BTMR_flgHtgPwrReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion8;
  } else {
    if (rtb_DataTypeConversion1 != 0) {
      BTMR_pHtgPwrReq = BTMR_ThmalReqCalc_B.Merge1_f;
    } else {
      BTMR_pHtgPwrReq = 0.0F;
    }

    BTMR_flgHtgPwrReq = rtb_DataTypeConversion1;
  }

  rtb_BTMR_flgHtgDrvSOC = (BTMR_ThmalReqCalc_B.stBrsSts ==
    BTMR_ThmalReqCalc_ConstB.DataTypeConversion_i);
  BTMR_ThmalReqCalc_Chart(rtb_BTMR_flgHtgDrvSOC !=
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_b, BTMR_cntThmalReqVal_C,
    &BTMR_ThmalReqCalc_B.sf_Chart_l, &BTMR_ThmalReqCalc_DW.sf_Chart_l);
  if (BTMR_ThmalReqCalc_B.sf_Chart_l.flg_out) {
    rtb_BTMR_flgBrsEna1 = BTMR_ThmalReqCalc_DW.Delay1_DSTATE_bv;
  } else {
    rtb_BTMR_flgBrsEna1 = rtb_BTMR_flgHtgDrvSOC;
  }

  if (rtb_BTMR_flgBrsEna1) {
    BTMR_flgBrsPwrReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_br;
  } else {
    BTMR_flgBrsPwrReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_m;
  }

  BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_b = rtb_BTMR_flgHtgDrvSOC;
  BTMR_ThmalReqCalc_DW.Delay1_DSTATE_bv = rtb_BTMR_flgBrsEna1;
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t861CoolNormLv2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_hj,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_hj);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t861CoolNormLv3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_at,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_at);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t861CoolNormExitLv2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bza,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_bza);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t861CoolNormExitLv3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ea,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ea);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT <= BTMR_t861CoolNormIntLv0Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ny,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ny);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT >= BTMR_t861CoolNormIntLv1Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_fx,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_fx);
  rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.stCoolSts;
  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion_l)
  {
    if (!BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgPwrCalc_MODE) {
      BTMR_ThmalReqCalc_DW.Delay1_DSTATE_a = 0U;
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_a = 0U;
      BTMR_ThmalReqCalc_DW.is_CoolNormStage1 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_CoolNormStage2 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_CoolNormStage3 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_active_c12_BTMR_ThmalReqCalc = 0U;
      BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
        BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g = enmThmCoolNormStg_861_Default;
      BTMR_ThmalReqCalc_Chart_Reset(&BTMR_ThmalReqCalc_B.sf_Chart_gy,
        &BTMR_ThmalReqCalc_DW.sf_Chart_gy);
      BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgPwrCalc_MODE = true;
    }

    if (BTMR_ThmalReqCalc_DW.is_active_c12_BTMR_ThmalReqCalc == 0U) {
      BTMR_ThmalReqCalc_DW.is_active_c12_BTMR_ThmalReqCalc = 1U;
      BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
        BTMR_ThmalRe_IN_CoolNormDefault;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g = enmThmCoolNormStg_861_Default;
    } else {
      switch (BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc) {
       case BTMR_ThmalRe_IN_CoolNormDefault:
        BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
          BTMR_ThmalReq_IN_CoolNormStage1;
        BTMR_ThmalReqCalc_DW.is_CoolNormStage1 = BTMR_Thm_IN_CoolNormStage1Start;
        BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g = enmThmCoolNormStg_861_Stg_Lv1Res;
        break;

       case BTMR_ThmalReq_IN_CoolNormStage1:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_hj.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolNormStage1 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage2;
          BTMR_ThmalReqCalc_DW.is_CoolNormStage2 =
            BTMR_Thm_IN_CoolNormStage2Start;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
            enmThmCoolNormStg_861_Stg_Lv2Res;
        } else if (BTMR_ThmalReqCalc_DW.is_CoolNormStage1 ==
                   BTMR_Thm_IN_CoolNormStage1Pause) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_fx.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolNormStage1 =
              BTMR_Thm_IN_CoolNormStage1Start;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
              enmThmCoolNormStg_861_Stg_Lv1Res;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ny.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolNormStage1 =
              BTMR_Thm_IN_CoolNormStage1Pause;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
              enmThmCoolNormStg_861_Stg_Lv1Red;
          }
        }
        break;

       case BTMR_ThmalReq_IN_CoolNormStage2:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_bza.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolNormStage2 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage1;
          BTMR_ThmalReqCalc_DW.is_CoolNormStage1 =
            BTMR_Thm_IN_CoolNormStage1Start;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
            enmThmCoolNormStg_861_Stg_Lv1Res;
        } else if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_at.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolNormStage2 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage3;
          BTMR_ThmalReqCalc_DW.is_CoolNormStage3 =
            BTMR_Thm_IN_CoolNormStage3Start;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
            enmThmCoolNormStg_861_Stg_Lv3Res;
        } else if (BTMR_ThmalReqCalc_DW.is_CoolNormStage2 ==
                   BTMR_Thm_IN_CoolNormStage2Pause) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_fx.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolNormStage2 =
              BTMR_Thm_IN_CoolNormStage2Start;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
              enmThmCoolNormStg_861_Stg_Lv2Res;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ny.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolNormStage2 =
              BTMR_Thm_IN_CoolNormStage2Pause;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
              enmThmCoolNormStg_861_Stg_Lv2Red;
          }
        }
        break;

       default:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ea.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolNormStage3 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c12_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolNormStage2;
          BTMR_ThmalReqCalc_DW.is_CoolNormStage2 =
            BTMR_Thm_IN_CoolNormStage2Start;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
            enmThmCoolNormStg_861_Stg_Lv2Res;
        } else if (BTMR_ThmalReqCalc_DW.is_CoolNormStage3 ==
                   BTMR_Thm_IN_CoolNormStage3Pause) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_fx.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolNormStage3 =
              BTMR_Thm_IN_CoolNormStage3Start;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
              enmThmCoolNormStg_861_Stg_Lv3Res;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ny.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolNormStage3 =
              BTMR_Thm_IN_CoolNormStage3Pause;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g =
              enmThmCoolNormStg_861_Stg_Lv3Red;
          }
        }
        break;
      }
    }

    rtb_DataTypeConversion_b = BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g;
    BTMR_ThmalReqCalc_Chart(rtb_DataTypeConversion_b !=
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_a, BTMR_cntThmalReqVal_C,
      &BTMR_ThmalReqCalc_B.sf_Chart_gy, &BTMR_ThmalReqCalc_DW.sf_Chart_gy);
    if (BTMR_ThmalReqCalc_B.sf_Chart_gy.flg_out) {
      rtb_Switch_j = BTMR_ThmalReqCalc_DW.Delay1_DSTATE_a;
    } else {
      rtb_Switch_j = rtb_DataTypeConversion_b;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_b) {
      if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion4_o) {
        if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion5_m) {
          if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion6_d) {
            if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion7_j)
            {
              if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion8_a)
              {
                BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pNormClntPwrLv3_C;
              } else {
                BTMR_ThmalReqCalc_B.Merge1_o = 0.0F;
              }
            } else {
              BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pNormClntPwrLv2_C;
            }
          } else {
            BTMR_ThmalReqCalc_B.Merge1_o = 0.0F;
          }
        } else {
          BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pNormClntPwrLv1_C;
        }
      } else {
        BTMR_ThmalReqCalc_B.Merge1_o = 0.0F;
      }
    } else {
      BTMR_ThmalReqCalc_B.Merge1_o = 0.0F;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_c) {
      BTMR_ThmalReqCalc_B.Merge_c =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_g;
    } else {
      BTMR_ThmalReqCalc_B.Merge_c =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_g;
    }

    BTMR_ThmalReqCalc_DW.Delay1_DSTATE_a = rtb_Switch_j;
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_a = rtb_DataTypeConversion_b;
  } else {
    if (BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgPwrCalc_MODE) {
      BTMR_ThmalReqCalc_DW.BTMR_CoolNormFlgPwrCalc_MODE = false;
    }
  }

  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t861CoolChrgAces2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_f3,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_f3);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax >=
    BTMR_t861CoolChrgAces3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_d5,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_d5);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t861CoolChrgExitLv2Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g5,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_g5);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tCellTempMax <=
    BTMR_t861CoolChrgExitLv3Temp_C, BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ky,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ky);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT <= BTMR_t861CoolChrgIntLv2Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ikh,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ikh);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT >= BTMR_t861CoolChrgIntLv5Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_as,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_as);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT <= BTMR_t861CoolChrgIntLv1Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ls,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ls);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT >= BTMR_t861CoolChrgIntLv4Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_k1,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_k1);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT <= BTMR_t861CoolChrgIntLv0Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_p5,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_p5);
  BTMR_Thmal_BMSDebounceStartZero(BSPR_tClntUsT >= BTMR_t861CoolChrgIntLv3Temp_C,
    BTMR_tiTempDebs_C, BTMR_tiTempBase_C,
    &BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ld,
    &BTMR_ThmalReqCalc_DW.BMSDebounceStartZero_ld);
  if (rtb_DataTypeConversion1 == BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_i)
  {
    if (!BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgPwrCalc_MODE) {
      BTMR_ThmalReqCalc_DW.Delay1_DSTATE_f = 0U;
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_d = 0U;
      BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_CoolChrgStage3 = BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_DW.is_active_c10_BTMR_ThmalReqCalc = 0U;
      BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
        BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f = enmThmCoolChrgStg_861_Default;
      BTMR_ThmalReqCalc_Chart_Reset(&BTMR_ThmalReqCalc_B.sf_Chart_n,
        &BTMR_ThmalReqCalc_DW.sf_Chart_n);
      BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgPwrCalc_MODE = true;
    }

    if (BTMR_ThmalReqCalc_DW.is_active_c10_BTMR_ThmalReqCalc == 0U) {
      BTMR_ThmalReqCalc_DW.is_active_c10_BTMR_ThmalReqCalc = 1U;
      BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
        BTMR_ThmalRe_IN_CoolChrgDefault;
      BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f = enmThmCoolChrgStg_861_Default;
    } else {
      switch (BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc) {
       case BTMR_ThmalRe_IN_CoolChrgDefault:
        BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
          BTMR_ThmalReq_IN_CoolChrgStage1;
        BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 = BTMR_Thma_IN_CoolChrgStage1Norm;
        BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f = enmThmCoolChrgStg_861_Stg_Lv1Res;
        break;

       case BTMR_ThmalReq_IN_CoolChrgStage1:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_f3.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage2;
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 =
            BTMR_Thma_IN_CoolChrgStage2Norm;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
            enmThmCoolChrgStg_861_Stg_Lv2Res;
        } else if (BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 ==
                   BTMR_Thma_IN_CoolChrgStage1Norm) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ikh.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 =
              BTMR_Th_IN_CoolChrgStage1Reduce;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
              enmThmCoolChrgStg_861_Stg_Lv1Red;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_as.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 =
              BTMR_Thma_IN_CoolChrgStage1Norm;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
              enmThmCoolChrgStg_861_Stg_Lv1Res;
          }
        }
        break;

       case BTMR_ThmalReq_IN_CoolChrgStage2:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_g5.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage1;
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage1 =
            BTMR_Thma_IN_CoolChrgStage1Norm;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
            enmThmCoolChrgStg_861_Stg_Lv1Res;
        } else if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_d5.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage3;
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage3 =
            BTMR_Thma_IN_CoolChrgStage3Norm;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
            enmThmCoolChrgStg_861_Stg_Lv3Res;
        } else if (BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 ==
                   BTMR_Thma_IN_CoolChrgStage2Norm) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ls.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 =
              BTMR_Th_IN_CoolChrgStage2Reduce;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
              enmThmCoolChrgStg_861_Stg_Lv2Red;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_k1.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 =
              BTMR_Thma_IN_CoolChrgStage2Norm;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
              enmThmCoolChrgStg_861_Stg_Lv2Res;
          }
        }
        break;

       default:
        if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ky.Switch) {
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage3 =
            BTMR_Thmal_IN_NO_ACTIVE_CHILD_k;
          BTMR_ThmalReqCalc_DW.is_c10_BTMR_ThmalReqCalc =
            BTMR_ThmalReq_IN_CoolChrgStage2;
          BTMR_ThmalReqCalc_DW.is_CoolChrgStage2 =
            BTMR_Thma_IN_CoolChrgStage2Norm;
          BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
            enmThmCoolChrgStg_861_Stg_Lv2Res;
        } else if (BTMR_ThmalReqCalc_DW.is_CoolChrgStage3 ==
                   BTMR_Thma_IN_CoolChrgStage3Norm) {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_p5.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolChrgStage3 =
              BTMR_Th_IN_CoolChrgStage3Reduce;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
              enmThmCoolChrgStg_861_Stg_Lv3Red;
          }
        } else {
          if (BTMR_ThmalReqCalc_B.BMSDebounceStartZero_ld.Switch) {
            BTMR_ThmalReqCalc_DW.is_CoolChrgStage3 =
              BTMR_Thma_IN_CoolChrgStage3Norm;
            BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f =
              enmThmCoolChrgStg_861_Stg_Lv3Res;
          }
        }
        break;
      }
    }

    rtb_DataTypeConversion_b = BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f;
    BTMR_ThmalReqCalc_Chart(rtb_DataTypeConversion_b !=
      BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_d, BTMR_cntThmalReqVal_C,
      &BTMR_ThmalReqCalc_B.sf_Chart_n, &BTMR_ThmalReqCalc_DW.sf_Chart_n);
    if (BTMR_ThmalReqCalc_B.sf_Chart_n.flg_out) {
      rtb_Switch_j = BTMR_ThmalReqCalc_DW.Delay1_DSTATE_f;
    } else {
      rtb_Switch_j = rtb_DataTypeConversion_b;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_l) {
      if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion4_g) {
        if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion5_c) {
          if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion6_j) {
            if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion7_by)
            {
              if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion8_o)
              {
                BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pChrgClntPwrLv6_C;
              } else {
                BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pChrgClntPwrLv5_C;
              }
            } else {
              BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pChrgClntPwrLv4_C;
            }
          } else {
            BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pChrgClntPwrLv3_C;
          }
        } else {
          BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pChrgClntPwrLv2_C;
        }
      } else {
        BTMR_ThmalReqCalc_B.Merge1_o = BTMR_pChrgClntPwrLv1_C;
      }
    } else {
      BTMR_ThmalReqCalc_B.Merge1_o = 0.0F;
    }

    if (rtb_Switch_j != BTMR_ThmalReqCalc_ConstB.DataTypeConversion3_a) {
      BTMR_ThmalReqCalc_B.Merge_c =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion1_j;
    } else {
      BTMR_ThmalReqCalc_B.Merge_c =
        BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_k2;
    }

    BTMR_ThmalReqCalc_DW.Delay1_DSTATE_f = rtb_Switch_j;
    BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_d = rtb_DataTypeConversion_b;
  } else {
    if (BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgPwrCalc_MODE) {
      BTMR_ThmalReqCalc_DW.BTMR_CoolChrgFlgPwrCalc_MODE = false;
    }
  }

  if (rtb_DataTypeConversion1 != 0) {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_B.Merge_c;
  } else {
    rtb_DataTypeConversion1 = BTMR_ThmalReqCalc_ConstB.DataTypeConversion5_e;
  }

  if (BTMR_flgCoolPwrCal_C) {
    BTMR_flgClntPwrReq = (uint8_T)BTMR_flgCoolPwrCal_C;
    BTMR_pClntPwrReq = BTMR_pCoolPwrVal_C;
  } else if (BTMR_flgBrsPwrReq != 0) {
    BTMR_flgClntPwrReq = BTMR_ThmalReqCalc_ConstB.DataTypeConversion2_l;
    BTMR_pClntPwrReq = 0.0F;
  } else {
    BTMR_flgClntPwrReq = rtb_DataTypeConversion1;
    if (rtb_DataTypeConversion1 != 0) {
      BTMR_pClntPwrReq = BTMR_ThmalReqCalc_B.Merge1_o;
    } else {
      BTMR_pClntPwrReq = 0.0F;
    }
  }

  if (BTMR_flgHtgTempReq >= BTMR_flgHtgPwrReq) {
    BTMR_flgHeatReq = BTMR_flgHtgTempReq;
  } else {
    BTMR_flgHeatReq = BTMR_flgHtgPwrReq;
  }

  if (BTMR_flgClntTempReq >= BTMR_flgClntPwrReq) {
    BTMR_flgCoolReq = BTMR_flgClntTempReq;
  } else {
    BTMR_flgCoolReq = BTMR_flgClntPwrReq;
  }

  BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE = BMCR_stBmsModeCtrl;
  BTMR_ThmalReqCalc_DW.DelayInput1_DSTATE_p = BMCR_stBmsModeCtrl;
}

/* Model initialize function */
void BTMR_ThmalReqCalc_initialize(void)
{
  BTMR_ThmalReqCalc_B.stBrsSts_o = enmThmBrsSts_INACTIVE;
  BTMR_ThmalReqCalc_B.stHtgSts_g = enmThmHeatSts_InActive;
  BTMR_ThmalReqCalc_B.stCoolSts_m = enmThmCoolSts_InActive;
  BTMR_ThmalReqCalc_B.BTMR_stsClntStg_j = enmThmCoolNormStg_891_Default;
  BTMR_ThmalReqCalc_B.BTMR_stsClntStg = enmThmCoolChrgStg_891_Default;
  BTMR_ThmalReqCalc_B.stBrsSts = enmThmBrsSts_INACTIVE;
  BTMR_ThmalReqCalc_B.stHtgSts = enmThmHeatSts_InActive;
  BTMR_ThmalReqCalc_B.stCoolSts = enmThmCoolSts_InActive;
  BTMR_ThmalReqCalc_B.BTMR_stsHeatStg = enmThmDCHeatStg_861_Default;
  BTMR_ThmalReqCalc_B.BTMR_stsClntStg_g = enmThmCoolNormStg_861_Default;
  BTMR_ThmalReqCalc_B.BTMR_stsClntStg_f = enmThmCoolChrgStg_861_Default;
}

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