/*
 * File: COMR_MsgRcDiag.c
 *
 * Code generated for Simulink model 'COMR_MsgRcDiag'.
 *
 * Model version                  : A1.1_0
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Fri Nov 20 15:52:00 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_MsgRcDiag.h"
#include "COMR_MsgRcDiag_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_RcMsg050Mis_ASW;
volatile uint8_T DFC_RcMsg2A3Mis_ASW;
volatile uint8_T DFC_RcMsg2A5Mis_ASW;
volatile uint8_T DFC_RcMsg2A7Mis_ASW;
volatile uint8_T DFC_RcMsg2E0Mis_ASW;
volatile uint8_T DFC_RcMsg2E1Mis_ASW;
volatile uint8_T DFC_RcMsg2EBMis_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 uint8_T COMR_cntRCMsg050Pre;
volatile uint8_T COMR_cntRCMsg2A3Pre;
volatile uint8_T COMR_cntRCMsg2A5Pre;
volatile uint8_T COMR_cntRCMsg2A7Pre;
volatile uint8_T COMR_cntRCMsg2E1Pre;
volatile uint8_T COMR_cntRCMsg2E6Pre;
volatile boolean_T COMR_flgRcMsg050MissErr;
volatile boolean_T COMR_flgRcMsg2A3MissErr;
volatile boolean_T COMR_flgRcMsg2A5MissErr;
volatile boolean_T COMR_flgRcMsg2A7MissErr;
volatile boolean_T COMR_flgRcMsg2E1MissErr;
volatile boolean_T COMR_flgRcMsg2E6MissErr;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_COMR_MsgRcDiag_T COMR_MsgRcDiag_B;

/* Block states (auto storage) */
DW_COMR_MsgRcDiag_T COMR_MsgRcDiag_DW;

