delay.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. #include "common.h"
  2. #include "delay.h"
  3. #include "drv_usart.h"
  4. #include "drv_usart_2.h"
  5. #include "drv_io.h"
  6. #include "drv_can.h"
  7. #include "measure_temprature.h"
  8. #include "app_rs485_1.h"
  9. #include "app_rs485_2.h"
  10. #include "app.h"
  11. #include "app_can.h"
  12. #include "app_bms_1.h"
  13. #include "app_bms_2.h"
  14. #include "app_end_ctr.h"
  15. #include "app_adas.h"
  16. #include "low_power.h"
  17. #include "hardware_test.h"
  18. static uint32_t delay = 0;
  19. uint32_t utc_seconds = 1505216210;// 2017/9/12 19:37:50
  20. uint16_t s_ms ;
  21. void systick_close(void)
  22. {
  23. //close tick
  24. SysTick->CTRL &= ~SysTick_CTRL_TICKINT_Msk;
  25. SysTick->CTRL &= ~SysTick_CTRL_ENABLE_Msk;
  26. }
  27. void delay_1us(uint16_t cnt)
  28. {
  29. uint32_t count = 3*cnt;
  30. while(count--);
  31. }
  32. /*!
  33. \brief configure systick
  34. \param[in] none
  35. \param[out] none
  36. \retval none
  37. */
  38. void systick_config(void)
  39. {
  40. if (SysTick_Config(SystemCoreClock / 1000))
  41. {
  42. /* Capture error */
  43. while (1);
  44. }
  45. NVIC_SetPriority(SysTick_IRQn, 0x00U);
  46. delay = 0;
  47. s_ms = 0;
  48. }
  49. /*!
  50. \brief delay a time in milliseconds
  51. \param[in] count: count in milliseconds
  52. \param[out] none
  53. \retval none
  54. */
  55. void delay_1ms(uint32_t count)
  56. {
  57. delay = count;
  58. while(0 != delay);
  59. }
  60. #if 0
  61. /*!
  62. \brief delay decrement
  63. \param[in] none
  64. \param[out] none
  65. \retval none
  66. */
  67. void delay_decrement(void)
  68. {
  69. if (0 != delay){
  70. delay--;
  71. }
  72. }
  73. #endif
  74. void SysTick_Handler(void)
  75. {
  76. //uint8_t i,j;
  77. if(++s_ms >= 1000)
  78. {
  79. utc_seconds++;
  80. s_ms = 0;
  81. Measure_Temprature_Delay();
  82. Save_Param_Time_Out();
  83. }
  84. if (0 != delay){
  85. delay--;
  86. }
  87. ACC2_PWM();
  88. Uart1_Time_Out();
  89. Uart2_Time_Out();
  90. ACC12_OVER_Loader_Timeout();
  91. if(sub_rs485_time_out_1.set)
  92. {
  93. if(++sub_rs485_time_out_1.count >= RS485_COM_TIMEOUT)
  94. {
  95. RS485_busy_1 = 0;
  96. sub_rs485_time_out_1.set = 0;
  97. sub_rs485_time_out_1.count = 0;
  98. if(sub_rs485_time_out_1.com_err_flag == 0)
  99. {
  100. sub_rs485_time_out_1.com_err_flag = 1;
  101. sub_rs485_time_out_1.com_err_count = 1;
  102. }
  103. else
  104. {
  105. if(++sub_rs485_time_out_1.com_err_count >= RS485_COM_ERROR)
  106. {
  107. sub_rs485_time_out_1.com_err_count = 0;
  108. g_event |= SUB_BMS_1_RS485_DISC_EVENT;
  109. }
  110. }
  111. }
  112. }
  113. if(sub_rs485_time_out_2.set)
  114. {
  115. if(++sub_rs485_time_out_2.count >= RS485_COM_TIMEOUT)
  116. {
  117. RS485_busy_2 = 0;
  118. sub_rs485_time_out_2.set = 0;
  119. sub_rs485_time_out_2.count = 0;
  120. if(sub_rs485_time_out_2.com_err_flag == 0)
  121. {
  122. sub_rs485_time_out_2.com_err_flag = 1;
  123. sub_rs485_time_out_2.com_err_count = 1;
  124. }
  125. else
  126. {
  127. if(++sub_rs485_time_out_2.com_err_count >= RS485_COM_ERROR)
  128. {
  129. sub_rs485_time_out_2.com_err_count = 0;
  130. g_event |= SUB_BMS_2_RS485_DISC_EVENT;
  131. }
  132. }
  133. }
  134. }
  135. #if 0
  136. Send_Sub_BMS_CMD_Delay();
  137. #else
  138. if(send_delay.set)
  139. {
  140. ++send_delay.count;
  141. if(send_delay.count >= 400)
  142. {
  143. send_delay.count = 0;
  144. if(update_bat.ub_bat != UPDATE_BAT_2)
  145. g_event |= SUB_BMS_2_SEND_CMD_EVENT;
  146. }
  147. else if(send_delay.count == 200)
  148. {
  149. if(update_bat.ub_bat != UPDATE_BAT_1)
  150. g_event |= SUB_BMS_1_SEND_CMD_EVENT;
  151. }
  152. }
  153. #endif
  154. //Check_CB_Oper_Sta_Delay();
  155. if(side_stay_dec_delay.set)
  156. side_stay_dec_delay.count++;
  157. if(soak_dec_delay.set)
  158. soak_dec_delay.count++;
  159. if(sti_dec_delay.set)
  160. sti_dec_delay.count++;
  161. if(repair_dec_delay.set)
  162. repair_dec_delay.count++;
  163. if(qd_dec_delay.set)
  164. qd_dec_delay.count++;
  165. if(xl_dec_delay.set)
  166. xl_dec_delay.count++;
  167. if(acc2_dec_delay.set)
  168. acc2_dec_delay.count++;
  169. if(left_light_delay.set)
  170. {
  171. ++left_light_delay.count;
  172. if(left_light_delay.count >= ZONG_TIME)
  173. {
  174. Left_Light_Enable(1);
  175. left_light_delay.count = 0;
  176. }
  177. else if(left_light_delay.count >= LIANG_TIME)
  178. {
  179. Left_Light_Enable(0);
  180. }
  181. }
  182. if(right_light_delay.set)
  183. {
  184. ++right_light_delay.count;
  185. if(right_light_delay.count >= ZONG_TIME)
  186. {
  187. Right_Light_Enable(1);
  188. right_light_delay.count = 0;
  189. }
  190. else if(right_light_delay.count >= LIANG_TIME)
  191. {
  192. Right_Light_Enable(0);
  193. }
  194. }
  195. Bms_1_Self_Send_Timeout();
  196. Bms_2_Self_Send_Timeout();
  197. End_Ctr_Self_Send_Timeout();
  198. ADAS_Timeout();
  199. Shield_XL_Timeout();
  200. Check_Charger_Timeout();
  201. Series_Delay_Timeout();
  202. Enter_Sleep_Delay_Timeout();
  203. HT_Reboot_Timeout();
  204. }