/*
 * File: COMR_MsgChkSumDiag.c
 *
 * Code generated for Simulink model 'COMR_MsgChkSumDiag'.
 *
 * Model version                  : A1.0_0
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Fri Nov 20 15:25:01 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 "COMR_MsgChkSumDiag.h"
#include "COMR_MsgChkSumDiag_private.h"

/* Exported data definition */

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

/* Definition for custom storage class: Volatile */
volatile uint8_T DFC_ChkSumMsg050Err_ASW;
volatile uint8_T DFC_ChkSumMsg2A3Err_ASW;
volatile uint8_T DFC_ChkSumMsg2A5Err_ASW;
volatile uint8_T DFC_ChkSumMsg2A7Err_ASW;
volatile uint8_T DFC_ChkSumMsg2E0Err_ASW;
volatile uint8_T DFC_ChkSumMsg2E1Err_ASW;
volatile uint8_T DFC_ChkSumMsg2EBErr_ASW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T COMR_bChkSumMsg050Det;
volatile boolean_T COMR_bChkSumMsg050Heal;
volatile boolean_T COMR_bChkSumMsg2A3Det;
volatile boolean_T COMR_bChkSumMsg2A3Heal;
volatile boolean_T COMR_bChkSumMsg2E1Det;
volatile boolean_T COMR_bChkSumMsg2E1Heal;
volatile boolean_T COMR_bChkSumMsg2E6Det;
volatile boolean_T COMR_bChkSumMsg2E6Heal;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_COMR_MsgChkSumDiag_T COMR_MsgChkSumDiag_B;

/* Block states (auto storage) */
DW_COMR_MsgChkSumDiag_T COMR_MsgChkSumDiag_DW;

