/*
 * File: BSPR_BattTempDsmDiag.c
 *
 * Code generated for Simulink model 'BSPR_BattTempDsmDiag'.
 *
 * Model version                  : 1.1322
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Thu Nov 19 11:36:27 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_BattTempDsmDiag.h"
#include "BSPR_BattTempDsmDiag_private.h"

/* Exported data definition */

/* 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_BattTAlrmMax_ASW;     /* Out of range high alarm  level error of battery temperature sensor */
volatile uint8_T DFC_BattTAlrmMin_ASW;     /* Out of range low alarm  level error of battery temperature sensor */
volatile uint8_T DFC_BattTCnstMax_ASW;     /* Consistent error  of battery temperature sensor */
volatile uint8_T DFC_BattTFaultMax_ASW;    /* Out of range high serious level error of battery temperature sensor */
volatile uint8_T DFC_BattTFaultMin_ASW;    /* Out of range low serious level error of battery temperature sensor */
volatile uint8_T DFC_BattTGradtMax_ASW;    /* Gradt error  of battery temperature sensor */
volatile uint8_T DFC_BattTHopMax_ASW;      /* Jitter error of battery temperature sensor */
volatile uint8_T DFC_BattTWarnMax_ASW;     /* Out of range high alarm level error of battery temperature sensor */
volatile uint8_T DFC_BattTWarnMin_ASW;     /* Out of range low alarm  level error of battery temperature sensor */
volatile uint8_T DFC_CellTAlrmMax_ASW;     /* Out of range high alarm  level error of battery temperature sensor */
volatile uint8_T DFC_CellTAlrmMin_ASW;     /* Out of range low alarm  level error of battery temperature sensor */
volatile uint8_T DFC_CellTCnstMax_ASW;     /* Consistent error  of battery temperature sensor */
volatile uint8_T DFC_CellTFaultMax_ASW;    /* Out of range high serious level error of battery temperature sensor */
volatile uint8_T DFC_CellTFaultMin_ASW;    /* Out of range low serious level error of battery temperature sensor */
volatile uint8_T DFC_CellTGradtMax_ASW;    /* Gradt error  of battery temperature sensor */
volatile uint8_T DFC_CellTHopMax_ASW;      /* Jitter error of battery temperature sensor */
volatile uint8_T DFC_CellTWarnMax_ASW;     /* Out of range high alarm level error of battery temperature sensor */
volatile uint8_T DFC_CellTWarnMin_ASW;     /* Out of range low alarm  level error of battery temperature sensor */

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block states (auto storage) */
DW_BSPR_BattTempDsmDiag_T BSPR_BattTempDsmDiag_DW;

