123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585 |
- /**
- * @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_1; //DC12V端口参数
- BIKELEDCHECK_STR BikeLedCheck_DC_2; //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)
- {
- //DC1灯参数
- BikeLedCheck_DC_1.uwBike_LedVolt =volt & 0x0f;//电压
- BikeLedCheck_DC_1.uwBike_LedMode=8; //模式
- //DC2灯参数
- BikeLedCheck_DC_2.uwBike_LedVolt =(volt & 0x0f00)>>8; //电压
- BikeLedCheck_DC_2.uwBike_LedMode = (volt & 0xf000)>>12;//模式
- BikeLedCheck_DC_2.uwBike_LedFun=2;
- //BAT灯模式
- BikeLedCheck_F.uwBike_LedMode=5;
- BikeLedCheck_F.uwBike_LedFun=0;
- //DC1灯电压设置
- if( BikeLedCheck_DC_1.uwBike_LedVolt == 12) //拉低短路
- {
- IO_LED1_6or12V_Choise_H(); //12V使能
- }
- else //高阻
- {
- IO_LED1_6or12V_Choise_L();//6V输出使能
- }
- //DC2灯电压设置
- if( BikeLedCheck_DC_2.uwBike_LedVolt == 12) //拉低短路
- {
- IO_LED2_6or12V_Choise_H(); //12V使能
- }
- else //高阻
- {
- IO_LED2_6or12V_Choise_L();//6V输出使能
- }
- }
- /***************************************************************
- 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;
- DL_TimerG_setCaptureCompareValue(PWM_F_INST, 0, GPIO_PWM_F_C1_IDX);//max=2304
- }
- else
- {
- //DC1灯控制
- ledfunctions[BikeLedCheck_DC_1.uwBike_LedMode](&BikeLedCheck_DC_1);
- if( BikeLedCheck_DC_1.blBike_LedSta==TRUE)
- {
- IO_LED1_6or12V_EN_H();
- }
- else
- {
- IO_LED1_6or12V_EN_L();
- }
- //DC2灯控制
- ledfunctions[BikeLedCheck_DC_2.uwBike_LedMode](&BikeLedCheck_DC_2);
- if( BikeLedCheck_DC_2.blBike_LedSta==TRUE)
- {
- IO_LED2_6or12V_EN_H();
- }
- else
- {
- IO_LED2_6or12V_EN_L();
- }
- //BAT灯控制
- #if 1
- ledfunctions[BikeLedCheck_F.uwBike_LedMode](&BikeLedCheck_F);
- if (BikeLedCheck_F.blBike_LedSta == TRUE)
- {
- DL_TimerG_startCounter(PWM_F_INST);
- BikeLedCheck_F.uwBikeLight_PWM = 1500;
- DL_TimerG_setCaptureCompareValue(PWM_F_INST, BikeLedCheck_F.uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);
- }
- else
- {
- BikeLedCheck_F.uwBikeLight_PWM = 0;
- DL_TimerG_setCaptureCompareValue(PWM_F_INST, BikeLedCheck_F.uwBikeLight_PWM, GPIO_PWM_F_C1_IDX);
- DL_TimerG_stopCounter(PWM_F_INST);
- }
- #elif(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; //前灯允许开灯启动,总开关
- 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);
- }
- 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
- //BAT灯检测
- 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;
- }
- }
- }
- 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)
- {
- if(mode == F_PWM_byte)
- {
- p->uwBikeLight_PWM = LIGHT_FIRSTPWM;
- }
- else
- {
- p->uwBikeLight_PWM = LIGHTBLR_FIRSTPWM;
- }
- }
- else if(p->uwBike_OpenPreTime <= 3)
- {
- if((p->uwBike_OpenLedEn == 0)&&(p->blBike_LedCurErr == TRUE))
- {
- p->uwBikeLight_PWM = LIGHT_SECTPWM ;
- }
- else
- {
- p->uwBikeLight_PWM = 0;
- }
- }
- if((p->uwBike_OpenPreTime > 2) && (p->uwBikeLight_PWM != 0))
- {
- 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
- }
- }
- /*************************************************************************
- Local Functions (N/A)
- *************************************************************************/
- /*************************************************************************
- End of this File (EOF)!
- Do not put anything after this part!
- *************************************************************************/
|