/*
 * File: SOH_Cal.c
 *
 * Code generated for Simulink model 'SOH'.
 *
 * Company                        : AIWAYS
 * Author                         : zhangzy
 * Model version                  : 'M100C100'
 * Simulink Coder version         : 8.13 (R2017b) 24-Jul-2017
 * C/C++ source code generated on : Fri Oct 23 15:05:51 2020
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: Infineon->TriCore
 * Code generation objectives:
 *    1. MISRA C:2012 guidelines
 *    2. Safety precaution
 * Validation result: Not run
 */

#include "rtwtypes.h"
#include "SOH_types.h"

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

/* Definition for custom storage class: UAESCalibrationUint16 */
const volatile uint16_T CaSOH_CalenderDayTable1_Day[40] = { 0U, 100U, 200U, 300U,
  400U, 500U, 600U, 700U, 800U, 900U, 1000U, 1100U, 1200U, 1300U, 1400U, 1500U,
  1600U, 1700U, 1800U, 1900U, 2000U, 2100U, 2200U, 2300U, 2400U, 2500U, 2600U,
  2700U, 2800U, 2900U, 3000U, 3100U, 3200U, 3300U, 3400U, 3500U, 3600U, 3700U,
  3800U, 3900U } ;                     /* 15℃日历寿命的查表值 */

const volatile uint16_T CaSOH_CalenderDayTable2_Day[40] = { 0U, 100U, 200U, 300U,
  400U, 500U, 600U, 700U, 800U, 900U, 1000U, 1100U, 1200U, 1300U, 1400U, 1500U,
  1600U, 1700U, 1800U, 1900U, 2000U, 2100U, 2200U, 2300U, 2400U, 2500U, 2600U,
  2700U, 2800U, 2900U, 3000U, 3100U, 3200U, 3300U, 3400U, 3500U, 3600U, 3700U,
  3800U, 3900U } ;                     /* 25℃日历寿命的查表值 */

const volatile uint16_T CaSOH_CalenderDayTable3_Day[40] = { 0U, 100U, 200U, 300U,
  400U, 500U, 600U, 700U, 800U, 900U, 1000U, 1100U, 1200U, 1300U, 1400U, 1500U,
  1600U, 1700U, 1800U, 1900U, 2000U, 2100U, 2200U, 2300U, 2400U, 2500U, 2600U,
  2700U, 2800U, 2900U, 3000U, 3100U, 3200U, 3300U, 3400U, 3500U, 3600U, 3700U,
  3800U, 3900U } ;                     /* 35℃日历寿命的查表值 */

const volatile uint16_T CaSOH_CalenderDayTable4_Day[40] = { 0U, 100U, 200U, 300U,
  400U, 500U, 600U, 700U, 800U, 900U, 1000U, 1100U, 1200U, 1300U, 1400U, 1500U,
  1600U, 1700U, 1800U, 1900U, 2000U, 2100U, 2200U, 2300U, 2400U, 2500U, 2600U,
  2700U, 2800U, 2900U, 3000U, 3100U, 3200U, 3300U, 3400U, 3500U, 3600U, 3700U,
  3800U, 3900U } ;                     /* 45℃日历寿命的查表值 */

const volatile uint16_T CaSOH_ChrgOCVSOCCellVolt_mV[30] = { 3390U, 3450U, 3490U,
  3540U, 3570U, 3600U, 3610U, 3630U, 3640U, 3660U, 3690U, 3740U, 3790U, 3840U,
  3890U, 3950U, 4010U, 4070U, 4130U, 4200U, 4280U, 4281U, 4282U, 4283U, 4284U,
  4285U, 4286U, 4287U, 4288U, 4289U } ;/* 充电OCV-SOC中单体电压 */

const volatile uint16_T CaSOH_DisChrgOCVSOCCellVolt_mV[30] = { 3390U, 3430U,
  3480U, 3520U, 3550U, 3580U, 3600U, 3620U, 3630U, 3650U, 3680U, 3730U, 3780U,
  3830U, 3880U, 3940U, 4000U, 4060U, 4130U, 4200U, 4280U, 4281U, 4282U, 4283U,
  4284U, 4285U, 4286U, 4287U, 4288U, 4289U } ;/* 放电OCV-SOC中单体电压 */

