123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- #include "tasks.h"
- #include "usart.h"
- #include "var.h"
- #include "functional_safety_key.h"
- Key_Flag_Struct_t Key_Flag;
- Key_Status_Struct_t Key_Recv_Status;
- Key_Status_Struct_t Key_Scan_Status;
- PBU_TE_STATUS PBU_TE_Status=HANDSHAKE_NO;
- void Scan_Key(void)
- {
- static uint32_t DelayTimeCnt_power=0,DelayTimeCnt_walk=0,DelayTimeCnt_dec=0,DelayTimeCnt_add=0,DelayTimeCnt_start=0;
- static uint8_t Flag_key_power = 0;
- static uint8_t Flag_key_walk = 0;
- static uint8_t Flag_key_dec = 0;
- static uint8_t Flag_key_add = 0;
- static uint8_t Flag_Start = 0;
- if(Scan_Key_Start == 0x01)
- {
- if(Flag_Start == 0)
- {
- DelayTimeCnt_start = SysTime_5ms;
- Flag_Start = 1;
- }
- if(TimeCntDiff_5ms(DelayTimeCnt_start) > 4)
- {
- Scan_Key_Start = 0x00;
- Flag_Start = 0;
- SendKeyStatusToTE();
- }
- /* Processing power button */
- if( *(Key_On_Off.ADC_result)<1000 )
- {
- if(Flag_key_power == 0)
- {
- DelayTimeCnt_power = SysTime_5ms;
- Flag_key_power = 1;
- }
-
- if(TimeCntDiff_5ms(DelayTimeCnt_power) > 1)
- {
- if( *(Key_On_Off.ADC_result)<1000 )
- {
- Key_Scan_Status.Status_Bit.Power = 0x00;
- Flag_key_power = 0;
- }
- }
- }
- else if(*(Key_On_Off.ADC_result)>3000)
- {
- Key_Scan_Status.Status_Bit.Power = 0x01;
- Flag_key_power = 0;
- }
-
- /* Processing Walk button */
- if( *(Key_Walk.ADC_result)<1000 )
- {
- if(Flag_key_walk == 0)
- {
- DelayTimeCnt_walk = SysTime_5ms;
- Flag_key_walk = 1;
- }
- if(TimeCntDiff_5ms(DelayTimeCnt_walk) > 1)
- {
- if(*(Key_Walk.ADC_result)<1000)
- {
- Key_Scan_Status.Status_Bit.Walk = 0x00;
- Flag_key_walk = 0;
- }
- }
- }
- else if(*(Key_Walk.ADC_result)>3000)
- {
- Key_Scan_Status.Status_Bit.Walk = 0x01;
- Flag_key_walk = 0;
- }
-
- /* Processing DEC button */
- if( *(Key_Down.ADC_result)<1000 )
- {
- if(Flag_key_dec == 0)
- {
- DelayTimeCnt_dec = SysTime_5ms;
- Flag_key_dec = 1;
- }
-
- if(TimeCntDiff_5ms(DelayTimeCnt_dec) > 1)
- {
- if( *(Key_Down.ADC_result)<1000 )
- {
- Key_Scan_Status.Status_Bit.Dec = 0x00;
- Flag_key_dec = 0;
- }
- }
- }
- else if(*(Key_Down.ADC_result)>3000)
- {
- Key_Scan_Status.Status_Bit.Dec = 0x01;
- Flag_key_dec = 0;
- }
- /* Processing ADD button */
- if( *(Key_Up.ADC_result)<1000 )
- {
- if(Flag_key_add == 0)
- {
- DelayTimeCnt_add = SysTime_5ms;
- Flag_key_add = 1;
- }
-
- if(TimeCntDiff_5ms(DelayTimeCnt_add) > 1)
- {
- if(*(Key_Up.ADC_result)<1000)
- {
- Key_Scan_Status.Status_Bit.Add = 0x00;
- Flag_key_add = 0;
- }
- }
- }
- else if(*(Key_Up.ADC_result)>3000)
- {
- Key_Scan_Status.Status_Bit.Add = 0x01;
- Flag_key_add = 0;
- }
- }
- }
- void SendKeyStatusToTE(void)
- {
- uint8_t send_buffer[256];
- uint8_t mode;
-
- mode = 0x0C; //0x11:read,0x16:write,0x0C:report
- /* Add command word */
- send_buffer[0] = 0x11;
- send_buffer[1] = 0x01;
- /* Add data */
- send_buffer[2] = Key_Scan_Status.Status;
- /* Send data */
- SendCmdData(mode, send_buffer, 3);
- }
- void SendMotorEnableToTE(void)
- {
- uint8_t send_buffer[3];
- uint8_t mode;
-
- mode = 0x0C; //0x11:read,0x16:write,0x0C:report
- /* Shut down information command word */
- send_buffer[0] = 0x44;
- send_buffer[1] = 0x01;
- /* Add data */
- send_buffer[2] = 0x01;
- /* Send data */
- SendCmdData(mode, send_buffer, 3);
- }
- void SendMotorDisableToTE(void)
- {
- uint8_t send_buffer[3];
- uint8_t mode;
-
- mode = 0x0C; //0x11:read,0x16:write,0x0C:report
- /* Shut down information command word */
- send_buffer[0] = 0x44;
- send_buffer[1] = 0x01;
- /* Add data */
- send_buffer[2] = 0x00;
- /* Send data */
- SendCmdData(mode, send_buffer, 3);
- }
- void Error_Key_Process(void)
- {
- static uint32_t LongDelayTimeCnt_On_Off = 0;
- static uint32_t LongDelayTimeCnt_Walk = 0;
- static uint32_t LongDelayTimeCnt_Down = 0;
- static uint32_t LongDelayTimeCnt_Up = 0;
- static uint32_t LongDelayTimeCnt_Light = 0;
-
- static uint8_t Flag1_1 = 0;
- static uint8_t Flag2_1 = 0;
- static uint8_t Flag3_1 = 0;
- static uint8_t Flag4_1 = 0;
- static uint8_t Flag6_1 = 0;
-
- /* Processing power key */
- #if 0
- if(*(Key_On_Off.ADC_result)<1000)
- {
- if(Flag1_1 == 0)
- {
- LongDelayTimeCnt_On_Off = SysTime_5ms;
- Flag1_1 = 1;
- }
- if(TimeCntDiff_5ms(LongDelayTimeCnt_On_Off) >= FAILURE_TIME)
- {
- if(*(Key_On_Off.ADC_result)<1000)
- {
- Key_Flag.power_long_press = 1;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Power = 0x01;
- Flag1_1 = 0;
- }
- }
- }
- else if(*(Key_On_Off.ADC_result)>3000)
- {
- Key_Flag.power_long_press = 0;
- Flag1_1 = 0;
- }
- #endif
-
- /* Processing Walk key */
- if(*(Key_Walk.ADC_result)<1000)
- {
- if(Flag2_1 == 0)
- {
- LongDelayTimeCnt_Walk = SysTime_5ms;
- Flag2_1 = 1;
- }
- if(TimeCntDiff_5ms(LongDelayTimeCnt_Walk) >= FAILURE_TIME)
- {
- if(*(Key_Walk.ADC_result)<1000)
- {
- Key_Flag.walk_long_press = 1;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Walk = 0x01;
- Flag2_1 = 0;
- }
- }
- }
- else if(*(Key_Walk.ADC_result)>3000)
- {
- Key_Flag.walk_long_press = 0;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Walk = 0x00;
- Flag2_1 = 0;
- }
-
- /* Processing Down key */
- if(*(Key_Down.ADC_result)<1000)
- {
- if(Flag3_1 == 0)
- {
- LongDelayTimeCnt_Down = SysTime_5ms;
- Flag3_1 = 1;
- }
- if(TimeCntDiff_5ms(LongDelayTimeCnt_Down) >= FAILURE_TIME)
- {
- if(*(Key_Down.ADC_result)<1000)
- {
- Key_Flag.dec_long_press = 1;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Dec = 0x01;
- Flag3_1 = 0;
- }
- }
- }
- else if(*(Key_Down.ADC_result)>3000)
- {
- Key_Flag.dec_long_press = 0;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Dec = 0x00;
- Flag3_1 = 0;
- }
- /* Processing ADD key */
- if(*(Key_Up.ADC_result)<1000)
- {
- if(Flag4_1 == 0)
- {
- LongDelayTimeCnt_Up = SysTime_5ms;
- Flag4_1 = 1;
- }
- if((PBU_AssitMode_Status.PBU_AssistMode_Flag == PBU_AssistMode_Flag_Walk)||(PBU_AssitMode_Status.PBU_AssistMode_Flag == PBU_AssistMode_Flag_WalkSby))
- LongDelayTimeCnt_Up = SysTime_5ms;
-
- if(TimeCntDiff_5ms(LongDelayTimeCnt_Up) >= FAILURE_TIME)
- {
- if(*(Key_Up.ADC_result)<1000)
- {
- Key_Flag.add_long_press = 1;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Add = 0x01;
- Flag4_1 = 0;
- }
- }
- }
- else if(*(Key_Up.ADC_result)>3000)
- {
- Key_Flag.add_long_press = 0;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Add = 0x00;
- Flag4_1 = 0;
- }
-
- /* Processing LIGHT key */
- if(*(Key_Light.ADC_result)<1000)
- {
- if(Flag6_1 == 0)
- {
- LongDelayTimeCnt_Light = SysTime_5ms;
- Flag6_1 = 1;
- }
-
- /* Handle long press 10s */
- if(TimeCntDiff_5ms(LongDelayTimeCnt_Light) >= FAILURE_TIME)
- {
- if(*(Key_Light.ADC_result)<1000)
- {
- Key_Flag.light_long_press = 1;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Light = 0x01;
- Flag6_1 = 0;
- }
- }
- }
- else if(*(Key_Light.ADC_result)>3000)
- {
- Key_Flag.light_long_press = 0;
- PBU_hardwareErrorCode.ERROR_Bit.Key_Light = 0x00;
- Flag6_1 = 0;
- }
- }
- void Scan_Key_ADC_Error(void)
- {
- static uint16_t On_Off_error_cnt = 0;
- static uint16_t Walk_error_cnt = 0;
- static uint16_t Up_error_cnt = 0;
- static uint16_t Down_error_cnt = 0;
- static uint16_t Light_error_cnt = 0;
-
- #if 0
- ////////////On_Off判断////////////////////////
- if((*(Key_On_Off.ADC_result)>1000)&&(*(Key_On_Off.ADC_result)<3000))
- {
- On_Off_error_cnt++;
- }
- else
- {
- On_Off_error_cnt=0;
- }
-
- if(On_Off_error_cnt>5000)
- {
- PBU_hardwareErrorCode.ERROR_Bit.Key_Power = 0x01;
- }
- #endif
- ////////////Walk判断////////////////////////
- if((*(Key_Walk.ADC_result)>1000)&&(*(Key_Walk.ADC_result)<3000))
- {
- Walk_error_cnt++;
- }
- else
- {
- Walk_error_cnt=0;
- }
-
- if(Walk_error_cnt>5000)
- {
- PBU_hardwareErrorCode.ERROR_Bit.Key_Walk = 0x01;
- }
- ////////////Add判断////////////////////////
- if((*(Key_Up.ADC_result)>1000)&&(*(Key_Up.ADC_result)<3000))
- {
- Up_error_cnt++;
- }
- else
- {
- Up_error_cnt=0;
- }
-
- if(Up_error_cnt>5000)
- {
- PBU_hardwareErrorCode.ERROR_Bit.Key_Add = 0x01;
- }
- ////////////Down判断////////////////////////
- if((*(Key_Down.ADC_result)>1000)&&(*(Key_Down.ADC_result)<3000))
- {
- Down_error_cnt++;
- }
- else
- {
- Down_error_cnt=0;
- }
-
- if(Down_error_cnt>5000)
- {
- PBU_hardwareErrorCode.ERROR_Bit.Key_Dec = 0x01;
- }
- ////////////Light判断////////////////////////
- if((*(Key_Light.ADC_result)>1000)&&(*(Key_Light.ADC_result)<3000))
- {
- Light_error_cnt++;
- }
- else
- {
- Light_error_cnt=0;
- }
-
- if(Light_error_cnt>5000)
- {
- PBU_hardwareErrorCode.ERROR_Bit.Key_Light = 0x01;
- }
- }
- void Power_Mos_Check(void)
- {
- static uint16_t Power_Mos_error_cnt = 0;
- if((ADC_Result[0]>2000)&&(*(Key_On_Off.ADC_result)>3000))
- {
- Power_Mos_error_cnt ++;
- }
- else
- Power_Mos_error_cnt=0;
-
- if(Power_Mos_error_cnt>3)
- {
- Power_Mos_error_cnt=0;
- PBU_ErrorCode.ERROR_Bit.MOS_Fault =1;
- }
- }
- void Vin_test_Check(void)
- {
- if((ADC_Result[0]<3000)&&(ADC_Result[0]>1000))
- {
- Vin_test_TimeCnt=SysTime_5ms;
- }
-
- if(TimeCntDiff_5ms(Vin_test_TimeCnt) >= 400)
- {
- PBU_ErrorCode.ERROR_Bit.Hardware_Fault =1;
- }
- }
|