/*
 * File: BCMR_DChrgComProc.c
 *
 * Code generated for Simulink model 'BCMR_DChrgComProc'.
 *
 * Model version                  : 1.100
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Sun Feb 28 20:36:49 2021
 *
 * 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 "BCMR_DChrgComProc.h"
#include "BCMR_DChrgComProc_private.h"

/* Exported block signals */
MSG_BRM_P1 BCMR_strMsgBRM_P1;          /* '<S42>/Bus Creator1' */
MSG_BCP_P2 BCMR_strMsgBCP_P2;          /* '<S43>/Bus Creator' */
MSG_BSD_P4 BCMR_strMsgBSD_P4;          /* '<S40>/Bus Creator' */
MSG_BSM_P3 BCMR_strMsgBSM_P3;          /* '<S56>/Bus Creator2' */
MSG_BCL_P3 BCMR_strMsgBCL_P3;          /* '<S54>/Bus Creator' */
MSG_BCS_P3 BCMR_strMsgBCS_P3;          /* '<S55>/Bus Creator1' */
MSG_BST_P3 BCMR_strMsgBST_P3;          /* '<S57>/Bus Creator3' */
MSG_BHM_P1 BCMR_strMsgBHM_P1;          /* '<S41>/Bus Creator' */
MSG_BRO_P2 BCMR_strMsgBRO_P2;          /* '<S44>/Bus Creator1' */
MSG_BEM_ERR BCMR_strMsgBEM_ERR;        /* '<S47>/Bus Creator' */

/* Exported data definition */

/* Definition for custom storage class: FileScope */
static boolean_T CEM_RxTimeoutErr;
static boolean_T CST_RxStopChrg;

#define ASW1_OEM_START_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BCMR_bRxCrmIdtfRstNg;
volatile boolean_T BCMR_bRxCrmIdtfRstOk;
volatile boolean_T BCMR_bRxCroRdyNg;
volatile boolean_T BCMR_bRxCroRdyOk;
volatile uint8_T BCMR_stDChrgerActStop;/* BST */
volatile boolean_T BCMR_verDChrgCom2015;
volatile real32_T COMR_iDcChrgMaxCurrOutputPmtdCml;
volatile real32_T COMR_iDcChrgMinCurrOutputPmtdCml;
volatile real32_T COMR_iDcChrgOutputCurrCcs;
volatile real32_T COMR_tiDcChrgTimeActualCcs;
volatile real32_T COMR_uDcChrgMaxVoltOutputPmtdCml;
volatile real32_T COMR_uDcChrgMinVoltOutputPmtdCml;
volatile real32_T COMR_vDcChrgOutputVoltCcs;
volatile uint8_T DFC_DChrgMsgTimeout_ASW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block states (auto storage) */
DW_BCMR_DChrgComProc_T BCMR_DChrgComProc_DW;

/* External inputs (root inport signals with auto storage) */
ExtU_BCMR_DChrgComProc_T BCMR_DChrgComProc_U;

