/*
 * File: BSPR_BattCurrCoord.c
 *
 * Code generated for Simulink model 'BSPR_BattCurrCoord'.
 *
 * Model version                  : 1.1181
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Mon Aug  2 17:32:11 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 "BSPR_BattCurrCoord.h"
#include "BSPR_BattCurrCoord_private.h"

/* Named constants for Chart: '<S5>/AdapOs' */
#define BSPR_BattC_IN_CurrAdapCoord_Stt ((uint8_T)2U)
#define BSPR_BattCu_IN_CurrAdapCalc_Stt ((uint8_T)1U)
#define BSPR_BattCurrCoord_IN_End_Stt  ((uint8_T)3U)
#define BSPR_BattCurrCoord_IN_Ini_Stt  ((uint8_T)4U)

/* Exported data definition */

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

/* Definition for custom storage class: Volatile */
volatile real32_T BSPR_iCurrOfsAdap;   /* Self-adaption current for battery current sensor */
volatile uint8_T DFC_BMSSplyPwrAbnToCAB_ASW;
volatile uint8_T DFC_BMSSplyPwrAbnToLem_ASW;
volatile uint8_T DFC_BattCurrMismatchErr_ASW;
volatile uint8_T DFC_CABDevFlt_ASW;
volatile uint8_T DFC_CABErr_ASW;
volatile uint8_T DFC_CABVoltOutOfRng_ASW;
volatile uint8_T DFC_CurrRngErr_ASW;       /* Currrent out of range fault */
volatile uint8_T DFC_HwCurrElecSCG_ASW;
volatile uint8_T DFC_HwCurrElecSCP_ASW;
volatile uint8_T DFC_PackCrntSaf_ASW;
volatile uint8_T DFC_TwoCurrSnsrFlt_ASW;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BSPR_TwoCurrSnsrFlt_flg;
volatile boolean_T BSPR_bBattMismatchErrDet;
volatile boolean_T BSPR_bBattMismatchErrHeal;
volatile boolean_T BSPR_bCABCurrVld;
volatile boolean_T BSPR_bCabErrDet;
volatile boolean_T BSPR_bCabErrHeal;
volatile boolean_T BSPR_bCurrAdapCalcEn;/* Condition for battery current self-adaption */
volatile boolean_T BSPR_bCurrAdapCoordEn;/* Condition for battery current self-adaption */
volatile boolean_T BSPR_bCurrAdapEn;   /* Condition for battery current self-adaption */
volatile boolean_T BSPR_bCurrRngChkErr;/* Error flag for current sensor out of range check */
volatile boolean_T BSPR_bCurrRngChkOk; /* Ok flag for current sensor out of range check */
volatile boolean_T BSPR_bHwCurrElecSCPErrDet;
volatile boolean_T BSPR_bHwCurrElecSCPErrHeal;
volatile boolean_T BSPR_bHwCurrVld;
volatile uint32_T BSPR_cntCurrStbCalc; /*  Stable period statistics for battery current sensor self-adaption */
volatile uint32_T BSPR_cntCurrStbPerCalc;/* Total period  statistics for battery current sensor self-adaption */
volatile real32_T BSPR_iBattCurr;      /* Battery current after coordinating */
volatile real32_T BSPR_iBattCurrCalc;
volatile real32_T BSPR_iBattCurrFil;
volatile real32_T BSPR_iBattCurrRaw;
volatile real32_T BSPR_iCurrStbAvrgCalc;/* Average current during battery current sensor self-adaption */
volatile real32_T BSPR_iCurrStbMaxCalc;/* Max current during battery current sensor self-adaption */
volatile real32_T BSPR_iCurrStbMinCalc;/* Min current during battery current sensor self-adaption */
volatile uint8_T BSPR_stBattCurrMismatchErr;
volatile uint8_T BSPR_stCABErr;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM2_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BSPR_BattCurrCoord_T BSPR_BattCurrCoord_B;

/* Block states (auto storage) */
DW_BSPR_BattCurrCoord_T BSPR_BattCurrCoord_DW;

