/*
 * File: BMCR_ModMag.c
 *
 * Code generated for Simulink model 'BMCR_ModMag'.
 *
 * Model version                  : 'M1.5.5'
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Thu Aug 12 10:50:12 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 "BMCR_ModMag.h"
#include "BMCR_ModMag_private.h"

/* Named constants for Chart: '<S2>/BMCR' */
#define BMCR_IN_DC_Charge_DisConnecting ((uint8_T)7U)
#define BMCR_ModMag_IN_AC_Charge       ((uint8_T)1U)
#define BMCR_ModMag_IN_AC_Charge_Stop  ((uint8_T)2U)
#define BMCR_ModMag_IN_After_Run       ((uint8_T)3U)
#define BMCR_ModMag_IN_AutoAddress     ((uint8_T)4U)
#define BMCR_ModMag_IN_Balance         ((uint8_T)5U)
#define BMCR_ModMag_IN_DC_Charge       ((uint8_T)6U)
#define BMCR_ModMag_IN_DC_Charge_Stop  ((uint8_T)8U)
#define BMCR_ModMag_IN_DR_off          ((uint8_T)1U)
#define BMCR_ModMag_IN_Default         ((uint8_T)1U)
#define BMCR_ModMag_IN_EOL             ((uint8_T)9U)
#define BMCR_ModMag_IN_Fault           ((uint8_T)2U)
#define BMCR_ModMag_IN_Fault_Mode      ((uint8_T)10U)
#define BMCR_ModMag_IN_HV_Disconnecting ((uint8_T)11U)
#define BMCR_ModMag_IN_HV_OFF          ((uint8_T)12U)
#define BMCR_ModMag_IN_HV_ON           ((uint8_T)13U)
#define BMCR_ModMag_IN_Init            ((uint8_T)14U)
#define BMCR_ModMag_IN_MR_off          ((uint8_T)3U)
#define BMCR_ModMag_IN_NO_ACTIVE_CHILD ((uint8_T)0U)
#define BMCR_ModMag_IN_No_Wk           ((uint8_T)1U)
#define BMCR_ModMag_IN_Operation       ((uint8_T)2U)
#define BMCR_ModMag_IN_PreHeat         ((uint8_T)15U)
#define BMCR_ModMag_IN_PreHeat_ready   ((uint8_T)16U)
#define BMCR_ModMag_IN_Precharge       ((uint8_T)17U)
#define BMCR_ModMag_IN_ShunDown        ((uint8_T)18U)
#define BMCR_ModMag_IN_Standby         ((uint8_T)19U)
#define BMCR_ModMag_IN_Standby_1       ((uint8_T)1U)
#define BMCR_ModMag_IN_Standby_2       ((uint8_T)2U)
#define BMCR_ModMag_IN_V2X             ((uint8_T)20U)
#define BMCR_ModMag_IN_Vcu_permit      ((uint8_T)21U)
#define BMCR_ModMag_IN_WK_VCU1         ((uint8_T)2U)
#define BMCR_ModMag_IN_Wait_off        ((uint8_T)4U)

/* Exported block signals */
boolean_T BMCR_stWakSrc;               /* '<S3>/Logical Operator' */

/* Exported data definition */
#define ASW1_OEM_START_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: OutputSignal */
volatile boolean_T BMCR_ICWakeUp;
volatile boolean_T BMCR_RTCWakeup;
volatile boolean_T BMCR_TPLWakeup;
volatile boolean_T BMCR_bAutoAdrsEna;
volatile uint8_T BMCR_bBmuShutdown;
volatile boolean_T BMCR_bDChrgPwrDwnReq;
volatile boolean_T BMCR_bDChrgPwrUpReq;
volatile boolean_T BMCR_bPwrDownReqVald;
volatile boolean_T BMCR_bPwrDwnReq;
volatile boolean_T BMCR_bPwrUpReq;
volatile boolean_T BMCR_bPwrUpReqVald;
volatile boolean_T BMCR_bWkUpVCU;
volatile boolean_T BMCR_flgBmsOTAMode;
volatile boolean_T BMCR_flgBmsSlp;
volatile boolean_T BMCR_flgPwrDownReq;
volatile boolean_T BMCR_flgPwrUpReq;
volatile uint8_T BMCR_stBmsModeCtrl;
volatile boolean_T BMCR_stNMRelease;

