mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-01 19:54:32 +02:00
fix set UART_FORCE_XOFF
can't stop new Tx request issue
This commit is contained in:
@@ -232,20 +232,17 @@ static void IRAM_ATTR flush_uarts(void)
|
|||||||
static void IRAM_ATTR suspend_uarts(void)
|
static void IRAM_ATTR suspend_uarts(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SOC_UART_NUM; ++i) {
|
for (int i = 0; i < SOC_UART_NUM; ++i) {
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
#ifndef CONFIG_IDF_TARGET_ESP32
|
||||||
/* Note: Set `UART_FORCE_XOFF` can't stop new Tx request. */
|
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) continue;
|
||||||
REG_SET_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XOFF);
|
#endif
|
||||||
while (REG_GET_FIELD(UART_STATUS_REG(i), UART_ST_UTX_OUT) != 0) {
|
uart_ll_force_xoff(i);
|
||||||
;
|
#if SOC_UART_SUPPORT_FSM_TX_WAIT_SEND
|
||||||
}
|
uint32_t uart_fsm = 0;
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
do {
|
||||||
if (periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
|
uart_fsm = uart_ll_get_fsm_status(i);
|
||||||
REG_CLR_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XON);
|
} while (!(uart_fsm == UART_FSM_IDLE || uart_fsm == UART_FSM_TX_WAIT_SEND));
|
||||||
REG_SET_BIT(UART_FLOW_CONF_REG(i), UART_SW_FLOW_CON_EN | UART_FORCE_XOFF);
|
#else
|
||||||
while (REG_GET_FIELD(UART_FSM_STATUS_REG(i), UART_ST_UTX_OUT) != 0) {
|
while (uart_ll_get_fsm_status(i) != 0) {}
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,17 +250,10 @@ static void IRAM_ATTR suspend_uarts(void)
|
|||||||
static void IRAM_ATTR resume_uarts(void)
|
static void IRAM_ATTR resume_uarts(void)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < SOC_UART_NUM; ++i) {
|
for (int i = 0; i < SOC_UART_NUM; ++i) {
|
||||||
#ifdef CONFIG_IDF_TARGET_ESP32
|
#ifndef CONFIG_IDF_TARGET_ESP32
|
||||||
REG_CLR_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XOFF);
|
if (!periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) continue;
|
||||||
REG_SET_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XON);
|
|
||||||
REG_CLR_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XON);
|
|
||||||
#elif CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3
|
|
||||||
if (periph_ll_periph_enabled(PERIPH_UART0_MODULE + i)) {
|
|
||||||
REG_CLR_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XOFF);
|
|
||||||
REG_SET_BIT(UART_FLOW_CONF_REG(i), UART_FORCE_XON);
|
|
||||||
REG_CLR_BIT(UART_FLOW_CONF_REG(i), UART_SW_FLOW_CON_EN | UART_FORCE_XON);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
uart_ll_force_xon(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -894,6 +894,45 @@ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
|
|||||||
return tout_thrd;
|
return tout_thrd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xoff.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xoff(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
/* Note: Set `UART_FORCE_XOFF` can't stop new Tx request. */
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XOFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xon.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xon(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XOFF);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get UART final state machine status.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return UART module FSM status.
|
||||||
|
*/
|
||||||
|
static inline uint32_t uart_ll_get_fsm_status(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
return REG_GET_FIELD(UART_STATUS_REG(uart_num), UART_ST_UTX_OUT);
|
||||||
|
}
|
||||||
|
|
||||||
#undef UART_LL_TOUT_REF_FACTOR_DEFAULT
|
#undef UART_LL_TOUT_REF_FACTOR_DEFAULT
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@@ -884,6 +884,47 @@ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
|
|||||||
return UART_RX_TOUT_THRHD_V;
|
return UART_RX_TOUT_THRHD_V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xoff.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xoff(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_SW_FLOW_CON_EN | UART_FORCE_XOFF);
|
||||||
|
REG_SET_BIT(UART_ID_REG(uart_num), UART_UPDATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xon.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xon(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XOFF);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_SW_FLOW_CON_EN | UART_FORCE_XON);
|
||||||
|
REG_SET_BIT(UART_ID_REG(uart_num), UART_UPDATE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get UART final state machine status.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return UART module FSM status.
|
||||||
|
*/
|
||||||
|
static inline uint32_t uart_ll_get_fsm_status(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
return REG_GET_FIELD(UART_FSM_STATUS_REG(uart_num), UART_ST_UTX_OUT);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -826,6 +826,45 @@ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
|
|||||||
return UART_RX_TOUT_THRHD_V;
|
return UART_RX_TOUT_THRHD_V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xoff.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xoff(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_SW_FLOW_CON_EN | UART_FORCE_XOFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xon.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xon(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XOFF);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_SW_FLOW_CON_EN | UART_FORCE_XON);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get UART final state machine status.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return UART module FSM status.
|
||||||
|
*/
|
||||||
|
static inline uint32_t uart_ll_get_fsm_status(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
return REG_GET_FIELD(UART_FSM_STATUS_REG(uart_num), UART_ST_UTX_OUT);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -852,6 +852,45 @@ static inline uint16_t uart_ll_max_tout_thrd(uart_dev_t *hw)
|
|||||||
return UART_RX_TOUT_THRHD_V;
|
return UART_RX_TOUT_THRHD_V;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xoff.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xoff(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_SW_FLOW_CON_EN | UART_FORCE_XOFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Force UART xon.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return None.
|
||||||
|
*/
|
||||||
|
static inline void uart_ll_force_xon(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XOFF);
|
||||||
|
REG_SET_BIT(UART_FLOW_CONF_REG(uart_num), UART_FORCE_XON);
|
||||||
|
REG_CLR_BIT(UART_FLOW_CONF_REG(uart_num), UART_SW_FLOW_CON_EN | UART_FORCE_XON);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get UART final state machine status.
|
||||||
|
*
|
||||||
|
* @param uart_num UART port number, the max port number is (UART_NUM_MAX -1).
|
||||||
|
*
|
||||||
|
* @return UART module FSM status.
|
||||||
|
*/
|
||||||
|
static inline uint32_t uart_ll_get_fsm_status(uart_port_t uart_num)
|
||||||
|
{
|
||||||
|
return REG_GET_FIELD(UART_FSM_STATUS_REG(uart_num), UART_ST_UTX_OUT);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@@ -27,6 +27,11 @@ extern "C" {
|
|||||||
// ESP32-C3 have 2 UART
|
// ESP32-C3 have 2 UART
|
||||||
#define SOC_UART_NUM (2)
|
#define SOC_UART_NUM (2)
|
||||||
|
|
||||||
|
// UART has an extra TX_WAIT_SEND state when the FIFO is not empty and XOFF is enabled
|
||||||
|
#define SOC_UART_SUPPORT_FSM_TX_WAIT_SEND (1)
|
||||||
|
#define UART_FSM_IDLE (0x0)
|
||||||
|
#define UART_FSM_TX_WAIT_SEND (0xf)
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user