/* Model step function */
void BCMR_DChrgComProc_step(void)
{
  boolean_T rtb_LogicalOperator3_d;
  real32_T rtb_Switch2;
  real32_T rtb_Product_j;
  real32_T tmp;
  BCMR_verDChrgCom2015 = ((COMR_strMsgCHM_P1.COMR_numComVer == 2015U) ||
    (COMR_strMsgCHM_P1.COMR_numComVer == 257U));
  COMR_iDcChrgMaxCurrOutputPmtdCml =
    COMR_strMsgCML_P2.COMR_iDcChrgMaxCurrOutputPmtdCml;
  COMR_uDcChrgMaxVoltOutputPmtdCml =
    COMR_strMsgCML_P2.COMR_uDcChrgMaxVoltOutputPmtdCml;
  COMR_uDcChrgMinVoltOutputPmtdCml =
    COMR_strMsgCML_P2.COMR_uDcChrgMinVoltOutputPmtdCml;
  if (BCMR_verDChrgCom2015) {
    COMR_iDcChrgMinCurrOutputPmtdCml =
      COMR_strMsgCML_P2.COMR_iDcChrgMinCurrOutputPmtdCml;
  } else {
    COMR_iDcChrgMinCurrOutputPmtdCml = 0.0F;
  }

  COMR_iDcChrgOutputCurrCcs = COMR_strMsgCCS_P3.COMR_iDcChrgOutputCurrCcs;
  COMR_vDcChrgOutputVoltCcs = COMR_strMsgCCS_P3.COMR_vDcChrgOutputVoltCcs;
  CST_RxStopChrg = ((COMR_strMsgCST_P3.COMR_stRchSetCondCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stMnlStopCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgErrStopCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stBmsStopActCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgerOvrTempErrCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgerCnntErrCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgerInrOvrTempErrCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stEnrgTxAbnrmErrCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgerSrmErrCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stOtherErrCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgCurrAbnrmCst == 1) ||
                    (COMR_strMsgCST_P3.COMR_stChrgVoltAbnrmCst == 1));
  BCMR_stDChrgerActStop = (uint8_T)(COMR_flgRxCST && CST_RxStopChrg);
  BCMR_strMsgBCL_P3.BCMR_iDcChrgCurrReqBcl = -BCMR_iDChrgCurrReqCalc;
  BCMR_strMsgBCL_P3.BCMR_vDcChrgVoltReqBcl = BCMR_uDcChrgVoltReqCalc;
  BCMR_strMsgBCL_P3.BCMR_stDcChrgModeBcl = BCMR_stDChrgModeBcl;
  rtb_Product_j = (real32_T)fmod((real32_T)floor(BCMR_tiRemDChrgTime), 65536.0F);
  BCMR_strMsgBCS_P3.BCMR_tiDcChrgRemTimeBcs = (uint16_T)(rtb_Product_j < 0.0F ?
    (int32_T)(uint16_T)-(int16_T)(uint16_T)-rtb_Product_j : (int32_T)(uint16_T)
    rtb_Product_j);
  BCMR_strMsgBCS_P3.BCMR_vDcChrgVoltBcs = BSPR_uDChrgVolt;
  BCMR_strMsgBCS_P3.BCMR_iDcChrgCurrBcs = BSPR_iBattCurr;
  BCMR_strMsgBCS_P3.BCMR_uMaxCellVoltBcs = BSPR_uCellVoltMax;
  BCMR_strMsgBCS_P3.BCMR_numMaxCellVoltGrpNumBcs = BSPR_idxCellVoltMax;
  rtb_Product_j = (real32_T)fmod((real32_T)floor(BSER_rSocDspl), 256.0F);
  BCMR_strMsgBCS_P3.BCMR_rSocDsplBcs = (uint8_T)(rtb_Product_j < 0.0F ? (int32_T)
    (uint8_T)-(int8_T)(uint8_T)-rtb_Product_j : (int32_T)(uint8_T)rtb_Product_j);
  BCMR_strMsgBSM_P3.BCMR_tBattMinTempBsm = BSPR_tCellTempMin;
  BCMR_strMsgBSM_P3.BCMR_stBattCellVoltErrBsm = BCMR_stDcBattCellVoltErr;
  BCMR_strMsgBSM_P3.BCMR_stChrgEnaBsm = (uint8_T)!BCMR_bDChrgStopEna;
  BCMR_strMsgBSM_P3.BCMR_stBattInsulationErrBsm = BCMR_stDcBattInsulationErr;
  BCMR_strMsgBSM_P3.BCMR_numMaxCellVoltAddrBsm = BSPR_idxCellVoltMax;
  BCMR_strMsgBSM_P3.BCMR_stBattOutputContErrBsm = BCMR_stDChrgCnntErr;
  BCMR_strMsgBSM_P3.BCMR_stBattChrgCurrOvrErrBsm = BCMR_stBattDChrgCurrOvrErr;
  BCMR_strMsgBSM_P3.BCMR_stBattTempOvrErrBsm = BCMR_stDcBattTempOvrErr;
  if (BCMR_BATTSOCERRBSMENA_C) {
    BCMR_strMsgBSM_P3.BCMR_stBattSocErrBsm = BCMR_stDcBattSocErr;
  } else {
    BCMR_strMsgBSM_P3.BCMR_stBattSocErrBsm = 0U;
  }

  BCMR_strMsgBSM_P3.BCMR_numBattMaxTemptAddrBsm = BSPR_idxCellTempMax;
  BCMR_strMsgBSM_P3.BCMR_numBattMinTemptAddrBsm = BSPR_idxCellTempMin;
  BCMR_strMsgBSM_P3.BCMR_tBattMaxTempBsm = BSPR_tCellTempMax;
  BCMR_strMsgBST_P3.BCMR_stRchSocLmtBst = BCMR_stDcRchCellVoltLmt;
  BCMR_strMsgBST_P3.BCMR_stRchPackVoltLmtBst = BCMR_stDcRchCellVoltLmt;
  BCMR_strMsgBST_P3.BCMR_stRchCellVoltLmtBst = BCMR_stDcRchCellVoltLmt;
  BCMR_strMsgBST_P3.BCMR_stChrgerActStopBst = BCMR_flgDChrgStopCActive;
  BCMR_strMsgBST_P3.BCMR_stBattInsulationErrBst = BCMR_stDcBattInsulationErr;
  BCMR_strMsgBST_P3.BCMR_stOutpCnntOvrTempErrBst = BCMR_stDcOutpCnntOvrTempErr;
  BCMR_strMsgBST_P3.BCMR_stPcbOvrTempErrBst = 0U;
  BCMR_strMsgBST_P3.BCMR_stChrgCnntErrBst = BCMR_stDChrgCnntErr;
  BCMR_strMsgBST_P3.BCMR_stBattOvrTempErrBst = BCMR_stDcBattTempOvrErr;
  BCMR_strMsgBST_P3.BCMR_stMainRelayErrBst = BCMR_stMainRelayErr;
  BCMR_strMsgBST_P3.BCMR_stCC2ChkVoltErrBst = BCMR_stCC2ChkVoltErr;
  BCMR_strMsgBST_P3.BCMR_stOtherErrBst = BCMR_stOtherErr;
  BCMR_strMsgBST_P3.BCMR_stChrgCurrAbnrmBst = BCMR_stBattDChrgCurrOvrErr;
  BCMR_strMsgBST_P3.BCMR_stChrgVoltAbnrmBst = BCMR_stBattDChrgVoltOvrErr;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3901TimeoutBem = BCMR_stSpn3901TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3902TimeoutBem = BCMR_stSpn3902TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3903TimeoutBem = BCMR_stSpn3903TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3904TimeoutBem = BCMR_stSpn3904TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3905TimeoutBem = BCMR_stSpn3905TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3906TimeoutBem = BCMR_stSpn3906TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stSpn3907TimeoutBem = BCMR_stSpn3907TimeoutBem;
  BCMR_strMsgBEM_ERR.BCMR_stOtherErrBem = BCMR_stOtherErrBem;
  rtb_LogicalOperator3_d = !BCMR_DChrgComProc_DW.Delay1_DSTATE_f;
  BCMR_DChrgComProc_DW.Delay1_DSTATE_f = BCMR_bDChrgWkup;
  if (rtb_LogicalOperator3_d && BCMR_bDChrgWkup) {
    rtb_Switch2 = 0.0F;
  } else if (BSPR_uBattVolt >= BCMR_DChrgComProc_DW.Delay1_DSTATE) {
    rtb_Switch2 = BSPR_uBattVolt;
  } else {
    rtb_Switch2 = BCMR_DChrgComProc_DW.Delay1_DSTATE;
  }

  if (BCMR_G1E0PLATFORMSWCOM_C) {
    BCMR_strMsgBCP_P2.BCMR_uPackVoltBcp = BSPR_uBattVolt;
  } else {
    BCMR_strMsgBCP_P2.BCMR_uPackVoltBcp = rtb_Switch2;
  }

  BCMR_strMsgBCP_P2.BCMR_vMaxChrgCellVoltPmtdBcp =
    BCMR_UMAXCHRGCELLVOLTPMTDBCP_C;
  BCMR_strMsgBCP_P2.BCMR_iMaxChrgCurrPmtdBcp = BCMR_IMAXCHRGCURRPMTDBCP_C;
  BCMR_strMsgBCP_P2.BCMR_eBattRatedEnrgBcp = BCMR_EBATTRATEDENRGBCP_C;
  BCMR_strMsgBCP_P2.BCMR_vBattRatdPackVoltBcpLow = BCMR_UBATTRATDPACKVOLTBCP_C;
  BCMR_strMsgBCP_P2.BCMR_vBattRatdPackVoltBcpHigh = BCMR_UBATTRATDPACKVOLTBCP_C;
  BCMR_strMsgBCP_P2.BCMR_cMaxTempPmtdBcp = BCMR_TMAXTEMPPMTDBCP_C;
  BCMR_strMsgBCP_P2.BCMR_rSocDsplBcp = BSER_rSocDspl;
  BCMR_strMsgBRO_P2.BCMR_stBmsRdyBro = BCMR_stBmsRdyBro;
  BCMR_strMsgBHM_P1.BCMR_uMaxPmtdChrgPackVoltBhm = BCMR_UMAXPMTDCHRGVOLT_C;
  if (BCMR_flgDChrgVer2015) {
    BCMR_strMsgBRM_P1.BCMR_numComVerBrm = BCMR_NUMCOMVER2015BRM_C;
  } else {
    BCMR_strMsgBRM_P1.BCMR_numComVerBrm = BCMR_NUMCOMVER2011BRM_C;
  }

  BCMR_strMsgBRM_P1.BCMR_numBattTypeBrm = BCMR_NUMBATTTYPEBRM_C;
  BCMR_strMsgBRM_P1.BCMR_ahBattRatdCpctyBrm = BCMR_AHBATTRATDCPCTYBRM_C;
  BCMR_strMsgBRM_P1.BCMR_vBattRatdPackVoltBrm1 = BCMR_UBATTRATDPACKVOLTBRM_C;
  BCMR_strMsgBRM_P1.BCMR_vBattRatdPackVoltBrm2 = BCMR_UBATTRATDPACKVOLTBRM_C;
  BCMR_strMsgBRM_P1.BCMR_numProducerName =
    BCMR_DChrgComProc_ConstB.DataTypeConversion14;
  BCMR_strMsgBRM_P1.BCMR_numBattSerialNum1 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion15;
  BCMR_strMsgBRM_P1.BCMR_numBattSerialNum2 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion16;
  BCMR_strMsgBRM_P1.BCMR_numBattPrdtYear =
    BCMR_DChrgComProc_ConstB.DataTypeConversion17;
  BCMR_strMsgBRM_P1.BCMR_numBattPrdtMonth =
    BCMR_DChrgComProc_ConstB.DataTypeConversion;
  BCMR_strMsgBRM_P1.BCMR_numBattPrdtDay =
    BCMR_DChrgComProc_ConstB.DataTypeConversion1;
  BCMR_strMsgBRM_P1.BCMR_cntDChrgCnt1 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion2;
  BCMR_strMsgBRM_P1.BCMR_cntDChrgCnt2 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion3;
  BCMR_strMsgBRM_P1.BCMR_idOwnerID =
    BCMR_DChrgComProc_ConstB.DataTypeConversion4;
  BCMR_strMsgBRM_P1.BCMR_Reserved = BCMR_DChrgComProc_ConstB.DataTypeConversion5;
  BCMR_strMsgBRM_P1.BCMR_idVIN1 = BCMR_DChrgComProc_ConstB.DataTypeConversion6;
  BCMR_strMsgBRM_P1.BCMR_idVIN2 = BCMR_DChrgComProc_ConstB.DataTypeConversion7;
  BCMR_strMsgBRM_P1.BCMR_idVIN3 = BCMR_DChrgComProc_ConstB.DataTypeConversion9;
  BCMR_strMsgBRM_P1.BCMR_idVIN4 = BCMR_DChrgComProc_ConstB.DataTypeConversion8;
  BCMR_strMsgBRM_P1.BCMR_idVIN5 = BCMR_DChrgComProc_ConstB.DataTypeConversion10;
  BCMR_strMsgBRM_P1.BCMR_vSoftVer1 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion11;
  BCMR_strMsgBRM_P1.BCMR_vSoftVer2 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion12;
  BCMR_strMsgBRM_P1.BCMR_vSoftVer3 =
    BCMR_DChrgComProc_ConstB.DataTypeConversion13;
  BCMR_strMsgBSD_P4.BCMR_tBattMaxTempBsd = BSPR_tCellTempMax;
  BCMR_strMsgBSD_P4.BCMR_tBattMinTempBsd = BSPR_tCellTempMin;
  BCMR_strMsgBSD_P4.BCMR_vBattMinCellVoltBsd = BSPR_uCellVoltMin;
  BCMR_strMsgBSD_P4.BCMR_vBattMaxCellVoltBsd = BSPR_uCellVoltMax;
  rtb_Product_j = (real32_T)fmod((real32_T)floor(BSER_rSocDspl), 256.0F);
  BCMR_strMsgBSD_P4.BCMR_rBattSocBsd = (uint8_T)(rtb_Product_j < 0.0F ? (int32_T)
    (uint8_T)-(int8_T)(uint8_T)-rtb_Product_j : (int32_T)(uint8_T)rtb_Product_j);
  if (BCMR_DChrgComProc_DW.Delay2_DSTATE) {
    DFC_DChrgMsgTimeout_ASW = (uint8_T)~(uint8_T)((uint8_T)~DFC_DChrgMsgTimeout_ASW | 8U);
  } else if (BCMR_flgTxBEM) {
    DFC_DChrgMsgTimeout_ASW = (uint8_T)(DFC_DChrgMsgTimeout_ASW | 152U);
  } else {
    DFC_DChrgMsgTimeout_ASW = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
      ~DFC_DChrgMsgTimeout_ASW | 16U) | 8U);
  }

  BCMR_DChrgComProc_DW.Delay2_DSTATE = false;
  if (COMR_flgRxCRM) {
    rtb_Product_j = 0.01F;
  } else {
    rtb_Product_j = 0.0F;
  }

  if (0.03F <= BCMR_DChrgComProc_DW.Delay_DSTATE_j) {
    tmp = 0.03F;
  } else {
    tmp = BCMR_DChrgComProc_DW.Delay_DSTATE_j;
  }

  rtb_Product_j = (rtb_Product_j + tmp) * (real32_T)COMR_flgRxCRM;
  BCMR_DChrgComProc_DW.Delay_DSTATE_j = rtb_Product_j;
  if (rtb_Product_j > 0.03F) {
    BCMR_bRxCrmIdtfRstNg = (COMR_strMsgCRM_P1.COMR_stIdtfRstCrm == 0);
    BCMR_bRxCrmIdtfRstOk = (COMR_strMsgCRM_P1.COMR_stIdtfRstCrm == 170);
  } else {
    BCMR_bRxCrmIdtfRstNg = false;
    BCMR_bRxCrmIdtfRstOk = false;
  }

  if (COMR_flgRxCRO) {
    rtb_Product_j = 0.01F;
  } else {
    rtb_Product_j = 0.0F;
  }

  if (0.03F <= BCMR_DChrgComProc_DW.Delay_DSTATE) {
    tmp = 0.03F;
  } else {
    tmp = BCMR_DChrgComProc_DW.Delay_DSTATE;
  }

  rtb_Product_j = (rtb_Product_j + tmp) * (real32_T)COMR_flgRxCRO;
  BCMR_DChrgComProc_DW.Delay_DSTATE = rtb_Product_j;
  if (rtb_Product_j > 0.03F) {
    BCMR_bRxCroRdyNg = (COMR_strMsgCRO_P2.COMR_stChrgRdyCro == 0);
    BCMR_bRxCroRdyOk = (COMR_strMsgCRO_P2.COMR_stChrgRdyCro == 170);
  } else {
    BCMR_bRxCroRdyNg = false;
    BCMR_bRxCroRdyOk = false;
  }

  COMR_tiDcChrgTimeActualCcs = (real32_T)
    COMR_strMsgCCS_P3.COMR_tiDcChrgTimeActualCcs;
  CEM_RxTimeoutErr = ((COMR_strMsgCEM_ERR.COMR_stRcvBrmTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stRcvBcpTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stRcvBroOkTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stRcvBcsTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stRcvBclTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stRcvBstTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stRcvBsdTimeOutCem == 1) ||
                      (COMR_strMsgCEM_ERR.COMR_stOtherErrCem == 1));
  BCMR_DChrgComProc_DW.Delay1_DSTATE = rtb_Switch2;
}

/* Model initialize function */
void BCMR_DChrgComProc_initialize(void)
{
  BCMR_DChrgComProc_DW.Delay1_DSTATE_f = true;
  BCMR_DChrgComProc_DW.Delay2_DSTATE = true;
}

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