]> granicus.if.org Git - esp-idf/commitdiff
driver(uart): Add API to get the position of cmd_char
authorkooho <2229179028@qq.com>
Tue, 3 Apr 2018 04:34:16 +0000 (12:34 +0800)
committerkooho <2229179028@qq.com>
Tue, 3 Apr 2018 04:34:16 +0000 (12:34 +0800)
components/driver/include/driver/uart.h
components/driver/uart.c

index 273b7869f457d327c1f299c0b0dba265362bc7f9..f6419c0e8770f3b70140bac3114acad7a0e0e454 100644 (file)
@@ -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
index 0b5638a90f6b764eb24da6d7ec7cfed8dac9d131..efd56abf8479076362577475ba2f5bfb830b18a6 100644 (file)
@@ -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);