#define ASW1_OEM_STOP_SEC_DEFAULT_RAM1_CLEARED_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Block signals (auto storage) */
B_BMCR_ModMag_T BMCR_ModMag_B;

/* Block states (auto storage) */
DW_BMCR_ModMag_T BMCR_ModMag_DW;

/* External inputs (root inport signals with auto storage) */
ExtU_BMCR_ModMag_T BMCR_ModMag_U;

/* Forward declaration for local functions */
static void BMCR_ModMag_Fault_Mode(void);
static void BMCR_ModMag_HV_OFF(void);
static void BMCR_ModMag_HV_ON(void);
static void BMCR_ModMag_Init(void);
static void BMCR_ModMag_PreHeat(void);
static void BMCR_ModMag_PreHeat_ready(void);
static void BMCR_ModMag_Precharge(void);
static void BMCR_ModMag_Standby(void);
static void BMCR_ModMag_V2X(void);
static void BMCR_ModMag_Operation(void);

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_Fault_Mode(void)
{
  BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
  switch (BMCR_ModMag_DW.is_Fault_Mode) {
   case BMCR_ModMag_IN_DR_off:
    if (BMCR_ModMag_DW.DcChrgCnt > 10.0) {
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_MR_off;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
    } else {
      BMCR_ModMag_DW.DcChrgCnt++;
    }
    break;

   case BMCR_ModMag_IN_Fault:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    if ((DSMR_stFaultRank == 4) && BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c) {
      BMCR_ModMag_DW.DcChrgCnt = 0.0;
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_DR_off;
      BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = false;
      BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = true;
    } else if ((DSMR_stFaultRank == 4) && (!BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c))
    {
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_MR_off;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
    } else {
      if ((DSMR_stFaultRank == 3) && (BMCR_ModMag_DW.temporalCounter_i1 >= 100U))
      {
        BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Wait_off;
        BMCR_ModMag_DW.temporalCounter_i1 = 0U;
        BMCR_ModMag_B.BMCR_flgPwrDownReq_n = true;
        BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
        BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
        BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
      }
    }
    break;

   case BMCR_ModMag_IN_MR_off:
    if (((BCCR_stBmsCtrMode == 90) || (BCCR_stBmsCtrMode == 7) ||
         (BCCR_stBmsCtrMode == 0) || (BCCR_stBmsCtrMode == 14) ||
         (BCCR_stBmsCtrMode == 17)) && (!BMCR_stWakSrc)) {
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_After_Run;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AfterRun;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
    }
    break;

   default:
    if ((COMR_stPwrUpDwnVcuReq == 2) || (BMCR_ModMag_DW.temporalCounter_i1 >=
         100U)) {
      if (!BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c) {
        BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_MR_off;
        BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
        BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      } else {
        BMCR_ModMag_DW.DcChrgCnt = 0.0;
        BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_DR_off;
        BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = false;
        BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = true;
      }
    }
    break;
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_HV_OFF(void)
{
  BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = HVOff;
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else if (!BMCR_stWakSrc) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_After_Run;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AfterRun;
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
  } else {
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = false;
    BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = false;
    BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = false;
    BMCR_ModMag_B.BMCR_flgPwrDownReq_n = false;
    BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
    BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
    BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
    if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
      BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
    } else {
      if (BSPR_bDCWkUp || BSPR_bACWkUp) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
      }
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_HV_ON(void)
{
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else if (COMR_stEol) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_EOL;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = EolMode;
    BMCR_ModMag_DW.BMCR_flgEolOut = false;
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = GbRTE_MainPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = !GbRTE_MainPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = GbRTE_DChrgPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = !GbRTE_DChrgPwrUpReq_flg;
  } else if ((COMR_stPreThmVcuPmt == 1) && (BCMR_stAChrgPreThmReq == 1) &&
             (BCMR_stHoldTempReq != 1) && (COMR_stObcChrg == 1)) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Vcu_permit;
    BMCR_ModMag_B.BMCR_flgPwrUpReq_k = true;
    BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
  } else if (COMR_stPwrUpDwnVcuReq == 2) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
    BMCR_ModMag_DW.BMCR_flgEolOut = false;
  } else if (BCMR_bDChrgRdy) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_DC_Charge;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
    BMCR_ModMag_B.BMCR_flgPwrUpReq_k = true;
    BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
    BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = DcChrgMode;
    BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = true;
    BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = false;
  } else if (BCMR_bAChrgRdy && (BCMR_stAChrgPreThmReq != 1)) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_AC_Charge;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
    BMCR_ModMag_B.BMCR_flgPwrUpReq_k = true;
    BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
    BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AcChrgMode;
  } else if (BCMR_bAcDischgRdy) {
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_V2X;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = V2XMode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
    BMCR_ModMag_B.BMCR_flgPwrUpReq_k = true;
    BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
    BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
  } else if (BMCR_ModMag_DW.is_HV_ON == BMCR_ModMag_IN_No_Wk) {
    if (BMCR_stWakSrc) {
      BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_WK_VCU1;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = HVOn;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    } else {
      if (BMCR_ModMag_DW.temporalCounter_i1 >= 3000U) {
        BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
        BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
        BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
        BMCR_ModMag_DW.BMCR_flgEolOut = false;
      }
    }
  } else {
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = HVOn;
    if ((!BMCR_stWakSrc) && (COMR_stPwrUpDwnVcuReq != 2)) {
      BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_No_Wk;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    } else {
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_Init(void)
{
  BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Initial;
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
    BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
    BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
    if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
      BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
    } else {
      if (BSPR_bDCWkUp || BSPR_bACWkUp) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
      }
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_PreHeat(void)
{
  BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = PreHeatMode;
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else {
    if (BCMR_stAChrgPreThmReq != 1) {
      BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
      BMCR_ModMag_B.BMCR_flgPwrDownReq_n = false;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
      if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_PreHeat_ready(void)
{
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else if ((BCCR_stBmsCtrMode == 7) && (COMR_stPreThmEna == 1)) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_PreHeat;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = PreHeatMode;
  } else {
    if ((COMR_stPwrUpDwnVcuReq == 2) && (COMR_stPreThmEna != 1) &&
        (BMCR_ModMag_DW.temporalCounter_i1 >= BMCR_PreheatDelayTi_C * 100U)) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      BMCR_ModMag_DW.BMCR_flgEolOut = false;
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_Precharge(void)
{
  BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Precharge;
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else if (COMR_stEol) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_EOL;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = EolMode;
    BMCR_ModMag_DW.BMCR_flgEolOut = false;
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = GbRTE_MainPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = !GbRTE_MainPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = GbRTE_DChrgPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = !GbRTE_DChrgPwrUpReq_flg;
  } else if (BCCR_stBmsCtrMode == 4) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_ON;
    BMCR_ModMag_DW.is_HV_ON = BMCR_ModMag_IN_WK_VCU1;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = HVOn;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
  } else {
    if ((!BMCR_stWakSrc) || (COMR_stPwrUpDwnVcuReq == 2)) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      BMCR_ModMag_DW.BMCR_flgEolOut = false;
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_Standby(void)
{
  boolean_T guard1 = false;
  boolean_T guard2 = false;
  BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
  BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
  BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else if (COMR_stEol) {
    BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_EOL;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = EolMode;
    BMCR_ModMag_DW.BMCR_flgEolOut = false;
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = GbRTE_MainPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = !GbRTE_MainPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = GbRTE_DChrgPwrUpReq_flg;
    BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = !GbRTE_DChrgPwrUpReq_flg;
  } else if (COMR_stPwrUpDwnVcuReq == 1) {
    BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Precharge;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Precharge;
    BMCR_ModMag_B.BMCR_bPwrUpReq_m = true;
    BMCR_ModMag_B.BMCR_bPwrDwnReq_p = false;
  } else {
    guard1 = false;
    guard2 = false;
    if (BCMR_stHoldTempObsvr == 1) {
      BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
      guard1 = true;
    } else if ((COMR_stPwrUpDwnVcuReq != 1) && (BCMR_bAChrgPwrUpReq ||
                BCMR_bDChrgPwrUpReq)) {
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
      BMCR_ModMag_B.BMCR_flgPwrUpReq_k = true;
      BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
      guard1 = true;
    } else if (!BMCR_stWakSrc) {
      if (BSER_stBalInteChgFlg == 1) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Balance;
        BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = ServiceMode;
        BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
        BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      } else if (BSER_stBalInteChgFlg != 1) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_After_Run;
        BMCR_ModMag_DW.temporalCounter_i1 = 0U;
        BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AfterRun;
        BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
        BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      } else {
        guard2 = true;
      }
    } else {
      guard2 = true;
    }

    if (guard2) {
      if (BAAR_flagAutoAdrsEna) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_AutoAddress;
        BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AutoAddrMode;
        BMCR_ModMag_B.BMCR_bAutoAdrsEna_d = true;
      } else if ((COMR_stPwrUpDwnVcuReq == 2) && BMCR_ModMag_DW.BMCR_flgEolOut)
      {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
        BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
        BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
        BMCR_ModMag_DW.BMCR_flgEolOut = false;
      } else if (BMCR_ModMag_DW.is_Standby == BMCR_ModMag_IN_Standby_1) {
        if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
        }
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    }

    if (guard1) {
      BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_NO_ACTIVE_CHILD;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
      if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_V2X(void)
{
  BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = V2XMode;
  if (DSMR_stFaultRank >= 3) {
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
    BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
    BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
    BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
  } else {
    if (BCMR_bAChrgPwrDwnReq) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_AC_Charge_Stop;
      BMCR_ModMag_B.BMCR_flgPwrDownReq_n = true;
      BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
      BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
      BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
      BMCR_ModMag_DW.i_BMM = 0U;
    }
  }
}

/* Function for Chart: '<S2>/BMCR' */
static void BMCR_ModMag_Operation(void)
{
  int32_T tmp;
  switch (BMCR_ModMag_DW.is_Operation) {
   case BMCR_ModMag_IN_AC_Charge:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AcChrgMode;
    if (DSMR_stFaultRank >= 3) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    } else {
      if (BCMR_bAChrgPwrDwnReq) {
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_AC_Charge_Stop;
        BMCR_ModMag_B.BMCR_flgPwrDownReq_n = true;
        BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
        BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
        BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
        BMCR_ModMag_DW.i_BMM = 0U;
      }
    }
    break;

   case BMCR_ModMag_IN_AC_Charge_Stop:
    if (DSMR_stFaultRank >= 3) {
      BMCR_ModMag_DW.i_BMM = 0U;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    } else if ((COMR_stPwrUpDwnVcuReq == 2) || (BMCR_ModMag_DW.i_BMM >= 300)) {
      BMCR_ModMag_DW.i_BMM = 0U;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      BMCR_ModMag_DW.BMCR_flgEolOut = false;
    } else {
      tmp = BMCR_ModMag_DW.i_BMM + 1;
      if (tmp > 65535) {
        tmp = 65535;
      }

      BMCR_ModMag_DW.i_BMM = (uint16_T)tmp;
    }
    break;

   case BMCR_ModMag_IN_After_Run:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AfterRun;
    if (BMCR_stWakSrc) {
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = false;
      BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = false;
      BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = false;
      BMCR_ModMag_B.BMCR_flgPwrDownReq_n = false;
      BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
      if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    } else if (BMCR_ModMag_DW.temporalCounter_i1 >= BMCR_ReadySleepTi_C * 100U)
    {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_ShunDown;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = true;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 1U;
    } else {
      if (BSER_stBalInteChgFlg == 1) {
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Balance;
        BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = ServiceMode;
        BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
        BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      }
    }
    break;

   case BMCR_ModMag_IN_AutoAddress:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AutoAddrMode;
    if (!BAAR_flagAutoAdrsEna) {
      BMCR_ModMag_B.BMCR_bAutoAdrsEna_d = false;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
      if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    }
    break;

   case BMCR_ModMag_IN_Balance:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = ServiceMode;
    if ((BSER_stBalInteChgFlg != 1) || BMCR_stWakSrc) {
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = false;
      BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = false;
      BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = false;
      BMCR_ModMag_B.BMCR_flgPwrDownReq_n = false;
      BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
      if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    }
    break;

   case BMCR_ModMag_IN_DC_Charge:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = DcChrgMode;
    if (DSMR_stFaultRank >= 3) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    } else {
      if (!BCMR_bDChrgRdy) {
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_DC_Charge_Stop;
        BMCR_ModMag_B.BMCR_flgPwrDownReq_n = true;
        BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
        BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
        BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
      }
    }
    break;

   case BMCR_IN_DC_Charge_DisConnecting:
    if (DSMR_stFaultRank >= 3) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    } else if (((COMR_stPwrUpDwnVcuReq == 2) || ((BCCR_stBmsDChrgCtrMode == 6) &&
      BCMR_bDChrgPwrDwnReq)) && (BMCR_ModMag_DW.BMCR_cntDcMRDwn >
                BMCR_cntDcMRDwn_C)) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_Disconnecting;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      BMCR_ModMag_DW.BMCR_flgEolOut = false;
    } else {
      tmp = BMCR_ModMag_DW.BMCR_cntDcMRDwn + 1;
      if (tmp > 65535) {
        tmp = 65535;
      }

      BMCR_ModMag_DW.BMCR_cntDcMRDwn = (uint16_T)tmp;
    }
    break;

   case BMCR_ModMag_IN_DC_Charge_Stop:
    if (DSMR_stFaultRank >= 3) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    } else {
      if (COMR_stPwrUpDwnVcuReq == 2) {
        BMCR_ModMag_DW.is_Operation = BMCR_IN_DC_Charge_DisConnecting;
        BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = false;
        BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = true;
        BMCR_ModMag_DW.BMCR_cntDcMRDwn = 0U;
      }
    }
    break;

   case BMCR_ModMag_IN_EOL:
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = EolMode;
    if (!BMCR_stWakSrc) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_After_Run;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = AfterRun;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
    } else if ((!COMR_stEol) && BMCR_stWakSrc) {
      BMCR_ModMag_DW.BMCR_flgEolOut = true;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
      BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
      BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
      if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
        BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
        BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
      } else {
        if (BSPR_bDCWkUp || BSPR_bACWkUp) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
        }
      }
    } else {
      BMCR_ModMag_DW.BMCR_flgEolOut = false;
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = GbRTE_MainPwrUpReq_flg;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = !GbRTE_MainPwrUpReq_flg;
      BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c = GbRTE_DChrgPwrUpReq_flg;
      BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i = !GbRTE_DChrgPwrUpReq_flg;
    }
    break;

   case BMCR_ModMag_IN_Fault_Mode:
    BMCR_ModMag_Fault_Mode();
    break;

   case BMCR_ModMag_IN_HV_Disconnecting:
    if (DSMR_stFaultRank >= 3) {
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Fault_Mode;
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = (BSPR_bDCWkUp || BSPR_bACWkUp);
      BMCR_ModMag_DW.is_Fault_Mode = BMCR_ModMag_IN_Fault;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
      BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = FaultMode;
    } else {
      if ((BCCR_stBmsCtrMode == 90) || (BCCR_stBmsCtrMode == 0) ||
          (BCCR_stBmsCtrMode == 7) || (BCCR_stBmsCtrMode == 14) ||
          (BCCR_stBmsCtrMode == 17)) {
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_HV_OFF;
        BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = HVOff;
        if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
        }
      }
    }
    break;

   case BMCR_ModMag_IN_HV_OFF:
    BMCR_ModMag_HV_OFF();
    break;

   case BMCR_ModMag_IN_HV_ON:
    BMCR_ModMag_HV_ON();
    break;

   case BMCR_ModMag_IN_Init:
    BMCR_ModMag_Init();
    break;

   case BMCR_ModMag_IN_PreHeat:
    BMCR_ModMag_PreHeat();
    break;

   case BMCR_ModMag_IN_PreHeat_ready:
    BMCR_ModMag_PreHeat_ready();
    break;

   case BMCR_ModMag_IN_Precharge:
    BMCR_ModMag_Precharge();
    break;

   case BMCR_ModMag_IN_ShunDown:
    BMCR_ModMag_B.BMCR_flgBmsSlp_h = true;
    BMCR_ModMag_B.BMCR_bBmuShutdown_e = 1U;
    break;

   case BMCR_ModMag_IN_Standby:
    BMCR_ModMag_Standby();
    break;

   case BMCR_ModMag_IN_V2X:
    BMCR_ModMag_V2X();
    break;

   default:
    if ((BCMR_stAChrgPreThmReq == 1) && (COMR_stPwrUpDwnVcuReq == 2)) {
      BMCR_ModMag_B.BMCR_bPwrUpReq_m = false;
      BMCR_ModMag_B.BMCR_bPwrDwnReq_p = true;
      BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_PreHeat_ready;
      BMCR_ModMag_DW.temporalCounter_i1 = 0U;
    } else {
      if (BCMR_stAChrgPreThmReq != 1) {
        BMCR_ModMag_B.BMCR_flgPwrUpReq_k = false;
        BMCR_ModMag_B.BMCR_flgPwrDownReq_n = false;
        BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Standby;
        BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Standby;
        BMCR_ModMag_B.BMCR_flgBmsSlp_h = false;
        BMCR_ModMag_B.BMCR_bBmuShutdown_e = 0U;
        if ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp)) {
          BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_2;
          BMCR_ModMag_B.BMCR_bWkUpVCU_l = false;
        } else {
          if (BSPR_bDCWkUp || BSPR_bACWkUp) {
            BMCR_ModMag_DW.is_Standby = BMCR_ModMag_IN_Standby_1;
            BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
          }
        }
      }
    }
    break;
  }
}