/* Model step function */
void BSPR_BattCurrCoord_step(void)
{
  real32_T average;
  boolean_T rtb_RelationalOperator1_h;
  uint32_T rtb_Switch3;
  uint32_T rtb_Add5;
  real32_T rtb_MinMax2;
  real32_T rtb_Product_ha3;
  real32_T rtb_MinMax4;
  real32_T rtb_MinMax5;
  uint32_T rtb_Add2;
  uint8_T rtb_Switch4_nx;
  int32_T i;
  if (BSPR_stBmsSelfChk == BSPR_stBMSSelfChkCmpl_C) {
    BSPR_TwoCurrSnsrFlt_flg = ((DFC_TwoCurrSnsrFlt_ASW & 24) == 24);
    rtb_MinMax2 = (real32_T)fabs(BSPR_iAdCurr);
    rtb_RelationalOperator1_h = (rtb_MinMax2 > BSPR_iLemCabSw_C);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiLemCabSwTiDly_C < BSPR_BattCurrCoord_DW.Delay_DSTATE) {
      average = BSPR_tiLemCabSwTiDly_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE = rtb_Product_ha3;
    BSPR_bCabErrDet = COMR_bCabErrStatus;
    BSPR_bCABCurrVld = !(COMR_flgTmtCAB || BSPR_bCabErrDet);
    BSPR_bHwCurrVld = !(((DFC_HwCurrElecSCP_ASW & 24) == 24) || ((DFC_HwCurrElecSCG_ASW
      & 24) == 24));
    if (BSPR_bCABCurrVld && BSPR_bHwCurrVld) {
      if (rtb_Product_ha3 > BSPR_tiLemCabSwTiDly_C) {
        BSPR_iBattCurrRaw = BSPR_iAdCurr;
      } else {
        BSPR_iBattCurrRaw = COMR_iBattCurr;
      }
    } else if (BSPR_bCABCurrVld) {
      BSPR_iBattCurrRaw = COMR_iBattCurr;
    } else {
      if (BSPR_bHwCurrVld) {
        BSPR_iBattCurrRaw = BSPR_iAdCurr;
      }
    }

    if (BSPR_TwoCurrSnsrFlt_flg) {
      rtb_Product_ha3 = BSPR_TwoCurrSnsrFltCurr_C;
    } else {
      rtb_Product_ha3 = BSPR_iBattCurrRaw;
    }

    if (BSPR_BattCurrCoord_DW.UnitDelay_DSTATE) {
      BSPR_BattCurrCoord_DW.count = 0U;
      BSPR_BattCurrCoord_DW.sum = 0.0F;
      for (i = 0; i < 5; i++) {
        BSPR_BattCurrCoord_DW.buffer[i] = 0.0F;
      }

      average = 0.0F;
      BSPR_BattCurrCoord_DW.index = 0U;
    } else {
      if (BSPR_BattCurrCoord_DW.count >= BSPR_cntCurrMovAvg_C) {
        BSPR_BattCurrCoord_DW.sum -=
          BSPR_BattCurrCoord_DW.buffer[BSPR_BattCurrCoord_DW.index];
      } else {
        BSPR_BattCurrCoord_DW.count++;
      }

      BSPR_BattCurrCoord_DW.sum += rtb_Product_ha3;
      BSPR_BattCurrCoord_DW.buffer[BSPR_BattCurrCoord_DW.index] =
        rtb_Product_ha3;
      average = BSPR_BattCurrCoord_DW.sum / (real32_T)
        BSPR_BattCurrCoord_DW.count;
      if (BSPR_BattCurrCoord_DW.index >= BSPR_cntCurrMovAvg_C - 1) {
        BSPR_BattCurrCoord_DW.index = 0U;
      } else {
        BSPR_BattCurrCoord_DW.index++;
      }
    }

    BSPR_iBattCurrFil = average;
    if (BSPR_iBattCurrFilEna_C) {
      BSPR_iBattCurrCalc = BSPR_iBattCurrFil;
    } else {
      BSPR_iBattCurrCalc = rtb_Product_ha3;
    }

    rtb_MinMax4 = (real32_T)fabs(BSPR_iBattCurrCalc);
    rtb_RelationalOperator1_h = (rtb_MinMax4 >= BSPR_iSystemOverCurrDet_C);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiSystemOverCurrDet_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_e) {
      average = BSPR_tiSystemOverCurrDet_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_e;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_e = rtb_Product_ha3;
    rtb_RelationalOperator1_h = !rtb_RelationalOperator1_h;
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiSystemOverCurrDet_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_c) {
      average = BSPR_tiSystemOverCurrDet_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_c;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_c = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_PackCrntSaf_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiSystemOverCurrDet_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_PackCrntSaf_ASW | 152U);
    } else if (average > BSPR_tiSystemOverCurrDet_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_PackCrntSaf_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE = rtb_Switch4_nx;
    DFC_PackCrntSaf_ASW = rtb_Switch4_nx;
    rtb_Product_ha3 = (real32_T)fabs(COMR_iBattCurr - BSPR_iAdCurr);
    rtb_RelationalOperator1_h = ((rtb_MinMax2 < BSPR_iBattCurrMisMatchDec_C) &&
      ((real32_T)fabs(COMR_iBattCurr) < BSPR_iBattCurrMisMatchDec_C) &&
      ((rtb_Product_ha3 > BSPR_iBattCurrMismatchThrd_C) && (rtb_Product_ha3 >
      rtb_MinMax4 * BSPR_facBattCurrMismatch_C)) && BSPR_bHwCurrVld &&
      BSPR_bCABCurrVld);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCurrMismatchDec_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_o3) {
      average = BSPR_tiCurrMismatchDec_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_o3;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_bBattMismatchErrDet = (rtb_Product_ha3 > BSPR_tiCurrMismatchDec_C);
    BSPR_BattCurrCoord_DW.Delay_DSTATE_o3 = rtb_Product_ha3;
    rtb_RelationalOperator1_h = !rtb_RelationalOperator1_h;
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCurrMismatchHeal_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_av) {
      average = BSPR_tiCurrMismatchHeal_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_av;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_bBattMismatchErrHeal = (rtb_Product_ha3 > BSPR_tiCurrMismatchHeal_C);
    BSPR_BattCurrCoord_DW.Delay_DSTATE_av = rtb_Product_ha3;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_m) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_BattCurrMismatchErr_ASW |
        8U);
    } else if (BSPR_bBattMismatchErrDet) {
      rtb_Switch4_nx = (uint8_T)(DFC_BattCurrMismatchErr_ASW | 152U);
    } else if (BSPR_bBattMismatchErrHeal) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_BattCurrMismatchErr_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_f;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_m = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_f = rtb_Switch4_nx;
    DFC_BattCurrMismatchErr_ASW = rtb_Switch4_nx;
    BSPR_stBattCurrMismatchErr = (uint8_T)((DFC_BattCurrMismatchErr_ASW & 24) == 24);
    if (BSPR_bCabErrDet) {
      average = 0.01F;
    } else {
      average = 0.0F;
    }

    if (BSPR_tiCABErrDet_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_h) {
      rtb_MinMax2 = BSPR_tiCABErrDet_C;
    } else {
      rtb_MinMax2 = BSPR_BattCurrCoord_DW.Delay_DSTATE_h;
    }

    rtb_Product_ha3 = (average + rtb_MinMax2) * (real32_T)BSPR_bCabErrDet;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_h = rtb_Product_ha3;
    BSPR_bCabErrHeal = !COMR_bCabErrStatus;
    if (BSPR_bCabErrHeal) {
      average = 0.01F;
    } else {
      average = 0.0F;
    }

    if (BSPR_tiCABErrHeal_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_id) {
      rtb_MinMax2 = BSPR_tiCABErrHeal_C;
    } else {
      rtb_MinMax2 = BSPR_BattCurrCoord_DW.Delay_DSTATE_id;
    }

    average = (average + rtb_MinMax2) * (real32_T)BSPR_bCabErrHeal;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_id = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_a) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_CABErr_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiCABErrDet_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_CABErr_ASW | 152U);
    } else if (average > BSPR_tiCABErrHeal_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CABErr_ASW | 16U)
        | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_k;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_a = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_k = rtb_Switch4_nx;
    DFC_CABErr_ASW = rtb_Switch4_nx;
    BSPR_stCABErr = (uint8_T)((DFC_CABErr_ASW & 24) == 24);
    rtb_RelationalOperator1_h = ((BSPR_stCABErr != 0) && (!BSPR_bHwCurrVld));
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiTwoCurrSnsrFlt_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_o) {
      average = BSPR_tiTwoCurrSnsrFlt_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_o;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_o = rtb_Product_ha3;
    rtb_RelationalOperator1_h = !rtb_RelationalOperator1_h;
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiTwoCurrSnsrFlt_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_cl) {
      average = BSPR_tiTwoCurrSnsrFlt_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_cl;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_cl = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_d) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_TwoCurrSnsrFlt_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiTwoCurrSnsrFlt_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_TwoCurrSnsrFlt_ASW | 152U);
    } else if (average > BSPR_tiTwoCurrSnsrFlt_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_TwoCurrSnsrFlt_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_e;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_d = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_e = rtb_Switch4_nx;
    DFC_TwoCurrSnsrFlt_ASW = rtb_Switch4_nx;
    rtb_RelationalOperator1_h = (BSPR_uHwCurr > BSPR_uHwCurrElecSCP_C);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiHwCurrElecSCP_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_g5) {
      average = BSPR_tiHwCurrElecSCP_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_g5;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_bHwCurrElecSCPErrDet = (rtb_Product_ha3 > BSPR_tiHwCurrElecSCP_C);
    BSPR_BattCurrCoord_DW.Delay_DSTATE_g5 = rtb_Product_ha3;
    rtb_RelationalOperator1_h = !rtb_RelationalOperator1_h;
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiHwCurrElecSCP_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_i) {
      average = BSPR_tiHwCurrElecSCP_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_i;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_bHwCurrElecSCPErrHeal = (rtb_Product_ha3 > BSPR_tiHwCurrElecSCP_C);
    BSPR_BattCurrCoord_DW.Delay_DSTATE_i = rtb_Product_ha3;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_ha) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_HwCurrElecSCP_ASW | 8U);
    } else if (BSPR_bHwCurrElecSCPErrDet) {
      rtb_Switch4_nx = (uint8_T)(DFC_HwCurrElecSCP_ASW | 152U);
    } else if (BSPR_bHwCurrElecSCPErrHeal) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_HwCurrElecSCP_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_a;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_ha = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_a = rtb_Switch4_nx;
    DFC_HwCurrElecSCP_ASW = rtb_Switch4_nx;
    rtb_RelationalOperator1_h = (BSPR_uHwCurr < BSPR_uHwCurrElecSCG_C);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiHwCurrElecSCG_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_g) {
      average = BSPR_tiHwCurrElecSCG_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_g;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_g = rtb_Product_ha3;
    rtb_RelationalOperator1_h = !rtb_RelationalOperator1_h;
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiHwCurrElecSCG_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_ex) {
      average = BSPR_tiHwCurrElecSCG_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_ex;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_ex = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_h) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_HwCurrElecSCG_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiHwCurrElecSCG_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_HwCurrElecSCG_ASW | 152U);
    } else if (average > BSPR_tiHwCurrElecSCG_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_HwCurrElecSCG_ASW
        | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_h;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_h = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_h = rtb_Switch4_nx;
    DFC_HwCurrElecSCG_ASW = rtb_Switch4_nx;
    rtb_RelationalOperator1_h = (COMR_stCabErrInfo == 70);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCABVoltOutOfRngDet_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_a) {
      average = BSPR_tiCABVoltOutOfRngDet_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_a;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_a = rtb_Product_ha3;
    rtb_RelationalOperator1_h = (COMR_stCabErrInfo == 100);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCABVoltOutOfRngHeal_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_d) {
      average = BSPR_tiCABVoltOutOfRngHeal_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_d;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_d = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_l) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_CABVoltOutOfRng_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiCABVoltOutOfRngDet_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_CABVoltOutOfRng_ASW | 152U);
    } else if (average > BSPR_tiCABVoltOutOfRngHeal_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_CABVoltOutOfRng_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_kw;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_l = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_kw = rtb_Switch4_nx;
    DFC_CABVoltOutOfRng_ASW = rtb_Switch4_nx;
    rtb_RelationalOperator1_h = ((COMR_stCabErrInfo == 64) || (COMR_stCabErrInfo
      == 66) || (COMR_stCabErrInfo == 68) || (COMR_stCabErrInfo == 71) ||
      (COMR_stCabErrInfo == 73) || (COMR_stCabErrInfo == 74) ||
      (COMR_stCabErrInfo == 75));
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCABDevFltDet_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_ja) {
      average = BSPR_tiCABDevFltDet_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_ja;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_ja = rtb_Product_ha3;
    rtb_RelationalOperator1_h = (COMR_stCabErrInfo == 100);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCABDevFltHeal_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_j) {
      average = BSPR_tiCABDevFltHeal_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_j;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_j = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_n) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_CABDevFlt_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiCABDevFltDet_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_CABDevFlt_ASW | 152U);
    } else if (average > BSPR_tiCABDevFltHeal_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CABDevFlt_ASW |
        16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_c;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_n = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_c = rtb_Switch4_nx;
    DFC_CABDevFlt_ASW = rtb_Switch4_nx;
    rtb_RelationalOperator1_h = ((BSW_uCabCurr < BSPR_uCABSplyVoltLoFlt_C) &&
      BMCR_bOutputVolt12vEna);
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCABSplyVoltDeb_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_ke) {
      average = BSPR_tiCABSplyVoltDeb_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_ke;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_ke = rtb_Product_ha3;
    rtb_RelationalOperator1_h = (BMCR_bOutputVolt12vEna && (BSW_uCabCurr >=
      BSPR_uCABSplyVoltLoHeal_C));
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiCABSplyVoltDeb_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_bu) {
      average = BSPR_tiCABSplyVoltDeb_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_bu;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_bu = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_c) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_BMSSplyPwrAbnToCAB_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiCABSplyVoltDeb_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_BMSSplyPwrAbnToCAB_ASW | 152U);
    } else if (average > BSPR_tiCABSplyVoltDeb_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_BMSSplyPwrAbnToCAB_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_n;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_c = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_n = rtb_Switch4_nx;
    DFC_BMSSplyPwrAbnToCAB_ASW = rtb_Switch4_nx;
    rtb_RelationalOperator1_h = ((BSW_uReservedSig8 >= BSPR_uLemSplyVoltHiFlt_C)
      || (BSW_uReservedSig8 <= BSPR_uLemSplyVoltLoFlt_C));
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiLemSplyVoltDeb_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_b) {
      average = BSPR_tiLemSplyVoltDeb_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_b;
    }

    rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
      rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_b = rtb_Product_ha3;
    rtb_RelationalOperator1_h = ((BSW_uReservedSig8 >= BSPR_uLemSplyVoltLoNorm_C)
      && (BSW_uReservedSig8 <= BSPR_uLemSplyVoltHiNorm_C));
    if (rtb_RelationalOperator1_h) {
      rtb_MinMax5 = 0.01F;
    } else {
      rtb_MinMax5 = 0.0F;
    }

    if (BSPR_tiLemSplyVoltDeb_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_k) {
      average = BSPR_tiLemSplyVoltDeb_C;
    } else {
      average = BSPR_BattCurrCoord_DW.Delay_DSTATE_k;
    }

    average = (rtb_MinMax5 + average) * (real32_T)rtb_RelationalOperator1_h;
    BSPR_BattCurrCoord_DW.Delay_DSTATE_k = average;
    if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_f) {
      rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_BMSSplyPwrAbnToLem_ASW | 8U);
    } else if (rtb_Product_ha3 > BSPR_tiLemSplyVoltDeb_C) {
      rtb_Switch4_nx = (uint8_T)(DFC_BMSSplyPwrAbnToLem_ASW | 152U);
    } else if (average > BSPR_tiLemSplyVoltDeb_C) {
      rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)
        ~DFC_BMSSplyPwrAbnToLem_ASW | 16U) | 8U);
    } else {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_j;
    }

    BSPR_BattCurrCoord_DW.Delay2_DSTATE_f = false;
    BSPR_BattCurrCoord_DW.Delay3_DSTATE_j = rtb_Switch4_nx;
    DFC_BMSSplyPwrAbnToLem_ASW = rtb_Switch4_nx;
    BSPR_BattCurrCoord_DW.UnitDelay_DSTATE = false;
  }

  rtb_RelationalOperator1_h = ((BSPR_iBattCurrCalc > BSPR_iCurrRngHi_C) ||
    (BSPR_iBattCurrCalc < BSPR_iCurrRngLo_C));
  if (rtb_RelationalOperator1_h) {
    rtb_MinMax5 = 0.01F;
  } else {
    rtb_MinMax5 = 0.0F;
  }

  if (BSPR_tiCurrRngChkErr_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_f) {
    average = BSPR_tiCurrRngChkErr_C;
  } else {
    average = BSPR_BattCurrCoord_DW.Delay_DSTATE_f;
  }

  rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
    rtb_RelationalOperator1_h;
  BSPR_bCurrRngChkErr = (rtb_Product_ha3 > BSPR_tiCurrRngChkErr_C);
  BSPR_BattCurrCoord_DW.Delay_DSTATE_f = rtb_Product_ha3;
  rtb_RelationalOperator1_h = !rtb_RelationalOperator1_h;
  if (rtb_RelationalOperator1_h) {
    rtb_MinMax5 = 0.01F;
  } else {
    rtb_MinMax5 = 0.0F;
  }

  if (BSPR_tiCurrRngChkErr_C < BSPR_BattCurrCoord_DW.Delay_DSTATE_o1) {
    average = BSPR_tiCurrRngChkErr_C;
  } else {
    average = BSPR_BattCurrCoord_DW.Delay_DSTATE_o1;
  }

  rtb_Product_ha3 = (rtb_MinMax5 + average) * (real32_T)
    rtb_RelationalOperator1_h;
  BSPR_bCurrRngChkOk = (rtb_Product_ha3 > BSPR_tiCurrRngChkErr_C);
  BSPR_BattCurrCoord_DW.Delay_DSTATE_o1 = rtb_Product_ha3;
  if (BSPR_BattCurrCoord_DW.Delay2_DSTATE_k) {
    rtb_Switch4_nx = (uint8_T)~(uint8_T)((uint8_T)~DFC_CurrRngErr_ASW | 8U);
  } else if (BSPR_bCurrRngChkErr) {
    rtb_Switch4_nx = (uint8_T)(DFC_CurrRngErr_ASW | 152U);
  } else if (BSPR_bCurrRngChkOk) {
    rtb_Switch4_nx = (uint8_T)((uint8_T)~(uint8_T)((uint8_T)~DFC_CurrRngErr_ASW |
      16U) | 8U);
  } else {
    rtb_Switch4_nx = BSPR_BattCurrCoord_DW.Delay3_DSTATE_p;
  }

  BSPR_BattCurrCoord_DW.Delay2_DSTATE_k = false;
  BSPR_BattCurrCoord_DW.Delay3_DSTATE_p = rtb_Switch4_nx;
  DFC_CurrRngErr_ASW = rtb_Switch4_nx;
  if (BSPR_BattCurrCoord_DW.is_active_c3_BSPR_BattCurrCoord == 0U) {
    BSPR_BattCurrCoord_DW.is_active_c3_BSPR_BattCurrCoord = 1U;
    BSPR_BattCurrCoord_DW.is_c3_BSPR_BattCurrCoord =
      BSPR_BattCurrCoord_IN_Ini_Stt;
    BSPR_BattCurrCoord_DW.ini_counter = 1U;
    BSPR_bCurrAdapCalcEn = false;
    BSPR_bCurrAdapCoordEn = false;
  } else {
    switch (BSPR_BattCurrCoord_DW.is_c3_BSPR_BattCurrCoord) {
     case BSPR_BattCu_IN_CurrAdapCalc_Stt:
      BSPR_bCurrAdapCalcEn = true;
      BSPR_bCurrAdapCoordEn = false;
      if ((BSPR_BattCurrCoord_DW.BSPR_tiCurrAdapAllw >= BSPR_tiCurrAdapAllw_C) ||
          (BCCR_stBmsCtrMode == 3)) {
        BSPR_BattCurrCoord_DW.is_c3_BSPR_BattCurrCoord =
          BSPR_BattC_IN_CurrAdapCoord_Stt;
        BSPR_bCurrAdapCalcEn = false;
        BSPR_bCurrAdapCoordEn = true;
      } else {
        BSPR_BattCurrCoord_DW.BSPR_tiCurrAdapAllw += 0.01F;
      }
      break;

     case BSPR_BattC_IN_CurrAdapCoord_Stt:
      BSPR_BattCurrCoord_DW.is_c3_BSPR_BattCurrCoord =
        BSPR_BattCurrCoord_IN_End_Stt;
      BSPR_bCurrAdapCalcEn = false;
      BSPR_bCurrAdapCoordEn = false;
      break;

     case BSPR_BattCurrCoord_IN_End_Stt:
      BSPR_bCurrAdapCalcEn = false;
      BSPR_bCurrAdapCoordEn = false;
      break;

     default:
      BSPR_bCurrAdapCalcEn = false;
      BSPR_bCurrAdapCoordEn = false;
      if (BSPR_BattCurrCoord_DW.ini_counter >= 3) {
        BSPR_BattCurrCoord_DW.is_c3_BSPR_BattCurrCoord =
          BSPR_BattCu_IN_CurrAdapCalc_Stt;
        BSPR_BattCurrCoord_DW.ini_counter = 0U;
        BSPR_bCurrAdapCalcEn = true;
        BSPR_bCurrAdapCoordEn = false;
        BSPR_BattCurrCoord_DW.BSPR_tiCurrAdapAllw = 0.0F;
      } else {
        i = BSPR_BattCurrCoord_DW.ini_counter + 1;
        if (i > 255) {
          i = 255;
        }

        BSPR_BattCurrCoord_DW.ini_counter = (uint8_T)i;
      }
      break;
    }
  }

  if (BSPR_bCurrAdapCalcEn) {
    if (BSPR_BattCurrCoord_DW.UnitDelay4_DSTATE < 20) {
      rtb_Switch4_nx = BSPR_BattCurrCoord_DW.UnitDelay4_DSTATE;
    } else {
      rtb_Switch4_nx = 20U;
    }

    rtb_Switch4_nx++;
    if (!(rtb_Switch4_nx <= 20)) {
      rtb_Switch4_nx = 0U;
    }

    rtb_RelationalOperator1_h = ((BSPR_BattCurrCoord_DW.Delay1_DSTATE != 0) && (
      !(rtb_Switch4_nx != 0)));
    rtb_Add2 = rtb_RelationalOperator1_h +
      BSPR_BattCurrCoord_DW.UnitDelay5_DSTATE;
    if (rtb_RelationalOperator1_h) {
      rtb_Switch3 = (uint32_T)(BSPR_BattCurrCoord_DW.UnitDelay3_DSTATE <=
        BSPR_iCurrStbPerDiffThres_C);
    } else {
      rtb_Switch3 = 0U;
    }

    rtb_Switch3 += BSPR_BattCurrCoord_DW.UnitDelay6_DSTATE;
    rtb_Product_ha3 = BSPR_BattCurrCoord_DW.UnitDelay7_DSTATE +
      BSPR_iBattCurrCalc;
    rtb_Add5 = BSPR_BattCurrCoord_DW.UnitDelay8_DSTATE + 1U;
    if (!(rtb_Switch4_nx != 0)) {
      average = 500.0F;
    } else {
      average = BSPR_BattCurrCoord_DW.UnitDelay10_DSTATE;
    }

    if (!(average < BSPR_iBattCurrCalc)) {
      average = BSPR_iBattCurrCalc;
    }

    if (rtb_Switch4_nx > 0) {
      rtb_MinMax2 = BSPR_BattCurrCoord_DW.UnitDelay1_DSTATE;
    } else {
      rtb_MinMax2 = -500.0F;
    }

    if (!(rtb_MinMax2 > BSPR_iBattCurrCalc)) {
      rtb_MinMax2 = BSPR_iBattCurrCalc;
    }

    if (BSPR_BattCurrCoord_DW.UnitDelay9_DSTATE < BSPR_iBattCurrCalc) {
      rtb_MinMax4 = BSPR_BattCurrCoord_DW.UnitDelay9_DSTATE;
    } else {
      rtb_MinMax4 = BSPR_iBattCurrCalc;
    }

    if (BSPR_BattCurrCoord_DW.UnitDelay16_DSTATE > BSPR_iBattCurrCalc) {
      rtb_MinMax5 = BSPR_BattCurrCoord_DW.UnitDelay16_DSTATE;
    } else {
      rtb_MinMax5 = BSPR_iBattCurrCalc;
    }

    BSPR_cntCurrStbCalc = BSPR_BattCurrCoord_DW.UnitDelay11_DSTATE;
    BSPR_cntCurrStbPerCalc = BSPR_BattCurrCoord_DW.UnitDelay12_DSTATE;
    BSPR_iCurrStbAvrgCalc = BSPR_BattCurrCoord_DW.UnitDelay13_DSTATE;
    BSPR_iCurrStbMaxCalc = BSPR_BattCurrCoord_DW.UnitDelay14_DSTATE;
    BSPR_iCurrStbMinCalc = BSPR_BattCurrCoord_DW.UnitDelay15_DSTATE;
    BSPR_BattCurrCoord_DW.UnitDelay4_DSTATE = rtb_Switch4_nx;
    BSPR_BattCurrCoord_DW.Delay1_DSTATE = rtb_Switch4_nx;
    BSPR_BattCurrCoord_DW.UnitDelay5_DSTATE = rtb_Add2;
    BSPR_BattCurrCoord_DW.UnitDelay3_DSTATE = rtb_MinMax2 - average;
    BSPR_BattCurrCoord_DW.UnitDelay6_DSTATE = rtb_Switch3;
    BSPR_BattCurrCoord_DW.UnitDelay7_DSTATE = rtb_Product_ha3;
    BSPR_BattCurrCoord_DW.UnitDelay8_DSTATE = rtb_Add5;
    BSPR_BattCurrCoord_DW.UnitDelay10_DSTATE = average;
    BSPR_BattCurrCoord_DW.UnitDelay1_DSTATE = rtb_MinMax2;
    BSPR_BattCurrCoord_DW.UnitDelay9_DSTATE = rtb_MinMax4;
    BSPR_BattCurrCoord_DW.UnitDelay16_DSTATE = rtb_MinMax5;
    BSPR_BattCurrCoord_DW.UnitDelay11_DSTATE = rtb_Switch3;
    BSPR_BattCurrCoord_DW.UnitDelay12_DSTATE = rtb_Add2;
    BSPR_BattCurrCoord_DW.UnitDelay13_DSTATE = rtb_Product_ha3 / (real32_T)
      rtb_Add5;
    BSPR_BattCurrCoord_DW.UnitDelay14_DSTATE = rtb_MinMax5;
    BSPR_BattCurrCoord_DW.UnitDelay15_DSTATE = rtb_MinMax4;
  }

  if (BSPR_bCurrAdapCoordEn) {
    if ((real32_T)BSPR_cntCurrStbPerCalc >= BSPR_cntCurrStbPerMin_C) {
      rtb_RelationalOperator1_h = (BSPR_cntCurrStbCalc >=
        BSPR_rCurrStbAdapThres_C * (real32_T)BSPR_cntCurrStbPerCalc);
    } else {
      rtb_RelationalOperator1_h = false;
    }

    BSPR_BattCurrCoord_B.LogicalOperator1 = (rtb_RelationalOperator1_h &&
      ((real32_T)fabs(BSPR_iCurrStbAvrgCalc) <= BSPR_iCurrStbAdapThres_C) &&
      (BSPR_iCurrStbMaxCalc - BSPR_iCurrStbMinCalc <= BSPR_iCurrStbDiffThres_C));
  }

  BSPR_bCurrAdapEn = BSPR_BattCurrCoord_B.LogicalOperator1;
  rtb_RelationalOperator1_h = ((!BSPR_BattCurrCoord_DW.Delay1_DSTATE_d) &&
    BSPR_bCurrAdapEn);
  if (BSPR_BattCurrCoord_DW.UnitDelay12_DSTATE_e || rtb_RelationalOperator1_h) {
    BSPR_iCurrOfsAdap = BSPR_iCurrStbAvrgCalc;
  } else {
    BSPR_iCurrOfsAdap = BSPR_iCurrOfsAdap_nvm;
  }

  if ((real32_T)fabs(BSPR_iCurrOfsAdap) >= BSPR_iCurrActAdapThres_C) {
    rtb_Product_ha3 = BSPR_iBattCurrCalc;
  } else {
    rtb_Product_ha3 = BSPR_iBattCurrCalc - BSPR_iCurrOfsAdap;
  }

  if (rtb_Product_ha3 > BSPR_iCurrRngHiLim_C) {
    BSPR_iBattCurr = BSPR_iCurrRngHiLim_C;
  } else if (rtb_Product_ha3 < BSPR_iCurrRngLoLim_C) {
    BSPR_iBattCurr = BSPR_iCurrRngLoLim_C;
  } else {
    BSPR_iBattCurr = rtb_Product_ha3;
  }

  BSPR_BattCurrCoord_DW.UnitDelay12_DSTATE_e = (rtb_RelationalOperator1_h ||
    BSPR_BattCurrCoord_DW.UnitDelay12_DSTATE_e);
  BSPR_BattCurrCoord_DW.Delay1_DSTATE_d = BSPR_bCurrAdapEn;
}

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

  /* block I/O */

  /* custom signals */
  BSPR_iCurrOfsAdap = 0.0F;
  BSPR_iBattCurr = 0.0F;
  BSPR_stBattCurrMismatchErr = ((uint8_T)0U);
  BSPR_stCABErr = ((uint8_T)0U);
  BSPR_bCurrAdapEn = false;
  BSPR_TwoCurrSnsrFlt_flg = false;
  BSPR_bCABCurrVld = false;
  BSPR_bHwCurrVld = false;
  BSPR_BattCurrCoord_DW.Delay1_DSTATE_d = true;
  BSPR_BattCurrCoord_DW.UnitDelay_DSTATE = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_m = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_a = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_d = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_ha = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_h = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_l = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_n = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_c = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_f = true;
  BSPR_BattCurrCoord_DW.Delay2_DSTATE_k = true;
  BSPR_BattCurrCoord_DW.UnitDelay9_DSTATE = 500.0F;
  BSPR_BattCurrCoord_DW.UnitDelay16_DSTATE = -500.0F;
}

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