From ab70fc6301afb2afd5290d992beb343ab3723cb1 Mon Sep 17 00:00:00 2001 From: zwsd Date: Tue, 28 Jun 2022 18:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=BF=9B=E5=8E=BB=E4=B8=B2?= =?UTF-8?q?=E5=8F=A3=E4=B8=AD=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zstm32uart_irq_rx_service.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/zstm32uart_irq_rx_service.c b/zstm32uart_irq_rx_service.c index 148b651..914e533 100644 --- a/zstm32uart_irq_rx_service.c +++ b/zstm32uart_irq_rx_service.c @@ -1,8 +1,36 @@ #include "zstm32uart_irq_rx_service.h" +__weak void HOOK_ZUART_RxCpltCallback(UART_HandleTypeDef* huart, uint8_t rxdata) {} static zstm32uart_t* s_table; static int s_table_size; +/** + * @brief 串口相关衔接点处理 + */ +static inline void start_receive(UART_HandleTypeDef* huart) { + for (size_t i = 0; i < s_table_size; i++) { + if (huart == s_table[i].huart) { + HAL_UART_Receive_IT(s_table[i].huart, &s_table->rxbuf, 1); + return; + } + } +} + +static inline uint8_t getrxdata(UART_HandleTypeDef* huart) { + for (size_t i = 0; i < s_table_size; i++) { + if (huart == s_table[i].huart) { + return s_table[i].rxbuf; + } + } + //代码如果走到这里,说明某个串口中断被触发了,但却没有登记该串口 + return 0; +} + +void HAL_UART_RxCpltCallback(UART_HandleTypeDef* huart) { + HOOK_ZUART_RxCpltCallback(huart, getrxdata(huart)); + start_receive(huart); +} + void uart_service_start_all_uart_rx(zstm32uart_t* table, int size) { s_table = table; s_table_size = size;