/* Model step function */
void BMCR_ModMag_step(void)
{
  boolean_T rtb_LogicalOperator1;
  boolean_T rtb_LogicalOperator3;
  real32_T rtb_Product;
  real32_T tmp;
  BMCR_stWakSrc = (BSPR_bDCWkUp || BSPR_bACWkUp || BSPR_bKl15WkUp ||
                   (BSW_stSysNetWkUp != 1));
  if (BMCR_ModMag_DW.temporalCounter_i1 < MAX_uint32_T) {
    BMCR_ModMag_DW.temporalCounter_i1++;
  }

  if (BMCR_ModMag_DW.is_active_c3_BMCR_ModMag == 0U) {
    BMCR_ModMag_DW.is_active_c3_BMCR_ModMag = 1U;
    BMCR_ModMag_B.BMCR_bPwrUpReqVald_f = true;
    BMCR_ModMag_B.BMCR_bPwrDownReqVald_n = true;
    BMCR_ModMag_DW.is_c3_BMCR_ModMag = BMCR_ModMag_IN_Default;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Default;
  } else if (BMCR_ModMag_DW.is_c3_BMCR_ModMag == BMCR_ModMag_IN_Default) {
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Default;
    if (BSPR_bDCWkUp || BSPR_bACWkUp) {
      BMCR_ModMag_B.BMCR_bWkUpVCU_l = true;
    }

    BMCR_ModMag_DW.is_c3_BMCR_ModMag = BMCR_ModMag_IN_Operation;
    BMCR_ModMag_DW.is_Operation = BMCR_ModMag_IN_Init;
    BMCR_ModMag_B.BMCR_stBmsModeCtrl_n = Initial;
    BMCR_ModMag_DW.BMCR_flgEolOut = false;
  } else {
    BMCR_ModMag_Operation();
  }

  BMCR_bWkUpVCU = BMCR_ModMag_B.BMCR_bWkUpVCU_l;
  BMCR_stBmsModeCtrl = BMCR_ModMag_B.BMCR_stBmsModeCtrl_n;
  BMCR_bBmuShutdown = BMCR_ModMag_B.BMCR_bBmuShutdown_e;
  BMCR_flgBmsSlp = BMCR_ModMag_B.BMCR_flgBmsSlp_h;
  BMCR_bAutoAdrsEna = BMCR_ModMag_B.BMCR_bAutoAdrsEna_d;
  BMCR_bPwrUpReq = BMCR_ModMag_B.BMCR_bPwrUpReq_m;
  BMCR_bPwrDwnReq = BMCR_ModMag_B.BMCR_bPwrDwnReq_p;
  BMCR_bDChrgPwrUpReq = BMCR_ModMag_B.BMCR_bDChrgPwrUpReq_c;
  BMCR_bDChrgPwrDwnReq = BMCR_ModMag_B.BMCR_bDChrgPwrDwnReq_i;
  BMCR_flgPwrDownReq = BMCR_ModMag_B.BMCR_flgPwrDownReq_n;
  BMCR_flgPwrUpReq = BMCR_ModMag_B.BMCR_flgPwrUpReq_k;
  BMCR_bPwrDownReqVald = BMCR_ModMag_B.BMCR_bPwrDownReqVald_n;
  BMCR_bPwrUpReqVald = BMCR_ModMag_B.BMCR_bPwrUpReqVald_f;
  BMCR_flgBmsOTAMode = (BSW_stOTAMode == 1);
  rtb_LogicalOperator1 = ((!BSPR_bDCWkUp) && (!BSPR_bACWkUp) && (!BSPR_bKl15WkUp));
  rtb_LogicalOperator3 = ((!(BCCR_bMNegCtrSwtOn || BCCR_bPreChCtrSwtOn ||
    BCCR_bDChrgPosCtrSwtOn || BCCR_bDChrgNegCtrSwtOn || BCCR_bMPosCtrSwtOn)) &&
    rtb_LogicalOperator1);
  if (rtb_LogicalOperator3) {
    rtb_Product = 0.01F;
  } else {
    rtb_Product = 0.0F;
  }

  if (BMCR_NMReleasTi_C < BMCR_ModMag_DW.Delay_DSTATE) {
    tmp = BMCR_NMReleasTi_C;
  } else {
    tmp = BMCR_ModMag_DW.Delay_DSTATE;
  }

  rtb_Product = (rtb_Product + tmp) * (real32_T)rtb_LogicalOperator3;
  BMCR_ModMag_DW.Delay_DSTATE = rtb_Product;
  BMCR_RTCWakeup = ((BSW_stSysWkUpSrc & 16) != 0);
  BMCR_TPLWakeup = ((BSW_stSysWkUpSrc & 256) != 0);
  BMCR_stNMRelease = ((rtb_Product > BMCR_NMReleasTi_C) || (rtb_LogicalOperator1
    && (BMCR_RTCWakeup || BMCR_TPLWakeup)));
  BMCR_ICWakeUp = (BCCR_bMNegCtrSwtOn && BCCR_bMPosCtrSwtOn &&
                   rtb_LogicalOperator1);
}

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

  /* block I/O */

  /* custom signals */
  BMCR_stBmsModeCtrl = ((uint8_T)254U);
  BMCR_bBmuShutdown = ((uint8_T)0U);
  BMCR_flgBmsOTAMode = false;
  BMCR_RTCWakeup = false;
  BMCR_TPLWakeup = false;
  BMCR_stNMRelease = false;
  BMCR_ICWakeUp = false;
  BMCR_bWkUpVCU = false;
  BMCR_flgBmsSlp = false;
  BMCR_bAutoAdrsEna = false;
  BMCR_bPwrUpReq = false;
  BMCR_bPwrDwnReq = false;
  BMCR_bDChrgPwrUpReq = false;
  BMCR_bDChrgPwrDwnReq = false;
  BMCR_flgPwrDownReq = false;
  BMCR_flgPwrUpReq = false;
  BMCR_bPwrDownReqVald = false;
  BMCR_bPwrUpReqVald = false;

  /* external inputs */
  BMCR_ModMag_U.COMR_stVcuAllwSlp = 0.0F;
}

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