You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. #include "zstm32uart_irq_rx_service.h"
  2. __weak void HOOK_ZUART_RxCpltCallback(UART_HandleTypeDef* huart, uint8_t rxdata) {}
  3. static zstm32uart_t* s_table;
  4. static int s_table_size;
  5. /**
  6. * @brief
  7. */
  8. static inline void start_receive(UART_HandleTypeDef* huart) {
  9. for (size_t i = 0; i < s_table_size; i++) {
  10. if (huart == s_table[i].huart) {
  11. HAL_UART_Receive_IT(s_table[i].huart, &s_table->rxbuf, 1);
  12. return;
  13. }
  14. }
  15. }
  16. static inline uint8_t getrxdata(UART_HandleTypeDef* huart) {
  17. for (size_t i = 0; i < s_table_size; i++) {
  18. if (huart == s_table[i].huart) {
  19. return s_table[i].rxbuf;
  20. }
  21. }
  22. //代码如果走到这里,说明某个串口中断被触发了,但却没有登记该串口
  23. return 0;
  24. }
  25. void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) {
  26. HOOK_ZUART_RxCpltCallback(huart, getrxdata(huart));
  27. start_receive(huart);
  28. }
  29. void uart_service_start_all_uart_rx(zstm32uart_t* table, int size) {
  30. s_table = table;
  31. s_table_size = size;
  32. for (size_t i = 0; i < s_table_size; i++) {
  33. HAL_UART_Receive_IT(s_table[i].huart, &s_table->rxbuf, 1);
  34. }
  35. }