bikelight.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  1. /**
  2. * @file Bikelight.c
  3. * @author
  4. * @brief light of ebike
  5. * @version 0.1
  6. * @date 2023-06-20
  7. *
  8. * @copyright Copyright (c) 2021
  9. *
  10. */
  11. #define BIKELIGHT_
  12. /************************************************************************
  13. Beginning of File, do not put anything above here except notes
  14. Compiler Directives:
  15. *************************************************************************/
  16. #include "syspar.h"
  17. #include "typedefine.h"
  18. #include "mathtool.h"
  19. #include "bikelight.h"
  20. #include "hwsetup.h"
  21. #include "power.h"
  22. #include "CodePara.h"
  23. #include "adc.h"
  24. #include "UserGpio_Config.h"
  25. #include "ti_msp_dl_config.h"
  26. #include "bikebrake.h"
  27. //----------------------------
  28. BIKELEDCHECK_STR BikeLedCheck_F;//前灯参数
  29. BIKELEDCHECK_STR BikeLedCheck_B;//尾灯参数
  30. BIKELEDCHECK_STR BikeLedCheck_L;//左灯参数
  31. BIKELEDCHECK_STR BikeLedCheck_R;//右灯参数
  32. BIKELEDCHECK_STR BikeLedCheck_DC;//DC12V端口参数
  33. //LED_PWM_STR BikePwmChoice;
  34. void LED_EnableDeal(BIKELEDCHECK_STR *p,UWORD switchAction,LED_PWM_STR mode );
  35. void LedMode_One(BIKELEDCHECK_STR *BikeLedSel);//模式1 开灯低亮,刹车高亮
  36. void LedMode_Two(BIKELEDCHECK_STR *BikeLedSel);//模式2 开灯高亮,刹车闪烁
  37. void LedMode_Three(BIKELEDCHECK_STR *BikeLedSel);//模式3 刹车高亮
  38. void LedMode_Four(BIKELEDCHECK_STR *BikeLedSel);//模式4 刹车闪烁
  39. void LedMode_Five(BIKELEDCHECK_STR *BikeLedSel);//模式5 开机亮
  40. void LedMode_Six(BIKELEDCHECK_STR *BikeLedSel);//模式6 超速闪烁报警 国标车
  41. void LedMode_Seven(BIKELEDCHECK_STR *BikeLedSel);//模式7 开机低亮,刹车高亮
  42. void LedMode_Eight(BIKELEDCHECK_STR *BikeLedSel);//模式8 开灯亮,关灯灭
  43. // 函数指针类型定义
  44. typedef void (*FunctionPointer)(BIKELEDCHECK_STR *BikeLedSel);
  45. // 函数指针数组
  46. FunctionPointer ledfunctions[16] = {LedMode_One,LedMode_One, LedMode_Two, LedMode_Three, LedMode_Four,LedMode_Five,LedMode_Six,LedMode_Seven,LedMode_Eight,
  47. LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight};
  48. /***************************************************************
  49. Function: LedMode_One
  50. Description: //模式1 开灯低亮,刹车高亮
  51. Call by: 1ms
  52. Input Variables:
  53. Output/Return Variables: N/A
  54. Subroutine Call: N/A;
  55. Reference: N/A
  56. ****************************************************************/
  57. void LedMode_One(BIKELEDCHECK_STR *BikeLedSel)
  58. {
  59. if((BikeBrake_blGetstate()==TRUE)&&(cp_stBikeRunInfoPara.uwLightSwitch==0))//尾灯低亮,刹车高亮
  60. {
  61. if(BikeLedSel->uwLeddelaycnt>0)
  62. {
  63. BikeLedSel->uwLeddelaycnt--;
  64. BikeLedSel->blBike_LedSta=FALSE;
  65. }
  66. else
  67. {
  68. BikeLedSel->blBike_LedSta=TRUE;
  69. }
  70. }
  71. else
  72. {
  73. if(cp_stBikeRunInfoPara.uwLightSwitch!=0)
  74. {
  75. BikeLedSel->uwLedAddcnt++;
  76. if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
  77. {
  78. BikeLedSel->uwLedAddcnt=0;
  79. }
  80. if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
  81. {
  82. BikeLedSel->blBike_LedSta=TRUE;
  83. if(BikeBrake_blGetstate()==TRUE)
  84. {
  85. BikeLedSel->uwLedAddcnt=0;
  86. }
  87. }
  88. else
  89. {
  90. BikeLedSel->blBike_LedSta=FALSE;
  91. }
  92. }
  93. else
  94. {
  95. BikeLedSel->blBike_LedSta=FALSE;
  96. BikeLedSel->uwLedAddcnt=0;
  97. }
  98. BikeLedSel->uwLeddelaycnt=10;
  99. }
  100. }
  101. /***************************************************************
  102. Function: LedMode_Two
  103. Description: //模式2 开灯高亮,刹车闪烁
  104. Call by: 1ms
  105. Input Variables:
  106. Output/Return Variables: N/A
  107. Subroutine Call: N/A;
  108. Reference: N/A
  109. ****************************************************************/
  110. void LedMode_Two(BIKELEDCHECK_STR *BikeLedSel)
  111. {
  112. if(BikeBrake_blGetstate()==TRUE) //尾灯高亮,刹车闪烁
  113. {
  114. BikeLedSel->uwLedAddcnt++;
  115. if(BikeLedSel->uwLedAddcnt > BikeLedFlickerCycle)
  116. {
  117. BikeLedSel->uwLedAddcnt=0;
  118. }
  119. if(BikeLedSel->uwLedAddcnt<BikeLedFlickerDuty)
  120. {
  121. BikeLedSel->blBike_LedSta=TRUE;
  122. }
  123. else
  124. {
  125. BikeLedSel->blBike_LedSta=FALSE;
  126. }
  127. }
  128. else
  129. {
  130. if(cp_stBikeRunInfoPara.uwLightSwitch!=0)
  131. {
  132. BikeLedSel->blBike_LedSta=TRUE;
  133. }
  134. else
  135. {
  136. BikeLedSel->blBike_LedSta=FALSE;
  137. }
  138. BikeLedSel->uwLedAddcnt=0;
  139. }
  140. }
  141. /***************************************************************
  142. Function: LedMode_Three
  143. Description: 模式3 刹车高亮
  144. Call by: 1ms
  145. Input Variables:
  146. Output/Return Variables: N/A
  147. Subroutine Call: N/A;
  148. Reference: N/A
  149. ****************************************************************/
  150. void LedMode_Three(BIKELEDCHECK_STR *BikeLedSel)
  151. {
  152. if(BikeBrake_blGetstate()==TRUE) //刹车高亮
  153. {
  154. //BikeLedSel->blBike_LedSta=TRUE;
  155. if(BikeLedSel->uwLeddelaycnt>0)
  156. {
  157. BikeLedSel->uwLeddelaycnt--;
  158. BikeLedSel->blBike_LedSta=FALSE;
  159. }
  160. else
  161. {
  162. BikeLedSel->blBike_LedSta=TRUE;
  163. }
  164. }
  165. else
  166. {
  167. BikeLedSel->uwLeddelaycnt=20;
  168. BikeLedSel->blBike_LedSta=FALSE;
  169. }
  170. }
  171. /***************************************************************
  172. Function: LedMode_Four
  173. Description: 模式4 刹车闪烁
  174. Call by: 1ms
  175. Input Variables:
  176. Output/Return Variables: N/A
  177. Subroutine Call: N/A;
  178. Reference: N/A
  179. ****************************************************************/
  180. void LedMode_Four(BIKELEDCHECK_STR *BikeLedSel)
  181. {
  182. if(BikeBrake_blGetstate()==TRUE) //刹车闪烁
  183. {
  184. BikeLedSel->uwLedAddcnt++;
  185. if(BikeLedSel->uwLedAddcnt > BikeLedFlickerCycle)
  186. {
  187. BikeLedSel->uwLedAddcnt=0;
  188. }
  189. if(BikeLedSel->uwLedAddcnt<BikeLedFlickerDuty)
  190. {
  191. BikeLedSel->blBike_LedSta=TRUE;
  192. }
  193. else
  194. {
  195. BikeLedSel->blBike_LedSta=FALSE;
  196. }
  197. }
  198. else
  199. {
  200. BikeLedSel->blBike_LedSta=FALSE;
  201. }
  202. }
  203. /***************************************************************
  204. Function: LedMode_Five
  205. Description: 模式5 开机亮
  206. Call by: 1ms
  207. Input Variables:
  208. Output/Return Variables: N/A
  209. Subroutine Call: N/A;
  210. Reference: N/A
  211. ****************************************************************/
  212. void LedMode_Five(BIKELEDCHECK_STR *BikeLedSel)
  213. {
  214. BikeLedSel->blBike_LedSta=TRUE; //开机常亮
  215. }
  216. /***************************************************************
  217. Function: LedMode_Six
  218. Description: 模式6 超速闪烁报警 国标车
  219. Call by: 1ms
  220. Input Variables:
  221. Output/Return Variables: N/A
  222. Subroutine Call: N/A;
  223. Reference: N/A
  224. ****************************************************************/
  225. void LedMode_Six (BIKELEDCHECK_STR *BikeLedSel)
  226. {
  227. if(cp_stBikeRunInfoPara.BikeSpeedKmH>=BikeLedOverSpeedMax) //超速报警
  228. {
  229. BikeLedSel->uwLedAddcnt++;
  230. if(BikeLedSel->uwLedAddcnt > BikeLedOverSpedCycle)
  231. {
  232. BikeLedSel->uwLedAddcnt=0;
  233. }
  234. if(BikeLedSel->uwLedAddcnt<BikeLedOverSpedDuty)
  235. {
  236. BikeLedSel->blBike_LedSta=TRUE;
  237. }
  238. else
  239. {
  240. BikeLedSel->blBike_LedSta=FALSE;
  241. }
  242. }
  243. else if(cp_stBikeRunInfoPara.BikeSpeedKmH<=BikeLedOverSpeedMin)
  244. {
  245. BikeLedSel->blBike_LedSta=FALSE;
  246. BikeLedSel->uwLedAddcnt=0;
  247. }
  248. }
  249. /***************************************************************
  250. Function: LedMode_Seven
  251. Description: 模式7 开机低亮,刹车高亮
  252. Call by: 1ms
  253. Input Variables:
  254. Output/Return Variables: N/A
  255. Subroutine Call: N/A;
  256. Reference: N/A
  257. ****************************************************************/
  258. void LedMode_Seven(BIKELEDCHECK_STR *BikeLedSel)
  259. {
  260. // if(BikeBrake_blGetstate()==TRUE)
  261. // {
  262. // BikeLedSel->blBike_LedSta=TRUE;
  263. // }
  264. // else
  265. // {
  266. // BikeLedSel->uwLedAddcnt++;
  267. // if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
  268. // {
  269. // BikeLedSel->uwLedAddcnt=0;
  270. // }
  271. // if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
  272. // {
  273. // BikeLedSel->blBike_LedSta=TRUE;
  274. // }
  275. // else
  276. // {
  277. // BikeLedSel->blBike_LedSta=FALSE;
  278. // }
  279. //
  280. // }
  281. BikeLedSel->uwLedAddcnt++;
  282. if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
  283. {
  284. BikeLedSel->uwLedAddcnt=0;
  285. }
  286. if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
  287. {
  288. BikeLedSel->blBike_LedSta=TRUE;
  289. if(BikeBrake_blGetstate()==TRUE)
  290. {
  291. BikeLedSel->uwLedAddcnt=0;
  292. }
  293. }
  294. else
  295. {
  296. BikeLedSel->blBike_LedSta=FALSE;
  297. }
  298. }
  299. /***************************************************************
  300. Function: LedMode_Eight
  301. Description: 模式8 开灯亮,关灯灭
  302. Call by: 1ms
  303. Input Variables:
  304. Output/Return Variables: N/A
  305. Subroutine Call: N/A;
  306. Reference: N/A
  307. ****************************************************************/
  308. void LedMode_Eight(BIKELEDCHECK_STR *BikeLedSel)
  309. {
  310. if (cp_stBikeRunInfoPara.uwLightSwitch == 1)//仪表开灯亮,仪表关灯灭
  311. {
  312. BikeLedSel->blBike_LedSta=TRUE;
  313. }
  314. else
  315. {
  316. BikeLedSel->blBike_LedSta=FALSE;
  317. }
  318. }
  319. /***************************************************************
  320. Function: bikelight_voBikeLightInit;
  321. Description: bike light control initialization
  322. Call by: FSM_voInit
  323. Input Variables: N/A
  324. Output/Return Variables: N/A
  325. Subroutine Call: N/A;
  326. Reference: N/A
  327. ****************************************************************/
  328. void bikelight_voBikeLightInit(BIKELEDCHECK_STR *LedPoit)
  329. {
  330. LedPoit->uwBike_LedOffErrCnt=0;
  331. LedPoit->uwBike_OpenPreTime=0;
  332. LedPoit->uwBike_OpenLedEn=0;
  333. LedPoit->uwBikeLight_PWM=0;
  334. LedPoit->uwBike_LedCheckLowTime=0;
  335. LedPoit->uwLedAddcnt=0;
  336. LedPoit->uwBike_keyLedLowSta=0;
  337. LedPoit->uwBike_keyLedHighSta=0;
  338. LedPoit->blBike_LedSta=FALSE;
  339. LedPoit->uwBikeLight_PWM=0;
  340. LedPoit->blBike_LedCurErr=0;
  341. }
  342. /***************************************************************
  343. Function: bikelight_voBikeLightCoef;
  344. Description: 滤波时间/阈值电压设定参数更新 ,参数输入端
  345. uwBike_LedMode:
  346. 0x01:模式1,连接尾灯,开灯时低亮,刹车时高亮
  347. 0x02:模式2,连接尾灯,开灯时高亮,刹车时闪烁
  348. 0x03:模式3,连接刹车灯,刹车时高亮
  349. 0x04:模式4,连接刹车灯,刹车时闪烁
  350. 0x05:模式5,开机常亮
  351. 0x06:模式6,连接蜂鸣器,超速报警
  352. 0x07:模式7,开机低亮,刹车高亮
  353. 0x08:模式8,仅开灯高亮,关灯灭
  354. uwBike_LedFun 模式功能选择
  355. 0-PWM电池电压有保护,
  356. 1-前后灯分别控PWM6/12V无保护,
  357. 2-DCDC输出
  358. Call by:初始化,接收数据更新
  359. Input Variables: N/A
  360. Output/Return Variables: N/A
  361. Subroutine Call: N/A;
  362. Reference: N/A
  363. ****************************************************************/
  364. void bikelight_voBikeLightCoef(UWORD volt)
  365. {
  366. //前灯
  367. BikeLedCheck_F.uwBike_LedVolt =volt & 0x0f;
  368. BikeLedCheck_F.uwBike_LedMode=8; //前灯模式
  369. BikeLedCheck_F.uwBike_LedFun=0;
  370. //尾灯
  371. BikeLedCheck_B.uwBike_LedMode = (volt & 0xf000)>>12;//尾灯模式
  372. BikeLedCheck_B.uwBike_LedVolt =(volt & 0x0f00)>>8;
  373. BikeLedCheck_B.uwBike_LedFun=0;
  374. //左灯模式
  375. BikeLedCheck_L.uwBike_LedMode=5;
  376. BikeLedCheck_L.uwBike_LedFun=0;
  377. //右灯模式
  378. BikeLedCheck_R.uwBike_LedMode=5;
  379. BikeLedCheck_L.uwBike_LedFun=0;
  380. if( BikeLedCheck_F.uwBike_LedVolt == 12) //拉低短路
  381. {
  382. IO_LED_6or12V_Choise_H(); //12V使能
  383. }
  384. else //高阻
  385. {
  386. IO_LED_6or12V_Choise_L();//6V输出使能
  387. }
  388. BikeLedCheck_DC.uwBike_LedMode=5;
  389. }
  390. /***************************************************************
  391. Function: bikelight_voBikeLightControl;
  392. Description: bike light control initialization
  393. Call by: 1ms
  394. Input Variables: switchAction-开灯情况,Brate_Sta-刹车状态, uwBike_LedMode-尾灯模式
  395. Output/Return Variables: N/A
  396. Subroutine Call: N/A;
  397. Reference: N/A
  398. ****************************************************************/
  399. void bikelight_voBikeLightControl(UWORD switchAction, BOOL Brate_Sta )
  400. {
  401. if( power_stPowStateOut.blPowerStartupFlg ==FALSE)
  402. {
  403. BikeLedCheck_F.blBike_LedSta=FALSE;
  404. BikeLedCheck_B.blBike_LedSta=FALSE;
  405. BikeLedCheck_L.blBike_LedSta=FALSE;
  406. BikeLedCheck_R.blBike_LedSta=FALSE;
  407. DL_TimerG_setCaptureCompareValue(PWM_F_INST, 0, GPIO_PWM_F_C1_IDX);//max=2304
  408. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, 0, GPIO_PWM_B_L_C1_IDX);//max=2304
  409. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, 0, GPIO_PWM_B_L_C0_IDX);//max=2304
  410. DL_TimerG_setCaptureCompareValue(PWM_R_INST, 0, GPIO_PWM_R_C1_IDX);//max=2304
  411. }
  412. else
  413. {
  414. if(( BikeLedCheck_F.uwBike_LedFun==1) ||(BikeLedCheck_B.uwBike_LedFun==1)||(BikeLedCheck_L.uwBike_LedFun==1)||(BikeLedCheck_R.uwBike_LedFun==1))
  415. {
  416. IO_LED_6or12V_EN_H();
  417. }
  418. else
  419. {
  420. ledfunctions[BikeLedCheck_DC.uwBike_LedMode](&BikeLedCheck_DC);
  421. if( BikeLedCheck_DC.blBike_LedSta==TRUE) //尾灯控制
  422. {
  423. IO_LED_6or12V_EN_H();
  424. }
  425. else
  426. {
  427. IO_LED_6or12V_EN_L();
  428. }
  429. }
  430. //-----------尾灯处理--------
  431. #if(BIKELEDOPEN_R_ENABLE!=0)
  432. ledfunctions[BikeLedCheck_B.uwBike_LedMode](&BikeLedCheck_B);
  433. if( BikeLedCheck_B.blBike_LedSta==TRUE) //尾灯控制
  434. {
  435. if(BikeLedCheck_B.uwBike_keyLedHighSta==0)
  436. {
  437. BikeLedCheck_B.uwBike_keyLedHighSta=1;
  438. BikeLedCheck_B.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  439. BikeLedCheck_B.uwBike_LedOffErrCnt=0; //10秒一检测计时
  440. BikeLedCheck_B.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  441. BikeLedCheck_B.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  442. BikeLedCheck_B.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  443. BikeLedCheck_B.blBike_LedCurErr=FALSE;
  444. // DL_TimerG_startCounter(PWM_B_L_INST);
  445. DL_Timer_overrideCCPOut(PWM_B_L_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, GPIO_PWM_B_L_C1_IDX);
  446. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_15_EDGE_FALL |DL_GPIO_PIN_15_EDGE_RISE);
  447. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_15_EDGE_RISE;
  448. }
  449. if((BikeLedCheck_B.uwBike_OpenLedEn==0) &&(BikeLedCheck_B.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  450. {
  451. LED_EnableDeal(&BikeLedCheck_B,1,B_PWM_byte);
  452. }
  453. else
  454. {
  455. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_15_EDGE_FALL |DL_GPIO_PIN_15_EDGE_RISE);
  456. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_15_EDGE_FALL;
  457. }
  458. BikeLedCheck_B.uwBike_keyLedLowSta=1;
  459. }
  460. else
  461. {
  462. BikeLedCheck_B.uwBike_keyLedHighSta=0;
  463. if(BikeLedCheck_B.uwBike_keyLedLowSta!=0)
  464. {
  465. BikeLedCheck_B.uwBike_keyLedLowSta=0;
  466. BikeLedCheck_B.uwBikeLight_PWM=0;
  467. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, BikeLedCheck_B.uwBikeLight_PWM, GPIO_PWM_B_L_C1_IDX);//max=2304
  468. }
  469. }
  470. #endif
  471. // ---------------前灯处理------------
  472. #if(BIKELEDOPEN_F_ENABLE!=0)
  473. ledfunctions[BikeLedCheck_F.uwBike_LedMode](&BikeLedCheck_F);
  474. if (BikeLedCheck_F.blBike_LedSta == TRUE)
  475. {
  476. if(BikeLedCheck_F.uwBike_keyLedHighSta==0)
  477. {
  478. BikeLedCheck_F.uwBike_keyLedHighSta=1;
  479. BikeLedCheck_F.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  480. BikeLedCheck_F.uwBike_LedOffErrCnt=0; //10秒一检测计时
  481. BikeLedCheck_F.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  482. BikeLedCheck_F.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  483. BikeLedCheck_F.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  484. DL_COMP_setDACCode0(COMP_FLEDCHECK_INST, 0x0f);
  485. BikeLedCheck_F.blBike_LedCurErr=FALSE;
  486. DL_TimerG_startCounter(PWM_F_INST);
  487. }
  488. if((BikeLedCheck_F.uwBike_OpenLedEn==0) &&(BikeLedCheck_F.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  489. {
  490. LED_EnableDeal(&BikeLedCheck_F,1,F_PWM_byte);
  491. }
  492. else
  493. {
  494. //#if(DCDC_12S6V_SEL_EN!=1)
  495. if( BikeLedCheck_F.uwBike_LedFun!=1)
  496. DL_COMP_setDACCode0(COMP_FLEDCHECK_INST, 0x4f);
  497. //#endif
  498. }
  499. BikeLedCheck_F.uwBike_keyLedLowSta=1;
  500. }
  501. else
  502. {
  503. BikeLedCheck_F.uwBike_keyLedHighSta=0;
  504. if(BikeLedCheck_F.uwBike_keyLedLowSta!=0)
  505. {
  506. BikeLedCheck_F.uwBike_keyLedLowSta=0;
  507. BikeLedCheck_F.uwBikeLight_PWM=0;
  508. DL_TimerG_setCaptureCompareValue(PWM_F_INST, BikeLedCheck_F.uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);//max=2304
  509. }
  510. }
  511. #endif
  512. //------------右灯处理------
  513. ledfunctions[BikeLedCheck_R.uwBike_LedMode](&BikeLedCheck_R);
  514. if(BikeLedCheck_R.blBike_LedSta==TRUE) //
  515. {
  516. if(BikeLedCheck_R.uwBike_keyLedHighSta==0)
  517. {
  518. BikeLedCheck_R.uwBike_keyLedHighSta=1;
  519. BikeLedCheck_R.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  520. BikeLedCheck_R.uwBike_LedOffErrCnt=0; //10秒一检测计时
  521. BikeLedCheck_R.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  522. BikeLedCheck_R.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  523. BikeLedCheck_R.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  524. BikeLedCheck_R.blBike_LedCurErr=FALSE;
  525. DL_TimerG_startCounter(PWM_R_INST);
  526. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_8_EDGE_RISE |DL_GPIO_PIN_8_EDGE_FALL);
  527. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_8_EDGE_RISE;
  528. }
  529. if((BikeLedCheck_R.uwBike_OpenLedEn==0) &&(BikeLedCheck_R.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  530. {
  531. LED_EnableDeal(&BikeLedCheck_R,1,R_PWM_byte);
  532. }
  533. else
  534. {
  535. GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_8_EDGE_RISE |DL_GPIO_PIN_8_EDGE_FALL);
  536. GPIOB->POLARITY15_0 |=DL_GPIO_PIN_8_EDGE_FALL;
  537. }
  538. BikeLedCheck_R.uwBike_keyLedLowSta=1;
  539. }
  540. else
  541. {
  542. BikeLedCheck_R.uwBike_keyLedHighSta=0;
  543. if(BikeLedCheck_R.uwBike_keyLedLowSta!=0)
  544. {
  545. BikeLedCheck_R.uwBike_keyLedLowSta=0;
  546. BikeLedCheck_R.uwBikeLight_PWM=0;
  547. DL_TimerG_setCaptureCompareValue(PWM_R_INST, BikeLedCheck_R.uwBikeLight_PWM, GPIO_PWM_R_C1_IDX);//max=2304
  548. }
  549. }
  550. //------------左灯处理------
  551. ledfunctions[BikeLedCheck_L.uwBike_LedMode](&BikeLedCheck_L);
  552. if(BikeLedCheck_L.blBike_LedSta==TRUE) //
  553. {
  554. if(BikeLedCheck_L.uwBike_keyLedHighSta==0)
  555. {
  556. BikeLedCheck_L.uwBike_keyLedHighSta=1;
  557. BikeLedCheck_L.uwBike_OpenLedEn=0;//开灯瞬间处理标志
  558. BikeLedCheck_L.uwBike_LedOffErrCnt=0; //10秒一检测计时
  559. BikeLedCheck_L.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
  560. BikeLedCheck_L.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
  561. BikeLedCheck_L.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
  562. BikeLedCheck_L.blBike_LedCurErr=FALSE;
  563. //DL_TimerG_startCounter(PWM_B_L_INST);
  564. DL_Timer_overrideCCPOut(PWM_B_L_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, GPIO_PWM_B_L_C0_IDX);
  565. GPIOA->POLARITY15_0 &= ~(DL_GPIO_PIN_3_EDGE_RISE |DL_GPIO_PIN_3_EDGE_FALL);
  566. GPIOA->POLARITY15_0 |=DL_GPIO_PIN_3_EDGE_RISE;
  567. }
  568. if((BikeLedCheck_L.uwBike_OpenLedEn==0) &&(BikeLedCheck_L.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
  569. {
  570. LED_EnableDeal(&BikeLedCheck_L,1,L_PWM_byte);
  571. }
  572. else
  573. {
  574. GPIOA->POLARITY15_0 &= ~(DL_GPIO_PIN_3_EDGE_RISE |DL_GPIO_PIN_3_EDGE_FALL);
  575. GPIOA->POLARITY15_0 |=DL_GPIO_PIN_3_EDGE_FALL;
  576. }
  577. BikeLedCheck_L.uwBike_keyLedLowSta=1;
  578. }
  579. else
  580. {
  581. BikeLedCheck_L.uwBike_keyLedHighSta=0;
  582. if(BikeLedCheck_L.uwBike_keyLedLowSta!=0)
  583. {
  584. BikeLedCheck_L.uwBike_keyLedLowSta=0;
  585. BikeLedCheck_L.uwBikeLight_PWM=0;
  586. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, BikeLedCheck_L.uwBikeLight_PWM, GPIO_PWM_B_L_C0_IDX);//max=2304
  587. }
  588. }
  589. //---------------------
  590. #if(BIKE_OXFORD_EN!=0)
  591. IO_FORWARDLED_ON(); //开前灯
  592. IO_BACKLED_ON();
  593. #endif
  594. //--------------LED电路检测----------
  595. //-------F_LED
  596. if( BikeLedCheck_F.uwBike_LedFun!=1)
  597. {
  598. if((BikeLedCheck_F.blBike_LedCurErr==TRUE )&&(BikeLedCheck_F.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
  599. {
  600. BikeLedCheck_F.uwBike_LedOffErrCnt++;
  601. if(BikeLedCheck_F.uwBike_LedOffErrCnt>2000) //1000ms
  602. {
  603. BikeLedCheck_F.uwBike_keyLedHighSta=0;
  604. BikeLedCheck_F.uwBike_LedOffErrCnt=0;
  605. BikeLedCheck_F.blBike_LedCurErr=FALSE;
  606. BikeLedCheck_F.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  607. }
  608. }
  609. else
  610. {
  611. BikeLedCheck_F.uwBike_LedOffErrCnt=0;
  612. }
  613. }
  614. //------B_LED
  615. if( BikeLedCheck_B.uwBike_LedFun!=1)
  616. {
  617. if((BikeLedCheck_B.blBike_LedCurErr==TRUE)&&(BikeLedCheck_B.blBike_LedSta == TRUE)) //后灯恢复检测
  618. {
  619. BikeLedCheck_B.uwBike_LedOffErrCnt++;
  620. if(BikeLedCheck_B.uwBike_LedOffErrCnt>2000)
  621. {
  622. BikeLedCheck_B.uwBike_keyLedHighSta=0;
  623. BikeLedCheck_B.uwBike_LedOffErrCnt=0;
  624. BikeLedCheck_B.blBike_LedCurErr=FALSE;
  625. BikeLedCheck_B.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  626. }
  627. }
  628. else
  629. {
  630. BikeLedCheck_B.uwBike_LedOffErrCnt=0;
  631. }
  632. }
  633. //------R_LED
  634. if( BikeLedCheck_R.uwBike_LedFun!=1)
  635. {
  636. if((BikeLedCheck_R.blBike_LedCurErr==TRUE )&&(BikeLedCheck_R.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
  637. {
  638. BikeLedCheck_R.uwBike_LedOffErrCnt++;
  639. if(BikeLedCheck_R.uwBike_LedOffErrCnt>2000) //1000ms
  640. {
  641. BikeLedCheck_R.uwBike_keyLedHighSta=0;
  642. BikeLedCheck_R.uwBike_LedOffErrCnt=0;
  643. BikeLedCheck_R.blBike_LedCurErr=FALSE;
  644. BikeLedCheck_R.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  645. }
  646. }
  647. else
  648. {
  649. BikeLedCheck_R.uwBike_LedOffErrCnt=0;
  650. }
  651. }
  652. //------L_LED
  653. if( BikeLedCheck_L.uwBike_LedFun!=1)
  654. {
  655. if((BikeLedCheck_L.blBike_LedCurErr==TRUE )&&(BikeLedCheck_L.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
  656. {
  657. BikeLedCheck_L.uwBike_LedOffErrCnt++;
  658. if(BikeLedCheck_L.uwBike_LedOffErrCnt>2000) //1000ms
  659. {
  660. BikeLedCheck_L.uwBike_keyLedHighSta=0;
  661. BikeLedCheck_L.uwBike_LedOffErrCnt=0;
  662. BikeLedCheck_L.blBike_LedCurErr=FALSE;
  663. BikeLedCheck_L.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
  664. }
  665. }
  666. else
  667. {
  668. BikeLedCheck_L.uwBike_LedOffErrCnt=0;
  669. }
  670. }
  671. //------
  672. }
  673. }
  674. void LED_EnableDeal(BIKELEDCHECK_STR *p,UWORD switchAction,LED_PWM_STR mode )
  675. {
  676. if(switchAction!=0)
  677. {
  678. if(p->uwBike_OpenPreTime<2000)
  679. p->uwBike_OpenPreTime++;
  680. if(p->uwBike_OpenPreTime<=2)//2ms
  681. {
  682. if(mode==F_PWM_byte)
  683. {
  684. p->uwBikeLight_PWM=LIGHT_FIRSTPWM;//
  685. }
  686. else
  687. {
  688. p->uwBikeLight_PWM=LIGHTBLR_FIRSTPWM;//
  689. if(p->uwBike_LedFun ==1 )
  690. p->uwBikeLight_PWM=LIGHT_FIRSTPWM;// 4us
  691. }
  692. }
  693. else if(p->uwBike_OpenPreTime<=3) //4
  694. {
  695. // p->uwBikeLight_PWM =691 ;//720;//
  696. if((p->uwBike_OpenLedEn ==0)&&(p->blBike_LedCurErr==TRUE))
  697. {
  698. p->uwBikeLight_PWM =LIGHT_SECTPWM ;//720;//
  699. }
  700. else
  701. {
  702. p->uwBikeLight_PWM=0;
  703. }
  704. if(p->uwBike_LedFun ==1 ) //去掉保护
  705. {
  706. p->uwBikeLight_PWM = LIGHTBLR_NoProPWM;
  707. }
  708. }
  709. // else if(p->uwBike_OpenPreTime>=1000)
  710. // {
  711. // p->uwBikeLight_PWM=0;//
  712. // p->uwBike_OpenLedEn=1;
  713. // }
  714. if((p->uwBike_OpenPreTime>2) && ((p->uwBikeLight_PWM!=0)||(p->uwBike_LedFun ==1 )))// ||(p->uwBike_LedCheckLowTime>=2)
  715. {
  716. p->blBike_LedCurErr=FALSE;
  717. p->uwBike_OpenLedEn=1;
  718. }
  719. if(p->uwBike_OpenLedEn!=0) //
  720. {
  721. p->uwBikeLight_PWM=LIGHT_MAXPWM;//
  722. }
  723. }
  724. else
  725. {
  726. p->uwBikeLight_PWM=0;//
  727. }
  728. if(mode==F_PWM_byte)
  729. {
  730. DL_TimerG_setCaptureCompareValue(PWM_F_INST, p->uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);//max=2304
  731. }
  732. else if(mode==B_PWM_byte)
  733. {
  734. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, p->uwBikeLight_PWM, GPIO_PWM_B_L_C1_IDX);//max=2304
  735. }
  736. else if(mode==L_PWM_byte)
  737. {
  738. DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, p->uwBikeLight_PWM, GPIO_PWM_B_L_C0_IDX);//max=2304
  739. }
  740. else if(mode==R_PWM_byte)
  741. {
  742. DL_TimerG_setCaptureCompareValue(PWM_R_INST, p->uwBikeLight_PWM, GPIO_PWM_R_C1_IDX);//max=2304
  743. }
  744. }
  745. /*************************************************************************
  746. Local Functions (N/A)
  747. *************************************************************************/
  748. /*************************************************************************
  749. End of this File (EOF)!
  750. Do not put anything after this part!
  751. *************************************************************************/