/*
 * File: BSPR_BattTempPlausDiag.c
 *
 * Code generated for Simulink model 'BSPR_BattTempPlausDiag'.
 *
 * Model version                  : 1.1419
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Fri Dec 11 09:29:30 2020
 *
 * 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 "BSPR_BattTempPlausDiag.h"
#include "BSPR_BattTempPlausDiag_private.h"

/* Named constants for Chart: '<S8>/NplDiagCalc' */
#define BSPR_BattTem_IN_DiagDisable_stt ((uint8_T)2U)
#define BSPR_BattTem_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define BSPR_BattTempPl_IN_CnstDiag_stt ((uint8_T)1U)

/* Named constants for Chart: '<S6>/JitterDiag' */
#define BSPR_BattT_IN_DiagDisable_stt_m ((uint8_T)1U)
#define BSPR_BattT_IN_DiagUCellProc_stt ((uint8_T)2U)
#define BSPR_BattTempPlausDi_IN_Ini_stt ((uint8_T)3U)
#define BSPR_Batt_IN_NO_ACTIVE_CHILD_e4 ((uint8_T)0U)

/* Exported data definition */

/* Definition for custom storage class: FileScope */
static boolean_T BSPR_bBattTCnstDiagSwt;
static boolean_T BSPR_bBattTHopDiagSwt;
static boolean_T BSPR_bCellTCnstDiagSwt;
static boolean_T BSPR_bCellTHopDiagSwt;
static boolean_T BSPR_bCellTempPlausDiagEn;
static boolean_T BSPR_bTempPlausDiagEn;
static real32_T BSPR_tSumBattTemp;
static real32_T BSPR_tSumCellTemp;

#define ASW1_OEM_START_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BSPR_bBattTCnstErrDet_A;/* Consistent error for battery temperature sensor */
volatile boolean_T BSPR_bBattTCnstErrHeal_A;/* Consistent healing condition for battery temperature sensor */
volatile boolean_T BSPR_bBattTCnstErrStt_A[48];/* Consistent error state for battery temperature sensor */
volatile boolean_T BSPR_bBattTHopErrDet_A[48];/* Jitter error for battery temperature sensor */
volatile boolean_T BSPR_bBattTHopErrHeal_A[48];/* Jitter healing condition for battery temperature sensor */
volatile boolean_T BSPR_bBattTHopErrStt_A[48];/* Jitter error state of battery temperature sensor */
volatile boolean_T BSPR_bCellTCnstErrDet_A;/* Consistent error for battery temperature sensor */
volatile boolean_T BSPR_bCellTCnstErrHeal_A;/* Consistent healing condition for battery temperature sensor */
volatile boolean_T BSPR_bCellTCnstErrStt_A[48];/* Consistent error state for battery temperature sensor */
volatile boolean_T BSPR_bCellTHopErrDet_A[48];/* Jitter error for battery temperature sensor */
volatile boolean_T BSPR_bCellTHopErrHeal_A[48];/* Jitter healing condition for battery temperature sensor */
volatile boolean_T BSPR_bCellTHopErrStt_A[48];/* Jitter error state of battery temperature sensor */
volatile uint16_T BSPR_cntBattTCnstErrDet_A[48];/* Consistent error detect debounce for battery temperature sensor */
volatile uint16_T BSPR_cntBattTCnstErrHeal_A[48];/* Consistent error heaing debounce for battery temperature sensor */
volatile uint16_T BSPR_cntBattTHopErrDet_A[48];/* Jitter error detect debounce for battery temperature sensor */
volatile uint16_T BSPR_cntBattTHopErrHeal_A[48];/* Jitter error heaing debounce for battery temperature sensor */
volatile uint16_T BSPR_cntCellTCnstErrDet_A[48];/* Consistent error detect debounce for battery temperature sensor */
volatile uint16_T BSPR_cntCellTCnstErrHeal_A[48];/* Consistent error heaing debounce for battery temperature sensor */
volatile uint16_T BSPR_cntCellTHopErrDet_A[48];/* Jitter error detect debounce for battery temperature sensor */
volatile uint16_T BSPR_cntCellTHopErrHeal_A[48];/* Jitter error heaing debounce for battery temperature sensor */
volatile boolean_T BSPR_flgBattTempDiagEna;/* Condition of difference between maximum and minimum for temperature consistent check */
volatile boolean_T BSPR_flgBattTempExtrDiffEna;/* Condition for temperature consistent check */
volatile boolean_T BSPR_flgCellTempDiagEna;/* Condition of difference between maximum and minimum for temperature consistent check */
volatile boolean_T BSPR_flgCellTempExtrDiffEna;/* Condition for temperature consistent check */
volatile real32_T BSPR_tAvrgBattTempFlt;/* Average temperature filtered with variance  for consistent check */
volatile real32_T BSPR_tAvrgBattTempVari;/* Average variance for battery temperature  */
volatile real32_T BSPR_tAvrgCellTempFlt;/* Average temperature filtered with variance  for consistent check */
volatile real32_T BSPR_tAvrgCellTempVari;/* Average variance for battery temperature  */
volatile real32_T BSPR_tBattTHopDiff_A[48];/* Difference between original battery  temperature and filtered battery temperature */
volatile real32_T BSPR_tBattTempCnstAvrg;/* Average temperature filtered with max/min temperature */
volatile real32_T BSPR_tBattTempDiag_A[48];/* Battery temperature filtered with lowpass K */
volatile real32_T BSPR_tBattTempVari_A[48];/* Variance for battery temperature  */
volatile real32_T BSPR_tCellTHopDiff_A[48];/* Difference between original battery  temperature and filtered battery temperature */
volatile real32_T BSPR_tCellTempCnstAvrg;/* Average temperature filtered with max/min temperature */
volatile real32_T BSPR_tCellTempDiag_A[48];/* Battery temperature filtered with lowpass K */
volatile real32_T BSPR_tCellTempVari_A[48];/* Variance for battery temperature  */
volatile real32_T BSPR_tSumBattTempFlt;/* Sum value for battery temperature filtered */
volatile real32_T BSPR_tSumBattTempVari;/* Sum value for battery temperature variance */
volatile real32_T BSPR_tSumCellTempFlt;/* Sum value for battery temperature filtered */
volatile real32_T BSPR_tSumCellTempVari;/* Sum value for battery temperature variance */

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BSPR_BattTempPlausDiag_T BSPR_BattTempPlausDiag_B;

/* Block states (auto storage) */
DW_BSPR_BattTempPlausDiag_T BSPR_BattTempPlausDiag_DW;

/* Forward declaration for local functions */
static void BSP_enter_internal_CnstDiag_stt(const real32_T rtu_BSPR_tBattTemp_A
  [48], real32_T rtu_BSPR_tAvrgBattTempFlt, boolean_T
  rtu_BSPR_flgBattTempDiagEna, boolean_T rtu_BSPR_flgBattTempExtrDiffEna,
  uint8_T rtu_BSPR_cntBattTSnsrNum, real32_T rtu_BSPR_tBattTCnstFaultThres_C,
  uint8_T rtu_BSPR_cntBattTCnstErrDet_C, uint8_T rtu_BSPR_cntBattTCnstErrHeal_C,
  B_NplDiagCalc_BSPR_BattTempPl_T *localB);

