/*
 * File: BCCR_CtrDsmDiag.c
 *
 * Code generated for Simulink model 'BCCR_CtrDsmDiag'.
 *
 * Model version                  : 1.1112F
 * Simulink Coder version         : 8.11F (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Mon Dec 10 11:39:46 2018
 *
 * 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 "BCCR_CtrDsmDiag.h"
#include "BCCR_CtrDsmDiag_private.h"

/* Exported data definition */

/* Volatile memory section */
 
 

/* Definition for custom storage class: Volatile */
volatile uint8_T DFC_DChrgNegStuckMax_ASW; /* Max fault of dc charge negative contactor */
volatile uint8_T DFC_DChrgNegStuckMin_ASW; /* Min fault of dc charge negative contactor */
volatile uint8_T DFC_DChrgPosStuckMax_ASW; /* Max fault of dc charge positive contactor */
volatile uint8_T DFC_DChrgPosStuckMin_ASW; /* Min fault of dc charge positive contactor */
volatile uint8_T DFC_MNegStuckMax_ASW;     /* Max fault of main negative contactor */
volatile uint8_T DFC_MNegStuckMin_ASW;     /* Min fault of main negative contactor */
volatile uint8_T DFC_MPosStuckMin_ASW;     /* Min fault of main positive contactor */
volatile uint8_T DFC_PosStuckMax_ASW;      /* Max fault of positive contactor include main positive contactor and precharge contactor */
volatile uint8_T DFC_PrStuckMin_ASW;       /* Min fault of precharge contactor */

 
 

/* Block states (auto storage) */
DW_BCCR_CtrDsmDiag_T BCCR_CtrDsmDiag_DW;

/* Model step function */
void BCCR_CtrDsmDiag_step(void)
{
  boolean_T rtb_Compare_b;
  uint8_T rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_o) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_PosStuckMax_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntMainCtrPlausDiag_CW & 1) == 1);
    if (rtb_Compare_b && BCCR_bStuckClsdMpPrErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_PosStuckMax_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckClsdMpPrErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_PosStuckMax_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_p;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_o = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_p = rtb_Switch4_mv;
  DFC_PosStuckMax_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_c2) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_MNegStuckMax_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntMainCtrPlausDiag_CW & 2) == 2);
    if (rtb_Compare_b && BCCR_bStuckClsdMnErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_MNegStuckMax_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckClsdMnErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MNegStuckMax_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_h;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_c2 = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_h = rtb_Switch4_mv;
  DFC_MNegStuckMax_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_k) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_PrStuckMin_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntMainCtrPlausDiag_CW & 4) == 4);
    if (rtb_Compare_b && BCCR_bStuckOpnPrErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_PrStuckMin_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckOpnPrErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_PrStuckMin_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_d;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_k = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_d = rtb_Switch4_mv;
  DFC_PrStuckMin_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_c) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_MNegStuckMin_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntMainCtrPlausDiag_CW & 8) == 8);
    if (rtb_Compare_b && BCCR_bStuckOpnMnErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_MNegStuckMin_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckOpnMnErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MNegStuckMin_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_n;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_c = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_n = rtb_Switch4_mv;
  DFC_MNegStuckMin_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_MPosStuckMin_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntMainCtrPlausDiag_CW & 16) == 16);
    if (rtb_Compare_b && BCCR_bStuckOpnMpErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_MPosStuckMin_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckOpnMpErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_MPosStuckMin_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE = rtb_Switch4_mv;
  DFC_MPosStuckMin_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_d) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgPosStuckMax_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntDChrgCtrPlausDiag_CW & 1) == 1);
    if (rtb_Compare_b && BCCR_bStuckClsdDChrgPosErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_DChrgPosStuckMax_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckClsdDChrgPosErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DChrgPosStuckMax_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_o;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_d = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_o = rtb_Switch4_mv;
  DFC_DChrgPosStuckMax_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_l) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgNegStuckMax_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntDChrgCtrPlausDiag_CW & 2) == 2);
    if (rtb_Compare_b && BCCR_bStuckClsdDChrgNegErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_DChrgNegStuckMax_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckClsdDChrgNegErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DChrgNegStuckMax_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_b;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_l = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_b = rtb_Switch4_mv;
  DFC_DChrgNegStuckMax_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_p) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgPosStuckMin_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntDChrgCtrPlausDiag_CW & 4) == 4);
    if (rtb_Compare_b && BCCR_bStuckOpnDChrgPosErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_DChrgPosStuckMin_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckOpnDChrgPosErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DChrgPosStuckMin_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_c;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_p = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_c = rtb_Switch4_mv;
  DFC_DChrgPosStuckMin_ASW = rtb_Switch4_mv;
  if (BCCR_CtrDsmDiag_DW.Delay2_DSTATE_a) {
    rtb_Switch4_mv = (uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgNegStuckMin_ASW | 8U);
  } else {
    rtb_Compare_b = ((BCCR_cntDChrgCtrPlausDiag_CW & 8) == 8);
    if (rtb_Compare_b && BCCR_bStuckOpnDChrgNegErrDet) {
      rtb_Switch4_mv = (uint8_T)(DFC_DChrgNegStuckMin_ASW | 152U);
    } else if ((!rtb_Compare_b) || BCCR_bStuckOpnDChrgNegErrHeal) {
      rtb_Switch4_mv = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_DChrgNegStuckMin_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_mv = BCCR_CtrDsmDiag_DW.Delay3_DSTATE_a;
    }
  }

  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_a = false;
  BCCR_CtrDsmDiag_DW.Delay3_DSTATE_a = rtb_Switch4_mv;
  DFC_DChrgNegStuckMin_ASW = rtb_Switch4_mv;
}

/* Model initialize function */
void BCCR_CtrDsmDiag_initialize(void)
{
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_o = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_c2 = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_k = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_c = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_d = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_l = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_p = true;
  BCCR_CtrDsmDiag_DW.Delay2_DSTATE_a = true;
}

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