/* Model step function */
void COMR_MsgRcDiag_step(void)
{
  boolean_T rtb_LogicalOperator1;
  real32_T rtb_Product;
  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_MsgRcDiag_DW.Delay_DSTATE) {
    tmp = 2.0F;
  } else {
    tmp = COMR_MsgRcDiag_DW.Delay_DSTATE;
  }

  rtb_Product = (rtb_Product + tmp) * (real32_T)rtb_LogicalOperator1;
  COMR_MsgRcDiag_DW.Delay_DSTATE = rtb_Product;
  if ((rtb_Product > 2.0F) && COMR_bLvComDiagEn && (!BSW_stOTAMode)) {
    if (!COMR_MsgRcDiag_DW.VcuObc_RC_Diag_MODE) {
      COMR_MsgRcDiag_DW.Delay2_DSTATE_b = true;
      COMR_MsgRcDiag_DW.Delay2_DSTATE_f = true;
      COMR_MsgRcDiag_DW.Delay2_DSTATE = true;
      COMR_MsgRcDiag_DW.VcuObc_RC_Diag_MODE = true;
    }

    COMR_flgRcMsg2A7MissErr = COMR_DFC_RcMsg2A7Mis;
    if (COMR_MsgRcDiag_DW.Delay2_DSTATE_b) {
      DFC_RcMsg2A7Mis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2A7Mis_ASW | 8U);
    } else if (COMR_flgRcMsg2A7MissErr) {
      DFC_RcMsg2A7Mis_ASW = (uint8_T)(DFC_RcMsg2A7Mis_ASW | 152U);
    } else {
      DFC_RcMsg2A7Mis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2A7Mis_ASW |
        16U) | 8U);
    }

    COMR_MsgRcDiag_DW.Delay2_DSTATE_b = false;
    COMR_flgRcMsg2A5MissErr = COMR_DFC_RcMsg2A5Mis;
    if (COMR_MsgRcDiag_DW.Delay2_DSTATE_f) {
      DFC_RcMsg2A5Mis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2A5Mis_ASW | 8U);
    } else if (COMR_flgRcMsg2A5MissErr) {
      DFC_RcMsg2A5Mis_ASW = (uint8_T)(DFC_RcMsg2A5Mis_ASW | 152U);
    } else {
      DFC_RcMsg2A5Mis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2A5Mis_ASW |
        16U) | 8U);
    }

    COMR_MsgRcDiag_DW.Delay2_DSTATE_f = false;
    COMR_flgRcMsg2A3MissErr = COMR_DFC_RcMsg2A3Mis;
    if (COMR_MsgRcDiag_DW.Delay2_DSTATE) {
      DFC_RcMsg2A3Mis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2A3Mis_ASW | 8U);
    } else if (COMR_flgRcMsg2A3MissErr) {
      DFC_RcMsg2A3Mis_ASW = (uint8_T)(DFC_RcMsg2A3Mis_ASW | 152U);
    } else {
      DFC_RcMsg2A3Mis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2A3Mis_ASW |
        16U) | 8U);
    }

    COMR_MsgRcDiag_DW.Delay2_DSTATE = false;
    COMR_cntRCMsg2A5Pre = 0U;
    COMR_cntRCMsg2A7Pre = 0U;
    COMR_cntRCMsg2A3Pre = COMR_MsgRcDiag_ConstB.Constant;
    if ((BMCR_stBmsModeCtrl == 11) || (BMCR_stBmsModeCtrl == 6)) {
      COMR_MsgRcDiag_B.COMR_DFC_RcMsg2E6Mis_j = COMR_DFC_RcMsg2E6Mis;
      if (COMR_MsgRcDiag_DW.Delay2_DSTATE_i) {
        DFC_RcMsg2E0Mis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2E0Mis_ASW | 8U);
      } else if (COMR_MsgRcDiag_B.COMR_DFC_RcMsg2E6Mis_j) {
        DFC_RcMsg2E0Mis_ASW = (uint8_T)(DFC_RcMsg2E0Mis_ASW | 152U);
      } else {
        DFC_RcMsg2E0Mis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_RcMsg2E0Mis_ASW | 16U) | 8U);
      }

      COMR_MsgRcDiag_DW.Delay2_DSTATE_i = false;
      COMR_MsgRcDiag_B.COMR_DFC_RcMsg2E1Mis_g = COMR_DFC_RcMsg2E1Mis;
      if (COMR_MsgRcDiag_DW.Delay2_DSTATE_c) {
        DFC_RcMsg2E1Mis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2E1Mis_ASW | 8U);
      } else if (COMR_MsgRcDiag_B.COMR_DFC_RcMsg2E1Mis_g) {
        DFC_RcMsg2E1Mis_ASW = (uint8_T)(DFC_RcMsg2E1Mis_ASW | 152U);
      } else {
        DFC_RcMsg2E1Mis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_RcMsg2E1Mis_ASW | 16U) | 8U);
      }

      COMR_MsgRcDiag_DW.Delay2_DSTATE_c = false;
      if (COMR_MsgRcDiag_DW.Delay2_DSTATE_g) {
        DFC_RcMsg2EBMis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg2EBMis_ASW | 8U);
      } else if (COMR_DFC_RcMsg2EBMis) {
        DFC_RcMsg2EBMis_ASW = (uint8_T)(DFC_RcMsg2EBMis_ASW | 152U);
      } else {
        DFC_RcMsg2EBMis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
          ~DFC_RcMsg2EBMis_ASW | 16U) | 8U);
      }

      COMR_MsgRcDiag_DW.Delay2_DSTATE_g = false;
      COMR_MsgRcDiag_B.OutportBufferForCOMR_cntRCMsg2E =
        COMR_MsgRcDiag_ConstB.Constant_g;
      COMR_MsgRcDiag_B.OutportBufferForCOMR_cntRCMsg_m =
        COMR_MsgRcDiag_ConstB.Constant1;
    }

    COMR_cntRCMsg2E1Pre = COMR_MsgRcDiag_B.OutportBufferForCOMR_cntRCMsg_m;
    COMR_cntRCMsg2E6Pre = COMR_MsgRcDiag_B.OutportBufferForCOMR_cntRCMsg2E;
    COMR_flgRcMsg2E1MissErr = COMR_MsgRcDiag_B.COMR_DFC_RcMsg2E1Mis_g;
    COMR_flgRcMsg2E6MissErr = COMR_MsgRcDiag_B.COMR_DFC_RcMsg2E6Mis_j;
  } else {
    if (COMR_MsgRcDiag_DW.VcuObc_RC_Diag_MODE) {
      COMR_MsgRcDiag_DW.VcuObc_RC_Diag_MODE = false;
    }
  }

  rtb_LogicalOperator1 = (BSPR_bKl15WkUp && (!COMR_stEol));
  if (rtb_LogicalOperator1) {
    rtb_Product = 0.01F;
  } else {
    rtb_Product = 0.0F;
  }

  if (2.0F <= COMR_MsgRcDiag_DW.Delay_DSTATE_b) {
    tmp = 2.0F;
  } else {
    tmp = COMR_MsgRcDiag_DW.Delay_DSTATE_b;
  }

  rtb_Product = (rtb_Product + tmp) * (real32_T)rtb_LogicalOperator1;
  COMR_MsgRcDiag_DW.Delay_DSTATE_b = rtb_Product;
  if ((rtb_Product > 2.0F) && COMR_bLvComDiagEn && (!BSW_stOTAMode)) {
    if (!COMR_MsgRcDiag_DW.Abm_RC_Diag_MODE) {
      COMR_MsgRcDiag_DW.Delay2_DSTATE_m = true;
      COMR_MsgRcDiag_DW.Abm_RC_Diag_MODE = true;
    }

    COMR_flgRcMsg050MissErr = COMR_DFC_RcMsg050Mis;
    if (COMR_MsgRcDiag_DW.Delay2_DSTATE_m) {
      DFC_RcMsg050Mis_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg050Mis_ASW | 8U);
    } else if (COMR_flgRcMsg050MissErr) {
      DFC_RcMsg050Mis_ASW = (uint8_T)(DFC_RcMsg050Mis_ASW | 152U);
    } else {
      DFC_RcMsg050Mis_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_RcMsg050Mis_ASW |
        16U) | 8U);
    }

    COMR_MsgRcDiag_DW.Delay2_DSTATE_m = false;
    COMR_cntRCMsg050Pre = COMR_MsgRcDiag_ConstB.Constant_b;
  } else {
    if (COMR_MsgRcDiag_DW.Abm_RC_Diag_MODE) {
      COMR_MsgRcDiag_DW.Abm_RC_Diag_MODE = false;
    }
  }
}

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

  /* block I/O */

  /* custom signals */
  COMR_cntRCMsg2A5Pre = ((uint8_T)0U);
  COMR_cntRCMsg2A7Pre = ((uint8_T)0U);
  COMR_cntRCMsg2A3Pre = ((uint8_T)0U);
  COMR_cntRCMsg2E1Pre = ((uint8_T)0U);
  COMR_cntRCMsg2E6Pre = ((uint8_T)0U);
  COMR_cntRCMsg050Pre = ((uint8_T)0U);
  COMR_flgRcMsg2A7MissErr = false;
  COMR_flgRcMsg2A5MissErr = false;
  COMR_flgRcMsg2A3MissErr = false;
  COMR_flgRcMsg2E1MissErr = false;
  COMR_flgRcMsg2E6MissErr = false;
  COMR_flgRcMsg050MissErr = false;
  COMR_MsgRcDiag_DW.Delay2_DSTATE_b = true;
  COMR_MsgRcDiag_DW.Delay2_DSTATE_f = true;
  COMR_MsgRcDiag_DW.Delay2_DSTATE = true;
  COMR_cntRCMsg2A3Pre = COMR_MsgRcDiag_ConstB.Constant;
  COMR_MsgRcDiag_DW.Delay2_DSTATE_i = true;
  COMR_MsgRcDiag_DW.Delay2_DSTATE_c = true;
  COMR_MsgRcDiag_DW.Delay2_DSTATE_g = true;
  COMR_MsgRcDiag_B.OutportBufferForCOMR_cntRCMsg2E =
    COMR_MsgRcDiag_ConstB.Constant_g;
  COMR_MsgRcDiag_B.OutportBufferForCOMR_cntRCMsg_m =
    COMR_MsgRcDiag_ConstB.Constant1;
  COMR_MsgRcDiag_DW.Delay2_DSTATE_m = true;
  COMR_cntRCMsg050Pre = COMR_MsgRcDiag_ConstB.Constant_b;
}

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