const volatile uint16_T CaSOH_QAUsageTable_Day[40] = { 0U, 100U, 200U, 300U,
  400U, 500U, 600U, 700U, 800U, 900U, 1000U, 1100U, 1200U, 1300U, 1400U, 1500U,
  1600U, 1700U, 1800U, 1900U, 2000U, 2100U, 2200U, 2300U, 2400U, 2500U, 2600U,
  2700U, 2800U, 2900U, 3000U, 3100U, 3200U, 3300U, 3400U, 3500U, 3600U, 3700U,
  3800U, 3900U } ;                     /* 质保时间使用寿命的查表值 */

const volatile uint16_T CcSOH_CellAbsvCap_Ah = 450U;/* 充放电容量累加值 */
const volatile uint16_T CcSOH_CellNumb_numb = 96U;/* 电芯个数 */
const volatile uint16_T CcSOH_OCVCorrectRunTime_ms = 5000U;/* OCV校准在系统运行后的标定时间内进行 */
const volatile uint16_T CcSOH_PackUsageTi_Day = 2555U;/* 电池包使用天数达到SOH计算切换时间 */
const volatile uint16_T CcSOH_SOH2EnaTiThrd_Day = 100U;/* 启用SOH2查表的天数阈值 */

#define ASW1_OEM_STOP_SEC_DEFAULT_CALIB_16
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_CALIB_32
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: UAESCalibrationUint32 */
const volatile uint32_T CcSOH_NVMOCVCorrdSumTi_ms = 432000000U;/* NVM存储的SOC修正累加时间 */
const volatile uint32_T CcSOH_SOH2EnaThrd_Ah = 5310U;/* 启用循环寿命查表的累计Ah数 */
const volatile uint32_T CcSOH_SOH2RunCycleTi_ms = 1800000U;/* 上电运行每60min运行一次日历寿命查表 */
const volatile uint32_T CcSOH_SOH3EnaThrd_Ah = 5310U;/* 启用QA寿命查表的累计Ah数 */
const volatile uint32_T CcSOH_VoltCurrVldDebTi_ms = 1000U;/* 电压电流无效debounce时间 */

#define ASW1_OEM_STOP_SEC_DEFAULT_CALIB_32
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_CALIB_8
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: UAESCalibrationUint8 */
const volatile boolean_T CbSOH_CapFltAlarmOvrSwt_flg = 0;/* GbSOH_CapFltAlarm_flg对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile boolean_T CbSOH_CapFltAlarmOvr_flg = 0;/* GbSOH_CapFltAlarm_flg对应的OverWrite值 */
const volatile boolean_T CbSOH_CapFltWarnOvrSwt_flg = 0;/* GbSOH_CapFltWarn_flg对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile boolean_T CbSOH_CapFltWarnOvr_flg = 0;/* GbSOH_CapFltWarn_flg对应的OverWrite值 */
const volatile boolean_T CbSOH_CurrBatCapOvrSwt_flg = 0;/* GcSOH_CurrBatCap_Ah对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile boolean_T CbSOH_ManuOCVCorrect_flg = 0;/* 手动开启OCV标定标志位，0-->1时开启，每个上电循环只能开启一次 */
const volatile boolean_T CbSOH_PackSOH1OvrSwt_flg = 0;/* GcSOH_PackSOH1_pct对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile boolean_T CbSOH_PackSOH2OvrSwt_flg = 0;/* GcSOH_PackSOH2_pct对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile boolean_T CbSOH_PackSOH3OvrSwt_flg = 0;/* GcSOH_PackSOH3_pct对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile boolean_T CbSOH_PackSOHOvrSwt_flg = 0;/* GcSOH_PackSOH_pct对应变量的Switch开关0:使用计算值；1:使用标定值 */
const volatile uint8_T CcSOH_CellVoltMeasTol_mV = 15U;/* OCV校准时最高最低单体电压采用误差值 */
const volatile uint8_T CcSOH_OCVCorrectSleepTime_min = 60U;/* OCV开启的休眠时间要求 */
const volatile uint8_T CcSOH_OCVPeakCellVoltDev_mV = 20U;/* OCV校准时极值电压偏差值标定值Deviation */
const volatile uint8_T CcSOH_OCVPeakCellVoltTime_ms = 100U;/* OCV校准时极值电压电压偏差值持续时间 */

#define ASW1_OEM_STOP_SEC_DEFAULT_CALIB_8
#include "Asw1_OEM_MemMap.h"
#define ASW1_OEM_START_SEC_DEFAULT_CALIB_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

