/*
 * File: BSPR_BattTempGradtDiag.c
 *
 * Code generated for Simulink model 'BSPR_BattTempGradtDiag'.
 *
 * Model version                  : A1.1_0
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Fri Oct  9 10:43:22 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_BattTempGradtDiag.h"
#include "BSPR_BattTempGradtDiag_private.h"
#include "look2_iflf_binlxpw.h"

/* Named constants for Chart: '<S6>/GradtDiag' */
#define BSPR_BattTem_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define BSPR_BattTempGradtDi_IN_Disable ((uint8_T)1U)
#define BSPR_BattTempGradtDi_IN_Result1 ((uint8_T)4U)
#define BSPR_BattTempGradtDi_IN_Result2 ((uint8_T)5U)
#define BSPR_BattTempGradtDiag_IN_Judge ((uint8_T)2U)
#define BSPR_BattTempGradtDiag_IN_Rep  ((uint8_T)3U)
#define BSPR_BattTempGradtDiag_IN_Step1 ((uint8_T)6U)
#define BSPR_BattTempGradtDiag_IN_Step2 ((uint8_T)7U)

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

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BSPR_bBattTGradtDiff_A[60];
volatile boolean_T BSPR_bBattTGradtErrDet;
volatile boolean_T BSPR_bBattTGradtErrHeal;
volatile boolean_T BSPR_bCellTGradtDiff_A[60];
volatile boolean_T BSPR_bCellTGradtErrDet;
volatile boolean_T BSPR_bCellTGradtErrHeal;
volatile uint16_T BSPR_cntBattGradtSum;
volatile real32_T BSPR_cntBattTGradtDiff_A[60];
volatile uint16_T BSPR_cntCellGradtSum;
volatile real32_T BSPR_cntCellTGradtDiff_A[60];
volatile boolean_T BSPR_flgBattTGradtEna;
volatile real32_T BSPR_tBattTGradtDiff_A[60];
volatile real32_T BSPR_tBattTempSec60s_A[60];
volatile real32_T BSPR_tBattTempSec_A[60];
volatile boolean_T BSPR_tCellTGradtDiff_A[60];
volatile real32_T BSPR_tCellTempSec60s_A[60];
volatile real32_T BSPR_tCellTempSec_A[60];

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BSPR_BattTempGradtDiag_T BSPR_BattTempGradtDiag_B;

/* Block states (auto storage) */
DW_BSPR_BattTempGradtDiag_T BSPR_BattTempGradtDiag_DW;