/* Forward declaration for local functions */
static void BSPR_enter_internal_MeanVal_stt(const real32_T rtu_BSPR_tBattTemp_A
  [48], real32_T rtu_BSPR_tBattTempCnstAvrg, uint8_T rtu_BSPR_cntBattTSnsrNum,
  B_MeanValCalc_BSPR_BattTempPl_T *localB);

/* Forward declaration for local functions */
static void BSPR_BattTempPlausDiag_LowPassK(real32_T u, real32_T u_old, real32_T k,
  real32_T *Temp_Out, real32_T *Temp_Diff);
static void enter_internal_DiagUCellProc_st(const real32_T rtu_BSPR_tBattTemp_A
  [48], uint8_T rtu_BSPR_cntBattTSnsrNum, real32_T rtu_BSPR_cofBattTLowPassK_C,
  real32_T rtu_BSPR_tBattTHopFaultThres_C, uint8_T rtu_BSPR_cntBattTHopErrDet_C,
  uint8_T rtu_BSPR_cntBattTHopErrHeal_C, B_JitterDiag_BSPR_BattTempPla_T *localB);

/* Function for Chart: '<S8>/NplDiagCalc' */
static void BSP_enter_internal_CnstDiag_stt(const real32_T rtu_BSPR_tBattTemp_A
  [48], real32_T rtu_BSPR_tAvrgBattTempFlt, boolean_T
  rtu_BSPR_flgBattTempDiagEna, boolean_T rtu_BSPR_flgBattTempExtrDiffEna,
  uint8_T rtu_BSPR_cntBattTSnsrNum, real32_T rtu_BSPR_tBattTCnstFaultThres_C,
  uint8_T rtu_BSPR_cntBattTCnstErrDet_C, uint8_T rtu_BSPR_cntBattTCnstErrHeal_C,
  B_NplDiagCalc_BSPR_BattTempPl_T *localB)
{
  uint8_T i;
  int32_T tmp;

  /* Condition  */
  if (rtu_BSPR_flgBattTempDiagEna) {
    /* Compare  */
    for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
      localB->BSPR_bBattTCnstErrStt_A_c[i] = ((real32_T)fabs
        (rtu_BSPR_tBattTemp_A[i] - rtu_BSPR_tAvrgBattTempFlt) >=
        rtu_BSPR_tBattTCnstFaultThres_C);
    }

    /* Debounce */
    for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
      if (localB->BSPR_bBattTCnstErrStt_A_c[i]) {
        tmp = localB->BSPR_cntBattTCnstErrDet_A_g[i] + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        localB->BSPR_cntBattTCnstErrDet_A_g[i] = (uint16_T)tmp;
        localB->BSPR_cntBattTCnstErrHeal_A_k[i] = 0U;
      } else {
        tmp = localB->BSPR_cntBattTCnstErrHeal_A_k[i] + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        localB->BSPR_cntBattTCnstErrHeal_A_k[i] = (uint16_T)tmp;
        localB->BSPR_cntBattTCnstErrDet_A_g[i] = 0U;
      }
    }

    /* Output error result */
    for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
      if (localB->BSPR_cntBattTCnstErrDet_A_g[i] > rtu_BSPR_cntBattTCnstErrDet_C)
      {
        localB->BSPR_cntBattTCnstErrDet_A_g[i] = rtu_BSPR_cntBattTCnstErrDet_C;
      }
    }

    /* Output ok result */
    for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
      if (localB->BSPR_cntBattTCnstErrHeal_A_k[i] >
          rtu_BSPR_cntBattTCnstErrHeal_C) {
        localB->BSPR_cntBattTCnstErrHeal_A_k[i] = rtu_BSPR_cntBattTCnstErrHeal_C;
      }
    }
  } else {
    if (!rtu_BSPR_flgBattTempExtrDiffEna) {
      for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
        localB->BSPR_bBattTCnstErrStt_A_c[i] = false;
        localB->BSPR_cntBattTCnstErrHeal_A_k[i] = 0U;
        localB->BSPR_cntBattTCnstErrDet_A_g[i] = 0U;
      }
    }
  }
}

/*
 * System reset for atomic system:
 *    '<S8>/NplDiagCalc'
 *    '<S26>/NplDiagCalc'
 */
void BSPR_BattTemp_NplDiagCalc_Reset(B_NplDiagCalc_BSPR_BattTempPl_T *localB,
  DW_NplDiagCalc_BSPR_BattTempP_T *localDW)
{
  int32_T i;
  localDW->is_active_c10_BSPR_BattTempPlau = 0U;
  localDW->is_c10_BSPR_BattTempPlausDiag = BSPR_BattTem_IN_NO_ACTIVE_CHILD;
  memset(&localB->BSPR_cntBattTCnstErrDet_A_g[0], 0, 48U * sizeof(uint16_T));
  memset(&localB->BSPR_cntBattTCnstErrHeal_A_k[0], 0, 48U * sizeof(uint16_T));
  for (i = 0; i < 48; i++) {
    localB->BSPR_bBattTCnstErrStt_A_c[i] = false;
  }
}

/*
 * Output and update for atomic system:
 *    '<S8>/NplDiagCalc'
 *    '<S26>/NplDiagCalc'
 */