/* Definition for custom storage class: UAESCalibrationUnspecified */
const volatile real32_T CaSOH_CalenderSOH_pct[40] = { 0.0F, 100.0F, 200.0F,
  300.0F, 400.0F, 500.0F, 600.0F, 700.0F, 800.0F, 900.0F, 1000.0F, 1100.0F,
  1200.0F, 1300.0F, 1400.0F, 1500.0F, 1600.0F, 1700.0F, 1800.0F, 1900.0F,
  2000.0F, 2100.0F, 2200.0F, 2300.0F, 2400.0F, 2500.0F, 2600.0F, 2700.0F,
  2800.0F, 2900.0F, 3000.0F, 3100.0F, 3200.0F, 3300.0F, 3400.0F, 3500.0F,
  3600.0F, 3700.0F, 3800.0F, 3900.0F } ;/* SOH的查表值 */

const volatile real32_T CaSOH_ChrgOCVSOCCellSOC_pct[30] = { 0.0F, 5.0F, 10.0F,
  15.0F, 20.0F, 25.0F, 30.0F, 35.0F, 40.0F, 45.0F, 50.0F, 55.0F, 60.0F, 65.0F,
  70.0F, 75.0F, 80.0F, 85.0F, 90.0F, 95.0F, 100.0F, 100.0F, 100.0F, 100.0F,
  100.0F, 100.0F, 100.0F, 100.0F, 100.0F, 100.0F } ;/* 充电OCV-SOC中单体SOC */

const volatile real32_T CaSOH_CycleCapAhTable1_Ah[40] = { 0.0F, 100.0F, 200.0F,
  300.0F, 400.0F, 500.0F, 600.0F, 700.0F, 800.0F, 900.0F, 1000.0F, 1100.0F,
  1200.0F, 1300.0F, 1400.0F, 1500.0F, 1600.0F, 1700.0F, 1800.0F, 1900.0F,
  2000.0F, 2100.0F, 2200.0F, 2300.0F, 2400.0F, 2500.0F, 2600.0F, 2700.0F,
  2800.0F, 2900.0F, 3000.0F, 3100.0F, 3200.0F, 3300.0F, 3400.0F, 3500.0F,
  3600.0F, 3700.0F, 3800.0F, 3900.0F } ;/* 15℃循环寿命的查表值 */

const volatile real32_T CaSOH_CycleCapAhTable2_Ah[40] = { 0.0F, 100.0F, 200.0F,
  300.0F, 400.0F, 500.0F, 600.0F, 700.0F, 800.0F, 900.0F, 1000.0F, 1100.0F,
  1200.0F, 1300.0F, 1400.0F, 1500.0F, 1600.0F, 1700.0F, 1800.0F, 1900.0F,
  2000.0F, 2100.0F, 2200.0F, 2300.0F, 2400.0F, 2500.0F, 2600.0F, 2700.0F,
  2800.0F, 2900.0F, 3000.0F, 3100.0F, 3200.0F, 3300.0F, 3400.0F, 3500.0F,
  3600.0F, 3700.0F, 3800.0F, 3900.0F } ;/* 25℃循环寿命的查表值 */

const volatile real32_T CaSOH_CycleCapAhTable3_Ah[40] = { 0.0F, 100.0F, 200.0F,
  300.0F, 400.0F, 500.0F, 600.0F, 700.0F, 800.0F, 900.0F, 1000.0F, 1100.0F,
  1200.0F, 1300.0F, 1400.0F, 1500.0F, 1600.0F, 1700.0F, 1800.0F, 1900.0F,
  2000.0F, 2100.0F, 2200.0F, 2300.0F, 2400.0F, 2500.0F, 2600.0F, 2700.0F,
  2800.0F, 2900.0F, 3000.0F, 3100.0F, 3200.0F, 3300.0F, 3400.0F, 3500.0F,
  3600.0F, 3700.0F, 3800.0F, 3900.0F } ;/* 35℃循环寿命的查表值 */