/* Model step function */
void BSPR_BattTempGradtDiag_step(void)
{
  real32_T rtb_u_j;
  real32_T Sum_i;
  int32_T i;
  BSPR_flgBattTGradtEna = !(((DFC_CellTempTmt_ASW & 16) == 16) || ((DFC_InCanBusOff_ASW
    & 16) == 16) || ((uint8_T)((uint32_T)COMR_bBattTempWireStt_A[0] +
    COMR_bBattTempWireStt_A[1]) > 0) || BTMR_flgHtgPwrReq || (BMCR_stBmsModeCtrl
    == 5));
  if (BSPR_flgBattTGradtEna) {
    if (!BSPR_BattTempGradtDiag_DW.GradtDiag_MODE) {
      BSPR_BattTempGradtDiag_DW.is_active_c3_BSPR_BattTempGradt = 0U;
      BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
        BSPR_BattTem_IN_NO_ACTIVE_CHILD;
      BSPR_BattTempGradtDiag_DW.i_e = 0U;
      BSPR_BattTempGradtDiag_DW.j_a = 0U;
      BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrDet_a = false;
      BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrHeal_n = false;
      BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = 0U;
      for (i = 0; i < 60; i++) {
        BSPR_BattTempGradtDiag_B.BSPR_tBattTGradtDiff_A_n[i] = 0.0F;
        BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[i] = 0.0F;
        BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[i] = 0.0F;
        BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtDiff_A_d[i] = false;
        BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i] = 0.0F;
      }

      BSPR_BattTempGradtDiag_DW.GradtDiag_MODE = true;
    }

    rtb_u_j = look2_iflf_binlxpw(COMR_tEnvT, COMR_iBattCurr, ((const real32_T *)
      &(COMR_tEnvT_A[0])), ((const real32_T *)&(COMR_iBattCurr_A[0])), ((const
      real32_T *)&(BSPR_tBattTGradtFaultThres_MAP[0])), rtCP__maxIndex, 6U);
    if (BSPR_BattTempGradtDiag_DW.is_active_c3_BSPR_BattTempGradt == 0U) {
      BSPR_BattTempGradtDiag_DW.is_active_c3_BSPR_BattTempGradt = 1U;
      if (!((BSPR_cntBattTGradtDiag_CW & 4) == 4)) {
        BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDi_IN_Disable;
        BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrHeal_n = true;
        BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrDet_a = false;
        BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = 0U;
        for (i = 0; i < 60; i++) {
          BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i] = 0.0F;
        }
      } else {
        BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDiag_IN_Step1;
        BSPR_BattTempGradtDiag_DW.i_e = 0U;
      }
    } else {
      switch (BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag) {
       case BSPR_BattTempGradtDi_IN_Disable:
        break;

       case BSPR_BattTempGradtDiag_IN_Judge:
        if (BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e >=
            BSPR_cntBattTGradtErrHeal_C) {
          BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDi_IN_Result2;
          BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrDet_a = true;
          BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrHeal_n = false;
        } else {
          if (BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e <
              BSPR_cntBattTGradtErrHeal_C) {
            BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
              BSPR_BattTempGradtDi_IN_Result1;
            BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrDet_a = false;
            BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrHeal_n = true;
          }
        }
        break;

       case BSPR_BattTempGradtDiag_IN_Rep:
        if (BSPR_BattTempGradtDiag_DW.j_a >= BSPR_cntBattTSnsrGDiag_C) {
          BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDiag_IN_Judge;
          Sum_i = -0.0F;
          for (i = 0; i < 60; i++) {
            BSPR_BattTempGradtDiag_B.BSPR_tBattTGradtDiff_A_n[i] =
              BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[i] -
              BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[i];
            BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtDiff_A_d[i] = ((real32_T)
              fabs(BSPR_BattTempGradtDiag_B.BSPR_tBattTGradtDiff_A_n[i]) -
              rtb_u_j >= 0.0F);
            BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i] =
              BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtDiff_A_d[i];
            Sum_i += BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i];
          }

          if (Sum_i < 65536.0F) {
            if (Sum_i >= 0.0F) {
              BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = (uint16_T)Sum_i;
            } else {
              BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = 0U;
            }
          } else {
            BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = MAX_uint16_T;
          }
        } else {
          BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[BSPR_BattTempGradtDiag_DW.j_a]
            = BSPR_tBattTempMax;
          i = BSPR_BattTempGradtDiag_DW.j_a + 1;
          if (i > 255) {
            i = 255;
          }

          BSPR_BattTempGradtDiag_DW.j_a = (uint8_T)i;
        }
        break;

       case BSPR_BattTempGradtDi_IN_Result1:
        BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDiag_IN_Rep;
        BSPR_BattTempGradtDiag_DW.i_e = 0U;
        BSPR_BattTempGradtDiag_DW.j_a = 0U;
        for (i = 0; i < 60; i++) {
          BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[i] =
            BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[i];
        }
        break;

       case BSPR_BattTempGradtDi_IN_Result2:
        BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDiag_IN_Rep;
        BSPR_BattTempGradtDiag_DW.i_e = 0U;
        BSPR_BattTempGradtDiag_DW.j_a = 0U;
        for (i = 0; i < 60; i++) {
          BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[i] =
            BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[i];
        }
        break;

       case BSPR_BattTempGradtDiag_IN_Step1:
        if (BSPR_BattTempGradtDiag_DW.i_e >= BSPR_cntBattTSnsrGDiag_C) {
          BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDiag_IN_Step2;
          BSPR_BattTempGradtDiag_DW.j_a = 0U;
        } else {
          BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[BSPR_BattTempGradtDiag_DW.i_e]
            = BSPR_tBattTempMax;
          i = BSPR_BattTempGradtDiag_DW.i_e + 1;
          if (i > 255) {
            i = 255;
          }

          BSPR_BattTempGradtDiag_DW.i_e = (uint8_T)i;
        }
        break;

       default:
        if (BSPR_BattTempGradtDiag_DW.j_a >= BSPR_cntBattTSnsrGDiag_C) {
          BSPR_BattTempGradtDiag_DW.is_c3_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDiag_IN_Judge;
          Sum_i = -0.0F;
          for (i = 0; i < 60; i++) {
            BSPR_BattTempGradtDiag_B.BSPR_tBattTGradtDiff_A_n[i] =
              BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[i] -
              BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[i];
            BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtDiff_A_d[i] = ((real32_T)
              fabs(BSPR_BattTempGradtDiag_B.BSPR_tBattTGradtDiff_A_n[i]) -
              rtb_u_j >= 0.0F);
            BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i] =
              BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtDiff_A_d[i];
            Sum_i += BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i];
          }

          if (Sum_i < 65536.0F) {
            if (Sum_i >= 0.0F) {
              BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = (uint16_T)Sum_i;
            } else {
              BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = 0U;
            }
          } else {
            BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e = MAX_uint16_T;
          }
        } else {
          BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[BSPR_BattTempGradtDiag_DW.j_a]
            = BSPR_tBattTempMax;
          i = BSPR_BattTempGradtDiag_DW.j_a + 1;
          if (i > 255) {
            i = 255;
          }

          BSPR_BattTempGradtDiag_DW.j_a = (uint8_T)i;
        }
        break;
      }
    }
  } else {
    if (BSPR_BattTempGradtDiag_DW.GradtDiag_MODE) {
      BSPR_BattTempGradtDiag_DW.GradtDiag_MODE = false;
    }
  }

  BSPR_cntBattGradtSum = BSPR_BattTempGradtDiag_B.BSPR_cntBattGradtSum_e;
  BSPR_bBattTGradtErrDet = BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrDet_a;
  BSPR_bBattTGradtErrHeal = BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtErrHeal_n;
  for (i = 0; i < 60; i++) {
    BSPR_tBattTGradtDiff_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_tBattTGradtDiff_A_n[i];
    BSPR_bBattTGradtDiff_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_bBattTGradtDiff_A_d[i];
    BSPR_cntBattTGradtDiff_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_cntBattTGradtDiff_A_n[i];
    BSPR_tBattTempSec_A[i] = BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec_A_a[i];
    BSPR_tBattTempSec60s_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_tBattTempSec60s_A_c[i];
  }

  if (BSPR_flgBattTGradtEna) {
    if (!BSPR_BattTempGradtDiag_DW.GradtDiag_Cell_MODE) {
      BSPR_BattTempGradtDiag_DW.is_active_c1_BSPR_BattTempGradt = 0U;
      BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
        BSPR_BattTem_IN_NO_ACTIVE_CHILD;
      BSPR_BattTempGradtDiag_DW.i = 0U;
      BSPR_BattTempGradtDiag_DW.j = 0U;
      BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrDet_m = false;
      BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrHeal_d = false;
      BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = 0U;
      for (i = 0; i < 60; i++) {
        BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] = false;
        BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[i] = 0.0F;
        BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[i] = 0.0F;
        BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtDiff_A_k[i] = false;
        BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i] = 0.0F;
      }

      BSPR_BattTempGradtDiag_DW.GradtDiag_Cell_MODE = true;
    }

    rtb_u_j = look2_iflf_binlxpw(COMR_tEnvT, COMR_iBattCurr, ((const real32_T *)
      &(COMR_tEnvT_A[0])), ((const real32_T *)&(COMR_iBattCurr_A[0])), ((const
      real32_T *)&(BSPR_tBattTGradtFaultThres_MAP[0])), rtCP__maxIndex_d, 6U);
    if (BSPR_BattTempGradtDiag_DW.is_active_c1_BSPR_BattTempGradt == 0U) {
      BSPR_BattTempGradtDiag_DW.is_active_c1_BSPR_BattTempGradt = 1U;
      if (!((BSPR_cntCellTGradtDiag_CW & 4) == 4)) {
        BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDi_IN_Disable;
        BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrHeal_d = true;
        BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrDet_m = false;
        BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = 0U;
        for (i = 0; i < 60; i++) {
          BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i] = 0.0F;
        }
      } else {
        BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDiag_IN_Step1;
        BSPR_BattTempGradtDiag_DW.i = 0U;
      }
    } else {
      switch (BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag) {
       case BSPR_BattTempGradtDi_IN_Disable:
        break;

       case BSPR_BattTempGradtDiag_IN_Judge:
        if (BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e >=
            BSPR_cntBattTGradtErrHeal_C) {
          BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDi_IN_Result2;
          BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrDet_m = true;
          BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrHeal_d = false;
        } else {
          if (BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e <
              BSPR_cntBattTGradtErrHeal_C) {
            BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
              BSPR_BattTempGradtDi_IN_Result1;
            BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrDet_m = false;
            BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrHeal_d = true;
          }
        }
        break;

       case BSPR_BattTempGradtDiag_IN_Rep:
        if (BSPR_BattTempGradtDiag_DW.j >= BSPR_cntBattTSnsrGDiag_C) {
          BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDiag_IN_Judge;

          /* BSPR_bCellTGradtDiff_A=((abs(BSPR_tCellTGradtDiff_A)-BSPR_tCellTGradtFaultThres_MAP) >= 0); */
          Sum_i = -0.0F;
          for (i = 0; i < 60; i++) {
            BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] =
              (BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[i] -
               BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[i] != 0.0F);
            BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtDiff_A_k[i] = (((real32_T)
              BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] >= rtb_u_j) ||
              ((real32_T)BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] <=
               -rtb_u_j));
            BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i] =
              BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtDiff_A_k[i];
            Sum_i += BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i];
          }

          if (Sum_i < 65536.0F) {
            if (Sum_i >= 0.0F) {
              BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = (uint16_T)Sum_i;
            } else {
              BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = 0U;
            }
          } else {
            BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = MAX_uint16_T;
          }
        } else {
          BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[BSPR_BattTempGradtDiag_DW.j]
            = BSPR_tCellTempMax;
          i = BSPR_BattTempGradtDiag_DW.j + 1;
          if (i > 255) {
            i = 255;
          }

          BSPR_BattTempGradtDiag_DW.j = (uint8_T)i;
        }
        break;

       case BSPR_BattTempGradtDi_IN_Result1:
        BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDiag_IN_Rep;
        BSPR_BattTempGradtDiag_DW.i = 0U;
        BSPR_BattTempGradtDiag_DW.j = 0U;
        for (i = 0; i < 60; i++) {
          BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[i] =
            BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[i];
        }
        break;

       case BSPR_BattTempGradtDi_IN_Result2:
        BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
          BSPR_BattTempGradtDiag_IN_Rep;
        BSPR_BattTempGradtDiag_DW.i = 0U;
        BSPR_BattTempGradtDiag_DW.j = 0U;
        for (i = 0; i < 60; i++) {
          BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[i] =
            BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[i];
        }
        break;

       case BSPR_BattTempGradtDiag_IN_Step1:
        if (BSPR_BattTempGradtDiag_DW.i >= BSPR_cntBattTSnsrGDiag_C) {
          BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDiag_IN_Step2;
          BSPR_BattTempGradtDiag_DW.j = 0U;
        } else {
          BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[BSPR_BattTempGradtDiag_DW.i]
            = BSPR_tCellTempMax;
          i = BSPR_BattTempGradtDiag_DW.i + 1;
          if (i > 255) {
            i = 255;
          }

          BSPR_BattTempGradtDiag_DW.i = (uint8_T)i;
        }
        break;

       default:
        if (BSPR_BattTempGradtDiag_DW.j >= BSPR_cntBattTSnsrGDiag_C) {
          BSPR_BattTempGradtDiag_DW.is_c1_BSPR_BattTempGradtDiag =
            BSPR_BattTempGradtDiag_IN_Judge;

          /* BSPR_bCellTGradtDiff_A=((abs(BSPR_tCellTGradtDiff_A)-BSPR_tCellTGradtFaultThres_MAP) >= 0); */
          Sum_i = -0.0F;
          for (i = 0; i < 60; i++) {
            BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] =
              (BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[i] -
               BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[i] != 0.0F);
            BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtDiff_A_k[i] = (((real32_T)
              BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] >= rtb_u_j) ||
              ((real32_T)BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i] <=
               -rtb_u_j));
            BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i] =
              BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtDiff_A_k[i];
            Sum_i += BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i];
          }

          if (Sum_i < 65536.0F) {
            if (Sum_i >= 0.0F) {
              BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = (uint16_T)Sum_i;
            } else {
              BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = 0U;
            }
          } else {
            BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e = MAX_uint16_T;
          }
        } else {
          BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[BSPR_BattTempGradtDiag_DW.j]
            = BSPR_tCellTempMax;
          i = BSPR_BattTempGradtDiag_DW.j + 1;
          if (i > 255) {
            i = 255;
          }

          BSPR_BattTempGradtDiag_DW.j = (uint8_T)i;
        }
        break;
      }
    }
  } else {
    if (BSPR_BattTempGradtDiag_DW.GradtDiag_Cell_MODE) {
      BSPR_BattTempGradtDiag_DW.GradtDiag_Cell_MODE = false;
    }
  }

  BSPR_cntCellGradtSum = BSPR_BattTempGradtDiag_B.BSPR_cntCellGradtSum_e;
  BSPR_bCellTGradtErrDet = BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrDet_m;
  BSPR_bCellTGradtErrHeal = BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtErrHeal_d;
  for (i = 0; i < 60; i++) {
    BSPR_tCellTGradtDiff_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_tCellTGradtDiff_A_n[i];
    BSPR_bCellTGradtDiff_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_bCellTGradtDiff_A_k[i];
    BSPR_cntCellTGradtDiff_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_cntCellTGradtDiff_A_i[i];
    BSPR_tCellTempSec_A[i] = BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec_A_b[i];
    BSPR_tCellTempSec60s_A[i] =
      BSPR_BattTempGradtDiag_B.BSPR_tCellTempSec60s_A_b[i];
  }
}

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

  /* block I/O */

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

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

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

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

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

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

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

  BSPR_cntBattGradtSum = ((uint16_T)0U);
  BSPR_cntCellGradtSum = ((uint16_T)0U);
  BSPR_flgBattTGradtEna = false;

  {
    int32_T i;
    for (i = 0; i < 60; i++) {
      BSPR_bBattTGradtDiff_A[i] = false;
    }
  }

  BSPR_bBattTGradtErrDet = false;
  BSPR_bBattTGradtErrHeal = false;

  {
    int32_T i;
    for (i = 0; i < 60; i++) {
      BSPR_tCellTGradtDiff_A[i] = false;
    }
  }

  {
    int32_T i;
    for (i = 0; i < 60; i++) {
      BSPR_bCellTGradtDiff_A[i] = false;
    }
  }

  BSPR_bCellTGradtErrDet = false;
  BSPR_bCellTGradtErrHeal = false;
}

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