Merge branch 'feature/uart_software_flow_control' into 'master'
uart: Add api call to switch on hardware support for 'software' flow control. (github #890) See merge request !1215
This commit is contained in:
commit
23f10e1a57
2 changed files with 33 additions and 0 deletions
|
@ -269,6 +269,20 @@ esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask);
|
||||||
*/
|
*/
|
||||||
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
|
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set software flow control.
|
||||||
|
*
|
||||||
|
* @param uart_num UART_NUM_0, UART_NUM_1 or UART_NUM_2
|
||||||
|
* @param enable switch on or off
|
||||||
|
* @param rx_thresh_xon low water mark
|
||||||
|
* @param rx_thresh_xoff high water mark
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* - ESP_OK Success
|
||||||
|
* - ESP_FAIL Parameter error
|
||||||
|
*/
|
||||||
|
esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get hardware flow control mode
|
* @brief Get hardware flow control mode
|
||||||
*
|
*
|
||||||
|
|
|
@ -29,6 +29,9 @@
|
||||||
#include "driver/uart.h"
|
#include "driver/uart.h"
|
||||||
#include "driver/gpio.h"
|
#include "driver/gpio.h"
|
||||||
|
|
||||||
|
#define XOFF (char)0x13
|
||||||
|
#define XON (char)0x11
|
||||||
|
|
||||||
static const char* UART_TAG = "uart";
|
static const char* UART_TAG = "uart";
|
||||||
#define UART_CHECK(a, str, ret_val) \
|
#define UART_CHECK(a, str, ret_val) \
|
||||||
if (!(a)) { \
|
if (!(a)) { \
|
||||||
|
@ -199,6 +202,22 @@ esp_err_t uart_set_line_inverse(uart_port_t uart_num, uint32_t inverse_mask)
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
esp_err_t uart_set_sw_flow_ctrl(uart_port_t uart_num, bool enable, uint8_t rx_thresh_xon, uint8_t rx_thresh_xoff)
|
||||||
|
{
|
||||||
|
UART_CHECK((uart_num < UART_NUM_MAX), "uart_num error", ESP_FAIL);
|
||||||
|
UART_CHECK((rx_thresh_xon < UART_FIFO_LEN), "rx flow xon thresh error", ESP_FAIL);
|
||||||
|
UART_CHECK((rx_thresh_xoff < UART_FIFO_LEN), "rx flow xon thresh error", ESP_FAIL);
|
||||||
|
UART_ENTER_CRITICAL(&uart_spinlock[uart_num]);
|
||||||
|
UART[uart_num]->flow_conf.sw_flow_con_en = enable? 1:0;
|
||||||
|
UART[uart_num]->flow_conf.xonoff_del = enable?1:0;
|
||||||
|
UART[uart_num]->swfc_conf.xon_threshold = rx_thresh_xon;
|
||||||
|
UART[uart_num]->swfc_conf.xoff_threshold = rx_thresh_xoff;
|
||||||
|
UART[uart_num]->swfc_conf.xon_char = XON;
|
||||||
|
UART[uart_num]->swfc_conf.xoff_char = XOFF;
|
||||||
|
UART_EXIT_CRITICAL(&uart_spinlock[uart_num]);
|
||||||
|
return ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//only when UART_HW_FLOWCTRL_RTS is set , will the rx_thresh value be set.
|
//only when UART_HW_FLOWCTRL_RTS is set , will the rx_thresh value be set.
|
||||||
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh)
|
esp_err_t uart_set_hw_flow_ctrl(uart_port_t uart_num, uart_hw_flowcontrol_t flow_ctrl, uint8_t rx_thresh)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue