/*
 * File: BSPR_CellVoltDiag.c
 *
 * Code generated for Simulink model 'BSPR_CellVoltDiag'.
 *
 * Model version                  : 1.1099
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Wed Jul 21 14:36:19 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 "BSPR_CellVoltDiag.h"
#include "BSPR_CellVoltDiag_private.h"
#include "look1_iflf_binlxpw.h"
#include "look2_iflf_binlxpw.h"

/* Exported data definition */

/* Definition for custom storage class: FileScope */
static boolean_T BSPR_bMaxFaultInhib;
static boolean_T BSPR_bMaxFusfInhib;
static boolean_T BSPR_bMinAlrmWarnInhib;
static boolean_T BSPR_bMinFaultInhib;
static boolean_T BSPR_bMinFusfInhib;
static real32_T BSPR_uCellVoltMeanCoord;
static real32_T BSPR_uCellVoltRngHiFusf;
static real32_T BSPR_uCellVoltRngHiWarnAlrm;
static real32_T BSPR_uCellVoltRngLoFault;
static real32_T BSPR_uCellVoltRngLoFusf;
static real32_T BSPR_uCellVoltRngLoWarnAlrm;
static real32_T BSPR_uSumExtmVoltCell;
static real32_T BSPR_uSumExtmVoltModu;

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

/* Definition for custom storage class: Volatile */
volatile uint8_T DFC_CellVoltAlrmMax_ASW;  /* Maximum alarm fault of cell voltage */
volatile uint8_T DFC_CellVoltAlrmMin_ASW;  /* Minimum alarm fault of cell voltage */
volatile uint8_T DFC_CellVoltFaultMax_ASW; /* Maximum fault of cell voltage */
volatile uint8_T DFC_CellVoltFaultMin_ASW; /* Minimum fault of cell voltage */
volatile uint8_T DFC_CellVoltFusfMax_ASW;  /* Maximum function safety fault of cell voltage */
volatile uint8_T DFC_CellVoltFusfMin_ASW;  /* Minimum function safety fault of cell voltage */
volatile uint8_T DFC_CellVoltNpl_ASW;      /* Npl fault of cell voltage */
volatile uint8_T DFC_CellVoltWarnMax_ASW;  /* Maximum warn fault of cell voltage */
volatile uint8_T DFC_CellVoltWarnMin_ASW;  /* Minimum warn fault of cell voltage */

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BSPR_bCellVoltMaxAlrmDet;/* Max alarm detect flag of out of range diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMaxFaultDet;/* Max fault detect flag of out of range diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMaxFaultHeal;/* Max fault healing flag of out of range diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMaxFusfDet;/* Max fault detect flag of out of range very high diagnosis for cell voltage  */
volatile boolean_T BSPR_bCellVoltMaxFusfHeal;/* Max fault healing flag of out of range very high diagnosis for cell voltage  */
volatile boolean_T BSPR_bCellVoltMaxHeal;/* Max alarm&warn healing flag of out of range high diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMaxWarnAlrm;/* Condition:battery current stable status */
volatile boolean_T BSPR_bCellVoltMaxWarnDet;/* Max warn detect flag of out of range high diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMinAlrmDet;/* Min alarm detect flag of out of range diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMinFaultDet;/* Min fault detect flag of out of range diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMinFaultHeal;/* Min fault healing flag of out of range diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMinFusfDet;/* Max fault detect flag of out of range very low diagnosis for cell voltage  */
volatile boolean_T BSPR_bCellVoltMinFusfHeal;/* Max fault healing flag of out of range very low diagnosis for cell voltage  */
volatile boolean_T BSPR_bCellVoltMinHeal;/* Min alarm&warn healing flag of out of range high diagnosis for cell voltage */
volatile boolean_T BSPR_bCellVoltMinWarnDet;/* Min warn detect flag of out of range high diagnosis for cell voltage */
volatile boolean_T BSPR_bMaxAlrmWarnInhib;/* Condition:battery current stable status */
volatile boolean_T BSPR_bUCellNplErrDet_A[150];/* Error detect flag for cell voltage plausible diagnosis */
volatile boolean_T BSPR_bUCellNplErrHeal_A[150];/* Error healing flag for cell voltage plausible diagnosis */
volatile boolean_T BSPR_bUCellNplErrStt_A[150];/* Error diagnosis status for cell voltage plausible diagnosis */
volatile uint16_T BSPR_cntUCellNplErrDet_A[150];/* Event debounce of error detect for cell voltage plausible diagnosis */
volatile uint16_T BSPR_cntUCellNplErrHeal_A[150];/* Event debounce of error heal for cell voltage plausible diagnosis */
volatile boolean_T BSPR_flgCellVoltDiagEn;/* Condition:battery current stable status */
volatile boolean_T BSPR_flgCurrHopEn;  /* Condition:battery current stable status */
volatile real32_T BSPR_uSumVoltCell;   /* Sum value for battery cell voltage in current system */
volatile real32_T BSPR_uVoltCellMean;  /* Model voltage for cell voltage diagnosis calculated through cell voltage */
volatile real32_T BSPR_uVoltModuMean;  /* Model voltage for cell voltage diagnosis calculated through module voltage */

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BSPR_CellVoltDiag_T BSPR_CellVoltDiag_B;

/* Block states (auto storage) */
DW_BSPR_CellVoltDiag_T BSPR_CellVoltDiag_DW;

/* Forward declaration for local functions */
static void BSPR_CellVoltDiag_sort(const real32_T f_MINP_CellVol[150], uint8_T
  num, real32_T f_Vol_ASD[150], uint8_T f_index[150]);
static void BSPR_CellVoltDiag_sort_e(const real32_T f_MINP_CellVol[24], uint8_T
  num, real32_T f_Vol_ASD[24], uint8_T f_index[24]);
static void enter_internal_DiagUCellProc_st(const real32_T
  *BSPR_uCellVoltNplDiag_CUR_m);

/*
 * Output and update for atomic system:
 *    '<S8>/CellVoltBMSDebounceStartZero8'
 *    '<S40>/CellVoltBMSDebounceStartZero4'
 *    '<S40>/CellVoltBMSDebounceStartZero5'
 *    '<S41>/CellVoltBMSDebounceStartZero6'
 *    '<S41>/CellVoltBMSDebounceStartZero7'
 *    '<S42>/CellVoltBMSDebounceStartZero'
 *    '<S42>/CellVoltBMSDebounceStartZero1'
 *    '<S42>/CellVoltBMSDebounceStartZero2'
 *    '<S42>/CellVoltBMSDebounceStartZero3'
 */
void B_CellVoltBMSDebounceStartZero8(boolean_T rtu_Signal, real32_T
  rtu_Hearl2Fault, real32_T rtu_FaultStep, real32_T rtu_Fault2Heal, real32_T
  rtu_HealStep, B_CellVoltBMSDebounceStartZer_T *localB,
  DW_CellVoltBMSDebounceStartZe_T *localDW)
{
  boolean_T rtb_RelationalOperator_d;
  boolean_T rtb_RelationalOperator_e;
  uint16_T rtb_Switch2_a;
  uint16_T rtb_Switch2_gz;
  real32_T tmp;
  if (localDW->StateName_o) {
    rtb_Switch2_a = 0U;
  } else {
    rtb_Switch2_a = localDW->StateName;
  }

  if (rtu_Signal) {
    tmp = (real32_T)fmod((real32_T)floor(rtu_FaultStep), 65536.0F);
    rtb_Switch2_a = (uint16_T)((uint32_T)(tmp < 0.0F ? (int32_T)(uint16_T)
      -(int16_T)(uint16_T)-tmp : (int32_T)(uint16_T)tmp) + rtb_Switch2_a);
    if (!(rtb_Switch2_a < 60000)) {
      rtb_Switch2_a = 60000U;
    }
  } else if (rtb_Switch2_a >= rtu_FaultStep) {
    tmp = (real32_T)fmod((real32_T)floor(rtu_FaultStep), 65536.0F);
    rtb_Switch2_a = (uint16_T)((uint32_T)rtb_Switch2_a - (tmp < 0.0F ? (int32_T)
      (uint16_T)-(int16_T)(uint16_T)-tmp : (int32_T)(uint16_T)tmp));
  } else {
    rtb_Switch2_a = 0U;
  }

  rtb_RelationalOperator_d = (rtb_Switch2_a > rtu_Hearl2Fault);
  if (localDW->StateName_n) {
    rtb_Switch2_gz = 0U;
  } else {
    rtb_Switch2_gz = localDW->StateName_d;
  }

  if (!rtu_Signal) {
    tmp = (real32_T)fmod((real32_T)floor(rtu_HealStep), 65536.0F);
    rtb_Switch2_gz = (uint16_T)((uint32_T)(tmp < 0.0F ? (int32_T)(uint16_T)
      -(int16_T)(uint16_T)-tmp : (int32_T)(uint16_T)tmp) + rtb_Switch2_gz);
    if (!(rtb_Switch2_gz < 60000)) {
      rtb_Switch2_gz = 60000U;
    }
  } else if (rtb_Switch2_gz >= rtu_HealStep) {
    tmp = (real32_T)fmod((real32_T)floor(rtu_HealStep), 65536.0F);
    rtb_Switch2_gz = (uint16_T)((uint32_T)rtb_Switch2_gz - (tmp < 0.0F ?
      (int32_T)(uint16_T)-(int16_T)(uint16_T)-tmp : (int32_T)(uint16_T)tmp));
  } else {
    rtb_Switch2_gz = 0U;
  }

  rtb_RelationalOperator_e = (rtb_Switch2_gz > rtu_Fault2Heal);
  if (!localB->Switch) {
    localB->Switch = rtb_RelationalOperator_d;
  } else {
    localB->Switch = !rtb_RelationalOperator_e;
  }

  localDW->StateName_o = rtb_RelationalOperator_d;
  localDW->StateName = rtb_Switch2_a;
  localDW->StateName_n = rtb_RelationalOperator_e;
  localDW->StateName_d = rtb_Switch2_gz;
}

