| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- #include "common.h"
- #include "delay.h"
- #include "drv_usart.h"
- #include "drv_usart_2.h"
- #include "drv_io.h"
- #include "drv_can.h"
- #include "measure_temprature.h"
- #include "app_rs485_1.h"
- #include "app_rs485_2.h"
- #include "app.h"
- #include "app_can.h"
- #include "app_bms_1.h"
- #include "app_bms_2.h"
- #include "app_end_ctr.h"
- #include "app_adas.h"
- #include "low_power.h"
- #include "hardware_test.h"
- uint64_t shark_mseconds;
- uint32_t utc_seconds = 1505216210;// 2017/9/12 19:37:50
- uint16_t s_ms ;
- void systick_close(void)
- {
- //close tick
-
- SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
- SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
- }
- void delay_1us(uint16_t cnt)
- {
- uint32_t count = 3*cnt;
- while(count--);
- }
- /*!
- \brief configure systick
- \param[in] none
- \param[out] none
- \retval none
- */
- void systick_config(void)
- {
- if (SysTick_Config(SystemCoreClock / 1000))
- {
- /* Capture error */
- while (1);
- }
- NVIC_SetPriority(SysTick_IRQn, 0x00U);
- s_ms = 0;
- }
- /*!
- \brief delay a time in milliseconds
- \param[in] count: count in milliseconds
- \param[out] none
- \retval none
- */
- void delay_1ms(uint32_t count)
- {
- uint64_t time = shark_mseconds + count;
- while (time > shark_mseconds);
- }
- #if 0
- /*!
- \brief delay decrement
- \param[in] none
- \param[out] none
- \retval none
- */
- void delay_decrement(void)
- {
- if (0 != delay){
- delay--;
- }
- }
- #endif
- void SysTick_Handler(void)
- {
- shark_mseconds++;
- //uint8_t i,j;
- if (BAT1_IS_OPEN() && sub_bms_info_1.open_times < 0xFFFF) {
- sub_bms_info_1.open_times++;
- }
- if (BAT2_IS_OPEN() && sub_bms_info_2.open_times < 0xFFFF) {
- sub_bms_info_2.open_times++;
- }
- if(++s_ms >= 1000)
- {
- utc_seconds++;
- s_ms = 0;
- Measure_Temprature_Delay();
- Save_Param_Time_Out();
- }
- ACC2_PWM();
-
- Uart1_Time_Out();
- Uart2_Time_Out();
- ACC12_OVER_Loader_Timeout();
- if(sub_rs485_time_out_1.set)
- {
- if(++sub_rs485_time_out_1.count >= RS485_COM_TIMEOUT)
- {
-
- RS485_busy_1 = 0;
- sub_rs485_time_out_1.set = 0;
- sub_rs485_time_out_1.count = 0;
- if(sub_rs485_time_out_1.com_err_flag == 0)
- {
- sub_rs485_time_out_1.com_err_flag = 1;
- sub_rs485_time_out_1.com_err_count = 1;
- }
- else
- {
- if(++sub_rs485_time_out_1.com_err_count >= RS485_COM_ERROR)
- {
- sub_rs485_time_out_1.com_err_count = 0;
- g_event |= SUB_BMS_1_RS485_DISC_EVENT;
- // if(test_info.ti_set)
- test_info.ti_bms_1.bms_err_cnt++;
- }
- }
-
- // if(test_info.ti_set)
- test_info.ti_bms_1.bms_err_timeout_cnt++;
-
- }
- }
-
- if(sub_rs485_time_out_2.set)
- {
- if(++sub_rs485_time_out_2.count >= RS485_COM_TIMEOUT)
- {
-
- RS485_busy_2 = 0;
- sub_rs485_time_out_2.set = 0;
- sub_rs485_time_out_2.count = 0;
- if(sub_rs485_time_out_2.com_err_flag == 0)
- {
- sub_rs485_time_out_2.com_err_flag = 1;
- sub_rs485_time_out_2.com_err_count = 1;
- }
- else
- {
- if(++sub_rs485_time_out_2.com_err_count >= RS485_COM_ERROR)
- {
- sub_rs485_time_out_2.com_err_count = 0;
- g_event |= SUB_BMS_2_RS485_DISC_EVENT;
- // if(test_info.ti_set)
- test_info.ti_bms_2.bms_err_cnt++;
- }
- }
- // if(test_info.ti_set)
- test_info.ti_bms_2.bms_err_timeout_cnt++;
- }
- }
- #if 0
- Send_Sub_BMS_CMD_Delay();
- #else
- if(send_delay.set)
- {
- ++send_delay.count;
- if(send_delay.count >= 400)
- {
- send_delay.count = 0;
- if(update_bat.ub_bat != UPDATE_BAT_2)
- g_event |= SUB_BMS_2_SEND_CMD_EVENT;
- }
- else if(send_delay.count == 200)
- {
- if(update_bat.ub_bat != UPDATE_BAT_1)
- g_event |= SUB_BMS_1_SEND_CMD_EVENT;
- }
- }
- #endif
- //Check_CB_Oper_Sta_Delay();
-
- if(side_stay_dec_delay.set)
- side_stay_dec_delay.count++;
- if(soak_dec_delay.set)
- soak_dec_delay.count++;
- if(sti_dec_delay.set)
- sti_dec_delay.count++;
- if(repair_dec_delay.set)
- repair_dec_delay.count++;
- if(qd_dec_delay.set)
- qd_dec_delay.count++;
- if(xl_dec_delay.set)
- xl_dec_delay.count++;
- if(acc2_dec_delay.set)
- acc2_dec_delay.count++;
-
-
-
- if(left_light_delay.set)
- {
- ++left_light_delay.count;
- if(left_light_delay.count >= ZONG_TIME)
- {
- Left_Light_Enable(1);
- left_light_delay.count = 0;
- }
- else if(left_light_delay.count >= LIANG_TIME)
- {
- Left_Light_Enable(0);
- }
- }
- if(right_light_delay.set)
- {
- ++right_light_delay.count;
- if(right_light_delay.count >= ZONG_TIME)
- {
- Right_Light_Enable(1);
- right_light_delay.count = 0;
- }
- else if(right_light_delay.count >= LIANG_TIME)
- {
- Right_Light_Enable(0);
- }
- }
- Bms_1_Self_Send_Timeout();
- Bms_2_Self_Send_Timeout();
- End_Ctr_Self_Send_Timeout();
- ADAS_Timeout();
- Shield_XL_Timeout();
- Check_Charger_Timeout();
- Series_Delay_Timeout();
- Enter_Sleep_Delay_Timeout();
- HT_Reboot_Timeout();
-
- }
|