* @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
*/
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
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);