void BSPR_BattTempPlausD_NplDiagCalc(const real32_T rtu_BSPR_tBattTemp_A[48],
  real32_T rtu_BSPR_tAvrgBattTempFlt, boolean_T rtu_BSPR_flgBattTempDiagEna,
  boolean_T rtu_BSPR_flgBattTempExtrDiffEna, uint8_T rtu_BSPR_cntBattTSnsrNum,
  real32_T rtu_BSPR_tBattTCnstFaultThres_C, uint8_T
  rtu_BSPR_cntBattTCnstErrDet_C, uint8_T rtu_BSPR_cntBattTCnstErrHeal_C,
  boolean_T rtu_BSPR_bBattTCnstDiagSwt, B_NplDiagCalc_BSPR_BattTempPl_T *localB,
  DW_NplDiagCalc_BSPR_BattTempP_T *localDW)
{
  uint8_T i;
  if (localDW->is_active_c10_BSPR_BattTempPlau == 0U) {
    localDW->is_active_c10_BSPR_BattTempPlau = 1U;
    localDW->is_c10_BSPR_BattTempPlausDiag = BSPR_BattTempPl_IN_CnstDiag_stt;
    BSP_enter_internal_CnstDiag_stt(rtu_BSPR_tBattTemp_A,
      rtu_BSPR_tAvrgBattTempFlt, rtu_BSPR_flgBattTempDiagEna,
      rtu_BSPR_flgBattTempExtrDiffEna, rtu_BSPR_cntBattTSnsrNum,
      rtu_BSPR_tBattTCnstFaultThres_C, rtu_BSPR_cntBattTCnstErrDet_C,
      rtu_BSPR_cntBattTCnstErrHeal_C, localB);
  } else if (localDW->is_c10_BSPR_BattTempPlausDiag ==
             BSPR_BattTempPl_IN_CnstDiag_stt) {
    if (!rtu_BSPR_bBattTCnstDiagSwt) {
      localDW->is_c10_BSPR_BattTempPlausDiag = BSPR_BattTem_IN_DiagDisable_stt;
      for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
        localB->BSPR_bBattTCnstErrStt_A_c[i] = false;
        localB->BSPR_cntBattTCnstErrHeal_A_k[i] = 0U;
        localB->BSPR_cntBattTCnstErrDet_A_g[i] = 0U;
      }
    } else {
      localDW->is_c10_BSPR_BattTempPlausDiag = BSPR_BattTempPl_IN_CnstDiag_stt;
      BSP_enter_internal_CnstDiag_stt(rtu_BSPR_tBattTemp_A,
        rtu_BSPR_tAvrgBattTempFlt, rtu_BSPR_flgBattTempDiagEna,
        rtu_BSPR_flgBattTempExtrDiffEna, rtu_BSPR_cntBattTSnsrNum,
        rtu_BSPR_tBattTCnstFaultThres_C, rtu_BSPR_cntBattTCnstErrDet_C,
        rtu_BSPR_cntBattTCnstErrHeal_C, localB);
    }
  } else {
    if (rtu_BSPR_bBattTCnstDiagSwt) {
      localDW->is_c10_BSPR_BattTempPlausDiag = BSPR_BattTempPl_IN_CnstDiag_stt;
      BSP_enter_internal_CnstDiag_stt(rtu_BSPR_tBattTemp_A,
        rtu_BSPR_tAvrgBattTempFlt, rtu_BSPR_flgBattTempDiagEna,
        rtu_BSPR_flgBattTempExtrDiffEna, rtu_BSPR_cntBattTSnsrNum,
        rtu_BSPR_tBattTCnstFaultThres_C, rtu_BSPR_cntBattTCnstErrDet_C,
        rtu_BSPR_cntBattTCnstErrHeal_C, localB);
    }
  }
}

/* Function for Chart: '<S10>/MeanValCalc' */
static void BSPR_enter_internal_MeanVal_stt(const real32_T rtu_BSPR_tBattTemp_A
  [48], real32_T rtu_BSPR_tBattTempCnstAvrg, uint8_T rtu_BSPR_cntBattTSnsrNum,
  B_MeanValCalc_BSPR_BattTempPl_T *localB)
{
  uint8_T i;
  uint8_T SumCnt;
  int32_T tmp;

  /*  Ini */
  for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
    localB->BSPR_tBattTempVari_A_e[i] = 0.0F;
  }

  /*  SumVariance */
  i = 0U;
  localB->BSPR_tSumBattTempVari_h = 0.0F;
  while (i < rtu_BSPR_cntBattTSnsrNum) {
    localB->BSPR_tBattTempVari_A_e[i] = (real32_T)pow((real32_T)fabs
      (rtu_BSPR_tBattTemp_A[i] - rtu_BSPR_tBattTempCnstAvrg), 2.0F);
    localB->BSPR_tSumBattTempVari_h += localB->BSPR_tBattTempVari_A_e[i];
    i++;
  }

  /*  AvrgCalc */
  localB->BSPR_tAvrgBattTempVari_i = localB->BSPR_tSumBattTempVari_h / (real32_T)
    rtu_BSPR_cntBattTSnsrNum;
  i = 0U;
  SumCnt = 0U;
  localB->BSPR_tSumBattTempFlt_f = 0.0F;
  localB->BSPR_tAvrgBattTempFlt_b = 0.0F;
  while (i < rtu_BSPR_cntBattTSnsrNum) {
    if (!(localB->BSPR_tBattTempVari_A_e[i] > localB->BSPR_tAvrgBattTempVari_i))
    {
      localB->BSPR_tSumBattTempFlt_f += rtu_BSPR_tBattTemp_A[i];
      tmp = SumCnt + 1;
      if (tmp > 255) {
        tmp = 255;
      }

      SumCnt = (uint8_T)tmp;
    }

    i++;
  }

  if (SumCnt < 1) {
    localB->BSPR_tAvrgBattTempFlt_b = localB->BSPR_tSumBattTempFlt_f;
  } else {
    localB->BSPR_tAvrgBattTempFlt_b = localB->BSPR_tSumBattTempFlt_f / (real32_T)
      SumCnt;
  }
}

/*
 * System reset for atomic system:
 *    '<S10>/MeanValCalc'
 *    '<S28>/MeanValCalc_Cell'
 */
void BSPR_BattTemp_MeanValCalc_Reset(B_MeanValCalc_BSPR_BattTempPl_T *localB,
  DW_MeanValCalc_BSPR_BattTempP_T *localDW)
{
  int32_T i;
  localDW->is_active_c5_BSPR_BattTempPlaus = 0U;
  localB->BSPR_tAvrgBattTempFlt_b = 0.0F;
  localB->BSPR_tSumBattTempVari_h = 0.0F;
  localB->BSPR_tSumBattTempFlt_f = 0.0F;
  for (i = 0; i < 48; i++) {
    localB->BSPR_tBattTempVari_A_e[i] = 0.0F;
  }

  localB->BSPR_tAvrgBattTempVari_i = 0.0F;
}

/*
 * Output and update for atomic system:
 *    '<S10>/MeanValCalc'
 *    '<S28>/MeanValCalc_Cell'
 */
void BSPR_BattTempPlausD_MeanValCalc(const real32_T rtu_BSPR_tBattTemp_A[48],
  real32_T rtu_BSPR_tBattTempCnstAvrg, uint8_T rtu_BSPR_cntBattTSnsrNum,
  B_MeanValCalc_BSPR_BattTempPl_T *localB, DW_MeanValCalc_BSPR_BattTempP_T
  *localDW)
{
  if (localDW->is_active_c5_BSPR_BattTempPlaus == 0U) {
    localDW->is_active_c5_BSPR_BattTempPlaus = 1U;
    BSPR_enter_internal_MeanVal_stt(rtu_BSPR_tBattTemp_A,
      rtu_BSPR_tBattTempCnstAvrg, rtu_BSPR_cntBattTSnsrNum, localB);
  } else {
    BSPR_enter_internal_MeanVal_stt(rtu_BSPR_tBattTemp_A,
      rtu_BSPR_tBattTempCnstAvrg, rtu_BSPR_cntBattTSnsrNum, localB);
  }
}

