AccPedCD.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  1. /********************************************************************************
  2. * 常州易控汽车电子股份有限公司
  3. * (c) Copyright 2009-2018 ECTEK
  4. * 保留所有权利
  5. ********************************************************************************
  6. * 工程名称:整车管理_车辆运动
  7. * 文件名: AccPedCD.h
  8. * 功能描述 : 油门踏板模块驱动
  9. * 引用记录:
  10. * 备注:
  11. * 修订记录:
  12. * 日期 版本 作者 描述
  13. * 2018.01.12 00.01.00 李中 第一版
  14. *******************************************************************************/
  15. #include "HardwareLib.h"
  16. #include "AccPedCD.h"
  17. /*********************************************************************************************/
  18. /*样例代码*/
  19. #ifdef _SAMPLE_CODE_
  20. uint16 AccPedCD_rFltUW,AccPedCD_rUW; //油门踏板位置
  21. uint16 AccPedCD_rRawUW; //类似bosch文档APPCD_rLinAPP1
  22. uint16 AccPedCD_uUW,AccPedCD_u2UW,AccPedCD_uFltUW;
  23. uint16 AccPedCD_uOldUW;
  24. uint8 AccPedCD_idxDeltaMonUB;
  25. sint16 AccPedCD_drUnFltW; //油门踏板斜率
  26. uint16 AccPedCD_rOldUW; //上一时刻油门踏板,用于斜率计算
  27. uint8 AccPedCD_bIdleSwtUB; //怠速开关状态,0:怠速位置 1:全负荷位置
  28. uint8 AccPedCD_bIdleRawUB; //怠速开关原始信号,怠速开关状态和怠速开关原始信号的关系与怠速开关类型相关
  29. uint8 AccPedCD_stMaxUB,AccPedCD_stMinUB,AccPedCD_stNplUB;
  30. uint8 AccPedCD_st2MaxUB,AccPedCD_st2MinUB;
  31. uint16 AccPedCD_facT1UW;
  32. uint8 Fid_APP1UB_mp; //加速踏板1故障禁止状态
  33. uint8 Fid_APP2UB_mp; //加速踏板2故障禁止状态
  34. uint16 AccPedCD_stAPPLatchUW; //上一循环加速踏板诊断的状态 1 部分故障, 2 完全故障, 3 部分恢复, 4完全正常
  35. uint16 AccPedCD_stRampUW; //故障恢复的Ramp状态,0 Ramp结束, 1 Ramp使能
  36. /*************************************************************/
  37. /*标定数据区开始(请不要在该区域加入非标定数据相关的内容) */
  38. #define MAPDATA_START_SEC_VAR_CONST
  39. #include "MemMap.h"
  40. /*AccPedCD_Cal*/
  41. PRAGMA_MAPDATA const uint16 AccPedCD_uSRCMaxUW_C=18428; /*AccPedCD_uSRCMaxUW_C,最大值*/
  42. PRAGMA_MAPDATA const uint16 AccPedCD_uSRCMinUW_C=2048; /*AccPedCD_uSRCMinUW_C,最小值*/
  43. PRAGMA_MAPDATA const uint16 AccPedCD_uMaxDiffUW_C=2047; /*AccPedCD_uMaxDiffUW_C,AccPed2与AccPed1最大相差多少...*/
  44. PRAGMA_MAPDATA const uint16 AccPedCD_uHighLimIdleUW_C=18427; /*AccPedCD_uHighLimIdleUW_C,怠速开关高限*/
  45. PRAGMA_MAPDATA const uint16 AccPedCD_uLowLimIdleUW_C=819; /*AccPedCD_uLowLimIdleUW_C,怠速开关低限*/
  46. PRAGMA_MAPDATA const uint16 AccPedCD_bPlausEnUW_C=1; /*AccPedCD_bPlausEnUW_C,油门合理性检测是否启用*/
  47. PRAGMA_MAPDATA const uint16 AccPedCD_rFltUW_C=0; /*数字油门,AccPedCD_rFltUW_C*/
  48. PRAGMA_MAPDATA const uint16 AccPedCD_bDigEnUW_C=1; /*油门控制模式,AccPedCD_bDigEnUW_C, 1为正常控制, 0为数字油门*/
  49. PRAGMA_MAPDATA const uint16 AccPedCD_swtUseUW_C=1; /*AccPedCD_swtUseUW_C,油门传感器类型,1:双油门,2:怠速开关,3:单油门*/
  50. PRAGMA_MAPDATA const uint16 AccPedCD_idxIdleSwtTypeUW_C=0; /*AccPedCD_idxIdleSwtTypeUW_C,怠速开关类型 ,0:接电源常开,1:接电源常闭,2:接地常开,3:接地常闭*/
  51. PRAGMA_MAPDATA const AccPedCD_rUW_CUR_TYPE AccPedCD_rUW_CUR=
  52. {
  53. 4,
  54. {
  55. 4505,14169,16380,20475
  56. },
  57. {
  58. 0,25600,25600,25600
  59. }
  60. }; /*油门标定,AccPedCD_rUW_CUR,系数256,单位%*/
  61. PRAGMA_MAPDATA const uint16 AccPedCD_rThresFltLowPosUW_C=3840; /*AccPedCD_rThresFltLowPosUW_C,小油门限*/
  62. PRAGMA_MAPDATA const uint16 AccPedCD_rThresFltMidPosUW_C=10240; /*AccPedCD_rThresFltMidPosUW_C,中油门限*/
  63. PRAGMA_MAPDATA const uint16 AccPedCD_facT1LowNegUW_C=0; /*AccPedCD_facT1LowNegUW_C,小油门负向滤波系数*/
  64. PRAGMA_MAPDATA const uint16 AccPedCD_facT1MidNegUW_C=0; /*AccPedCD_facT1MidNegUW_C,中油门负向滤波系数*/
  65. PRAGMA_MAPDATA const uint16 AccPedCD_facT1HighNegUW_C=0; /*AccPedCD_facT1HighNegUW_C,大油门负向滤波系数*/
  66. PRAGMA_MAPDATA const uint16 AccPedCD_facT1LowPosUW_C=750; /*AccPedCD_facT1LowPosUW_C,小油门正向滤波系数*/
  67. PRAGMA_MAPDATA const uint16 AccPedCD_facT1MidPosUW_C=250; /*AccPedCD_facT1MidPosUW_C,中油门正向滤波系数*/
  68. PRAGMA_MAPDATA const uint16 AccPedCD_facT1HighPosUW_C=250; /*AccPedCD_facT1HighPosUW_C,大油门正向滤波系数*/
  69. PRAGMA_MAPDATA const uint16 AccPedCD_duThresStationaryUW_C=123; /*AccPedCD_duThresStationaryUW_C,稳态油门变化范围*/
  70. PRAGMA_MAPDATA const uint16 AccPedCD_facT1StationaryUW_C=900; /*AccPedCD_facT1StationaryUW_C,稳态滤波系数*/
  71. PRAGMA_MAPDATA const uint16 AccPedCD_facDualRelUW_C=2; /*AccPedCD_facDualRelUW_C, 双油门两路信号的比例关系,第一路/第二路*/
  72. PRAGMA_MAPDATA const uint16 AccPedCD_drHealRmpUp_C=2560; /*AccPedCD_drHealRmpUp_C; 加速踏板故障恢复正向Ramp步长。APPCD_drHealRmpUp_C: healing ramp pos. slope<value>*/
  73. PRAGMA_MAPDATA const uint16 AccPedCD_drHealRmpDwn_C=2560; /*AccPedCD_drHealRmpDwn_C; 故障恢复时向下Ramp步长; APPCD_drHealRmpDwn_C: healing ramp neg. slope<value>*/
  74. #define MAPDATA_STOP_SEC_VAR_CONST
  75. #include "MemMap.h"
  76. /*标定数据区结束 */
  77. /*************************************************************/
  78. /***********************************************
  79. * 函数:油门踏板驱动模块初始化
  80. * 功能:初始化模块中应用到的各变量。
  81. ***********************************************/
  82. void AccPedCD_Init(void)
  83. {
  84. AccPedCD_uFltUW=0;
  85. AccPedCD_idxDeltaMonUB=0;
  86. AccPedCD_drUnFltW=0;
  87. AccPedCD_rOldUW=0;
  88. Fid_APP1UB_mp=0;
  89. Fid_APP2UB_mp=0;
  90. AccPedCD_stAPPLatchUW = _DFC_INDEX_FINALLY_HEALED_STATUS;
  91. AccPedCD_stRampUW=0;
  92. if(1==AccPedCD_swtUseUW_C)
  93. {
  94. //双油门
  95. //油门1
  96. AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
  97. AccPedCD_uOldUW=AccPedCD_uUW;
  98. //油门2
  99. AccPedCD_u2UW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED2_CHAN);
  100. }
  101. else
  102. {
  103. if(2==AccPedCD_swtUseUW_C)
  104. {
  105. //带怠速开关的油门
  106. //油门1
  107. AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
  108. AccPedCD_uOldUW=AccPedCD_uUW;
  109. //得到怠速开关状态
  110. AccPedCD_bIdleRawUB=DINDrv_GetChanState(_DIN_INDEX_BAK1_CHAN);
  111. if((0==AccPedCD_idxIdleSwtTypeUW_C)||(3==AccPedCD_idxIdleSwtTypeUW_C))
  112. {
  113. //接电常开或者接地常闭
  114. //AccPedCD_bIdleRawUB为1表明踏板踩下,在全负荷位置
  115. AccPedCD_bIdleSwtUB=AccPedCD_bIdleRawUB;
  116. }
  117. else
  118. {
  119. //接电常闭或者接地常开
  120. //AccPedCD_bIdleRawUB为0表明踏板踩下,在全负荷位置
  121. AccPedCD_bIdleSwtUB=(!AccPedCD_bIdleRawUB);
  122. }
  123. }
  124. else
  125. {
  126. //单油门
  127. AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
  128. AccPedCD_uOldUW=AccPedCD_uUW;
  129. }
  130. }
  131. AccPedCD_Update();
  132. }
  133. /***********************************************
  134. * 函数:油门信号滤波函数
  135. * 功能:判断油门为小中大油门及正负向,并进行滤波。
  136. ***********************************************/
  137. void AccPedCD_Filter(void)
  138. {
  139. //参数选取
  140. if(AccPedCD_rFltUW>AccPedCD_rRawUW)
  141. {
  142. //下降,3段滤波
  143. if(AccPedCD_rFltUW<AccPedCD_rThresFltLowPosUW_C)
  144. {
  145. AccPedCD_facT1UW=AccPedCD_facT1LowNegUW_C;
  146. }
  147. else
  148. {
  149. if(AccPedCD_rFltUW<AccPedCD_rThresFltMidPosUW_C)
  150. {
  151. AccPedCD_facT1UW=AccPedCD_facT1MidNegUW_C;
  152. }
  153. else
  154. {
  155. AccPedCD_facT1UW=AccPedCD_facT1HighNegUW_C;
  156. }
  157. }
  158. }
  159. else
  160. {
  161. //上升,3段滤波
  162. if(AccPedCD_rFltUW<AccPedCD_rThresFltLowPosUW_C)
  163. {
  164. AccPedCD_facT1UW=AccPedCD_facT1LowPosUW_C;
  165. }
  166. else
  167. {
  168. if(AccPedCD_rFltUW<AccPedCD_rThresFltMidPosUW_C)
  169. {
  170. AccPedCD_facT1UW=AccPedCD_facT1MidPosUW_C;
  171. }
  172. else
  173. {
  174. AccPedCD_facT1UW=AccPedCD_facT1HighPosUW_C;
  175. }
  176. }
  177. }
  178. //输出值计算
  179. ComLib_PT1U16(AccPedCD_uUW,(uint16)(_COMLIB_FACTOR_PT1-AccPedCD_facT1UW),AccPedCD_facT1UW,(uint16 *)&AccPedCD_uFltUW); //AD值滤波
  180. ComLib_PT1U16(AccPedCD_rUW,(uint16)(_COMLIB_FACTOR_PT1-AccPedCD_facT1UW),AccPedCD_facT1UW,(uint16 *)&AccPedCD_rFltUW); //油门滤波
  181. }
  182. /***********************************************
  183. * 函数:计算油门信号数值
  184. * 功能:根据步长计算油门信号增大或减小的数值。
  185. ***********************************************/
  186. void AccPedCD_Ramp(void)
  187. {
  188. //ramp
  189. if(1==AccPedCD_stRampUW)
  190. {
  191. //ramp使能状态 Ramp start
  192. if(AccPedCD_rRawUW>=AccPedCD_rUW)
  193. {
  194. //向上
  195. if((AccPedCD_rRawUW - AccPedCD_rUW)<=AccPedCD_drHealRmpUp_C)
  196. {
  197. //差值小于最小步长限制
  198. AccPedCD_rUW = AccPedCD_rRawUW;
  199. AccPedCD_stRampUW=0;//Ramp结束
  200. }
  201. else
  202. {
  203. AccPedCD_rUW += AccPedCD_drHealRmpUp_C;
  204. }
  205. }
  206. else
  207. {
  208. //向下
  209. if((AccPedCD_rUW - AccPedCD_rRawUW)<=AccPedCD_drHealRmpDwn_C)
  210. {
  211. //差值小于最小步长限制
  212. AccPedCD_rUW = AccPedCD_rRawUW;
  213. AccPedCD_stRampUW=0;//Ramp结束 Ramp end
  214. }
  215. else
  216. {
  217. AccPedCD_rUW -= AccPedCD_drHealRmpDwn_C;
  218. }
  219. }
  220. }
  221. else
  222. {
  223. AccPedCD_rUW=AccPedCD_rRawUW;
  224. }
  225. }
  226. /***********************************************
  227. * 函数:双油门信号处理
  228. * 功能:向DSM模块请求信息,判断当前状态为正常/部分正常/完全故障,根据状态进行更新操作。
  229. * 结构:请求故障状态信息,判断当前状态后,决定油门信号更新/清零/保持不变。
  230. ***********************************************/
  231. void AccPedCD_DualAnalog(void)
  232. {
  233. uint16 uDiffUW;
  234. /*获取油门相关FID状态:加速踏板1/2信号故障失效模式是否开启*/
  235. //双油门
  236. Fid_APP1UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP1);
  237. Fid_APP2UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP2);
  238. /*获取油门相关DFC故障水平:油门踏板1/2信号过高/低、油门NPL故障*/
  239. //第一油门SRC HIGH故障
  240. AccPedCD_stMaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHIGH);
  241. //第一油门SRC LOW故障
  242. AccPedCD_stMinUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGLOW);
  243. //第一油门NPL故障
  244. AccPedCD_stNplUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHNPL);
  245. //第二油门SRC HIGH故障
  246. AccPedCD_st2MaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED2_SIGHIGH);
  247. //第二油门SRC LOW故障
  248. AccPedCD_st2MinUB=DFC_GetDebState(_DFC_INDEX_ACCPED2_SIGLOW);
  249. if((_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMaxUB)||
  250. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_st2MaxUB)||
  251. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMinUB)||
  252. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_st2MinUB)||
  253. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stNplUB)||
  254. (Fid_APP1UB_mp==1)||
  255. (Fid_APP2UB_mp==1))
  256. {
  257. //完全故障
  258. AccPedCD_rUW=0;
  259. AccPedCD_rFltUW=0; //赋油门值为0
  260. AccPedCD_stRampUW=1; //Ramp start
  261. AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_DEFECTIVE_STATUS;
  262. }
  263. else
  264. {
  265. //非完全故障状态
  266. //检查合理性
  267. if(AccPedCD_uUW>=AccPedCD_facDualRelUW_C*AccPedCD_u2UW)
  268. {
  269. uDiffUW=AccPedCD_uUW-AccPedCD_facDualRelUW_C*AccPedCD_u2UW;
  270. }
  271. else
  272. {
  273. uDiffUW=AccPedCD_facDualRelUW_C*AccPedCD_u2UW-AccPedCD_uUW;
  274. }
  275. if((AccPedCD_uUW>AccPedCD_uSRCMaxUW_C)
  276. ||(AccPedCD_uUW<AccPedCD_uSRCMinUW_C)
  277. ||(AccPedCD_facDualRelUW_C*AccPedCD_u2UW>AccPedCD_uSRCMaxUW_C)
  278. ||(AccPedCD_facDualRelUW_C*AccPedCD_u2UW<AccPedCD_uSRCMinUW_C)
  279. ||((DINH_GetFIDState(_DINH_INDEX_FID_ACCPED_NPL)==0)&&(uDiffUW>AccPedCD_uMaxDiffUW_C))) //双油门合理性校验
  280. {
  281. //任何一项故障的状态,部分故障,则维持上一循环的值不动
  282. AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_DEFECTIVE_STATUS;
  283. }
  284. else
  285. {
  286. if((_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMaxUB)&&
  287. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_st2MaxUB)&&
  288. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMinUB)&&
  289. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_st2MinUB)&&
  290. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stNplUB))
  291. {
  292. //完全正常的状态
  293. AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_HEALED_STATUS;
  294. AccPedCD_Ramp();
  295. }
  296. else
  297. {
  298. //或部分恢复
  299. AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_HEALED_STATUS;
  300. }
  301. }
  302. AccPedCD_Filter();
  303. }
  304. }
  305. /***********************************************
  306. * 函数:单油门信号处理
  307. * 功能:向DSM模块请求信息,判断当前状态为正常/部分正常/完全故障,根据状态进行更新操作。
  308. * 结构:请求故障状态信息,判断当前状态后,决定油门信号更新/清零/保持不变。
  309. ***********************************************/
  310. void AccPedCD_SingleAnalog(void)
  311. {
  312. Fid_APP1UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP1);
  313. //第一油门SRC HIGH故障
  314. AccPedCD_stMaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHIGH);
  315. //第一油门SRC LOW故障
  316. AccPedCD_stMinUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGLOW);
  317. if((_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMaxUB)||
  318. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMinUB)||
  319. (Fid_APP1UB_mp==1))
  320. {
  321. //完全故障
  322. AccPedCD_rUW=0;
  323. AccPedCD_rFltUW=0; //赋油门值为0
  324. AccPedCD_stRampUW=1; //Ramp start
  325. AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_DEFECTIVE_STATUS;
  326. }
  327. else
  328. {
  329. if((AccPedCD_uUW>AccPedCD_uSRCMaxUW_C)
  330. ||(AccPedCD_uUW<AccPedCD_uSRCMinUW_C)) //单油门合理性校验
  331. {
  332. //任何一项故障的状态,部分故障,则维持上一循环的值不动
  333. AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_DEFECTIVE_STATUS;
  334. }
  335. else
  336. {
  337. if( (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMaxUB)&&
  338. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMinUB))
  339. {
  340. //完全正常的状态
  341. AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_HEALED_STATUS;
  342. AccPedCD_Ramp();
  343. }
  344. else
  345. {
  346. //或部分恢复
  347. AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_HEALED_STATUS;
  348. }
  349. }
  350. AccPedCD_Filter();
  351. }
  352. }
  353. /***********************************************
  354. * 函数:怠速开关油门信号处理
  355. * 功能:向DSM模块请求信息,判断当前状态为正常/部分正常/完全故障,根据状态进行更新操作。
  356. * 结构:请求故障状态信息,判断当前状态后,决定油门信号更新/清零/保持不变。
  357. ***********************************************/
  358. void AccPedCD_Switch(void)
  359. {
  360. //带怠速开关的油门
  361. Fid_APP1UB_mp=DINH_GetFIDState(_DINH_INDEX_FID_APP1);
  362. //第一油门SRC HIGH故障
  363. AccPedCD_stMaxUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHIGH);
  364. //第一油门SRC LOW故障
  365. AccPedCD_stMinUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGLOW);
  366. //第一油门NPL故障
  367. AccPedCD_stNplUB=DFC_GetDebState(_DFC_INDEX_ACCPED_SIGHNPL);
  368. if((_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMaxUB)||
  369. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stMinUB)||
  370. (_DFC_INDEX_FINALLY_DEFECTIVE_STATUS==AccPedCD_stNplUB)||
  371. (Fid_APP1UB_mp==1))
  372. {
  373. //完全故障
  374. AccPedCD_rUW=0;
  375. AccPedCD_rFltUW=0; //赋油门值为0
  376. AccPedCD_stRampUW=1; //Ramp start
  377. AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_DEFECTIVE_STATUS;
  378. }
  379. else
  380. {
  381. if((AccPedCD_uUW>AccPedCD_uSRCMaxUW_C)
  382. ||(AccPedCD_uUW<AccPedCD_uSRCMinUW_C)
  383. ||( (1==AccPedCD_bPlausEnUW_C)&&
  384. (((0==AccPedCD_bIdleSwtUB)&&(AccPedCD_uUW>AccPedCD_uHighLimIdleUW_C))||
  385. ((1==AccPedCD_bIdleSwtUB)&&(AccPedCD_uUW<AccPedCD_uLowLimIdleUW_C)))))
  386. {
  387. //任何一项故障的状态,部分故障,则维持上一循环的值不动
  388. AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_DEFECTIVE_STATUS;
  389. }
  390. else
  391. {
  392. if((_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMaxUB)&&
  393. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stMinUB)&&
  394. (_DFC_INDEX_FINALLY_HEALED_STATUS==AccPedCD_stNplUB))
  395. {
  396. //完全正常的状态
  397. AccPedCD_stAPPLatchUW=_DFC_INDEX_FINALLY_HEALED_STATUS;
  398. AccPedCD_Ramp();
  399. }
  400. else
  401. {
  402. //或部分恢复
  403. AccPedCD_stAPPLatchUW=_DFC_INDEX_PRELIMINARILY_HEALED_STATUS;
  404. }
  405. }
  406. AccPedCD_Filter();
  407. }
  408. }
  409. /***********************************************
  410. * 函数:更新油门信号入口函数
  411. * 功能:根据不同模式,计算并更新油门信号值。
  412. * 结构:根据标定变量判断当前状态为单油门/双油门/带怠速开关/不使用,确定配置后,再对通过相应函数更新信号。
  413. ***********************************************/
  414. void AccPedCD_Update(void)
  415. {
  416. if(AccPedCD_bDigEnUW_C==1)
  417. {
  418. AccPedCD_rFltUW=AccPedCD_rFltUW_C; //数字油门模式
  419. AccPedCD_rUW=AccPedCD_rFltUW_C; //滤波前油门也用数字油门接管
  420. }
  421. else
  422. {
  423. if(1==AccPedCD_swtUseUW_C)
  424. {
  425. //双油门
  426. //油门1
  427. AccPedCD_uOldUW=AccPedCD_uUW;
  428. AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
  429. //油门2
  430. AccPedCD_u2UW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED2_CHAN);
  431. AccPedCD_rRawUW=Intpol_u16u16((uint16 *)&AccPedCD_rUW_CUR,AccPedCD_uUW);
  432. AccPedCD_DualAnalog();
  433. }
  434. else
  435. {
  436. if(2==AccPedCD_swtUseUW_C)
  437. {
  438. //油门和怠速开关
  439. //油门1
  440. AccPedCD_uOldUW=AccPedCD_uUW;
  441. AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
  442. //得到怠速开关状态
  443. AccPedCD_bIdleRawUB=DINDrv_GetChanState(_DIN_INDEX_BAK1_CHAN);
  444. if(0==AccPedCD_idxIdleSwtTypeUW_C)
  445. {
  446. //常地型,AccPedCD_bIdleRawUB为1表明踏板踩下,在全负荷位置
  447. AccPedCD_bIdleSwtUB=AccPedCD_bIdleRawUB;
  448. }
  449. else
  450. {
  451. //常电型,AccPedCD_bIdleRawUB为0表明踏板踩下,在全负荷位置
  452. AccPedCD_bIdleSwtUB=(!AccPedCD_bIdleRawUB);
  453. }
  454. AccPedCD_rRawUW=Intpol_u16u16((uint16 *)&AccPedCD_rUW_CUR,AccPedCD_uUW);
  455. AccPedCD_Switch();
  456. }
  457. else
  458. {
  459. //单油门
  460. //油门1
  461. AccPedCD_uOldUW=AccPedCD_uUW;
  462. AccPedCD_uUW=ATDDrv_GetChanResult(_ATD_INDEX_ACCPED1_CHAN);
  463. AccPedCD_rRawUW=Intpol_u16u16((uint16 *)&AccPedCD_rUW_CUR,AccPedCD_uUW);
  464. AccPedCD_SingleAnalog();
  465. }
  466. }
  467. }
  468. AccPedCD_idxDeltaMonUB=(uint8)((AccPedCD_idxDeltaMonUB+1)%_ACCPED_DELTA_MONITOR_TIME);
  469. if(AccPedCD_idxDeltaMonUB==0)
  470. {
  471. //加速踏板斜率计算
  472. AccPedCD_drUnFltW=AccPedCD_rFltUW-AccPedCD_rOldUW;
  473. AccPedCD_rOldUW=AccPedCD_rFltUW;
  474. }
  475. }
  476. /***********************************************
  477. * 函数:油门相关故障监控
  478. * 功能:检测油门信号是否超限值/相关功能是否被禁用/信号值是否合理,如出现异常向DSM模块报告异常水平。
  479. * 结构:根据标定变量判断当前状态为单油门/双油门/带怠速开关/不使用,确定配置后,再对相应油门信号进行检测。
  480. ***********************************************/
  481. void AccPedCD_Monitor(void)
  482. {
  483. uint16 uDiffUW;
  484. //AccPedCD_swtUseUW_C
  485. //0: 不使用
  486. //1: 双油门
  487. //2: 带怠速开关
  488. if(1==AccPedCD_swtUseUW_C)
  489. {
  490. //双油门
  491. if(AccPedCD_uUW>AccPedCD_uSRCMaxUW_C)
  492. {
  493. /*对应DFC故障:油门踏板1信号过高*/
  494. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error
  495. }
  496. else
  497. {
  498. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK);
  499. }
  500. if(AccPedCD_uUW<AccPedCD_uSRCMinUW_C)
  501. {
  502. /*对应DFC故障:油门踏板1信号过低*/
  503. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGLOW,_DDRC_MASK_ANA_FT_LV_ERROR); //Min Error
  504. }
  505. else
  506. {
  507. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGLOW,_DDRC_MASK_ANA_FT_LV_OK);
  508. }
  509. if(AccPedCD_facDualRelUW_C*AccPedCD_u2UW>AccPedCD_uSRCMaxUW_C)
  510. {
  511. /*对应DFC故障:油门踏板2信号过高*/
  512. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED2_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error
  513. }
  514. else
  515. {
  516. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED2_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK);
  517. }
  518. if(AccPedCD_facDualRelUW_C*AccPedCD_u2UW<AccPedCD_uSRCMinUW_C)
  519. {
  520. /*对应DFC故障:油门踏板2信号过低*/
  521. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED2_SIGLOW,_DDRC_MASK_ANA_FT_LV_ERROR); //Min Error
  522. }
  523. else
  524. {
  525. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED2_SIGLOW,_DDRC_MASK_ANA_FT_LV_OK);
  526. }
  527. //双油门合理性校验
  528. /*油门相关功能是否被禁用*/
  529. if(DINH_GetFIDState(_DINH_INDEX_FID_ACCPED_NPL)==0)
  530. {
  531. //检查合理性
  532. if(AccPedCD_uUW>=AccPedCD_facDualRelUW_C*AccPedCD_u2UW)
  533. {
  534. uDiffUW=AccPedCD_uUW-AccPedCD_facDualRelUW_C*AccPedCD_u2UW;
  535. }
  536. else
  537. {
  538. uDiffUW=AccPedCD_facDualRelUW_C*AccPedCD_u2UW-AccPedCD_uUW;
  539. }
  540. /*对应DFC故障:油门信号不合理*/
  541. if(uDiffUW>AccPedCD_uMaxDiffUW_C)
  542. {
  543. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHNPL,_DDRC_MASK_ANA_FT_LV_ERROR); //NPL Error
  544. }
  545. else
  546. {
  547. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHNPL,_DDRC_MASK_ANA_FT_LV_OK);
  548. }
  549. }
  550. }
  551. else
  552. {
  553. if(2==AccPedCD_swtUseUW_C)
  554. {
  555. //带怠速开关的油门
  556. if(AccPedCD_uUW>AccPedCD_uSRCMaxUW_C)
  557. {
  558. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error
  559. }
  560. else
  561. {
  562. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK);
  563. }
  564. if(AccPedCD_uUW<AccPedCD_uSRCMinUW_C)
  565. {
  566. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGLOW,_DDRC_MASK_ANA_FT_LV_ERROR); //Min Error
  567. }
  568. else
  569. {
  570. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGLOW,_DDRC_MASK_ANA_FT_LV_OK);
  571. }
  572. //怠速开关和油门的诊断
  573. if(1==AccPedCD_bPlausEnUW_C)
  574. {
  575. //如果合理性检测使能
  576. if(((0==AccPedCD_bIdleSwtUB)&&(AccPedCD_uUW>AccPedCD_uHighLimIdleUW_C))||
  577. ((1==AccPedCD_bIdleSwtUB)&&(AccPedCD_uUW<AccPedCD_uLowLimIdleUW_C)))
  578. {
  579. //油门电压大于高限值后,怠速开关必须处于Full Load状态
  580. //油门电压小于低限制后,怠速开关必须处于Low Idle状态
  581. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHNPL,_DDRC_MASK_ANA_FT_LV_ERROR); //NPL Error
  582. }
  583. else
  584. {
  585. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHNPL,_DDRC_MASK_ANA_FT_LV_OK);
  586. }
  587. }
  588. }
  589. else
  590. {
  591. if(3==AccPedCD_swtUseUW_C)
  592. {
  593. //单油门
  594. if(AccPedCD_uUW>AccPedCD_uSRCMaxUW_C)
  595. {
  596. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_ERROR); //Max Error
  597. }
  598. else
  599. {
  600. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGHIGH,_DDRC_MASK_ANA_FT_LV_OK);
  601. }
  602. if(AccPedCD_uUW<AccPedCD_uSRCMinUW_C)
  603. {
  604. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGLOW,_DDRC_MASK_ANA_FT_LV_ERROR); //Min Error
  605. }
  606. else
  607. {
  608. DFC_ReportFaultLevel(_DFC_INDEX_ACCPED_SIGLOW,_DDRC_MASK_ANA_FT_LV_OK);
  609. }
  610. }
  611. }
  612. }
  613. }
  614. #endif //_SAMPLE_CODE_
  615. /*********************************************************************************************/