123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844 |
- /**
- * @file Bikelight.c
- * @author
- * @brief light of ebike
- * @version 0.1
- * @date 2023-06-20
- *
- * @copyright Copyright (c) 2021
- *
- */
- #define BIKELIGHT_
- /************************************************************************
- Beginning of File, do not put anything above here except notes
- Compiler Directives:
- *************************************************************************/
- #include "syspar.h"
- #include "typedefine.h"
- #include "mathtool.h"
- #include "bikelight.h"
- #include "hwsetup.h"
- #include "power.h"
- #include "CodePara.h"
- #include "adc.h"
- #include "UserGpio_Config.h"
- #include "ti_msp_dl_config.h"
- #include "bikebrake.h"
- //----------------------------
- BIKELEDCHECK_STR BikeLedCheck_F;//前灯参数
- BIKELEDCHECK_STR BikeLedCheck_B;//尾灯参数
- BIKELEDCHECK_STR BikeLedCheck_L;//左灯参数
- BIKELEDCHECK_STR BikeLedCheck_R;//右灯参数
- BIKELEDCHECK_STR BikeLedCheck_DC;//DC12V端口参数
- //LED_PWM_STR BikePwmChoice;
- void LED_EnableDeal(BIKELEDCHECK_STR *p,UWORD switchAction,LED_PWM_STR mode );
- void LedMode_One(BIKELEDCHECK_STR *BikeLedSel);//模式1 开灯低亮,刹车高亮
- void LedMode_Two(BIKELEDCHECK_STR *BikeLedSel);//模式2 开灯高亮,刹车闪烁
- void LedMode_Three(BIKELEDCHECK_STR *BikeLedSel);//模式3 刹车高亮
- void LedMode_Four(BIKELEDCHECK_STR *BikeLedSel);//模式4 刹车闪烁
- void LedMode_Five(BIKELEDCHECK_STR *BikeLedSel);//模式5 开机亮
- void LedMode_Six(BIKELEDCHECK_STR *BikeLedSel);//模式6 超速闪烁报警 国标车
- void LedMode_Seven(BIKELEDCHECK_STR *BikeLedSel);//模式7 开机低亮,刹车高亮
- void LedMode_Eight(BIKELEDCHECK_STR *BikeLedSel);//模式8 开灯亮,关灯灭
- // 函数指针类型定义
- typedef void (*FunctionPointer)(BIKELEDCHECK_STR *BikeLedSel);
- // 函数指针数组
- FunctionPointer ledfunctions[16] = {LedMode_One,LedMode_One, LedMode_Two, LedMode_Three, LedMode_Four,LedMode_Five,LedMode_Six,LedMode_Seven,LedMode_Eight,
- LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight,LedMode_Eight};
- /***************************************************************
- Function: LedMode_One
- Description: //模式1 开灯低亮,刹车高亮
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_One(BIKELEDCHECK_STR *BikeLedSel)
- {
- if((BikeBrake_blGetstate()==TRUE)&&(cp_stBikeRunInfoPara.uwLightSwitch==0))//尾灯低亮,刹车高亮
- {
- if(BikeLedSel->uwLeddelaycnt>0)
- {
- BikeLedSel->uwLeddelaycnt--;
- BikeLedSel->blBike_LedSta=FALSE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- }
- else
- {
- if(cp_stBikeRunInfoPara.uwLightSwitch!=0)
- {
- BikeLedSel->uwLedAddcnt++;
- if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
- {
- BikeLedSel->blBike_LedSta=TRUE;
- if(BikeBrake_blGetstate()==TRUE)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- BikeLedSel->uwLedAddcnt=0;
- }
- BikeLedSel->uwLeddelaycnt=10;
- }
- }
- /***************************************************************
- Function: LedMode_Two
- Description: //模式2 开灯高亮,刹车闪烁
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Two(BIKELEDCHECK_STR *BikeLedSel)
- {
- if(BikeBrake_blGetstate()==TRUE) //尾灯高亮,刹车闪烁
- {
- BikeLedSel->uwLedAddcnt++;
- if(BikeLedSel->uwLedAddcnt > BikeLedFlickerCycle)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- if(BikeLedSel->uwLedAddcnt<BikeLedFlickerDuty)
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- else
- {
- if(cp_stBikeRunInfoPara.uwLightSwitch!=0)
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- BikeLedSel->uwLedAddcnt=0;
- }
- }
- /***************************************************************
- Function: LedMode_Three
- Description: 模式3 刹车高亮
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Three(BIKELEDCHECK_STR *BikeLedSel)
- {
- if(BikeBrake_blGetstate()==TRUE) //刹车高亮
- {
- //BikeLedSel->blBike_LedSta=TRUE;
- if(BikeLedSel->uwLeddelaycnt>0)
- {
- BikeLedSel->uwLeddelaycnt--;
- BikeLedSel->blBike_LedSta=FALSE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- }
- else
- {
- BikeLedSel->uwLeddelaycnt=20;
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- /***************************************************************
- Function: LedMode_Four
- Description: 模式4 刹车闪烁
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Four(BIKELEDCHECK_STR *BikeLedSel)
- {
- if(BikeBrake_blGetstate()==TRUE) //刹车闪烁
- {
- BikeLedSel->uwLedAddcnt++;
- if(BikeLedSel->uwLedAddcnt > BikeLedFlickerCycle)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- if(BikeLedSel->uwLedAddcnt<BikeLedFlickerDuty)
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- /***************************************************************
- Function: LedMode_Five
- Description: 模式5 开机亮
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Five(BIKELEDCHECK_STR *BikeLedSel)
- {
- BikeLedSel->blBike_LedSta=TRUE; //开机常亮
- }
- /***************************************************************
- Function: LedMode_Six
- Description: 模式6 超速闪烁报警 国标车
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Six (BIKELEDCHECK_STR *BikeLedSel)
- {
- if(cp_stBikeRunInfoPara.BikeSpeedKmH>=BikeLedOverSpeedMax) //超速报警
- {
- BikeLedSel->uwLedAddcnt++;
- if(BikeLedSel->uwLedAddcnt > BikeLedOverSpedCycle)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- if(BikeLedSel->uwLedAddcnt<BikeLedOverSpedDuty)
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- else if(cp_stBikeRunInfoPara.BikeSpeedKmH<=BikeLedOverSpeedMin)
- {
- BikeLedSel->blBike_LedSta=FALSE;
- BikeLedSel->uwLedAddcnt=0;
- }
- }
- /***************************************************************
- Function: LedMode_Seven
- Description: 模式7 开机低亮,刹车高亮
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Seven(BIKELEDCHECK_STR *BikeLedSel)
- {
- // if(BikeBrake_blGetstate()==TRUE)
- // {
- // BikeLedSel->blBike_LedSta=TRUE;
- // }
- // else
- // {
- // BikeLedSel->uwLedAddcnt++;
- // if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
- // {
- // BikeLedSel->uwLedAddcnt=0;
- // }
- // if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
- // {
- // BikeLedSel->blBike_LedSta=TRUE;
- // }
- // else
- // {
- // BikeLedSel->blBike_LedSta=FALSE;
- // }
- //
- // }
- BikeLedSel->uwLedAddcnt++;
- if(BikeLedSel->uwLedAddcnt > BikeLedAddCycle)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- if(BikeLedSel->uwLedAddcnt<BikeLedAddDuty)
- {
- BikeLedSel->blBike_LedSta=TRUE;
- if(BikeBrake_blGetstate()==TRUE)
- {
- BikeLedSel->uwLedAddcnt=0;
- }
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- /***************************************************************
- Function: LedMode_Eight
- Description: 模式8 开灯亮,关灯灭
- Call by: 1ms
- Input Variables:
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void LedMode_Eight(BIKELEDCHECK_STR *BikeLedSel)
- {
- if (cp_stBikeRunInfoPara.uwLightSwitch == 1)//仪表开灯亮,仪表关灯灭
- {
- BikeLedSel->blBike_LedSta=TRUE;
- }
- else
- {
- BikeLedSel->blBike_LedSta=FALSE;
- }
- }
- /***************************************************************
- Function: bikelight_voBikeLightInit;
- Description: bike light control initialization
- Call by: FSM_voInit
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void bikelight_voBikeLightInit(BIKELEDCHECK_STR *LedPoit)
- {
- LedPoit->uwBike_LedOffErrCnt=0;
- LedPoit->uwBike_OpenPreTime=0;
- LedPoit->uwBike_OpenLedEn=0;
- LedPoit->uwBikeLight_PWM=0;
- LedPoit->uwBike_LedCheckLowTime=0;
- LedPoit->uwLedAddcnt=0;
- LedPoit->uwBike_keyLedLowSta=0;
- LedPoit->uwBike_keyLedHighSta=0;
- LedPoit->blBike_LedSta=FALSE;
- LedPoit->uwBikeLight_PWM=0;
- LedPoit->blBike_LedCurErr=0;
- }
- /***************************************************************
- Function: bikelight_voBikeLightCoef;
- Description: 滤波时间/阈值电压设定参数更新 ,参数输入端
- uwBike_LedMode:
- 0x01:模式1,连接尾灯,开灯时低亮,刹车时高亮
- 0x02:模式2,连接尾灯,开灯时高亮,刹车时闪烁
- 0x03:模式3,连接刹车灯,刹车时高亮
- 0x04:模式4,连接刹车灯,刹车时闪烁
- 0x05:模式5,开机常亮
- 0x06:模式6,连接蜂鸣器,超速报警
- 0x07:模式7,开机低亮,刹车高亮
- 0x08:模式8,仅开灯高亮,关灯灭
- uwBike_LedFun 模式功能选择
- 0-PWM电池电压有保护,
- 1-前后灯分别控PWM6/12V无保护,
- 2-DCDC输出
- Call by:初始化,接收数据更新
- Input Variables: N/A
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void bikelight_voBikeLightCoef(UWORD volt)
- {
- //前灯
- BikeLedCheck_F.uwBike_LedVolt =volt & 0x0f;
- BikeLedCheck_F.uwBike_LedMode=8; //前灯模式
- BikeLedCheck_F.uwBike_LedFun=0;
- //尾灯
- BikeLedCheck_B.uwBike_LedMode = (volt & 0xf000)>>12;//尾灯模式
- BikeLedCheck_B.uwBike_LedVolt =(volt & 0x0f00)>>8;
- BikeLedCheck_B.uwBike_LedFun=0;
- //左灯模式
- BikeLedCheck_L.uwBike_LedMode=5;
- BikeLedCheck_L.uwBike_LedFun=0;
- //右灯模式
- BikeLedCheck_R.uwBike_LedMode=5;
- BikeLedCheck_L.uwBike_LedFun=0;
- if( BikeLedCheck_F.uwBike_LedVolt == 12) //拉低短路
- {
- IO_LED_6or12V_Choise_H(); //12V使能
- }
- else //高阻
- {
- IO_LED_6or12V_Choise_L();//6V输出使能
- }
- BikeLedCheck_DC.uwBike_LedMode=5;
- }
- /***************************************************************
- Function: bikelight_voBikeLightControl;
- Description: bike light control initialization
- Call by: 1ms
- Input Variables: switchAction-开灯情况,Brate_Sta-刹车状态, uwBike_LedMode-尾灯模式
- Output/Return Variables: N/A
- Subroutine Call: N/A;
- Reference: N/A
- ****************************************************************/
- void bikelight_voBikeLightControl(UWORD switchAction, BOOL Brate_Sta )
- {
- if( power_stPowStateOut.blPowerStartupFlg ==FALSE)
- {
- BikeLedCheck_F.blBike_LedSta=FALSE;
- BikeLedCheck_B.blBike_LedSta=FALSE;
- BikeLedCheck_L.blBike_LedSta=FALSE;
- BikeLedCheck_R.blBike_LedSta=FALSE;
- DL_TimerG_setCaptureCompareValue(PWM_F_INST, 0, GPIO_PWM_F_C1_IDX);//max=2304
- DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, 0, GPIO_PWM_B_L_C1_IDX);//max=2304
- DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, 0, GPIO_PWM_B_L_C0_IDX);//max=2304
- DL_TimerG_setCaptureCompareValue(PWM_R_INST, 0, GPIO_PWM_R_C1_IDX);//max=2304
- }
- else
- {
- if(( BikeLedCheck_F.uwBike_LedFun==1) ||(BikeLedCheck_B.uwBike_LedFun==1)||(BikeLedCheck_L.uwBike_LedFun==1)||(BikeLedCheck_R.uwBike_LedFun==1))
- {
- IO_LED_6or12V_EN_H();
- }
- else
- {
- ledfunctions[BikeLedCheck_DC.uwBike_LedMode](&BikeLedCheck_DC);
- if( BikeLedCheck_DC.blBike_LedSta==TRUE) //尾灯控制
- {
- IO_LED_6or12V_EN_H();
- }
- else
- {
- IO_LED_6or12V_EN_L();
- }
- }
- //-----------尾灯处理--------
- #if(BIKELEDOPEN_R_ENABLE!=0)
- ledfunctions[BikeLedCheck_B.uwBike_LedMode](&BikeLedCheck_B);
- if( BikeLedCheck_B.blBike_LedSta==TRUE) //尾灯控制
- {
- if(BikeLedCheck_B.uwBike_keyLedHighSta==0)
- {
- BikeLedCheck_B.uwBike_keyLedHighSta=1;
- BikeLedCheck_B.uwBike_OpenLedEn=0;//开灯瞬间处理标志
- BikeLedCheck_B.uwBike_LedOffErrCnt=0; //10秒一检测计时
- BikeLedCheck_B.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
- BikeLedCheck_B.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
- BikeLedCheck_B.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
- BikeLedCheck_B.blBike_LedCurErr=FALSE;
- // DL_TimerG_startCounter(PWM_B_L_INST);
- DL_Timer_overrideCCPOut(PWM_B_L_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, GPIO_PWM_B_L_C1_IDX);
- GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_15_EDGE_FALL |DL_GPIO_PIN_15_EDGE_RISE);
- GPIOB->POLARITY15_0 |=DL_GPIO_PIN_15_EDGE_RISE;
- }
- if((BikeLedCheck_B.uwBike_OpenLedEn==0) &&(BikeLedCheck_B.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
- {
- LED_EnableDeal(&BikeLedCheck_B,1,B_PWM_byte);
- }
- else
- {
- GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_15_EDGE_FALL |DL_GPIO_PIN_15_EDGE_RISE);
- GPIOB->POLARITY15_0 |=DL_GPIO_PIN_15_EDGE_FALL;
- }
- BikeLedCheck_B.uwBike_keyLedLowSta=1;
- }
- else
- {
- BikeLedCheck_B.uwBike_keyLedHighSta=0;
- if(BikeLedCheck_B.uwBike_keyLedLowSta!=0)
- {
- BikeLedCheck_B.uwBike_keyLedLowSta=0;
- BikeLedCheck_B.uwBikeLight_PWM=0;
- DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, BikeLedCheck_B.uwBikeLight_PWM, GPIO_PWM_B_L_C1_IDX);//max=2304
- }
- }
- #endif
- // ---------------前灯处理------------
- #if(BIKELEDOPEN_F_ENABLE!=0)
- ledfunctions[BikeLedCheck_F.uwBike_LedMode](&BikeLedCheck_F);
- if (BikeLedCheck_F.blBike_LedSta == TRUE)
- {
- if(BikeLedCheck_F.uwBike_keyLedHighSta==0)
- {
- BikeLedCheck_F.uwBike_keyLedHighSta=1;
- BikeLedCheck_F.uwBike_OpenLedEn=0;//开灯瞬间处理标志
- BikeLedCheck_F.uwBike_LedOffErrCnt=0; //10秒一检测计时
- BikeLedCheck_F.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
- BikeLedCheck_F.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
- BikeLedCheck_F.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
- DL_COMP_setDACCode0(COMP_FLEDCHECK_INST, 0x0f);
- BikeLedCheck_F.blBike_LedCurErr=FALSE;
- DL_TimerG_startCounter(PWM_F_INST);
- }
- if((BikeLedCheck_F.uwBike_OpenLedEn==0) &&(BikeLedCheck_F.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
- {
- LED_EnableDeal(&BikeLedCheck_F,1,F_PWM_byte);
- }
- else
- {
- //#if(DCDC_12S6V_SEL_EN!=1)
- if( BikeLedCheck_F.uwBike_LedFun!=1)
- DL_COMP_setDACCode0(COMP_FLEDCHECK_INST, 0x4f);
- //#endif
- }
- BikeLedCheck_F.uwBike_keyLedLowSta=1;
- }
- else
- {
- BikeLedCheck_F.uwBike_keyLedHighSta=0;
- if(BikeLedCheck_F.uwBike_keyLedLowSta!=0)
- {
- BikeLedCheck_F.uwBike_keyLedLowSta=0;
- BikeLedCheck_F.uwBikeLight_PWM=0;
- DL_TimerG_setCaptureCompareValue(PWM_F_INST, BikeLedCheck_F.uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);//max=2304
- }
- }
- #endif
- //------------右灯处理------
- ledfunctions[BikeLedCheck_R.uwBike_LedMode](&BikeLedCheck_R);
- if(BikeLedCheck_R.blBike_LedSta==TRUE) //
- {
- if(BikeLedCheck_R.uwBike_keyLedHighSta==0)
- {
- BikeLedCheck_R.uwBike_keyLedHighSta=1;
- BikeLedCheck_R.uwBike_OpenLedEn=0;//开灯瞬间处理标志
- BikeLedCheck_R.uwBike_LedOffErrCnt=0; //10秒一检测计时
- BikeLedCheck_R.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
- BikeLedCheck_R.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
- BikeLedCheck_R.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
- BikeLedCheck_R.blBike_LedCurErr=FALSE;
- DL_TimerG_startCounter(PWM_R_INST);
- GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_8_EDGE_RISE |DL_GPIO_PIN_8_EDGE_FALL);
- GPIOB->POLARITY15_0 |=DL_GPIO_PIN_8_EDGE_RISE;
- }
- if((BikeLedCheck_R.uwBike_OpenLedEn==0) &&(BikeLedCheck_R.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
- {
- LED_EnableDeal(&BikeLedCheck_R,1,R_PWM_byte);
- }
- else
- {
- GPIOB->POLARITY15_0 &= ~(DL_GPIO_PIN_8_EDGE_RISE |DL_GPIO_PIN_8_EDGE_FALL);
- GPIOB->POLARITY15_0 |=DL_GPIO_PIN_8_EDGE_FALL;
- }
- BikeLedCheck_R.uwBike_keyLedLowSta=1;
- }
- else
- {
- BikeLedCheck_R.uwBike_keyLedHighSta=0;
- if(BikeLedCheck_R.uwBike_keyLedLowSta!=0)
- {
- BikeLedCheck_R.uwBike_keyLedLowSta=0;
- BikeLedCheck_R.uwBikeLight_PWM=0;
- DL_TimerG_setCaptureCompareValue(PWM_R_INST, BikeLedCheck_R.uwBikeLight_PWM, GPIO_PWM_R_C1_IDX);//max=2304
- }
- }
- //------------左灯处理------
- ledfunctions[BikeLedCheck_L.uwBike_LedMode](&BikeLedCheck_L);
- if(BikeLedCheck_L.blBike_LedSta==TRUE) //
- {
- if(BikeLedCheck_L.uwBike_keyLedHighSta==0)
- {
- BikeLedCheck_L.uwBike_keyLedHighSta=1;
- BikeLedCheck_L.uwBike_OpenLedEn=0;//开灯瞬间处理标志
- BikeLedCheck_L.uwBike_LedOffErrCnt=0; //10秒一检测计时
- BikeLedCheck_L.uwBike_OpenPreTime=0; //开灯瞬间5ms内处理计数
- BikeLedCheck_L.uwBike_LedCheckLowTime=0;//检测过流IO出现低电平次数
- BikeLedCheck_L.blBike_ForwardLedStart=TRUE; //前灯允许开灯启动,总开关
- BikeLedCheck_L.blBike_LedCurErr=FALSE;
- //DL_TimerG_startCounter(PWM_B_L_INST);
- DL_Timer_overrideCCPOut(PWM_B_L_INST, DL_TIMER_FORCE_OUT_DISABLED, DL_TIMER_FORCE_CMPL_OUT_DISABLED, GPIO_PWM_B_L_C0_IDX);
- GPIOA->POLARITY15_0 &= ~(DL_GPIO_PIN_3_EDGE_RISE |DL_GPIO_PIN_3_EDGE_FALL);
- GPIOA->POLARITY15_0 |=DL_GPIO_PIN_3_EDGE_RISE;
- }
- if((BikeLedCheck_L.uwBike_OpenLedEn==0) &&(BikeLedCheck_L.blBike_ForwardLedStart==TRUE)) //开灯检测,过流后每隔10秒检测1次
- {
- LED_EnableDeal(&BikeLedCheck_L,1,L_PWM_byte);
- }
- else
- {
- GPIOA->POLARITY15_0 &= ~(DL_GPIO_PIN_3_EDGE_RISE |DL_GPIO_PIN_3_EDGE_FALL);
- GPIOA->POLARITY15_0 |=DL_GPIO_PIN_3_EDGE_FALL;
- }
- BikeLedCheck_L.uwBike_keyLedLowSta=1;
- }
- else
- {
- BikeLedCheck_L.uwBike_keyLedHighSta=0;
- if(BikeLedCheck_L.uwBike_keyLedLowSta!=0)
- {
- BikeLedCheck_L.uwBike_keyLedLowSta=0;
- BikeLedCheck_L.uwBikeLight_PWM=0;
- DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, BikeLedCheck_L.uwBikeLight_PWM, GPIO_PWM_B_L_C0_IDX);//max=2304
- }
- }
- //---------------------
- #if(BIKE_OXFORD_EN!=0)
- IO_FORWARDLED_ON(); //开前灯
- IO_BACKLED_ON();
- #endif
- //--------------LED电路检测----------
- //-------F_LED
- if( BikeLedCheck_F.uwBike_LedFun!=1)
- {
- if((BikeLedCheck_F.blBike_LedCurErr==TRUE )&&(BikeLedCheck_F.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
- {
- BikeLedCheck_F.uwBike_LedOffErrCnt++;
- if(BikeLedCheck_F.uwBike_LedOffErrCnt>2000) //1000ms
- {
- BikeLedCheck_F.uwBike_keyLedHighSta=0;
- BikeLedCheck_F.uwBike_LedOffErrCnt=0;
- BikeLedCheck_F.blBike_LedCurErr=FALSE;
- BikeLedCheck_F.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
- }
- }
- else
- {
- BikeLedCheck_F.uwBike_LedOffErrCnt=0;
- }
- }
- //------B_LED
- if( BikeLedCheck_B.uwBike_LedFun!=1)
- {
- if((BikeLedCheck_B.blBike_LedCurErr==TRUE)&&(BikeLedCheck_B.blBike_LedSta == TRUE)) //后灯恢复检测
- {
- BikeLedCheck_B.uwBike_LedOffErrCnt++;
- if(BikeLedCheck_B.uwBike_LedOffErrCnt>2000)
- {
- BikeLedCheck_B.uwBike_keyLedHighSta=0;
- BikeLedCheck_B.uwBike_LedOffErrCnt=0;
- BikeLedCheck_B.blBike_LedCurErr=FALSE;
- BikeLedCheck_B.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
- }
- }
- else
- {
- BikeLedCheck_B.uwBike_LedOffErrCnt=0;
- }
- }
- //------R_LED
- if( BikeLedCheck_R.uwBike_LedFun!=1)
- {
- if((BikeLedCheck_R.blBike_LedCurErr==TRUE )&&(BikeLedCheck_R.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
- {
- BikeLedCheck_R.uwBike_LedOffErrCnt++;
- if(BikeLedCheck_R.uwBike_LedOffErrCnt>2000) //1000ms
- {
- BikeLedCheck_R.uwBike_keyLedHighSta=0;
- BikeLedCheck_R.uwBike_LedOffErrCnt=0;
- BikeLedCheck_R.blBike_LedCurErr=FALSE;
- BikeLedCheck_R.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
- }
- }
- else
- {
- BikeLedCheck_R.uwBike_LedOffErrCnt=0;
- }
- }
- //------L_LED
- if( BikeLedCheck_L.uwBike_LedFun!=1)
- {
- if((BikeLedCheck_L.blBike_LedCurErr==TRUE )&&(BikeLedCheck_L.blBike_LedSta == TRUE)) //过流标志,前灯恢复检测
- {
- BikeLedCheck_L.uwBike_LedOffErrCnt++;
- if(BikeLedCheck_L.uwBike_LedOffErrCnt>2000) //1000ms
- {
- BikeLedCheck_L.uwBike_keyLedHighSta=0;
- BikeLedCheck_L.uwBike_LedOffErrCnt=0;
- BikeLedCheck_L.blBike_LedCurErr=FALSE;
- BikeLedCheck_L.blBike_ForwardLedStart=TRUE;//前灯允许开灯启动,总开关
- }
- }
- else
- {
- BikeLedCheck_L.uwBike_LedOffErrCnt=0;
- }
- }
- //------
- }
- }
- void LED_EnableDeal(BIKELEDCHECK_STR *p,UWORD switchAction,LED_PWM_STR mode )
- {
- if(switchAction!=0)
- {
- if(p->uwBike_OpenPreTime<2000)
- p->uwBike_OpenPreTime++;
- if(p->uwBike_OpenPreTime<=2)//2ms
- {
- if(mode==F_PWM_byte)
- {
- p->uwBikeLight_PWM=LIGHT_FIRSTPWM;//
- }
- else
- {
- p->uwBikeLight_PWM=LIGHTBLR_FIRSTPWM;//
- if(p->uwBike_LedFun ==1 )
- p->uwBikeLight_PWM=LIGHT_FIRSTPWM;// 4us
- }
- }
- else if(p->uwBike_OpenPreTime<=3) //4
- {
- // p->uwBikeLight_PWM =691 ;//720;//
- if((p->uwBike_OpenLedEn ==0)&&(p->blBike_LedCurErr==TRUE))
- {
- p->uwBikeLight_PWM =LIGHT_SECTPWM ;//720;//
- }
- else
- {
- p->uwBikeLight_PWM=0;
- }
- if(p->uwBike_LedFun ==1 ) //去掉保护
- {
- p->uwBikeLight_PWM = LIGHTBLR_NoProPWM;
- }
- }
- // else if(p->uwBike_OpenPreTime>=1000)
- // {
- // p->uwBikeLight_PWM=0;//
- // p->uwBike_OpenLedEn=1;
- // }
- if((p->uwBike_OpenPreTime>2) && ((p->uwBikeLight_PWM!=0)||(p->uwBike_LedFun ==1 )))// ||(p->uwBike_LedCheckLowTime>=2)
- {
- p->blBike_LedCurErr=FALSE;
- p->uwBike_OpenLedEn=1;
- }
- if(p->uwBike_OpenLedEn!=0) //
- {
- p->uwBikeLight_PWM=LIGHT_MAXPWM;//
- }
- }
- else
- {
- p->uwBikeLight_PWM=0;//
- }
- if(mode==F_PWM_byte)
- {
- DL_TimerG_setCaptureCompareValue(PWM_F_INST, p->uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);//max=2304
- }
- else if(mode==B_PWM_byte)
- {
- DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, p->uwBikeLight_PWM, GPIO_PWM_B_L_C1_IDX);//max=2304
- }
- else if(mode==L_PWM_byte)
- {
- DL_TimerG_setCaptureCompareValue(PWM_B_L_INST, p->uwBikeLight_PWM, GPIO_PWM_B_L_C0_IDX);//max=2304
- }
- else if(mode==R_PWM_byte)
- {
- DL_TimerG_setCaptureCompareValue(PWM_R_INST, p->uwBikeLight_PWM, GPIO_PWM_R_C1_IDX);//max=2304
- }
- }
- /*************************************************************************
- Local Functions (N/A)
- *************************************************************************/
- /*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|