/* Function for Chart: '<S6>/JitterDiag' */
static void BSPR_BattTempPlausDiag_LowPassK(real32_T u, real32_T u_old, real32_T k,
  real32_T *Temp_Out, real32_T *Temp_Diff)
{
  *Temp_Out = (u - u_old) * k + u_old;
  *Temp_Diff = u - *Temp_Out;
}

/* Function for Chart: '<S6>/JitterDiag' */
static void enter_internal_DiagUCellProc_st(const real32_T rtu_BSPR_tBattTemp_A
  [48], uint8_T rtu_BSPR_cntBattTSnsrNum, real32_T rtu_BSPR_cofBattTLowPassK_C,
  real32_T rtu_BSPR_tBattTHopFaultThres_C, uint8_T rtu_BSPR_cntBattTHopErrDet_C,
  uint8_T rtu_BSPR_cntBattTHopErrHeal_C, B_JitterDiag_BSPR_BattTempPla_T *localB)
{
  real32_T Temp_Diff;
  real32_T Temp_Out;
  uint8_T i;
  int32_T tmp;

  /* Compare  */
  for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
    BSPR_BattTempPlausDiag_LowPassK((real32_T)rtu_BSPR_tBattTemp_A[i], (real32_T)
      localB->BSPR_tBattTempDiag_A_c[i], (real32_T)rtu_BSPR_cofBattTLowPassK_C,
      &Temp_Out, &Temp_Diff);
    localB->BSPR_tBattTempDiag_A_c[i] = (real32_T)Temp_Out;
    localB->BSPR_tBattTHopDiff_A_i[i] = (real32_T)Temp_Diff;
    localB->BSPR_bBattTHopErrStt_A_i[i] = ((real32_T)fabs
      (localB->BSPR_tBattTHopDiff_A_i[i]) >= rtu_BSPR_tBattTHopFaultThres_C);
  }

  /* Debounce */
  for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
    if (localB->BSPR_bBattTHopErrStt_A_i[i]) {
      tmp = localB->BSPR_cntBattTHopErrDet_A_f[i] + 1;
      if (tmp > 65535) {
        tmp = 65535;
      }

      localB->BSPR_cntBattTHopErrDet_A_f[i] = (uint16_T)tmp;
      localB->BSPR_cntBattTHopErrHeal_A_f[i] = 0U;
    } else {
      tmp = localB->BSPR_cntBattTHopErrHeal_A_f[i] + 1;
      if (tmp > 65535) {
        tmp = 65535;
      }

      localB->BSPR_cntBattTHopErrHeal_A_f[i] = (uint16_T)tmp;
      localB->BSPR_cntBattTHopErrDet_A_f[i] = 0U;
    }
  }

  /* Output error result */
  for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
    if (localB->BSPR_cntBattTHopErrDet_A_f[i] > rtu_BSPR_cntBattTHopErrDet_C) {
      localB->BSPR_bBattTHopErrDet_A_e[i] = true;
      localB->BSPR_cntBattTHopErrDet_A_f[i] = rtu_BSPR_cntBattTHopErrDet_C;
    } else {
      localB->BSPR_bBattTHopErrDet_A_e[i] = false;
    }
  }

  /* Output ok result */
  for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
    if (localB->BSPR_cntBattTHopErrHeal_A_f[i] > rtu_BSPR_cntBattTHopErrHeal_C)
    {
      localB->BSPR_bBattTHopErrHeal_A_m[i] = true;
      localB->BSPR_cntBattTHopErrHeal_A_f[i] = rtu_BSPR_cntBattTHopErrHeal_C;
    } else {
      localB->BSPR_bBattTHopErrHeal_A_m[i] = false;
    }
  }
}

/*
 * System reset for atomic system:
 *    '<S6>/JitterDiag'
 *    '<S24>/JitterDiag_Cell'
 */
void BSPR_BattTempP_JitterDiag_Reset(B_JitterDiag_BSPR_BattTempPla_T *localB,
  DW_JitterDiag_BSPR_BattTempPl_T *localDW)
{
  int32_T i;
  localDW->is_active_c1_BSPR_BattTempPlaus = 0U;
  localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_Batt_IN_NO_ACTIVE_CHILD_e4;
  for (i = 0; i < 48; i++) {
    localB->BSPR_tBattTempDiag_A_c[i] = 0.0F;
    localB->BSPR_tBattTHopDiff_A_i[i] = 0.0F;
    localB->BSPR_bBattTHopErrStt_A_i[i] = false;
    localB->BSPR_bBattTHopErrDet_A_e[i] = false;
    localB->BSPR_bBattTHopErrHeal_A_m[i] = false;
    localB->BSPR_cntBattTHopErrDet_A_f[i] = 0U;
    localB->BSPR_cntBattTHopErrHeal_A_f[i] = 0U;
  }
}

/*
 * Output and update for atomic system:
 *    '<S6>/JitterDiag'
 *    '<S24>/JitterDiag_Cell'
 */
void BSPR_BattTempPlausDi_JitterDiag(const real32_T rtu_BSPR_tBattTemp_A[48],
  uint8_T rtu_BSPR_cntBattTSnsrNum, real32_T rtu_BSPR_cofBattTLowPassK_C,
  real32_T rtu_BSPR_tBattTHopFaultThres_C, uint8_T rtu_BSPR_cntBattTHopErrDet_C,
  uint8_T rtu_BSPR_cntBattTHopErrHeal_C, boolean_T rtu_BSPR_bBattTHopDiagSwt,
  B_JitterDiag_BSPR_BattTempPla_T *localB, DW_JitterDiag_BSPR_BattTempPl_T
  *localDW)
{
  uint8_T i;
  if (localDW->is_active_c1_BSPR_BattTempPlaus == 0U) {
    localDW->is_active_c1_BSPR_BattTempPlaus = 1U;
    localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_BattTempPlausDi_IN_Ini_stt;

    /*  ini */
    for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
      localB->BSPR_tBattTempDiag_A_c[i] = rtu_BSPR_tBattTemp_A[i];
      localB->BSPR_tBattTHopDiff_A_i[i] = 0.0F;
    }
  } else {
    switch (localDW->is_c1_BSPR_BattTempPlausDiag) {
     case BSPR_BattT_IN_DiagDisable_stt_m:
      if (rtu_BSPR_bBattTHopDiagSwt) {
        localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_BattT_IN_DiagUCellProc_stt;
        enter_internal_DiagUCellProc_st(rtu_BSPR_tBattTemp_A,
          rtu_BSPR_cntBattTSnsrNum, rtu_BSPR_cofBattTLowPassK_C,
          rtu_BSPR_tBattTHopFaultThres_C, rtu_BSPR_cntBattTHopErrDet_C,
          rtu_BSPR_cntBattTHopErrHeal_C, localB);
      }
      break;

     case BSPR_BattT_IN_DiagUCellProc_stt:
      if (!rtu_BSPR_bBattTHopDiagSwt) {
        localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_BattT_IN_DiagDisable_stt_m;
        for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
          localB->BSPR_bBattTHopErrHeal_A_m[i] = true;
          localB->BSPR_bBattTHopErrDet_A_e[i] = false;
          localB->BSPR_bBattTHopErrStt_A_i[i] = false;
          localB->BSPR_cntBattTHopErrHeal_A_f[i] = 0U;
          localB->BSPR_cntBattTHopErrDet_A_f[i] = 0U;
        }
      } else {
        localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_BattT_IN_DiagUCellProc_stt;
        enter_internal_DiagUCellProc_st(rtu_BSPR_tBattTemp_A,
          rtu_BSPR_cntBattTSnsrNum, rtu_BSPR_cofBattTLowPassK_C,
          rtu_BSPR_tBattTHopFaultThres_C, rtu_BSPR_cntBattTHopErrDet_C,
          rtu_BSPR_cntBattTHopErrHeal_C, localB);
      }
      break;

     default:
      if (rtu_BSPR_bBattTHopDiagSwt) {
        localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_BattT_IN_DiagUCellProc_stt;
        enter_internal_DiagUCellProc_st(rtu_BSPR_tBattTemp_A,
          rtu_BSPR_cntBattTSnsrNum, rtu_BSPR_cofBattTLowPassK_C,
          rtu_BSPR_tBattTHopFaultThres_C, rtu_BSPR_cntBattTHopErrDet_C,
          rtu_BSPR_cntBattTHopErrHeal_C, localB);
      } else {
        localDW->is_c1_BSPR_BattTempPlausDiag = BSPR_BattT_IN_DiagDisable_stt_m;
        for (i = 0U; i < rtu_BSPR_cntBattTSnsrNum; i++) {
          localB->BSPR_bBattTHopErrHeal_A_m[i] = true;
          localB->BSPR_bBattTHopErrDet_A_e[i] = false;
          localB->BSPR_bBattTHopErrStt_A_i[i] = false;
          localB->BSPR_cntBattTHopErrHeal_A_f[i] = 0U;
          localB->BSPR_cntBattTHopErrDet_A_f[i] = 0U;
        }
      }
      break;
    }
  }
}

