/*
 * File: BSPR_ThmTempCalc.c
 *
 * Code generated for Simulink model 'BSPR_ThmTempCalc'.
 *
 * Model version                  : 1.68
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Wed Jun 17 19:44:56 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_ThmTempCalc.h"
#include "BSPR_ThmTempCalc_private.h"

/* Exported data definition */

/* Definition for custom storage class: OutputSignal */
volatile real32_T BSPR_tClntDsT;
volatile real32_T BSPR_tClntUsT;
volatile real32_T BSPR_uClntDsT;
volatile real32_T BSPR_uClntDsTFlt;
volatile real32_T BSPR_uClntUsT;
volatile real32_T BSPR_uClntUsTFlt;

/* Block signals (auto storage) */
B_BSPR_ThmTempCalc_T BSPR_ThmTempCalc_B;

/* Block states (auto storage) */
DW_BSPR_ThmTempCalc_T BSPR_ThmTempCalc_DW;

/* Model step function */
void BSPR_ThmTempCalc_step(void)
{
  boolean_T rtb_RelationalOperator;
  real32_T rtb_Gain2_j;
  rtb_RelationalOperator = (BSW_uClntUsT > BSPR_uClntUsTInitVal_C);
  if (rtb_RelationalOperator) {
    if (!BSPR_ThmTempCalc_DW.Subsystem_MODE) {
      BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_dg = 0.0F;
      BSPR_ThmTempCalc_DW.Delay_DSTATE_pf = 1.0F;
      BSPR_ThmTempCalc_DW.Subsystem_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uClntUsT;
    if (!(BSPR_ThmTempCalc_DW.Delay_DSTATE_pf > 0.0F)) {
      rtb_Gain2_j = (rtb_Gain2_j - BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_dg) *
        BSPR_cofClntTempFlt_C + BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_dg;
    }

    BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_dg = rtb_Gain2_j;
    BSPR_ThmTempCalc_DW.Delay_DSTATE_pf = 0.0F;
    BSPR_ThmTempCalc_B.uDLookupTable1_i = look1_iflf_binlcpw(rtb_Gain2_j,
      (&(BSPR_tCoolant_CUR_X[0])), (&(BSPR_tCoolant_CUR[0])), 170U);
    rtb_Gain2_j = BSPR_ThmTempCalc_B.uDLookupTable1_i;
  } else {
    if (BSPR_ThmTempCalc_DW.Subsystem_MODE) {
      BSPR_ThmTempCalc_DW.Subsystem_MODE = false;
    }

    rtb_Gain2_j = BSPR_tClntUsTInitVal_C;
  }

  if (rtb_Gain2_j > BSPR_tClntUsTUpLim_C) {
    BSPR_tClntUsT = BSPR_tClntUsTUpLim_C;
  } else if (rtb_Gain2_j < BSPR_tClntUsTLoLim_C) {
    BSPR_tClntUsT = BSPR_tClntUsTLoLim_C;
  } else {
    BSPR_tClntUsT = rtb_Gain2_j;
  }

  if (rtb_RelationalOperator) {
    if (!BSPR_ThmTempCalc_DW.Subsystem1_MODE) {
      BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_d = 0.0F;
      BSPR_ThmTempCalc_DW.Delay_DSTATE_p = 1.0F;
      BSPR_ThmTempCalc_DW.Subsystem1_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uClntUsT;
    if (BSPR_ThmTempCalc_DW.Delay_DSTATE_p > 0.0F) {
      BSPR_ThmTempCalc_B.Switch1_o = rtb_Gain2_j;
    } else {
      BSPR_ThmTempCalc_B.Switch1_o = (rtb_Gain2_j -
        BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_d) * BSPR_cofClntTempFlt_C +
        BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_d;
    }

    BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_d = BSPR_ThmTempCalc_B.Switch1_o;
    BSPR_ThmTempCalc_DW.Delay_DSTATE_p = 0.0F;
    BSPR_uClntUsTFlt = BSPR_ThmTempCalc_B.Switch1_o;
  } else {
    if (BSPR_ThmTempCalc_DW.Subsystem1_MODE) {
      BSPR_ThmTempCalc_DW.Subsystem1_MODE = false;
    }

    BSPR_uClntUsTFlt = BSPR_uClntUsTInitVal_C;
  }

  BSPR_uClntUsT = 0.001F * BSW_uClntUsT;
  rtb_RelationalOperator = (BSW_uClntDsT > BSPR_uClntDsTInitVal_C);
  if (rtb_RelationalOperator) {
    if (!BSPR_ThmTempCalc_DW.Subsystem2_MODE) {
      BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_e = 0.0F;
      BSPR_ThmTempCalc_DW.Delay_DSTATE_d = 1.0F;
      BSPR_ThmTempCalc_DW.Subsystem2_MODE = true;
    }

    rtb_Gain2_j = 0.001F * BSW_uClntDsT;
    if (!(BSPR_ThmTempCalc_DW.Delay_DSTATE_d > 0.0F)) {
      rtb_Gain2_j = (rtb_Gain2_j - BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_e) *
        BSPR_cofClntTempFlt_C + BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_e;
    }

    BSPR_ThmTempCalc_DW.UnitDelay_DSTATE_e = rtb_Gain2_j;
    BSPR_ThmTempCalc_DW.Delay_DSTATE_d = 0.0F;
    BSPR_ThmTempCalc_B.uDLookupTable1 = look1_iflf_binlcpw(rtb_Gain2_j,
      (&(BSPR_tCoolant_CUR_X[0])), (&(BSPR_tCoolant_CUR[0])), 170U);
    rtb_Gain2_j = BSPR_ThmTempCalc_B.uDLookupTable1;
  } else {
    if (BSPR_ThmTempCalc_DW.Subsystem2_MODE) {
      BSPR_ThmTempCalc_DW.Subsystem2_MODE = false;
    }

    rtb_Gain2_j = BSPR_tClntDsTInitVal_C;
  }

  if (rtb_Gain2_j > BSPR_tClntDsTUpLim_C) {
    BSPR_tClntDsT = BSPR_tClntDsTUpLim_C;
  } else if (rtb_Gain2_j < BSPR_tClntDsTLoLim_C) {
    BSPR_tClntDsT = BSPR_tClntDsTLoLim_C;
  } else {
    BSPR_tClntDsT = rtb_Gain2_j;
  }

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

    rtb_Gain2_j = 0.001F * BSW_uClntDsT;
    if (BSPR_ThmTempCalc_DW.Delay_DSTATE > 0.0F) {
      BSPR_ThmTempCalc_B.Switch1 = rtb_Gain2_j;
    } else {
      BSPR_ThmTempCalc_B.Switch1 = (rtb_Gain2_j -
        BSPR_ThmTempCalc_DW.UnitDelay_DSTATE) * BSPR_cofClntTempFlt_C +
        BSPR_ThmTempCalc_DW.UnitDelay_DSTATE;
    }

    BSPR_ThmTempCalc_DW.UnitDelay_DSTATE = BSPR_ThmTempCalc_B.Switch1;
    BSPR_ThmTempCalc_DW.Delay_DSTATE = 0.0F;
    BSPR_uClntDsTFlt = BSPR_ThmTempCalc_B.Switch1;
  } else {
    if (BSPR_ThmTempCalc_DW.Subsystem3_MODE) {
      BSPR_ThmTempCalc_DW.Subsystem3_MODE = false;
    }

    BSPR_uClntDsTFlt = BSPR_uClntDsTInitVal_C;
  }

  BSPR_uClntDsT = 0.001F * BSW_uClntDsT;
}

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

  /* block I/O */

  /* custom signals */
  BSPR_tClntUsT = 0.0F;
  BSPR_uClntUsTFlt = 0.0F;
  BSPR_uClntUsT = 0.0F;
  BSPR_tClntDsT = 0.0F;
  BSPR_uClntDsTFlt = 0.0F;
  BSPR_uClntDsT = 0.0F;
  BSPR_ThmTempCalc_DW.Delay_DSTATE_pf = 1.0F;
  BSPR_ThmTempCalc_DW.Delay_DSTATE_p = 1.0F;
  BSPR_ThmTempCalc_DW.Delay_DSTATE_d = 1.0F;
  BSPR_ThmTempCalc_DW.Delay_DSTATE = 1.0F;
}

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