/* Function for Chart: '<S17>/CompareCalc_CellVolt' */
static void BSPR_CellVoltDiag_sort(const real32_T f_MINP_CellVol[150], uint8_T
  num, real32_T f_Vol_ASD[150], uint8_T f_index[150])
{
  uint8_T f_i;
  uint8_T f_j;
  uint16_T temp;
  int32_T i;
  for (i = 0; i < 150; i++) {
    f_Vol_ASD[i] = 0.0F;
    f_index[i] = 0U;
  }

  for (f_i = 0U; f_i < num; f_i++) {
    f_Vol_ASD[f_i] = f_MINP_CellVol[f_i];
  }

  for (f_i = 0U; f_i < num; f_i++) {
    temp = 0U;
    f_index[f_i] = 0U;
    for (f_j = 0U; f_j < num; f_j++) {
      if (f_Vol_ASD[f_j] > temp) {
        temp = (uint16_T)f_Vol_ASD[f_j];
        f_index[f_i] = f_j;
      }
    }

    f_Vol_ASD[f_index[f_i]] = 0.0F;
  }

  for (f_i = 0U; f_i < num; f_i++) {
    f_Vol_ASD[f_i] = f_MINP_CellVol[f_index[f_i]];
  }
}

/* Function for Chart: '<S21>/CompareCalc_ModuVolt' */
static void BSPR_CellVoltDiag_sort_e(const real32_T f_MINP_CellVol[24], uint8_T
  num, real32_T f_Vol_ASD[24], uint8_T f_index[24])
{
  uint8_T f_i;
  uint8_T f_j;
  uint16_T temp;
  int32_T i;
  for (i = 0; i < 24; i++) {
    f_Vol_ASD[i] = 0.0F;
    f_index[i] = 0U;
  }

  for (f_i = 0U; f_i < num; f_i++) {
    f_Vol_ASD[f_i] = f_MINP_CellVol[f_i];
  }

  for (f_i = 0U; f_i < num; f_i++) {
    temp = 0U;
    f_index[f_i] = 0U;
    for (f_j = 0U; f_j < num; f_j++) {
      if (f_Vol_ASD[f_j] > temp) {
        temp = (uint16_T)f_Vol_ASD[f_j];
        f_index[f_i] = f_j;
      }
    }

    f_Vol_ASD[f_index[f_i]] = 0.0F;
  }

  for (f_i = 0U; f_i < num; f_i++) {
    f_Vol_ASD[f_i] = f_MINP_CellVol[f_index[f_i]];
  }
}

/* Function for Chart: '<S8>/NplDiagCalc' */
static void enter_internal_DiagUCellProc_st(const real32_T
  *BSPR_uCellVoltNplDiag_CUR_m)
{
  uint8_T i;
  int32_T tmp;
  if (BSPR_flgCellVoltDiagEn) {
    /* Compare  */
    for (i = 0U; i < BSPR_cntCellSerNum; i++) {
      BSPR_CellVoltDiag_B.BSPR_bUCellNplErrStt_A_f[i] = !((real32_T)fabs
        (BSPR_uCellVolt_A[i] - BSPR_uCellVoltMeanCoord) <=
        *BSPR_uCellVoltNplDiag_CUR_m);
    }

    /* Debounce */
    for (i = 0U; i < BSPR_cntCellSerNum; i++) {
      if (BSPR_CellVoltDiag_B.BSPR_bUCellNplErrStt_A_f[i]) {
        tmp = BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrDet_A_d[i] + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrDet_A_d[i] = (uint16_T)tmp;
        BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrHeal_A_e[i] = 0U;
      } else {
        tmp = BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrHeal_A_e[i] + 1;
        if (tmp > 65535) {
          tmp = 65535;
        }

        BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrHeal_A_e[i] = (uint16_T)tmp;
        BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrDet_A_d[i] = 0U;
      }
    }

    /* Output error result */
    for (i = 0U; i < BSPR_cntCellSerNum; i++) {
      if (BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrDet_A_d[i] >
          BSPR_cntUCellNplErrThres_C) {
        BSPR_CellVoltDiag_B.BSPR_bUCellNplErrDet_A_c[i] = true;
        BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrDet_A_d[i] =
          BSPR_cntUCellNplErrThres_C;
      } else {
        BSPR_CellVoltDiag_B.BSPR_bUCellNplErrDet_A_c[i] = false;
      }
    }

    /* Output ok result */
    for (i = 0U; i < BSPR_cntCellSerNum; i++) {
      if (BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrHeal_A_e[i] >
          BSPR_cntUCellNplOkThres_C) {
        BSPR_CellVoltDiag_B.BSPR_bUCellNplErrHeal_A_n[i] = true;
        BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrHeal_A_e[i] =
          BSPR_cntUCellNplOkThres_C;
      } else {
        BSPR_CellVoltDiag_B.BSPR_bUCellNplErrHeal_A_n[i] = false;
      }
    }
  }
}