const volatile real32_T CaSOH_CycleCapAhTable4_Ah[40] = { 0.0F, 100.0F, 200.0F,
  300.0F, 400.0F, 500.0F, 600.0F, 700.0F, 800.0F, 900.0F, 1000.0F, 1100.0F,
  1200.0F, 1300.0F, 1400.0F, 1500.0F, 1600.0F, 1700.0F, 1800.0F, 1900.0F,
  2000.0F, 2100.0F, 2200.0F, 2300.0F, 2400.0F, 2500.0F, 2600.0F, 2700.0F,
  2800.0F, 2900.0F, 3000.0F, 3100.0F, 3200.0F, 3300.0F, 3400.0F, 3500.0F,
  3600.0F, 3700.0F, 3800.0F, 3900.0F } ;/* 45℃循环寿命的查表值 */

const volatile real32_T CaSOH_DisChrgOCVSOCCellSOC_pct[30] = { 0.0F, 5.0F, 10.0F,
  15.0F, 20.0F, 25.0F, 30.0F, 35.0F, 40.0F, 45.0F, 50.0F, 55.0F, 60.0F, 65.0F,
  70.0F, 75.0F, 80.0F, 85.0F, 90.0F, 95.0F, 100.0F, 100.0F, 100.0F, 100.0F,
  100.0F, 100.0F, 100.0F, 100.0F, 100.0F, 100.0F } ;/* 放电OCV-SOC中单体电压 */

const volatile real32_T CaSOH_QACapAhTable_Ah[40] = { 0.0F, 100.0F, 200.0F,
  300.0F, 400.0F, 500.0F, 600.0F, 700.0F, 800.0F, 900.0F, 1000.0F, 1100.0F,
  1200.0F, 1300.0F, 1400.0F, 1500.0F, 1600.0F, 1700.0F, 1800.0F, 1900.0F,
  2000.0F, 2100.0F, 2200.0F, 2300.0F, 2400.0F, 2500.0F, 2600.0F, 2700.0F,
  2800.0F, 2900.0F, 3000.0F, 3100.0F, 3200.0F, 3300.0F, 3400.0F, 3500.0F,
  3600.0F, 3700.0F, 3800.0F, 3900.0F } ;/* 质保里程使用寿命的查表值 */

const volatile real32_T CcSOH_CellNormalCap_Ah = 153.0F;/* 充放电额定容量 */
const volatile real32_T CcSOH_CurrBatCapOvr_Ah = 0.0F;/* GcSOH_CurrBatCap_Ah对应的OverWrite值 */
const volatile real32_T CcSOH_OCVCorrectTemp_C = 15.0F;/* OCV修正的最小温度 */
const volatile real32_T CcSOH_PackSOH1Ovr_pct = 0.0F;/* GcSOH_PackSOH1_pct对应的OverWrite值 */
const volatile real32_T CcSOH_PackSOH2Ovr_pct = 0.0F;/* GcSOH_PackSOH2_pct对应的OverWrite值 */
const volatile real32_T CcSOH_PackSOH3Ovr_pct = 0.0F;/* GcSOH_PackSOH3_pct对应的OverWrite值 */
const volatile real32_T CcSOH_PackSOHOvr_pct = 0.0F;/* GcSOH_PackSOH_pct对应的OverWrite值 */
const volatile real32_T CcSOH_SOH2TempThrd1_C = 17.5F;/* SOH查表的温度阈值1—15℃ */
const volatile real32_T CcSOH_SOH2TempThrd2_C = 27.5F;/* SOH查表的温度阈值2—25℃ */
const volatile real32_T CcSOH_SOH2TempThrd3_C = 37.5F;/* SOH查表的温度阈值3—35℃ */
const volatile real32_T CcSOH_SOHAlarmThrd_pct = 0.7F;/* SOH低阀值的系数 */
const volatile real32_T CcSOH_SOHCalDiffSOCThrd_pct = 60.0F;/* NVM中与OCV修正的SOC差值大于标定值才进行SOH计算 */
const volatile real32_T CcSOH_SOHCalSOCThrd_pct = 1.0F;/* NVM中的SOC大于标定值才进行SOH计算 */
const volatile real32_T CcSOH_SOHHighThrd_pct = 1.2F;/* SOH高阀值的系数 */
const volatile real32_T CcSOH_SOHLowThrd_pct = 0.7F;/* SOH低阀值的系数 */
const volatile real32_T CcSOH_SOHWarningThrd_pct = 0.85F;/* SOH高阀值的系数 */

#define ASW1_OEM_STOP_SEC_DEFAULT_CALIB_UNSPECIFIED
#include "Asw1_OEM_MemMap.h"

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