uart_interface.c 972 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "uart_interface.h"
  2. #include <usart.h>
  3. uart_type uart_msg = {
  4. .rx_count_u8 = 0,
  5. .tx_count_u8 = 0,
  6. .rx_finished_flg = 0,
  7. .disconnect_flg = 0,
  8. .rx_over_time = 5,
  9. .rx_over_time_count = 0xFF,
  10. .disconnect_count = 0,
  11. };
  12. void uart_rx_ticks(void)
  13. {
  14. if (uart_msg.rx_over_time_count != 0xFF)
  15. {
  16. if (++uart_msg.rx_over_time_count >= uart_msg.rx_over_time)
  17. {
  18. uart_msg.rx_over_time_count = 0xFF;
  19. uart_msg.rx_finished_flg = 1;
  20. }
  21. }
  22. if (uart_msg.disconnect_count != 0xFFFF)
  23. {
  24. if (++uart_msg.disconnect_count >= 2500) // 5000ms
  25. {
  26. uart_msg.disconnect_count = 0xFFFF;
  27. uart_msg.disconnect_flg = 1;
  28. }
  29. }
  30. }
  31. void uart_start_send(uart_type *p_msg)
  32. {
  33. p_msg->tx_count_u8 = 0;
  34. UART_SEND_IT_DISABLE();
  35. LL_USART_TransmitData8(USART1, p_msg->tx[p_msg->tx_count_u8++]);
  36. UART_RECV_IT_ENABLE();
  37. }