/*
 * File: COMR_RtcCor.c
 *
 * Code generated for Simulink model 'COMR_RtcCor'.
 *
 * Model version                  : A1.1_0
 * Simulink Coder version         : 8.11 (R2016b) 25-Aug-2016
 * C/C++ source code generated on : Wed Jun 17 20:19:13 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 "COMR_RtcCor.h"
#include "COMR_RtcCor_private.h"

/* Exported data definition */

/* Definition for custom storage class: OutputSignal */
volatile boolean_T COMR_bRtcCorrectionEn;
volatile real32_T COMR_tiDiffStopTime;

/* Block signals (auto storage) */
B_COMR_RtcCor_T COMR_RtcCor_B;

/* Block states (auto storage) */
DW_COMR_RtcCor_T COMR_RtcCor_DW;

/* Model step function */
void COMR_RtcCor_step(void)
{
  boolean_T rtb_LogicalOperator;
  real32_T rtb_Product;
  real32_T tmp;
  rtb_LogicalOperator = (COMR_bStopTimeVldFlg && BSWIVI37FDataAvailable);
  if (rtb_LogicalOperator) {
    rtb_Product = 0.1F;
  } else {
    rtb_Product = 0.0F;
  }

  if (5.0F <= COMR_RtcCor_DW.Delay_DSTATE) {
    tmp = 5.0F;
  } else {
    tmp = COMR_RtcCor_DW.Delay_DSTATE;
  }

  rtb_Product = (real32_T)((rtb_Product + tmp) * (real32_T)rtb_LogicalOperator);
  rtb_LogicalOperator = (rtb_Product > 5.0F);
  COMR_RtcCor_DW.Delay_DSTATE = rtb_Product;
  if (rtb_LogicalOperator) {
    rtb_Product = (real32_T)fmod((real32_T)floor(((((((real32_T)COMR_BMSYear *
      365.0F + (real32_T)floor((real32_T)COMR_BMSYear / 4.0F)) - (real32_T)floor
      ((real32_T)COMR_BMSYear / 100.0F)) + (real32_T)COMR_BMSYear / 400.0F) +
      rtCP_Month2Day_tableData[plook_u32u8_bincka(COMR_BMSMonth,
      rtCP_Month2Day_bp01Data, 11U)]) + (real32_T)COMR_BMSDay) - ((((((real32_T)
      COMR_YearSet * 365.0F + (real32_T)floor((real32_T)COMR_YearSet / 4.0F)) -
      (real32_T)floor((real32_T)COMR_YearSet / 100.0F)) + (real32_T)COMR_YearSet
      / 400.0F) + rtCP_Month2Day_tableData_f[plook_u32u8_bincka(COMR_MonthSet,
      rtCP_Month2Day_bp01Data_k, 11U)]) + (real32_T)COMR_DaySet)), 65536.0F);
    COMR_tiDiffStopTime = (real32_T)((((rtb_Product < 0.0F ? (int32_T)(int16_T)
      -(int16_T)(uint16_T)-rtb_Product : (int32_T)(int16_T)(uint16_T)rtb_Product)
      * 1440 + (COMR_BMSHour - COMR_HourSet) * 60) + COMR_BMSMinute) -
      COMR_MinSet);
    COMR_RtcCor_B.RelationalOperator = ((real32_T)fabs(COMR_tiDiffStopTime) >
      30.0F);
  }

  COMR_bRtcCorrectionEn = (rtb_LogicalOperator &&
    COMR_RtcCor_B.RelationalOperator);
}

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

  /* block I/O */

  /* custom signals */
  COMR_tiDiffStopTime = 0.0F;
  COMR_bRtcCorrectionEn = false;
}

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