/* Model step function */
void BSPR_CellVoltDiag_step(void)
{
  uint8_T i;
  real32_T rtb_Switch1;
  boolean_T rtb_Compare_c;
  boolean_T rtb_Compare_i;
  boolean_T rtb_Compare_k;
  boolean_T rtb_BSPR_bCellVoltMinWarnAlrm;
  boolean_T rtb_Compare;
  real32_T rtb_Vol_ASD_j[150];
  uint8_T rtb_index_p[150];
  real32_T rtb_Vol_ASD[24];
  uint8_T rtb_index[24];
  int32_T i_0;
  if (BSPR_CellVoltDiag_DW.Delay_DSTATE > 0.0F) {
    rtb_Switch1 = BSPR_iBattCurr;
  } else {
    rtb_Switch1 = (BSPR_iBattCurr - BSPR_CellVoltDiag_DW.UnitDelay_DSTATE) *
      BSPR_cofCurrFltCellRng_C + BSPR_CellVoltDiag_DW.UnitDelay_DSTATE;
  }

  BSPR_CellVoltDiag_DW.UnitDelay_DSTATE = rtb_Switch1;
  BSPR_CellVoltDiag_DW.Delay_DSTATE = 0.0F;
  rtb_Switch1 = (real32_T)fabs(rtb_Switch1 - BSPR_iBattCurr);
  BSPR_flgCurrHopEn = (rtb_Switch1 <= BSPR_iCurrHopFltDiff_C);
  if (BSPR_cntCellVltRngEnvtCsdr_CW == 0) {
    i_0 = ((BSPR_tEnvTCellVoltRngHi_C >= COMR_tEnvT) && (COMR_tEnvT >=
            BSPR_tEnvTCellVoltRnglo_C));
  } else {
    i_0 = 1;
  }

  BSPR_flgCellVoltDiagEn = (BSPR_flgCurrHopEn && ((BSPR_iBattCurr <=
    BSPR_iCellVoltRngCurrHi_C) && (BSPR_iBattCurr >= BSPR_iCellVoltRngCurrLo_C))
    && ((BSPR_tCellTempMax <= BSPR_tBattTempCellVoltRngHi_C) &&
        (BSPR_tCellTempMin >= BSPR_tBattTempCellVoltRngLo_C)) && (i_0 != 0));
  rtb_Switch1 = BSPR_uCellVolt_A[0];
  for (i_0 = 0; i_0 < 149; i_0++) {
    rtb_Switch1 += BSPR_uCellVolt_A[i_0 + 1];
  }

  if (BSPR_CellVoltDiag_DW.is_active_c1_BSPR_CellVoltDiag == 0U) {
    BSPR_CellVoltDiag_DW.is_active_c1_BSPR_CellVoltDiag = 1U;

    /* Sort */
    for (i = 0U; i < BSPR_cntCellSerNum; i++) {
      BSPR_CellVoltDiag_DW.BSPR_uCellVoltDiag_A[i] = BSPR_uCellVolt_A[i];
    }

    BSPR_CellVoltDiag_sort(BSPR_CellVoltDiag_DW.BSPR_uCellVoltDiag_A,
      BSPR_cntCellSerNum, rtb_Vol_ASD_j, rtb_index_p);
  } else {
    /* Sort */
    for (i = 0U; i < BSPR_cntCellSerNum; i++) {
      BSPR_CellVoltDiag_DW.BSPR_uCellVoltDiag_A[i] = BSPR_uCellVolt_A[i];
    }

    BSPR_CellVoltDiag_sort(BSPR_CellVoltDiag_DW.BSPR_uCellVoltDiag_A,
      BSPR_cntCellSerNum, rtb_Vol_ASD_j, rtb_index_p);
  }

  if (BSPR_CellVoltDiag_DW.is_active_c2_BSPR_CellVoltDiag == 0U) {
    BSPR_CellVoltDiag_DW.is_active_c2_BSPR_CellVoltDiag = 1U;

    /*  SumCellVolt */
    i = 0U;
    BSPR_uSumExtmVoltCell = 0.0F;
    while (i < BSPR_cntCellAvlNum_C) {
      BSPR_uSumExtmVoltCell = BSPR_uSumExtmVoltCell + rtb_Vol_ASD_j[i];
      i++;
    }

    i_0 = BSPR_cntCellSerNum - BSPR_cntCellAvlNum_C;
    if (i_0 < 0) {
      i_0 = 0;
    }

    for (i = (uint8_T)i_0; i < BSPR_cntCellSerNum; i++) {
      BSPR_uSumExtmVoltCell = BSPR_uSumExtmVoltCell + rtb_Vol_ASD_j[i];
    }
  } else {
    /*  SumCellVolt */
    i = 0U;
    BSPR_uSumExtmVoltCell = 0.0F;
    while (i < BSPR_cntCellAvlNum_C) {
      BSPR_uSumExtmVoltCell = BSPR_uSumExtmVoltCell + rtb_Vol_ASD_j[i];
      i++;
    }

    i_0 = BSPR_cntCellSerNum - BSPR_cntCellAvlNum_C;
    if (i_0 < 0) {
      i_0 = 0;
    }

    for (i = (uint8_T)i_0; i < BSPR_cntCellSerNum; i++) {
      BSPR_uSumExtmVoltCell = BSPR_uSumExtmVoltCell + rtb_Vol_ASD_j[i];
    }
  }

  rtb_Switch1 -= BSPR_uSumExtmVoltCell;
  BSPR_uVoltCellMean = rtb_Switch1 / (real32_T)(uint8_T)(BSPR_cntCellSerNum -
    (uint8_T)(BSPR_cntCellAvlNum_C << 1));
  rtb_Switch1 = BSPR_uMdulVolt_A[0];
  for (i_0 = 0; i_0 < 15; i_0++) {
    rtb_Switch1 += BSPR_uMdulVolt_A[i_0 + 1];
  }

  if (BSPR_CellVoltDiag_DW.is_active_c7_BSPR_CellVoltDiag == 0U) {
    BSPR_CellVoltDiag_DW.is_active_c7_BSPR_CellVoltDiag = 1U;

    /* Sort */
    for (i = 0U; i < BSPR_cntModuSerNum; i++) {
      BSPR_CellVoltDiag_DW.BSPR_uModuVoltDiag_A[i] = BSPR_uMdulVolt_A[i];
    }

    BSPR_CellVoltDiag_sort_e(BSPR_CellVoltDiag_DW.BSPR_uModuVoltDiag_A,
      BSPR_cntModuSerNum, rtb_Vol_ASD, rtb_index);
  } else {
    /* Sort */
    for (i = 0U; i < BSPR_cntModuSerNum; i++) {
      BSPR_CellVoltDiag_DW.BSPR_uModuVoltDiag_A[i] = BSPR_uMdulVolt_A[i];
    }

    BSPR_CellVoltDiag_sort_e(BSPR_CellVoltDiag_DW.BSPR_uModuVoltDiag_A,
      BSPR_cntModuSerNum, rtb_Vol_ASD, rtb_index);
  }

  if (BSPR_CellVoltDiag_DW.is_active_c8_BSPR_CellVoltDiag == 0U) {
    BSPR_CellVoltDiag_DW.is_active_c8_BSPR_CellVoltDiag = 1U;

    /*  SumExtmVolt */
    i = 0U;
    BSPR_uSumExtmVoltModu = 0.0F;
    while (i < BSPR_cntModuAvlNum_C) {
      BSPR_uSumExtmVoltModu = BSPR_uSumExtmVoltModu + rtb_Vol_ASD[i];
      i++;
    }

    i_0 = BSPR_cntModuSerNum - BSPR_cntModuAvlNum_C;
    if (i_0 < 0) {
      i_0 = 0;
    }

    for (i = (uint8_T)i_0; i < BSPR_cntModuSerNum; i++) {
      BSPR_uSumExtmVoltModu = BSPR_uSumExtmVoltModu + rtb_Vol_ASD[i];
    }
  } else {
    /*  SumExtmVolt */
    i = 0U;
    BSPR_uSumExtmVoltModu = 0.0F;
    while (i < BSPR_cntModuAvlNum_C) {
      BSPR_uSumExtmVoltModu = BSPR_uSumExtmVoltModu + rtb_Vol_ASD[i];
      i++;
    }

    i_0 = BSPR_cntModuSerNum - BSPR_cntModuAvlNum_C;
    if (i_0 < 0) {
      i_0 = 0;
    }

    for (i = (uint8_T)i_0; i < BSPR_cntModuSerNum; i++) {
      BSPR_uSumExtmVoltModu = BSPR_uSumExtmVoltModu + rtb_Vol_ASD[i];
    }
  }

  rtb_Switch1 -= BSPR_uSumExtmVoltModu;
  BSPR_uVoltModuMean = rtb_Switch1 / (real32_T)(uint8_T)(BSPR_cntModuSerNum -
    (uint8_T)(BSPR_cntModuAvlNum_C << 1)) / 12.0F;
  if (BSPR_cntVoltCellMeanSwt_CW == 0) {
    BSPR_uCellVoltMeanCoord = BSPR_uVoltCellMean;
  } else {
    BSPR_uCellVoltMeanCoord = BSPR_uVoltModuMean;
  }

  rtb_Switch1 = look1_iflf_binlxpw(BSER_rSoh, ((const real32_T *)
    &(BSPR_uCellVoltNplDiag_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltNplDiag_CUR[0])), 4U);
  B_CellVoltBMSDebounceStartZero8(BSPR_flgCellVoltDiagEn && ((BSPR_uCellVoltMax
    - BSPR_uCellVoltMeanCoord >= rtb_Switch1) || (BSPR_uCellVoltMeanCoord -
    BSPR_uCellVoltMin >= rtb_Switch1)) && (BSPR_uCellVoltMin >
    BSPR_CellNplDetVoltThres_C), BSPR_tiUCellNplErrThres_C,
    BSPR_tiCellVoltDiagTask_C, BSPR_tiUCellNplOkThres_C,
    BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero8,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero8);
  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_g) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltNpl_ASW | 8U);
  } else {
    rtb_Compare = ((BSPR_cntCellVoltNplDiag_CW & 1) == 1);
    if (rtb_Compare && BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero8.Switch)
    {
      i = (uint8_T)(DFC_CellVoltNpl_ASW | 152U);
    } else {
      if (rtb_Compare) {
        rtb_Compare = !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero8.Switch;
      } else {
        rtb_Compare = true;
      }

      if (rtb_Compare) {
        i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltNpl_ASW | 16U) | 8U);
      } else {
        i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_e;
      }
    }
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_g = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_e = i;
  DFC_CellVoltNpl_ASW = i;
  BSPR_uSumVoltCell = BSPR_uVoltCellMean * (real32_T)BSPR_cntCellSerNum;
  if (BSPR_CellVoltDiag_DW.is_active_c6_BSPR_CellVoltDiag == 0U) {
    BSPR_CellVoltDiag_DW.is_active_c6_BSPR_CellVoltDiag = 1U;
    enter_internal_DiagUCellProc_st(&rtb_Switch1);
  } else {
    enter_internal_DiagUCellProc_st(&rtb_Switch1);
  }

  for (i_0 = 0; i_0 < 150; i_0++) {
    BSPR_bUCellNplErrDet_A[i_0] =
      BSPR_CellVoltDiag_B.BSPR_bUCellNplErrDet_A_c[i_0];
    BSPR_bUCellNplErrHeal_A[i_0] =
      BSPR_CellVoltDiag_B.BSPR_bUCellNplErrHeal_A_n[i_0];
    BSPR_bUCellNplErrStt_A[i_0] =
      BSPR_CellVoltDiag_B.BSPR_bUCellNplErrStt_A_f[i_0];
    BSPR_cntUCellNplErrDet_A[i_0] =
      BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrDet_A_d[i_0];
    BSPR_cntUCellNplErrHeal_A[i_0] =
      BSPR_CellVoltDiag_B.BSPR_cntUCellNplErrHeal_A_e[i_0];
  }

  BSPR_uCellVoltRngHiWarnAlrm = look2_iflf_binlxpw(BSER_rSoh, BSPR_tCellTempMax,
    ((const real32_T *)&(BSPR_uCellVoltRng_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltRng_CUR_Y[0])), ((const real32_T *)
    &(BSPR_uCellVoltRngHiWarnAlrm_CUR[0])), rtCP_BSPR_uCellVoltRngHiWarnAlr, 5U);
  rtb_Switch1 = look2_iflf_binlxpw(BSER_rSoh, BSPR_tCellTempMax, ((const
    real32_T *)&(BSPR_uCellVoltRng_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltRng_CUR_Y[0])), ((const real32_T *)
    &(BSPR_uCellVoltRngHiFault_CUR[0])), rtCP_BSPR_uCellVoltRngHiFault_C, 5U);
  BSPR_uCellVoltRngHiFusf = look2_iflf_binlxpw(BSER_rSoh, BSPR_tCellTempMax, ((
    const real32_T *)&(BSPR_uCellVoltRng_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltRng_CUR_Y[0])), ((const real32_T *)
    &(BSPR_uCellVoltRngHiFusf_CUR[0])), rtCP_BSPR_uCellVoltRngHiFusf_CU, 5U);
  B_CellVoltBMSDebounceStartZero8((BSPR_uCellVoltMax >= rtb_Switch1) &&
    (BSPR_uCellVoltMax < BSPR_uCellVoltRngHiFusf) && BSPR_flgCellVoltDiagEn,
    BSPR_tiCellVoltFault_C, BSPR_tiCellVoltDiagTask_C, BSPR_tiCellVoltFault_C,
    BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero4,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero4);
  rtb_Compare = ((BSPR_cntCellVoltRngDiag_CW & 4) == 4);
  BSPR_bCellVoltMaxFaultDet = (rtb_Compare &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero4.Switch);
  B_CellVoltBMSDebounceStartZero8((BSPR_uCellVoltMax >= BSPR_uCellVoltRngHiFusf)
    && BSPR_flgCellVoltDiagEn, BSPR_tiCellVoltFusf_C, BSPR_tiCellVoltDiagTask_C,
    BSPR_tiCellVoltFusf_C, BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero6,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero6);
  rtb_Compare_c = ((BSPR_cntCellVoltRngDiag_CW & 16) == 16);
  BSPR_bCellVoltMaxFusfDet = (rtb_Compare_c &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero6.Switch);
  BSPR_bMaxAlrmWarnInhib = (BSPR_bCellVoltMaxFaultDet ||
    BSPR_bCellVoltMaxFusfDet);
  BSPR_bCellVoltMaxWarnAlrm = ((BSPR_uCellVoltMax >= BSPR_uCellVoltRngHiWarnAlrm)
    && (BSPR_uCellVoltMax < rtb_Switch1) && (!BSPR_bMaxAlrmWarnInhib) &&
    BSPR_flgCellVoltDiagEn);
  B_CellVoltBMSDebounceStartZero8(BSPR_bCellVoltMaxWarnAlrm,
    BSPR_tiCellVoltAlrm_C, BSPR_tiCellVoltDiagTask_C, BSPR_tiCellVoltWarn_C,
    BSPR_tiCellVoltDiagTask_C, &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero);
  BSPR_bCellVoltMaxAlrmDet = (BSPR_bCellVoltAlrmDiag_C &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero.Switch);
  B_CellVoltBMSDebounceStartZero8(BSPR_bCellVoltMaxWarnAlrm,
    BSPR_tiCellVoltWarn_C, BSPR_tiCellVoltDiagTask_C, BSPR_tiCellVoltWarn_C,
    BSPR_tiCellVoltDiagTask_C + BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero1,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero1);
  rtb_Compare_i = ((BSPR_cntCellVoltRngDiag_CW & 1) == 1);
  if (rtb_Compare_i) {
    BSPR_bCellVoltMaxHeal =
      !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero1.Switch;
  } else {
    BSPR_bCellVoltMaxHeal = true;
  }

  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_a3) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltAlrmMax_ASW | 8U);
  } else if (BSPR_bCellVoltMaxAlrmDet) {
    i = (uint8_T)(DFC_CellVoltAlrmMax_ASW | 152U);
  } else if (BSPR_bCellVoltMaxHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltAlrmMax_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_a;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_a3 = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_a = i;
  DFC_CellVoltAlrmMax_ASW = i;
  BSPR_bCellVoltMaxWarnDet = (rtb_Compare_i &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero1.Switch);
  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_pr) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltWarnMax_ASW | 8U);
  } else if (BSPR_bCellVoltMaxWarnDet) {
    i = (uint8_T)(DFC_CellVoltWarnMax_ASW | 152U);
  } else if (BSPR_bCellVoltMaxHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltWarnMax_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_h;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_pr = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_h = i;
  DFC_CellVoltWarnMax_ASW = i;
  BSPR_uCellVoltRngLoWarnAlrm = look2_iflf_binlxpw(BSER_rSoh, BSPR_tCellTempMin,
    ((const real32_T *)&(BSPR_uCellVoltRng_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltRng_CUR_Y[0])), ((const real32_T *)
    &(BSPR_uCellVoltRngLoWarnAlrm_CUR[0])), rtCP_BSPR_uCellVoltRngLoWarnAlr, 5U);
  BSPR_uCellVoltRngLoFault = look2_iflf_binlxpw(BSER_rSoh, BSPR_tCellTempMin, ((
    const real32_T *)&(BSPR_uCellVoltRng_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltRng_CUR_Y[0])), ((const real32_T *)
    &(BSPR_uCellVoltRngLoFault_CUR[0])), rtCP_BSPR_uCellVoltRngLoFault_C, 5U);
  BSPR_uCellVoltRngLoFusf = look2_iflf_binlxpw(BSER_rSoh, BSPR_tCellTempMin, ((
    const real32_T *)&(BSPR_uCellVoltRng_CUR_X[0])), ((const real32_T *)
    &(BSPR_uCellVoltRng_CUR_Y[0])), ((const real32_T *)
    &(BSPR_uCellVoltRngLoFusf_CUR[0])), rtCP_BSPR_uCellVoltRngLoFusf_CU, 5U);
  B_CellVoltBMSDebounceStartZero8((BSPR_uCellVoltMin <= BSPR_uCellVoltRngLoFault)
    && (BSPR_uCellVoltMin > BSPR_uCellVoltRngLoFusf) && BSPR_flgCellVoltDiagEn,
    BSPR_tiCellVoltFault_C, BSPR_tiCellVoltDiagTask_C, BSPR_tiCellVoltFault_C,
    BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero5,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero5);
  rtb_Compare_i = ((BSPR_cntCellVoltRngDiag_CW & 8) == 8);
  BSPR_bCellVoltMinFaultDet = (rtb_Compare_i &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero5.Switch);
  B_CellVoltBMSDebounceStartZero8((BSPR_uCellVoltMin <= BSPR_uCellVoltRngLoFusf)
    && BSPR_flgCellVoltDiagEn, BSPR_tiCellVoltFusf_C, BSPR_tiCellVoltDiagTask_C,
    BSPR_tiCellVoltFusf_C, BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero7,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero7);
  rtb_Compare_k = ((BSPR_cntCellVoltRngDiag_CW & 32) == 32);
  BSPR_bCellVoltMinFusfDet = (rtb_Compare_k &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero7.Switch);
  BSPR_bMinAlrmWarnInhib = (BSPR_bCellVoltMinFaultDet ||
    BSPR_bCellVoltMinFusfDet);
  rtb_BSPR_bCellVoltMinWarnAlrm = ((BSPR_uCellVoltMin <=
    BSPR_uCellVoltRngLoWarnAlrm) && (BSPR_uCellVoltMin >
    BSPR_uCellVoltRngLoFault) && (!BSPR_bMinAlrmWarnInhib) &&
    BSPR_flgCellVoltDiagEn);
  B_CellVoltBMSDebounceStartZero8(rtb_BSPR_bCellVoltMinWarnAlrm,
    BSPR_tiCellVoltAlrm_C, BSPR_tiCellVoltDiagTask_C, BSPR_tiCellVoltWarn_C,
    BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero2,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero2);
  BSPR_bCellVoltMinAlrmDet = (BSPR_bCellVoltAlrmDiag_C &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero2.Switch);
  B_CellVoltBMSDebounceStartZero8(rtb_BSPR_bCellVoltMinWarnAlrm,
    BSPR_tiCellVoltWarn_C, BSPR_tiCellVoltDiagTask_C, BSPR_tiCellVoltWarn_C,
    BSPR_tiCellVoltDiagTask_C + BSPR_tiCellVoltDiagTask_C,
    &BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero3,
    &BSPR_CellVoltDiag_DW.CellVoltBMSDebounceStartZero3);
  rtb_BSPR_bCellVoltMinWarnAlrm = ((BSPR_cntCellVoltRngDiag_CW & 2) == 2);
  if (rtb_BSPR_bCellVoltMinWarnAlrm) {
    BSPR_bCellVoltMinHeal =
      !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero3.Switch;
  } else {
    BSPR_bCellVoltMinHeal = true;
  }

  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_f) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltAlrmMin_ASW | 8U);
  } else if (BSPR_bCellVoltMinAlrmDet) {
    i = (uint8_T)(DFC_CellVoltAlrmMin_ASW | 152U);
  } else if (BSPR_bCellVoltMinHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltAlrmMin_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_i;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_f = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_i = i;
  DFC_CellVoltAlrmMin_ASW = i;
  BSPR_bCellVoltMinWarnDet = (rtb_BSPR_bCellVoltMinWarnAlrm &&
    BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero3.Switch);
  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_p5) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltWarnMin_ASW | 8U);
  } else if (BSPR_bCellVoltMinWarnDet) {
    i = (uint8_T)(DFC_CellVoltWarnMin_ASW | 152U);
  } else if (BSPR_bCellVoltMinHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltWarnMin_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_b;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_p5 = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_b = i;
  DFC_CellVoltWarnMin_ASW = i;
  if (rtb_Compare) {
    BSPR_bCellVoltMaxFaultHeal =
      !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero4.Switch;
  } else {
    BSPR_bCellVoltMaxFaultHeal = true;
  }

  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_a) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFaultMax_ASW | 8U);
  } else if (BSPR_bCellVoltMaxFaultDet) {
    i = (uint8_T)(DFC_CellVoltFaultMax_ASW | 152U);
  } else if (BSPR_bCellVoltMaxFaultHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFaultMax_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_c;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_a = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_c = i;
  DFC_CellVoltFaultMax_ASW = i;
  if (rtb_Compare_i) {
    BSPR_bCellVoltMinFaultHeal =
      !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero5.Switch;
  } else {
    BSPR_bCellVoltMinFaultHeal = true;
  }

  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_ps) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFaultMin_ASW | 8U);
  } else if (BSPR_bCellVoltMinFaultDet) {
    i = (uint8_T)(DFC_CellVoltFaultMin_ASW | 152U);
  } else if (BSPR_bCellVoltMinFaultHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFaultMin_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_p;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_ps = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_p = i;
  DFC_CellVoltFaultMin_ASW = i;
  if (rtb_Compare_c) {
    BSPR_bCellVoltMaxFusfHeal =
      !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero6.Switch;
  } else {
    BSPR_bCellVoltMaxFusfHeal = true;
  }

  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE_p) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFusfMax_ASW | 8U);
  } else if (BSPR_bCellVoltMaxFusfDet) {
    i = (uint8_T)(DFC_CellVoltFusfMax_ASW | 152U);
  } else if (BSPR_bCellVoltMaxFusfHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFusfMax_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE_j;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE_p = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE_j = i;
  DFC_CellVoltFusfMax_ASW = i;
  if (rtb_Compare_k) {
    BSPR_bCellVoltMinFusfHeal =
      !BSPR_CellVoltDiag_B.CellVoltBMSDebounceStartZero7.Switch;
  } else {
    BSPR_bCellVoltMinFusfHeal = true;
  }

  if (BSPR_CellVoltDiag_DW.Delay2_DSTATE) {
    i = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFusfMin_ASW | 8U);
  } else if (BSPR_bCellVoltMinFusfDet) {
    i = (uint8_T)(DFC_CellVoltFusfMin_ASW | 152U);
  } else if (BSPR_bCellVoltMinFusfHeal) {
    i = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellVoltFusfMin_ASW | 16U) | 8U);
  } else {
    i = BSPR_CellVoltDiag_DW.Delay3_DSTATE;
  }

  BSPR_CellVoltDiag_DW.Delay2_DSTATE = false;
  BSPR_CellVoltDiag_DW.Delay3_DSTATE = i;
  DFC_CellVoltFusfMin_ASW = i;
  BSPR_bMaxFaultInhib = (BSPR_bCellVoltMaxFusfDet || BSPR_bCellVoltMaxAlrmDet ||
    BSPR_bCellVoltMaxWarnDet);
  BSPR_bMaxFusfInhib = (BSPR_bCellVoltMaxAlrmDet || BSPR_bCellVoltMaxWarnDet ||
                        BSPR_bCellVoltMaxFaultDet);
  BSPR_bMinFaultInhib = (BSPR_bCellVoltMinFusfDet || BSPR_bCellVoltMinAlrmDet ||
    BSPR_bCellVoltMinWarnDet);
  BSPR_bMinFusfInhib = (BSPR_bCellVoltMinAlrmDet || BSPR_bCellVoltMinWarnDet ||
                        BSPR_bCellVoltMinFaultDet);
}

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

  /* block I/O */

  /* custom signals */
  BSPR_uVoltCellMean = 0.0F;
  BSPR_uVoltModuMean = 0.0F;
  BSPR_uSumVoltCell = 0.0F;

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

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

  BSPR_flgCurrHopEn = false;

  {
    int32_T i;
    for (i = 0; i < 150; i++) {
      BSPR_bUCellNplErrDet_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 150; i++) {
      BSPR_bUCellNplErrHeal_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 150; i++) {
      BSPR_bUCellNplErrStt_A[i] = false;
    }
  }

  BSPR_bCellVoltMaxFaultDet = false;
  BSPR_bCellVoltMaxFusfDet = false;
  BSPR_bCellVoltMaxAlrmDet = false;
  BSPR_bCellVoltMaxHeal = false;
  BSPR_bCellVoltMaxWarnDet = false;
  BSPR_bCellVoltMinFaultDet = false;
  BSPR_bCellVoltMinFusfDet = false;
  BSPR_bCellVoltMinAlrmDet = false;
  BSPR_bCellVoltMinHeal = false;
  BSPR_bCellVoltMinWarnDet = false;
  BSPR_bCellVoltMaxFaultHeal = false;
  BSPR_bCellVoltMinFaultHeal = false;
  BSPR_bCellVoltMaxFusfHeal = false;
  BSPR_bCellVoltMinFusfHeal = false;
  BSPR_CellVoltDiag_DW.Delay_DSTATE = 1.0F;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_g = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_a3 = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_pr = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_f = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_p5 = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_a = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_ps = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE_p = true;
  BSPR_CellVoltDiag_DW.Delay2_DSTATE = true;
}

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