/* Model step function */
void BSPR_BattTempDsmDiag_step(void)
{
  uint8_T rtb_SumofElements;
  uint32_T tmp;
  int32_T i;
  uint8_T rtb_SumofElements1;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_b3) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTHopMax_ASW | 8U);
  } else {
    tmp = BSPR_bCellTHopErrDet_A[0];
    for (i = 0; i < 47; i++) {
      tmp += BSPR_bCellTHopErrDet_A[i + 1];
    }

    rtb_SumofElements = (uint8_T)tmp;
    tmp = BSPR_bCellTHopErrHeal_A[0];
    for (i = 0; i < 47; i++) {
      tmp += BSPR_bCellTHopErrHeal_A[i + 1];
    }

    rtb_SumofElements1 = (uint8_T)tmp;
    if ((rtb_SumofElements > 0) && (rtb_SumofElements1 < BSPR_cntCellTSnsrNum))
    {
      rtb_SumofElements = (uint8_T)(DFC_CellTHopMax_ASW | 152U);
    } else if ((rtb_SumofElements == 0) && (rtb_SumofElements1 ==
                BSPR_cntCellTSnsrNum)) {
      rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_CellTHopMax_ASW | 16U) | 8U);
    } else {
      rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_c;
    }
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_b3 = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_c = rtb_SumofElements;
  DFC_CellTHopMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_i) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTCnstMax_ASW | 8U);
  } else if (BSPR_bCellTCnstErrDet_A) {
    rtb_SumofElements = (uint8_T)(DFC_CellTCnstMax_ASW | 152U);
  } else if (BSPR_bCellTCnstErrHeal_A) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellTCnstMax_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_d;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_i = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_d = rtb_SumofElements;
  DFC_CellTCnstMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_e) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTGradtMax_ASW | 8U);
  } else if (BSPR_bCellTGradtErrDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTGradtMax_ASW | 152U);
  } else if (BSPR_bCellTGradtErrHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_CellTGradtMax_ASW | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_l;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_e = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_l = rtb_SumofElements;
  DFC_CellTGradtMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_f) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTWarnMax_ASW | 8U);
  } else if (BSPR_bCellTMaxWarnDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTWarnMax_ASW | 152U);
  } else if (BSPR_bCellTMaxWarnHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellTWarnMax_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_n;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_f = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_n = rtb_SumofElements;
  DFC_CellTWarnMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_a) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTAlrmMax_ASW | 8U);
  } else if (BSPR_bCellTMaxAlrmDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTAlrmMax_ASW | 152U);
  } else if (BSPR_bCellTMaxAlrmHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellTAlrmMax_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_j;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_a = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_j = rtb_SumofElements;
  DFC_CellTAlrmMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_h) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTFaultMax_ASW | 8U);
  } else if (BSPR_bCellTMaxFaultDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTFaultMax_ASW | 152U);
  } else if (BSPR_bCellTMaxFaultHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_CellTFaultMax_ASW | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_e;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_h = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_e = rtb_SumofElements;
  DFC_CellTFaultMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_b) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTWarnMin_ASW | 8U);
  } else if (BSPR_bCellTMinWarnDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTWarnMin_ASW | 152U);
  } else if (BSPR_bCellTMinWarnHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellTWarnMin_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_a;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_b = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_a = rtb_SumofElements;
  DFC_CellTWarnMin_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_p) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTAlrmMin_ASW | 8U);
  } else if (BSPR_bCellTMinAlrmDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTAlrmMin_ASW | 152U);
  } else if (BSPR_bCellTMinAlrmHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CellTAlrmMin_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_b;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_p = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_b = rtb_SumofElements;
  DFC_CellTAlrmMin_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_CellTFaultMin_ASW | 8U);
  } else if (BSPR_bCellTMinFaultDet) {
    rtb_SumofElements = (uint8_T)(DFC_CellTFaultMin_ASW | 152U);
  } else if (BSPR_bCellTMinFaultHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_CellTFaultMin_ASW | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE = rtb_SumofElements;
  DFC_CellTFaultMin_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_d) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTHopMax_ASW | 8U);
  } else {
    tmp = BSPR_bBattTHopErrDet_A[0];
    for (i = 0; i < 47; i++) {
      tmp += BSPR_bBattTHopErrDet_A[i + 1];
    }

    rtb_SumofElements = (uint8_T)tmp;
    tmp = BSPR_bBattTHopErrHeal_A[0];
    for (i = 0; i < 47; i++) {
      tmp += BSPR_bBattTHopErrHeal_A[i + 1];
    }

    rtb_SumofElements1 = (uint8_T)tmp;
    if ((rtb_SumofElements > 0) && (rtb_SumofElements1 < BSPR_cntBattTSnsrNum))
    {
      rtb_SumofElements = (uint8_T)(DFC_BattTHopMax_ASW | 152U);
    } else if ((rtb_SumofElements == 0) && (rtb_SumofElements1 ==
                BSPR_cntBattTSnsrNum)) {
      rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_BattTHopMax_ASW | 16U) | 8U);
    } else {
      rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_bj;
    }
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_d = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_bj = rtb_SumofElements;
  DFC_BattTHopMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_o2) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTCnstMax_ASW | 8U);
  } else if (BSPR_bBattTCnstErrDet_A) {
    rtb_SumofElements = (uint8_T)(DFC_BattTCnstMax_ASW | 152U);
  } else if (BSPR_bBattTCnstErrHeal_A) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_BattTCnstMax_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_bf;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_o2 = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_bf = rtb_SumofElements;
  DFC_BattTCnstMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_is) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTGradtMax_ASW | 8U);
  } else if (BSPR_bBattTGradtErrDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTGradtMax_ASW | 152U);
  } else if (BSPR_bBattTGradtErrHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_BattTGradtMax_ASW | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_hn;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_is = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_hn = rtb_SumofElements;
  DFC_BattTGradtMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_hi) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTWarnMax_ASW | 8U);
  } else if (BSPR_bBattTMaxWarnDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTWarnMax_ASW | 152U);
  } else if (BSPR_bBattTMaxWarnHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_BattTWarnMax_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_h;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_hi = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_h = rtb_SumofElements;
  DFC_BattTWarnMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_ec) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTAlrmMax_ASW | 8U);
  } else if (BSPR_bBattTMaxAlrmDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTAlrmMax_ASW | 152U);
  } else if (BSPR_bBattTMaxAlrmHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_BattTAlrmMax_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_d5;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_ec = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_d5 = rtb_SumofElements;
  DFC_BattTAlrmMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_ey) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTFaultMax_ASW | 8U);
  } else if (BSPR_bBattTMaxFaultDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTFaultMax_ASW | 152U);
  } else if (BSPR_bBattTMaxFaultHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_BattTFaultMax_ASW | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_jf;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_ey = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_jf = rtb_SumofElements;
  DFC_BattTFaultMax_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_j) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTWarnMin_ASW | 8U);
  } else if (BSPR_bBattTMinWarnDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTWarnMin_ASW | 152U);
  } else if (BSPR_bBattTMinWarnHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_BattTWarnMin_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_nu;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_j = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_nu = rtb_SumofElements;
  DFC_BattTWarnMin_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_g) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTAlrmMin_ASW | 8U);
  } else if (BSPR_bBattTMinAlrmDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTAlrmMin_ASW | 152U);
  } else if (BSPR_bBattTMinAlrmHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_BattTAlrmMin_ASW
      | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_p;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_g = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_p = rtb_SumofElements;
  DFC_BattTAlrmMin_ASW = rtb_SumofElements;
  if (BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_o) {
    rtb_SumofElements = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattTFaultMin_ASW | 8U);
  } else if (BSPR_bBattTMinFaultDet) {
    rtb_SumofElements = (uint8_T)(DFC_BattTFaultMin_ASW | 152U);
  } else if (BSPR_bBattTMinFaultHeal) {
    rtb_SumofElements = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_BattTFaultMin_ASW | 16U) | 8U);
  } else {
    rtb_SumofElements = BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_i;
  }

  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_o = false;
  BSPR_BattTempDsmDiag_DW.Delay3_DSTATE_i = rtb_SumofElements;
  DFC_BattTFaultMin_ASW = rtb_SumofElements;
}

/* Model initialize function */
void BSPR_BattTempDsmDiag_initialize(void)
{
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_b3 = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_i = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_e = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_f = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_a = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_h = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_b = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_p = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_d = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_o2 = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_is = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_hi = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_ec = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_ey = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_j = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_g = true;
  BSPR_BattTempDsmDiag_DW.Delay2_DSTATE_o = true;
}

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