/*
 * File: BSPR_DChrgTempCalc.c
 *
 * Code generated for Simulink model 'BSPR_DChrgTempCalc'.
 *
 * Model version                  : 1.59
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Wed Jun 17 11:17:58 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_DChrgTempCalc.h"
#include "BSPR_DChrgTempCalc_private.h"

/* Exported data definition */

/* Definition for custom storage class: OutputSignal */
volatile real32_T BSPR_tDcChNeg;
volatile real32_T BSPR_tDcChPos;
volatile real32_T BSPR_uDChrgNegTemp;
volatile real32_T BSPR_uDChrgNegTempFlt;
volatile real32_T BSPR_uDChrgPosTemp;
volatile real32_T BSPR_uDChrgPosTempFlt;

/* Block signals (auto storage) */
B_BSPR_DChrgTempCalc_T BSPR_DChrgTempCalc_B;

/* Block states (auto storage) */
DW_BSPR_DChrgTempCalc_T BSPR_DChrgTempCalc_DW;

/* Model step function */
void BSPR_DChrgTempCalc_step(void)
{
  boolean_T rtb_RelationalOperator;
  real32_T rtb_Gain2_j;
  rtb_RelationalOperator = (BSW_uDChrgPosTemp > BSPR_uDChrgPosTempInitVal_C);
  if (rtb_RelationalOperator) {
    if (!BSPR_DChrgTempCalc_DW.Subsystem_MODE) {
      BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_m = 0.0F;
      BSPR_DChrgTempCalc_DW.Delay_DSTATE_m = 1.0F;
      BSPR_DChrgTempCalc_DW.Subsystem_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uDChrgPosTemp;
    if (!(BSPR_DChrgTempCalc_DW.Delay_DSTATE_m > 0.0F)) {
      rtb_Gain2_j = (rtb_Gain2_j - BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_m) *
        BSPR_cofDChrgTempFlt_C + BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_m;
    }

    BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_m = rtb_Gain2_j;
    BSPR_DChrgTempCalc_DW.Delay_DSTATE_m = 0.0F;
    BSPR_DChrgTempCalc_B.uDLookupTable = look1_iflf_binlcpw(rtb_Gain2_j,
      (&(BSPR_tDcChrg_CUR_X[0])), (&(BSPR_tDcChrg_CUR[0])), 240U);
    rtb_Gain2_j = BSPR_DChrgTempCalc_B.uDLookupTable;
  } else {
    if (BSPR_DChrgTempCalc_DW.Subsystem_MODE) {
      BSPR_DChrgTempCalc_DW.Subsystem_MODE = false;
    }

    rtb_Gain2_j = BSPR_tDChrgPosTempInitVal_C;
  }

  if (rtb_Gain2_j > BSPR_tDChrgPosTempUpLim_C) {
    BSPR_tDcChPos = BSPR_tDChrgPosTempUpLim_C;
  } else if (rtb_Gain2_j < BSPR_tDChrgPosTempLoLim_C) {
    BSPR_tDcChPos = BSPR_tDChrgPosTempLoLim_C;
  } else {
    BSPR_tDcChPos = rtb_Gain2_j;
  }

  if (rtb_RelationalOperator) {
    if (!BSPR_DChrgTempCalc_DW.Subsystem1_MODE) {
      BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_f = 0.0F;
      BSPR_DChrgTempCalc_DW.Delay_DSTATE_b = 1.0F;
      BSPR_DChrgTempCalc_DW.Subsystem1_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uDChrgPosTemp;
    if (BSPR_DChrgTempCalc_DW.Delay_DSTATE_b > 0.0F) {
      BSPR_DChrgTempCalc_B.Switch1_l = rtb_Gain2_j;
    } else {
      BSPR_DChrgTempCalc_B.Switch1_l = (rtb_Gain2_j -
        BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_f) * BSPR_cofDChrgTempFlt_C +
        BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_f;
    }

    BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_f = BSPR_DChrgTempCalc_B.Switch1_l;
    BSPR_DChrgTempCalc_DW.Delay_DSTATE_b = 0.0F;
    BSPR_uDChrgPosTempFlt = BSPR_DChrgTempCalc_B.Switch1_l;
  } else {
    if (BSPR_DChrgTempCalc_DW.Subsystem1_MODE) {
      BSPR_DChrgTempCalc_DW.Subsystem1_MODE = false;
    }

    BSPR_uDChrgPosTempFlt = BSPR_uDChrgPosTempInitVal_C;
  }

  BSPR_uDChrgPosTemp = 0.001F * BSW_uDChrgPosTemp;
  rtb_RelationalOperator = (BSW_uDChrgNegTemp > BSPR_uDChrgNegTempInitVal_C);
  if (rtb_RelationalOperator) {
    if (!BSPR_DChrgTempCalc_DW.Subsystem2_MODE) {
      BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_b = 0.0F;
      BSPR_DChrgTempCalc_DW.Delay_DSTATE_e = 1.0F;
      BSPR_DChrgTempCalc_DW.Subsystem2_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uDChrgNegTemp;
    if (!(BSPR_DChrgTempCalc_DW.Delay_DSTATE_e > 0.0F)) {
      rtb_Gain2_j = (rtb_Gain2_j - BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_b) *
        BSPR_cofDChrgTempFlt_C + BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_b;
    }

    BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE_b = rtb_Gain2_j;
    BSPR_DChrgTempCalc_DW.Delay_DSTATE_e = 0.0F;
    BSPR_DChrgTempCalc_B.uDLookupTable1 = look1_iflf_binlcpw(rtb_Gain2_j,
      (&(BSPR_tDcChrg_CUR_X[0])), (&(BSPR_tDcChrg_CUR[0])), 240U);
    rtb_Gain2_j = BSPR_DChrgTempCalc_B.uDLookupTable1;
  } else {
    if (BSPR_DChrgTempCalc_DW.Subsystem2_MODE) {
      BSPR_DChrgTempCalc_DW.Subsystem2_MODE = false;
    }

    rtb_Gain2_j = BSPR_tDChrgNegTempInitVal_C;
  }

  if (rtb_Gain2_j > BSPR_tDChrgNegTempUpLim_C) {
    BSPR_tDcChNeg = BSPR_tDChrgNegTempUpLim_C;
  } else if (rtb_Gain2_j < BSPR_tDChrgNegTempLoLim_C) {
    BSPR_tDcChNeg = BSPR_tDChrgNegTempLoLim_C;
  } else {
    BSPR_tDcChNeg = rtb_Gain2_j;
  }

  if (rtb_RelationalOperator) {
    if (!BSPR_DChrgTempCalc_DW.Subsystem3_MODE) {
      BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE = 0.0F;
      BSPR_DChrgTempCalc_DW.Delay_DSTATE = 1.0F;
      BSPR_DChrgTempCalc_DW.Subsystem3_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uDChrgNegTemp;
    if (BSPR_DChrgTempCalc_DW.Delay_DSTATE > 0.0F) {
      BSPR_DChrgTempCalc_B.Switch1 = rtb_Gain2_j;
    } else {
      BSPR_DChrgTempCalc_B.Switch1 = (rtb_Gain2_j -
        BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE) * BSPR_cofDChrgTempFlt_C +
        BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE;
    }

    BSPR_DChrgTempCalc_DW.UnitDelay_DSTATE = BSPR_DChrgTempCalc_B.Switch1;
    BSPR_DChrgTempCalc_DW.Delay_DSTATE = 0.0F;
    BSPR_uDChrgNegTempFlt = BSPR_DChrgTempCalc_B.Switch1;
  } else {
    if (BSPR_DChrgTempCalc_DW.Subsystem3_MODE) {
      BSPR_DChrgTempCalc_DW.Subsystem3_MODE = false;
    }

    BSPR_uDChrgNegTempFlt = BSPR_uDChrgNegTempInitVal_C;
  }

  BSPR_uDChrgNegTemp = 0.001F * BSW_uDChrgNegTemp;
}

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

  /* block I/O */

  /* custom signals */
  BSPR_tDcChPos = 0.0F;
  BSPR_uDChrgPosTempFlt = 0.0F;
  BSPR_uDChrgPosTemp = 0.0F;
  BSPR_tDcChNeg = 0.0F;
  BSPR_uDChrgNegTempFlt = 0.0F;
  BSPR_uDChrgNegTemp = 0.0F;
  BSPR_DChrgTempCalc_DW.Delay_DSTATE_m = 1.0F;
  BSPR_DChrgTempCalc_DW.Delay_DSTATE_b = 1.0F;
  BSPR_DChrgTempCalc_DW.Delay_DSTATE_e = 1.0F;
  BSPR_DChrgTempCalc_DW.Delay_DSTATE = 1.0F;
}

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