From 305c788c60c68685020516d190cb48fa6b7871bb Mon Sep 17 00:00:00 2001 From: kooho <2229179028@qq.com> Date: Tue, 3 Apr 2018 12:34:16 +0800 Subject: [PATCH] driver(uart): Add API to get the position of cmd_char --- components/driver/include/driver/uart.h | 22 ++++++++++++++++++++++ components/driver/uart.c | 13 +++++++++++++ 2 files changed, 35 insertions(+) diff --git a/components/driver/include/driver/uart.h b/components/driver/include/driver/uart.h index 273b7869f..f6419c0e8 100644 --- a/components/driver/include/driver/uart.h +++ b/components/driver/include/driver/uart.h @@ -674,8 +674,11 @@ esp_err_t uart_disable_pattern_det_intr(uart_port_t uart_num); * @param pattern_chr character of the pattern * @param chr_num number of the character, 8bit value. * @param chr_tout timeout of the interval between each pattern characters, 24bit value, unit is APB (80Mhz) clock cycle. + * When the duration is less than this value, it will not take this data as at_cmd char * @param post_idle idle time after the last pattern character, 24bit value, unit is APB (80Mhz) clock cycle. + * When the duration is less than this value, it will not take the previous data as the last at_cmd char * @param pre_idle idle time before the first pattern character, 24bit value, unit is APB (80Mhz) clock cycle. + * When the duration is less than this value, it will not take this data as the first at_cmd char * * @return * - ESP_OK Success @@ -702,6 +705,25 @@ esp_err_t uart_enable_pattern_det_intr(uart_port_t uart_num, char pattern_chr, u */ int uart_pattern_pop_pos(uart_port_t uart_num); +/** + * @brief Return the nearest detected pattern position in buffer. + * The positions of the detected pattern are saved in a queue, + * This function do nothing to the queue. + * @note If the RX buffer is full and flow control is not enabled, + * the detected pattern may not be found in the rx buffer due to overflow. + * + * The following APIs will modify the pattern position info: + * uart_flush_input, uart_read_bytes, uart_driver_delete, uart_pop_pattern_pos + * It is the application's responsibility to ensure atomic access to the pattern queue and the rx data buffer + * when using pattern detect feature. + * + * @param uart_num UART port number + * @return + * - (-1) No pattern found for current index or parameter error + * - others the pattern position in rx buffer. + */ +int uart_pattern_get_pos(uart_port_t uart_num); + /** * @brief Allocate a new memory with the given length to save record the detected pattern position in rx buffer. * @param uart_num UART port number diff --git a/components/driver/uart.c b/components/driver/uart.c index 0b5638a90..efd56abf8 100644 --- a/components/driver/uart.c +++ b/components/driver/uart.c @@ -411,6 +411,19 @@ int uart_pattern_pop_pos(uart_port_t uart_num) return pos; } +int uart_pattern_get_pos(uart_port_t uart_num) +{ + UART_CHECK((p_uart_obj[uart_num]), "uart driver error", (-1)); + UART_ENTER_CRITICAL(&uart_spinlock[uart_num]); + uart_pat_rb_t* pat_pos = &p_uart_obj[uart_num]->rx_pattern_pos; + int pos = -1; + if (pat_pos != NULL && pat_pos->rd != pat_pos->wr) { + pos = pat_pos->data[pat_pos->rd]; + } + UART_EXIT_CRITICAL(&uart_spinlock[uart_num]); + return pos; +} + esp_err_t uart_pattern_queue_reset(uart_port_t uart_num, int queue_length) { UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);