/******************************************************************************** * 常州易控汽车电子股份有限公司 * (c) Copyright 2009-2018 ECTEK * 保留所有权利 ******************************************************************************** * 工程名称:整车管理_车辆运动 * 文件名: AccPedCD.h * 功能描述 : 油门踏板模块驱动 * 引用记录: * 备注: * 修订记录: * 日期 版本 作者 描述 * 2018.01.12 00.01.00 李中 第一版 *******************************************************************************/ #include "HardwareLib.h" #include "AccPedCD.h" /*********************************************************************************************/ /*样例代码*/ #ifdef _SAMPLE_CODE_ uint16 AccPedCD_rFltUW,AccPedCD_rUW; //油门踏板位置 uint16 AccPedCD_rRawUW; //类似bosch文档APPCD_rLinAPP1 uint16 AccPedCD_uUW,AccPedCD_u2UW,AccPedCD_uFltUW; uint16 AccPedCD_uOldUW; uint8 AccPedCD_idxDeltaMonUB; sint16 AccPedCD_drUnFltW; //油门踏板斜率 uint16 AccPedCD_rOldUW; //上一时刻油门踏板,用于斜率计算 uint8 AccPedCD_bIdleSwtUB; //怠速开关状态,0:怠速位置 1:全负荷位置 uint8 AccPedCD_bIdleRawUB; //怠速开关原始信号,怠速开关状态和怠速开关原始信号的关系与怠速开关类型相关 uint8 AccPedCD_stMaxUB,AccPedCD_stMinUB,AccPedCD_stNplUB; uint8 AccPedCD_st2MaxUB,AccPedCD_st2MinUB; uint16 AccPedCD_facT1UW; uint8 Fid_APP1UB_mp; //加速踏板1故障禁止状态 uint8 Fid_APP2UB_mp; //加速踏板2故障禁止状态 uint16 AccPedCD_stAPPLatchUW; //上一循环加速踏板诊断的状态 1 部分故障, 2 完全故障, 3 部分恢复, 4完全正常 uint16 AccPedCD_stRampUW; //故障恢复的Ramp状态,0 Ramp结束, 1 Ramp使能 /*************************************************************/ /*标定数据区开始(请不要在该区域加入非标定数据相关的内容) */ #define MAPDATA_START_SEC_VAR_CONST #include "MemMap.h" /*AccPedCD_Cal*/ PRAGMA_MAPDATA const uint16 AccPedCD_uSRCMaxUW_C=18428; /*AccPedCD_uSRCMaxUW_C,最大值*/ PRAGMA_MAPDATA const uint16 AccPedCD_uSRCMinUW_C=2048; /*AccPedCD_uSRCMinUW_C,最小值*/ PRAGMA_MAPDATA const uint16 AccPedCD_uMaxDiffUW_C=2047; /*AccPedCD_uMaxDiffUW_C,AccPed2与AccPed1最大相差多少...*/ PRAGMA_MAPDATA const uint16 AccPedCD_uHighLimIdleUW_C=18427; /*AccPedCD_uHighLimIdleUW_C,怠速开关高限*/ PRAGMA_MAPDATA const uint16 AccPedCD_uLowLimIdleUW_C=819; /*AccPedCD_uLowLimIdleUW_C,怠速开关低限*/ PRAGMA_MAPDATA const uint16 AccPedCD_bPlausEnUW_C=1; /*AccPedCD_bPlausEnUW_C,油门合理性检测是否启用*/ PRAGMA_MAPDATA const uint16 AccPedCD_rFltUW_C=0; /*数字油门,AccPedCD_rFltUW_C*/ PRAGMA_MAPDATA const uint16 AccPedCD_bDigEnUW_C=1; /*油门控制模式,AccPedCD_bDigEnUW_C, 1为正常控制, 0为数字油门*/ PRAGMA_MAPDATA const uint16 AccPedCD_swtUseUW_C=1; /*AccPedCD_swtUseUW_C,油门传感器类型,1:双油门,2:怠速开关,3:单油门*/ PRAGMA_MAPDATA const uint16 AccPedCD_idxIdleSwtTypeUW_C=0; /*AccPedCD_idxIdleSwtTypeUW_C,怠速开关类型 ,0:接电源常开,1:接电源常闭,2:接地常开,3:接地常闭*/ PRAGMA_MAPDATA const AccPedCD_rUW_CUR_TYPE AccPedCD_rUW_CUR= { 4, { 4505,14169,16380,20475 }, { 0,25600,25600,25600 } }; /*油门标定,AccPedCD_rUW_CUR,系数256,单位%*/ PRAGMA_MAPDATA const uint16 AccPedCD_rThresFltLowPosUW_C=3840; /*AccPedCD_rThresFltLowPosUW_C,小油门限*/ PRAGMA_MAPDATA const uint16 AccPedCD_rThresFltMidPosUW_C=10240; /*AccPedCD_rThresFltMidPosUW_C,中油门限*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1LowNegUW_C=0; /*AccPedCD_facT1LowNegUW_C,小油门负向滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1MidNegUW_C=0; /*AccPedCD_facT1MidNegUW_C,中油门负向滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1HighNegUW_C=0; /*AccPedCD_facT1HighNegUW_C,大油门负向滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1LowPosUW_C=750; /*AccPedCD_facT1LowPosUW_C,小油门正向滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1MidPosUW_C=250; /*AccPedCD_facT1MidPosUW_C,中油门正向滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1HighPosUW_C=250; /*AccPedCD_facT1HighPosUW_C,大油门正向滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_duThresStationaryUW_C=123; /*AccPedCD_duThresStationaryUW_C,稳态油门变化范围*/ PRAGMA_MAPDATA const uint16 AccPedCD_facT1StationaryUW_C=900; /*AccPedCD_facT1StationaryUW_C,稳态滤波系数*/ PRAGMA_MAPDATA const uint16 AccPedCD_facDualRelUW_C=2; /*AccPedCD_facDualRelUW_C, 双油门两路信号的比例关系,第一路/第二路*/ PRAGMA_MAPDATA const uint16 AccPedCD_drHealRmpUp_C=2560; /*AccPedCD_drHealRmpUp_C; 加速踏板故障恢复正向Ramp步长。APPCD_drHealRmpUp_C: healing ramp pos. slope*/ PRAGMA_MAPDATA const uint16 AccPedCD_drHealRmpDwn_C=2560; /*AccPedCD_drHealRmpDwn_C; 故障恢复时向下Ramp步长; APPCD_drHealRmpDwn_C: healing ramp neg. slope*/ #define MAPDATA_STOP_SEC_VAR_CONST #include "MemMap.h" /*标定数据区结束 */ /*************************************************************/ /*********************************************** * 函数:油门踏板驱动模块初始化 * 功能:初始化模块中应用到的各变量。 ***********************************************/ void AccPedCD_Init(void) { AccPedCD_uFltUW=0; AccPedCD_idxDeltaMonUB=0; AccPedCD_drUnFltW=0; AccPedCD_rOldUW=0; Fid_APP1UB_mp=0; Fid_APP2UB_mp=0; AccPedCD_stAPPLatchUW = _DFC_INDEX_FINALLY_HEALED_STATUS; AccPedCD_stRampUW=0; if(1==AccPedCD_swtUseUW_C) { //双油门 //油门1 AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN); AccPedCD_uOldUW=AccPedCD_uUW; //油门2 AccPedCD_u2UW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED2_CHAN); } else { if(2==AccPedCD_swtUseUW_C) { //带怠速开关的油门 //油门1 AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN); AccPedCD_uOldUW=AccPedCD_uUW; //得到怠速开关状态 AccPedCD_bIdleRawUB=DINDrv_GetChanState(_DIN_INDEX_BAK1_CHAN); if((0==AccPedCD_idxIdleSwtTypeUW_C)||(3==AccPedCD_idxIdleSwtTypeUW_C)) { //接电常开或者接地常闭 //AccPedCD_bIdleRawUB为1表明踏板踩下,在全负荷位置 AccPedCD_bIdleSwtUB=AccPedCD_bIdleRawUB; } else { //接电常闭或者接地常开 //AccPedCD_bIdleRawUB为0表明踏板踩下,在全负荷位置 AccPedCD_bIdleSwtUB=(!AccPedCD_bIdleRawUB); } } else { //单油门 AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN); AccPedCD_uOldUW=AccPedCD_uUW; } } AccPedCD_Update(); } /*********************************************** * 函数:油门信号滤波函数 * 功能:判断油门为小中大油门及正负向,并进行滤波。 ***********************************************/ void AccPedCD_Filter(void) { //参数选取 if(AccPedCD_rFltUW>AccPedCD_rRawUW) { //下降,3段滤波 if(AccPedCD_rFltUW=AccPedCD_rUW) { //向上 if((AccPedCD_rRawUW - AccPedCD_rUW)<=AccPedCD_drHealRmpUp_C) { //差值小于最小步长限制 AccPedCD_rUW = AccPedCD_rRawUW; AccPedCD_stRampUW=0;//Ramp结束 } else { AccPedCD_rUW += AccPedCD_drHealRmpUp_C; } } else { //向下 if((AccPedCD_rUW - AccPedCD_rRawUW)<=AccPedCD_drHealRmpDwn_C) { //差值小于最小步长限制 AccPedCD_rUW = AccPedCD_rRawUW; AccPedCD_stRampUW=0;//Ramp结束 Ramp end } else { AccPedCD_rUW -= AccPedCD_drHealRmpDwn_C; } } } else { AccPedCD_rUW=AccPedCD_rRawUW; } } /*********************************************** * 函数:双油门信号处理 * 功能:向DSM模块请求信息,判断当前状态为正常/部分正常/完全故障,根据状态进行更新操作。 * 结构:请求故障状态信息,判断当前状态后,决定油门信号更新/清零/保持不变。 ***********************************************/ void AccPedCD_DualAnalog(void) { uint16 uDiffUW; /*获取油门相关FID状态:加速踏板1/2信号故障失效模式是否开启*/ //双油门 Fid_APP1UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP1); Fid_APP2UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP2); /*获取油门相关DFC故障水平:油门踏板1/2信号过高/低、油门NPL故障*/ //第一油门SRC HIGH故障 AccPedCD_stMaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHIGH); //第一油门SRC LOW故障 AccPedCD_stMinUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGLOW); //第一油门NPL故障 AccPedCD_stNplUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHNPL); //第二油门SRC HIGH故障 AccPedCD_st2MaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED2_SIGHIGH); //第二油门SRC LOW故障 AccPedCD_st2MinUB=DFC_GetDebState(_DFC_INDEX_ACCPED2_SIGLOW); if((_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMaxUB)|| (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_st2MaxUB)|| (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMinUB)|| (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_st2MinUB)|| (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stNplUB)|| (Fid_APP1UB_mp==1)|| (Fid_APP2UB_mp==1)) { //完全故障 AccPedCD_rUW=0; AccPedCD_rFltUW=0; //赋油门值为0 AccPedCD_stRampUW=1; //Ramp start AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_DEFECTIVE_STATUS; } else { //非完全故障状态 //检查合理性 if(AccPedCD_uUW>=AccPedCD_facDualRelUW_C*AccPedCD_u2UW) { uDiffUW=AccPedCD_uUW-AccPedCD_facDualRelUW_C*AccPedCD_u2UW; } else { uDiffUW=AccPedCD_facDualRelUW_C*AccPedCD_u2UW-AccPedCD_uUW; } if((AccPedCD_uUW>AccPedCD_uSRCMaxUW_C) ||(AccPedCD_uUWAccPedCD_uSRCMaxUW_C) ||(AccPedCD_facDualRelUW_C*AccPedCD_u2UWAccPedCD_uMaxDiffUW_C))) //双油门合理性校验 { //任何一项故障的状态,部分故障,则维持上一循环的值不动 AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_DEFECTIVE_STATUS; } else { if((_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMaxUB)&& (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_st2MaxUB)&& (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMinUB)&& (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_st2MinUB)&& (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stNplUB)) { //完全正常的状态 AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_HEALED_STATUS; AccPedCD_Ramp(); } else { //或部分恢复 AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_HEALED_STATUS; } } AccPedCD_Filter(); } } /*********************************************** * 函数:单油门信号处理 * 功能:向DSM模块请求信息,判断当前状态为正常/部分正常/完全故障,根据状态进行更新操作。 * 结构:请求故障状态信息,判断当前状态后,决定油门信号更新/清零/保持不变。 ***********************************************/ void AccPedCD_SingleAnalog(void) { Fid_APP1UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP1); //第一油门SRC HIGH故障 AccPedCD_stMaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHIGH); //第一油门SRC LOW故障 AccPedCD_stMinUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGLOW); if((_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMaxUB)|| (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMinUB)|| (Fid_APP1UB_mp==1)) { //完全故障 AccPedCD_rUW=0; AccPedCD_rFltUW=0; //赋油门值为0 AccPedCD_stRampUW=1; //Ramp start AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_DEFECTIVE_STATUS; } else { if((AccPedCD_uUW>AccPedCD_uSRCMaxUW_C) ||(AccPedCD_uUWAccPedCD_uSRCMaxUW_C) ||(AccPedCD_uUWAccPedCD_uHighLimIdleUW_C))|| ((1==AccPedCD_bIdleSwtUB)&&(AccPedCD_uUWAccPedCD_uSRCMaxUW_C) { /*对应DFC故障:油门踏板1信号过高*/ DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error } else { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK); } if(AccPedCD_uUWAccPedCD_uSRCMaxUW_C) { /*对应DFC故障:油门踏板2信号过高*/ DFC_ReportFaultLevel(_DFC_INDEX_ACCPED2_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error } else { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED2_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK); } if(AccPedCD_facDualRelUW_C*AccPedCD_u2UW=AccPedCD_facDualRelUW_C*AccPedCD_u2UW) { uDiffUW=AccPedCD_uUW-AccPedCD_facDualRelUW_C*AccPedCD_u2UW; } else { uDiffUW=AccPedCD_facDualRelUW_C*AccPedCD_u2UW-AccPedCD_uUW; } /*对应DFC故障:油门信号不合理*/ if(uDiffUW>AccPedCD_uMaxDiffUW_C) { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHNPL,_DDRC_MASK_ANA_FT_LV_ERROR); //NPL Error } else { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHNPL,_DDRC_MASK_ANA_FT_LV_OK); } } } else { if(2==AccPedCD_swtUseUW_C) { //带怠速开关的油门 if(AccPedCD_uUW>AccPedCD_uSRCMaxUW_C) { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error } else { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK); } if(AccPedCD_uUWAccPedCD_uHighLimIdleUW_C))|| ((1==AccPedCD_bIdleSwtUB)&&(AccPedCD_uUWAccPedCD_uSRCMaxUW_C) { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error } else { DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK); } if(AccPedCD_uUW