/* Model step function */
void BSPR_BattTempPlausDiag_step(void)
{
  uint8_T i;
  real32_T rtb_Product_p;
  boolean_T rtb_Compare_j;
  boolean_T rtb_RelationalOperator_d;
  boolean_T rtb_RelationalOperator1_e;
  int32_T i_0;
  real32_T y;
  real32_T rtb_RelationalOperator_k;
  if (5.0F < BSPR_BattTempPlausDiag_DW.Delay_DSTATE_i) {
    y = 5.0F;
  } else {
    y = BSPR_BattTempPlausDiag_DW.Delay_DSTATE_i;
  }

  BSPR_bTempPlausDiagEn = (0.1F + y > 5.0F);
  BSPR_BattTempPlausDiag_DW.Delay_DSTATE_i = 0.1F + y;
  if (BSPR_bTempPlausDiagEn) {
    if (!BSPR_BattTempPlausDiag_DW.JitterDiag_MODE) {
      BSPR_BattTempP_JitterDiag_Reset(&BSPR_BattTempPlausDiag_B.sf_JitterDiag,
        &BSPR_BattTempPlausDiag_DW.sf_JitterDiag);
      BSPR_BattTempPlausDiag_DW.JitterDiag_MODE = true;
    }

    BSPR_bBattTHopDiagSwt = ((BSPR_cntBattTPlausDiag_CW & 1) == 1);
    BSPR_BattTempPlausDi_JitterDiag(((real32_T *)&(BSPR_tBattTemp_A[0])),
      BSPR_cntBattTSnsrNum, BSPR_cofBattTLowPassK_C, BSPR_tBattTHopFaultThres_C,
      BSPR_cntBattTHopErrDet_C, BSPR_cntBattTHopErrHeal_C, BSPR_bBattTHopDiagSwt,
      &BSPR_BattTempPlausDiag_B.sf_JitterDiag,
      &BSPR_BattTempPlausDiag_DW.sf_JitterDiag);
    for (i_0 = 0; i_0 < 48; i_0++) {
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTHopE[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_bBattTHopErrDet_A_e[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTHo_o[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_bBattTHopErrHeal_A_m[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTHo_j[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_bBattTHopErrStt_A_i[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattT_b[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_cntBattTHopErrDet_A_f[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattT_p[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_cntBattTHopErrHeal_A_f[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tBattTHopD[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_tBattTHopDiff_A_i[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tBattTempD[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag.BSPR_tBattTempDiag_A_c[i_0];
    }
  } else {
    if (BSPR_BattTempPlausDiag_DW.JitterDiag_MODE) {
      BSPR_BattTempPlausDiag_DW.JitterDiag_MODE = false;
    }
  }

  for (i_0 = 0; i_0 < 48; i_0++) {
    BSPR_tBattTempDiag_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tBattTempD[i_0];
    BSPR_tBattTHopDiff_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tBattTHopD[i_0];
    BSPR_bBattTHopErrStt_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTHo_j[i_0];
    BSPR_bBattTHopErrDet_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTHopE[i_0];
    BSPR_bBattTHopErrHeal_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTHo_o[i_0];
    BSPR_cntBattTHopErrDet_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattT_b[i_0];
    BSPR_cntBattTHopErrHeal_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattT_p[i_0];
  }

  if (BSPR_bTempPlausDiagEn) {
    if (!BSPR_BattTempPlausDiag_DW.CnstDiag_MODE_m) {
      BSPR_BattTempPlausDiag_DW.is_active_c4_BSPR_BattTempPlaus = 0U;
      BSPR_tSumBattTemp = 0.0F;
      BSPR_BattTempPlausDiag_DW.Delay_DSTATE_mn = 0.0F;
      BSPR_BattTempPlausDiag_DW.Delay_DSTATE_m = 0.0F;
      BSPR_BattTemp_MeanValCalc_Reset(&BSPR_BattTempPlausDiag_B.sf_MeanValCalc,
        &BSPR_BattTempPlausDiag_DW.sf_MeanValCalc);
      BSPR_BattTemp_NplDiagCalc_Reset(&BSPR_BattTempPlausDiag_B.sf_NplDiagCalc,
        &BSPR_BattTempPlausDiag_DW.sf_NplDiagCalc);
      BSPR_BattTempPlausDiag_DW.CnstDiag_MODE_m = true;
    }

    if (BSPR_BattTempPlausDiag_DW.is_active_c4_BSPR_BattTempPlaus == 0U) {
      BSPR_BattTempPlausDiag_DW.is_active_c4_BSPR_BattTempPlaus = 1U;

      /*  SumBattTemp */
      i = 0U;
      BSPR_tSumBattTemp = 0.0F;
      while (i < BSPR_cntBattTSnsrNum) {
        BSPR_tSumBattTemp = BSPR_tSumBattTemp + BSPR_tBattTemp_A[i];
        i++;
      }
    } else {
      /*  SumBattTemp */
      i = 0U;
      BSPR_tSumBattTemp = 0.0F;
      while (i < BSPR_cntBattTSnsrNum) {
        BSPR_tSumBattTemp = BSPR_tSumBattTemp + BSPR_tBattTemp_A[i];
        i++;
      }
    }

    i_0 = (int32_T)fmod((real32_T)BSPR_cntBattTSnsrNum - 2.0F, 256.0F);
    BSPR_BattTempPlausDiag_B.Divide_p = ((BSPR_tSumBattTemp - BSPR_tBattTempMax)
      - BSPR_tBattTempMin) / (real32_T)(i_0 < 0 ? (int32_T)(uint8_T)-(int8_T)
      (uint8_T)-(real32_T)i_0 : (int32_T)(uint8_T)i_0);
    y = BSPR_tBattTempMax - BSPR_tBattTempMin;
    rtb_Compare_j = ((BSPR_cntCellTPlausDiag_CW & 2) == 2);
    rtb_RelationalOperator_d = (y > BSPR_tBusbarTCnstFaultThres_C);
    rtb_RelationalOperator1_e = (y < BSPR_tBusbarTCnstHealThres_C);
    if (rtb_RelationalOperator_d) {
      rtb_RelationalOperator_k = 0.1F;
    } else {
      rtb_RelationalOperator_k = 0.0F;
    }

    if (BSPR_tiBattTCnstErrDet_C < BSPR_BattTempPlausDiag_DW.Delay_DSTATE_mn) {
      rtb_Product_p = BSPR_tiBattTCnstErrDet_C;
    } else {
      rtb_Product_p = BSPR_BattTempPlausDiag_DW.Delay_DSTATE_mn;
    }

    rtb_Product_p = (rtb_RelationalOperator_k + rtb_Product_p) * (real32_T)
      rtb_RelationalOperator_d;
    BSPR_BattTempPlausDiag_DW.Delay_DSTATE_mn = rtb_Product_p;
    BSPR_BattTempPlausDiag_B.Switch_a = (rtb_Compare_j && (rtb_Product_p >
      BSPR_tiBattTCnstErrDet_C));
    if (rtb_RelationalOperator1_e) {
      rtb_RelationalOperator_k = 0.1F;
    } else {
      rtb_RelationalOperator_k = 0.0F;
    }

    if (BSPR_tiBattTCnstErrHeal_C < BSPR_BattTempPlausDiag_DW.Delay_DSTATE_m) {
      rtb_Product_p = BSPR_tiBattTCnstErrHeal_C;
    } else {
      rtb_Product_p = BSPR_BattTempPlausDiag_DW.Delay_DSTATE_m;
    }

    rtb_Product_p = (rtb_RelationalOperator_k + rtb_Product_p) * (real32_T)
      rtb_RelationalOperator1_e;
    BSPR_BattTempPlausDiag_DW.Delay_DSTATE_m = rtb_Product_p;
    BSPR_BattTempPlausDiag_B.Switch1_l = ((!rtb_Compare_j) || (rtb_Product_p >
      BSPR_tiBattTCnstErrHeal_C));
    BSPR_bBattTCnstDiagSwt = ((BSPR_cntBattTPlausDiag_CW & 2) == 2);
    BSPR_BattTempPlausD_MeanValCalc(((real32_T *)&(BSPR_tBattTemp_A[0])),
      BSPR_BattTempPlausDiag_B.Divide_p, BSPR_cntBattTSnsrNum,
      &BSPR_BattTempPlausDiag_B.sf_MeanValCalc,
      &BSPR_BattTempPlausDiag_DW.sf_MeanValCalc);
    BSPR_flgBattTempDiagEna = ((BSPR_tBattTempCnstHi_C >= BSPR_tBattTempMax) &&
      (BSPR_tBattTempMin >= BSPR_tBattTempCnstLo_C) && ((real32_T)fabs
      (COMR_tEnvT - BSPR_BattTempPlausDiag_B.Divide_p) <=
      BSPR_tBattTempEnvtDiff_C));
    rtb_Product_p = (real32_T)fmod((real32_T)floor(y), 256.0F);
    BSPR_flgBattTempExtrDiffEna = ((rtb_Product_p < 0.0F ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-rtb_Product_p : (int32_T)(uint8_T)rtb_Product_p) >=
      BSPR_tBattTempCnstThres_C);
    BSPR_BattTempPlausD_NplDiagCalc(((real32_T *)&(BSPR_tBattTemp_A[0])),
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc.BSPR_tAvrgBattTempFlt_b,
      BSPR_flgBattTempDiagEna, BSPR_flgBattTempExtrDiffEna, BSPR_cntBattTSnsrNum,
      BSPR_tBattTCnstFaultThres_C, BSPR_cntBattTCnstErrDet_C,
      BSPR_cntBattTCnstErrHeal_C, BSPR_bBattTCnstDiagSwt,
      &BSPR_BattTempPlausDiag_B.sf_NplDiagCalc,
      &BSPR_BattTempPlausDiag_DW.sf_NplDiagCalc);
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgBattT =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc.BSPR_tAvrgBattTempFlt_b;
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgBat_p =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc.BSPR_tAvrgBattTempVari_i;
    for (i_0 = 0; i_0 < 48; i_0++) {
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTCnst[i_0] =
        BSPR_BattTempPlausDiag_B.sf_NplDiagCalc.BSPR_bBattTCnstErrStt_A_c[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattTCn[i_0] =
        BSPR_BattTempPlausDiag_B.sf_NplDiagCalc.BSPR_cntBattTCnstErrDet_A_g[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattT_h[i_0] =
        BSPR_BattTempPlausDiag_B.sf_NplDiagCalc.BSPR_cntBattTCnstErrHeal_A_k[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tBattTempV[i_0] =
        BSPR_BattTempPlausDiag_B.sf_MeanValCalc.BSPR_tBattTempVari_A_e[i_0];
    }

    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumBattTe =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc.BSPR_tSumBattTempFlt_f;
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumBatt_b =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc.BSPR_tSumBattTempVari_h;
  } else {
    if (BSPR_BattTempPlausDiag_DW.CnstDiag_MODE_m) {
      BSPR_BattTempPlausDiag_DW.CnstDiag_MODE_m = false;
    }
  }

  BSPR_tAvrgBattTempFlt =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgBattT;
  BSPR_tSumBattTempVari =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumBatt_b;
  BSPR_tSumBattTempFlt =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumBattTe;
  BSPR_tAvrgBattTempVari =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgBat_p;
  BSPR_tBattTempCnstAvrg = BSPR_BattTempPlausDiag_B.Divide_p;
  BSPR_bBattTCnstErrDet_A = BSPR_BattTempPlausDiag_B.Switch_a;
  BSPR_bBattTCnstErrHeal_A = BSPR_BattTempPlausDiag_B.Switch1_l;
  for (i_0 = 0; i_0 < 48; i_0++) {
    BSPR_tBattTempVari_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tBattTempV[i_0];
    BSPR_bBattTCnstErrStt_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bBattTCnst[i_0];
    BSPR_cntBattTCnstErrDet_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattTCn[i_0];
    BSPR_cntBattTCnstErrHeal_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattT_h[i_0];
  }

  if (5.0F < BSPR_BattTempPlausDiag_DW.Delay_DSTATE) {
    y = 5.0F;
  } else {
    y = BSPR_BattTempPlausDiag_DW.Delay_DSTATE;
  }

  BSPR_bCellTempPlausDiagEn = (0.1F + y > 5.0F);
  BSPR_BattTempPlausDiag_DW.Delay_DSTATE = 0.1F + y;
  if (BSPR_bCellTempPlausDiagEn) {
    if (!BSPR_BattTempPlausDiag_DW.JitterDiag_Cell_MODE) {
      BSPR_BattTempP_JitterDiag_Reset
        (&BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell,
         &BSPR_BattTempPlausDiag_DW.sf_JitterDiag_Cell);
      BSPR_BattTempPlausDiag_DW.JitterDiag_Cell_MODE = true;
    }

    BSPR_bCellTHopDiagSwt = ((BSPR_cntCellTPlausDiag_CW & 1) == 1);
    BSPR_BattTempPlausDi_JitterDiag(((real32_T *)&(BSPR_tCellTemp_A[0])),
      BSPR_cntCellTSnsrNum, BSPR_cofBattTLowPassK_C, BSPR_tBattTHopFaultThres_C,
      BSPR_cntBattTHopErrDet_C, BSPR_cntBattTHopErrHeal_C, BSPR_bCellTHopDiagSwt,
      &BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell,
      &BSPR_BattTempPlausDiag_DW.sf_JitterDiag_Cell);
    for (i_0 = 0; i_0 < 48; i_0++) {
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTHopE[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_bBattTHopErrDet_A_e[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTHo_a[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_bBattTHopErrHeal_A_m[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTHo_h[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_bBattTHopErrStt_A_i[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattTHo[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_cntBattTHopErrHeal_A_f[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntCellTHo[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_cntBattTHopErrDet_A_f[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tCellTHopD[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_tBattTHopDiff_A_i[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tCellTempD[i_0] =
        BSPR_BattTempPlausDiag_B.sf_JitterDiag_Cell.BSPR_tBattTempDiag_A_c[i_0];
    }
  } else {
    if (BSPR_BattTempPlausDiag_DW.JitterDiag_Cell_MODE) {
      BSPR_BattTempPlausDiag_DW.JitterDiag_Cell_MODE = false;
    }
  }

  for (i_0 = 0; i_0 < 48; i_0++) {
    BSPR_tCellTempDiag_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tCellTempD[i_0];
    BSPR_tCellTHopDiff_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tCellTHopD[i_0];
    BSPR_bCellTHopErrStt_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTHo_h[i_0];
    BSPR_bCellTHopErrDet_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTHopE[i_0];
    BSPR_bCellTHopErrHeal_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTHo_a[i_0];
    BSPR_cntCellTHopErrDet_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntCellTHo[i_0];
    BSPR_cntCellTHopErrHeal_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntBattTHo[i_0];
  }

  if (BSPR_bCellTempPlausDiagEn) {
    if (!BSPR_BattTempPlausDiag_DW.CnstDiag_MODE) {
      BSPR_BattTempPlausDiag_DW.is_active_c2_BSPR_BattTempPlaus = 0U;
      BSPR_tSumCellTemp = 0.0F;
      BSPR_BattTempPlausDiag_DW.Delay_DSTATE_f = 0.0F;
      BSPR_BattTempPlausDiag_DW.Delay_DSTATE_l = 0.0F;
      BSPR_BattTemp_MeanValCalc_Reset
        (&BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell,
         &BSPR_BattTempPlausDiag_DW.sf_MeanValCalc_Cell);
      BSPR_BattTemp_NplDiagCalc_Reset(&BSPR_BattTempPlausDiag_B.sf_NplDiagCalc_j,
        &BSPR_BattTempPlausDiag_DW.sf_NplDiagCalc_j);
      BSPR_BattTempPlausDiag_DW.CnstDiag_MODE = true;
    }

    if (BSPR_BattTempPlausDiag_DW.is_active_c2_BSPR_BattTempPlaus == 0U) {
      BSPR_BattTempPlausDiag_DW.is_active_c2_BSPR_BattTempPlaus = 1U;

      /*  SumBattTemp */
      i = 0U;
      BSPR_tSumCellTemp = 0.0F;
      while (i < BSPR_cntCellTSnsrNum) {
        BSPR_tSumCellTemp = BSPR_tSumCellTemp + BSPR_tCellTemp_A[i];
        i++;
      }
    } else {
      /*  SumBattTemp */
      i = 0U;
      BSPR_tSumCellTemp = 0.0F;
      while (i < BSPR_cntCellTSnsrNum) {
        BSPR_tSumCellTemp = BSPR_tSumCellTemp + BSPR_tCellTemp_A[i];
        i++;
      }
    }

    i_0 = (int32_T)fmod((real32_T)BSPR_cntCellTSnsrNum - 2.0F, 256.0F);
    BSPR_BattTempPlausDiag_B.Divide = ((BSPR_tSumCellTemp - BSPR_tCellTempMax) -
      BSPR_tCellTempMin) / (real32_T)(i_0 < 0 ? (int32_T)(uint8_T)-(int8_T)
      (uint8_T)-(real32_T)i_0 : (int32_T)(uint8_T)i_0);
    y = BSPR_tCellTempMax - BSPR_tCellTempMin;
    rtb_Compare_j = ((BSPR_cntCellTPlausDiag_CW & 2) == 2);
    rtb_RelationalOperator_d = (y > BSPR_tCellTCnstFaultThres_C);
    rtb_RelationalOperator1_e = (y < BSPR_tCellTCnstHealThres_C);
    if (rtb_RelationalOperator_d) {
      rtb_RelationalOperator_k = 0.1F;
    } else {
      rtb_RelationalOperator_k = 0.0F;
    }

    if (BSPR_tiBattTCnstErrDet_C < BSPR_BattTempPlausDiag_DW.Delay_DSTATE_f) {
      rtb_Product_p = BSPR_tiBattTCnstErrDet_C;
    } else {
      rtb_Product_p = BSPR_BattTempPlausDiag_DW.Delay_DSTATE_f;
    }

    rtb_Product_p = (rtb_RelationalOperator_k + rtb_Product_p) * (real32_T)
      rtb_RelationalOperator_d;
    BSPR_BattTempPlausDiag_DW.Delay_DSTATE_f = rtb_Product_p;
    BSPR_BattTempPlausDiag_B.Switch = (rtb_Compare_j && (rtb_Product_p >
      BSPR_tiBattTCnstErrDet_C));
    if (rtb_RelationalOperator1_e) {
      rtb_RelationalOperator_k = 0.1F;
    } else {
      rtb_RelationalOperator_k = 0.0F;
    }

    if (BSPR_tiBattTCnstErrHeal_C < BSPR_BattTempPlausDiag_DW.Delay_DSTATE_l) {
      rtb_Product_p = BSPR_tiBattTCnstErrHeal_C;
    } else {
      rtb_Product_p = BSPR_BattTempPlausDiag_DW.Delay_DSTATE_l;
    }

    rtb_Product_p = (rtb_RelationalOperator_k + rtb_Product_p) * (real32_T)
      rtb_RelationalOperator1_e;
    BSPR_BattTempPlausDiag_DW.Delay_DSTATE_l = rtb_Product_p;
    BSPR_BattTempPlausDiag_B.Switch1 = ((!rtb_Compare_j) || (rtb_Product_p >
      BSPR_tiBattTCnstErrHeal_C));
    BSPR_bCellTCnstDiagSwt = ((BSPR_cntCellTPlausDiag_CW & 2) == 2);
    BSPR_BattTempPlausD_MeanValCalc(((real32_T *)&(BSPR_tCellTemp_A[0])),
      BSPR_BattTempPlausDiag_B.Divide, BSPR_cntCellTSnsrNum,
      &BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell,
      &BSPR_BattTempPlausDiag_DW.sf_MeanValCalc_Cell);
    BSPR_flgCellTempDiagEna = ((BSPR_tBattTempCnstHi_C >= BSPR_tCellTempMax) &&
      (BSPR_tCellTempMin >= BSPR_tBattTempCnstLo_C) && ((real32_T)fabs
      (COMR_tEnvT - BSPR_BattTempPlausDiag_B.Divide) <= BSPR_tBattTempEnvtDiff_C));
    rtb_Product_p = (real32_T)fmod((real32_T)floor(y), 256.0F);
    BSPR_flgCellTempExtrDiffEna = ((rtb_Product_p < 0.0F ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-rtb_Product_p : (int32_T)(uint8_T)rtb_Product_p) >=
      BSPR_tBattTempCnstThres_C);
    BSPR_BattTempPlausD_NplDiagCalc(((real32_T *)&(BSPR_tCellTemp_A[0])),
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell.BSPR_tAvrgBattTempFlt_b,
      BSPR_flgCellTempDiagEna, BSPR_flgCellTempExtrDiffEna, BSPR_cntCellTSnsrNum,
      BSPR_tBattTCnstFaultThres_C, BSPR_cntBattTCnstErrDet_C,
      BSPR_cntBattTCnstErrHeal_C, BSPR_bCellTCnstDiagSwt,
      &BSPR_BattTempPlausDiag_B.sf_NplDiagCalc_j,
      &BSPR_BattTempPlausDiag_DW.sf_NplDiagCalc_j);
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgCellT =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell.BSPR_tAvrgBattTempFlt_b;
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgCel_m =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell.BSPR_tAvrgBattTempVari_i;
    for (i_0 = 0; i_0 < 48; i_0++) {
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTCnst[i_0] =
        BSPR_BattTempPlausDiag_B.sf_NplDiagCalc_j.BSPR_bBattTCnstErrStt_A_c[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntCellTCn[i_0] =
        BSPR_BattTempPlausDiag_B.sf_NplDiagCalc_j.BSPR_cntBattTCnstErrDet_A_g[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntCellT_n[i_0] =
        BSPR_BattTempPlausDiag_B.sf_NplDiagCalc_j.BSPR_cntBattTCnstErrHeal_A_k[i_0];
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tCellTempV[i_0] =
        BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell.BSPR_tBattTempVari_A_e[i_0];
    }

    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumCellTe =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell.BSPR_tSumBattTempFlt_f;
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumCell_h =
      BSPR_BattTempPlausDiag_B.sf_MeanValCalc_Cell.BSPR_tSumBattTempVari_h;
  } else {
    if (BSPR_BattTempPlausDiag_DW.CnstDiag_MODE) {
      BSPR_BattTempPlausDiag_DW.CnstDiag_MODE = false;
    }
  }

  BSPR_tAvrgCellTempFlt =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgCellT;
  BSPR_tSumCellTempVari =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumCell_h;
  BSPR_tSumCellTempFlt =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tSumCellTe;
  BSPR_tAvrgCellTempVari =
    BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tAvrgCel_m;
  BSPR_tCellTempCnstAvrg = BSPR_BattTempPlausDiag_B.Divide;
  BSPR_bCellTCnstErrDet_A = BSPR_BattTempPlausDiag_B.Switch;
  BSPR_bCellTCnstErrHeal_A = BSPR_BattTempPlausDiag_B.Switch1;
  for (i_0 = 0; i_0 < 48; i_0++) {
    BSPR_tCellTempVari_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_tCellTempV[i_0];
    BSPR_bCellTCnstErrStt_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_bCellTCnst[i_0];
    BSPR_cntCellTCnstErrDet_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntCellTCn[i_0];
    BSPR_cntCellTCnstErrHeal_A[i_0] =
      BSPR_BattTempPlausDiag_B.OutportBufferForBSPR_cntCellT_n[i_0];
  }
}

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

  /* block I/O */

  /* custom signals */
  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_tBattTempDiag_A[i] = 0.0F;
    }
  }

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

  BSPR_tAvrgBattTempFlt = 0.0F;
  BSPR_tSumBattTempVari = 0.0F;
  BSPR_tSumBattTempFlt = 0.0F;

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

  BSPR_tAvrgBattTempVari = 0.0F;
  BSPR_tBattTempCnstAvrg = 0.0F;

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

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

  BSPR_tAvrgCellTempFlt = 0.0F;
  BSPR_tSumCellTempVari = 0.0F;
  BSPR_tSumCellTempFlt = 0.0F;

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

  BSPR_tAvrgCellTempVari = 0.0F;
  BSPR_tCellTempCnstAvrg = 0.0F;

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntBattTHopErrDet_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntBattTHopErrHeal_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntBattTCnstErrDet_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntBattTCnstErrHeal_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntCellTHopErrDet_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntCellTHopErrHeal_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntCellTCnstErrDet_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_cntCellTCnstErrHeal_A[i] = ((uint16_T)0U);
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bBattTHopErrStt_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bBattTHopErrDet_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bBattTHopErrHeal_A[i] = false;
    }
  }

  BSPR_bBattTCnstErrDet_A = false;
  BSPR_bBattTCnstErrHeal_A = false;

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bBattTCnstErrStt_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bCellTHopErrStt_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bCellTHopErrDet_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bCellTHopErrHeal_A[i] = false;
    }
  }

  BSPR_bCellTCnstErrDet_A = false;
  BSPR_bCellTCnstErrHeal_A = false;

  {
    int32_T i;
    for (i = 0; i < 48; i++) {
      BSPR_bCellTCnstErrStt_A[i] = false;
    }
  }
}

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