/* Model step function */
void COMR_MsgChkSumDiag_step(void)
{
  boolean_T rtb_LogicalOperator1;
  real32_T rtb_Product;
  uint8_T rtb_Switch4_fh;
  boolean_T rtb_LogicalOperator1_0;
  real32_T tmp;
  rtb_LogicalOperator1 = ((BSPR_bKl15WkUp || VCAN_NMMsgRx || BMCR_bWkUpVCU) && (
    !COMR_stEol));
  if (rtb_LogicalOperator1) {
    rtb_Product = 0.01F;
  } else {
    rtb_Product = 0.0F;
  }

  if (2.0F <= COMR_MsgChkSumDiag_DW.Delay_DSTATE) {
    tmp = 2.0F;
  } else {
    tmp = COMR_MsgChkSumDiag_DW.Delay_DSTATE;
  }

  rtb_Product = (rtb_Product + tmp) * (real32_T)rtb_LogicalOperator1;
  COMR_MsgChkSumDiag_DW.Delay_DSTATE = rtb_Product;
  if ((rtb_Product > 2.0F) && COMR_bLvComDiagEn && (!BSW_stOTAMode)) {
    if (!COMR_MsgChkSumDiag_DW.MsgChkSumDiag_MODE) {
      COMR_MsgChkSumDiag_DW.Delay2_DSTATE_h = true;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE_p = 0U;
      COMR_MsgChkSumDiag_DW.Delay2_DSTATE_m = true;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE_h = 0U;
      COMR_MsgChkSumDiag_DW.Delay2_DSTATE = true;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE = 0U;
      COMR_MsgChkSumDiag_DW.Delay2_DSTATE_oa = true;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE_n = 0U;
      COMR_MsgChkSumDiag_DW.MsgChkSumDiag_MODE = true;
    }

    rtb_LogicalOperator1 = ((COMR_cntVcu2A3ChkSumDiag_CW & 16) == 16);
    COMR_bChkSumMsg2A3Det = (rtb_LogicalOperator1 && COMR_DFC_ChkSumMsg2A3Err);
    if (rtb_LogicalOperator1) {
      COMR_bChkSumMsg2A3Heal = !COMR_DFC_ChkSumMsg2A3Err;
    } else {
      COMR_bChkSumMsg2A3Heal = true;
    }

    if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE_h) {
      rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg2A3Err_ASW | 8U);
    } else if (COMR_bChkSumMsg2A3Det) {
      rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg2A3Err_ASW | 152U);
    } else if (COMR_bChkSumMsg2A3Heal) {
      rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_ChkSumMsg2A3Err_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE_p;
    }

    COMR_MsgChkSumDiag_DW.Delay2_DSTATE_h = false;
    COMR_MsgChkSumDiag_DW.Delay3_DSTATE_p = rtb_Switch4_fh;
    DFC_ChkSumMsg2A3Err_ASW = rtb_Switch4_fh;
    if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE_m) {
      rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg2A7Err_ASW | 8U);
    } else if (rtb_LogicalOperator1 && COMR_DFC_ChkSumMsg2A7Err) {
      rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg2A7Err_ASW | 152U);
    } else {
      if (rtb_LogicalOperator1) {
        rtb_LogicalOperator1_0 = !COMR_DFC_ChkSumMsg2A7Err;
      } else {
        rtb_LogicalOperator1_0 = true;
      }

      if (rtb_LogicalOperator1_0) {
        rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_ChkSumMsg2A7Err_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE_h;
      }
    }

    COMR_MsgChkSumDiag_DW.Delay2_DSTATE_m = false;
    COMR_MsgChkSumDiag_DW.Delay3_DSTATE_h = rtb_Switch4_fh;
    DFC_ChkSumMsg2A7Err_ASW = rtb_Switch4_fh;
    if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE) {
      rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg2A5Err_ASW | 8U);
    } else if (rtb_LogicalOperator1 && COMR_DFC_ChkSumMsg2A5Err) {
      rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg2A5Err_ASW | 152U);
    } else {
      if (rtb_LogicalOperator1) {
        rtb_LogicalOperator1 = !COMR_DFC_ChkSumMsg2A5Err;
      } else {
        rtb_LogicalOperator1 = true;
      }

      if (rtb_LogicalOperator1) {
        rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_ChkSumMsg2A5Err_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE;
      }
    }

    COMR_MsgChkSumDiag_DW.Delay2_DSTATE = false;
    COMR_MsgChkSumDiag_DW.Delay3_DSTATE = rtb_Switch4_fh;
    DFC_ChkSumMsg2A5Err_ASW = rtb_Switch4_fh;
    rtb_LogicalOperator1 = ((COMR_cntABM050ChkSumDiag_CW & 16) == 16);
    COMR_bChkSumMsg050Det = (rtb_LogicalOperator1 && COMR_DFC_ChkSumMsg050Err);
    if (rtb_LogicalOperator1) {
      COMR_bChkSumMsg050Heal = !COMR_DFC_ChkSumMsg050Err;
    } else {
      COMR_bChkSumMsg050Heal = true;
    }

    if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE_oa) {
      rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg050Err_ASW | 8U);
    } else if (COMR_bChkSumMsg050Det) {
      rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg050Err_ASW | 152U);
    } else if (COMR_bChkSumMsg050Heal) {
      rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_ChkSumMsg050Err_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE_n;
    }

    COMR_MsgChkSumDiag_DW.Delay2_DSTATE_oa = false;
    COMR_MsgChkSumDiag_DW.Delay3_DSTATE_n = rtb_Switch4_fh;
    DFC_ChkSumMsg050Err_ASW = rtb_Switch4_fh;
    if ((BCMR_stAChrgCnnt == 1) || (BMCR_stBmsModeCtrl == 6)) {
      if (!COMR_MsgChkSumDiag_DW.OBC_MODE) {
        COMR_MsgChkSumDiag_DW.Delay2_DSTATE_l = true;
        COMR_MsgChkSumDiag_DW.Delay3_DSTATE_j = 0U;
        COMR_MsgChkSumDiag_DW.Delay2_DSTATE_o = true;
        COMR_MsgChkSumDiag_DW.Delay3_DSTATE_c = 0U;
        COMR_MsgChkSumDiag_DW.Delay2_DSTATE_e = true;
        COMR_MsgChkSumDiag_DW.Delay3_DSTATE_l = 0U;
        COMR_MsgChkSumDiag_DW.OBC_MODE = true;
      }

      rtb_LogicalOperator1 = ((COMR_cntOBCChkSumDiag_CW & 16) == 16);
      COMR_MsgChkSumDiag_B.Switch2 = (rtb_LogicalOperator1 &&
        COMR_DFC_ChkSumMsg2E6Err);
      if (rtb_LogicalOperator1) {
        COMR_MsgChkSumDiag_B.Switch1 = !COMR_DFC_ChkSumMsg2E6Err;
      } else {
        COMR_MsgChkSumDiag_B.Switch1 = true;
      }

      if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE_l) {
        rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg2E0Err_ASW | 8U);
      } else if (COMR_MsgChkSumDiag_B.Switch2) {
        rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg2E0Err_ASW | 152U);
      } else if (COMR_MsgChkSumDiag_B.Switch1) {
        rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_ChkSumMsg2E0Err_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE_j;
      }

      COMR_MsgChkSumDiag_DW.Delay2_DSTATE_l = false;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE_j = rtb_Switch4_fh;
      DFC_ChkSumMsg2E0Err_ASW = rtb_Switch4_fh;
      rtb_LogicalOperator1 = ((COMR_cntOBCChkSumDiag_CW & 16) == 16);
      COMR_MsgChkSumDiag_B.Switch4 = (rtb_LogicalOperator1 &&
        COMR_DFC_ChkSumMsg2E1Err);
      if (rtb_LogicalOperator1) {
        COMR_MsgChkSumDiag_B.Switch3 = !COMR_DFC_ChkSumMsg2E1Err;
      } else {
        COMR_MsgChkSumDiag_B.Switch3 = true;
      }

      if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE_o) {
        rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg2E1Err_ASW | 8U);
      } else if (COMR_MsgChkSumDiag_B.Switch4) {
        rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg2E1Err_ASW | 152U);
      } else if (COMR_MsgChkSumDiag_B.Switch3) {
        rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_ChkSumMsg2E1Err_ASW | 16U) | 8U);
      } else {
        rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE_c;
      }

      COMR_MsgChkSumDiag_DW.Delay2_DSTATE_o = false;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE_c = rtb_Switch4_fh;
      DFC_ChkSumMsg2E1Err_ASW = rtb_Switch4_fh;
      if (COMR_MsgChkSumDiag_DW.Delay2_DSTATE_e) {
        rtb_Switch4_fh = (uint8_T)~(uint8_T)((uint8_T)~DFC_ChkSumMsg2EBErr_ASW | 8U);
      } else {
        rtb_LogicalOperator1 = ((COMR_cntOBCChkSumDiag_CW & 16) == 16);
        if (rtb_LogicalOperator1 && COMR_DFC_ChkSumMsg2EBErr) {
          rtb_Switch4_fh = (uint8_T)(DFC_ChkSumMsg2EBErr_ASW | 152U);
        } else {
          if (rtb_LogicalOperator1) {
            rtb_LogicalOperator1 = !COMR_DFC_ChkSumMsg2EBErr;
          } else {
            rtb_LogicalOperator1 = true;
          }

          if (rtb_LogicalOperator1) {
            rtb_Switch4_fh = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
              ~DFC_ChkSumMsg2EBErr_ASW | 16U) | 8U);
          } else {
            rtb_Switch4_fh = COMR_MsgChkSumDiag_DW.Delay3_DSTATE_l;
          }
        }
      }

      COMR_MsgChkSumDiag_DW.Delay2_DSTATE_e = false;
      COMR_MsgChkSumDiag_DW.Delay3_DSTATE_l = rtb_Switch4_fh;
      DFC_ChkSumMsg2EBErr_ASW = rtb_Switch4_fh;
    } else {
      if (COMR_MsgChkSumDiag_DW.OBC_MODE) {
        COMR_MsgChkSumDiag_DW.OBC_MODE = false;
      }
    }

    COMR_bChkSumMsg2E1Det = COMR_MsgChkSumDiag_B.Switch4;
    COMR_bChkSumMsg2E1Heal = COMR_MsgChkSumDiag_B.Switch3;
    COMR_bChkSumMsg2E6Det = COMR_MsgChkSumDiag_B.Switch2;
    COMR_bChkSumMsg2E6Heal = COMR_MsgChkSumDiag_B.Switch1;
  } else {
    if (COMR_MsgChkSumDiag_DW.MsgChkSumDiag_MODE) {
      if (COMR_MsgChkSumDiag_DW.OBC_MODE) {
        COMR_MsgChkSumDiag_DW.OBC_MODE = false;
      }

      COMR_MsgChkSumDiag_DW.MsgChkSumDiag_MODE = false;
    }
  }
}

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

  /* block I/O */

  /* custom signals */
  COMR_bChkSumMsg2A3Det = false;
  COMR_bChkSumMsg2A3Heal = false;
  COMR_bChkSumMsg050Det = false;
  COMR_bChkSumMsg050Heal = false;
  COMR_bChkSumMsg2E1Det = false;
  COMR_bChkSumMsg2E1Heal = false;
  COMR_bChkSumMsg2E6Det = false;
  COMR_bChkSumMsg2E6Heal = false;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE_h = true;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE_m = true;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE = true;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE_oa = true;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE_l = true;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE_o = true;
  COMR_MsgChkSumDiag_DW.Delay2_DSTATE_e = true;
}

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