cpu/esp32: required uart_set_baudrate changes
Function uart_set_baudrate which is only used internally was made static and renamed to _uart_set_baudrate to indicate that it is an internal function. Furthermore, an additional waiting for flushed TX FIFO added. The reconfiguration is now handled as critical section.
This commit is contained in:
parent
f5da4a1c9f
commit
b42106e738
@ -100,6 +100,7 @@ static struct uart_hw_t _uarts[] = {
|
||||
extern void uart_div_modify(uint8_t uart_no, uint32_t div);
|
||||
|
||||
/* forward declaration of internal functions */
|
||||
static int _uart_set_baudrate(uart_t uart, uint32_t baudrate);
|
||||
static uint8_t IRAM _uart_rx_one_char (uart_t uart);
|
||||
static void _uart_tx_one_char(uart_t uart, uint8_t data);
|
||||
static void _uart_intr_enable (uart_t uart);
|
||||
@ -291,7 +292,7 @@ static void _uart_config (uart_t uart)
|
||||
/* for UART0 and UART1, we can us the ROM function */
|
||||
uart_div_modify(uart, (UART_CLK_FREQ << 4) / _uarts[uart].baudrate);
|
||||
}
|
||||
else if (uart_set_baudrate(uart, _uarts[uart].baudrate) != UART_OK) {
|
||||
else if (_uart_set_baudrate(uart, _uarts[uart].baudrate) != UART_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -318,12 +319,19 @@ static void _uart_config (uart_t uart)
|
||||
}
|
||||
}
|
||||
|
||||
int uart_set_baudrate(uart_t uart, uint32_t baudrate)
|
||||
static int _uart_set_baudrate(uart_t uart, uint32_t baudrate)
|
||||
{
|
||||
DEBUG("%s uart=%d, rate=%d\n", __func__, uart, baudrate);
|
||||
|
||||
CHECK_PARAM_RET (uart < UART_NUMOF, -1);
|
||||
|
||||
/* wait until TX FIFO is empty */
|
||||
while (_uarts[uart].regs->status.txfifo_cnt != 0) { }
|
||||
|
||||
critical_enter();
|
||||
|
||||
_uarts[uart].baudrate = baudrate;
|
||||
|
||||
/* use APB_CLK */
|
||||
_uarts[uart].regs->conf0.tick_ref_always_on = 1;
|
||||
/* compute and set the integral and the decimal part */
|
||||
@ -331,5 +339,6 @@ int uart_set_baudrate(uart_t uart, uint32_t baudrate)
|
||||
_uarts[uart].regs->clk_div.div_int = clk >> 4;
|
||||
_uarts[uart].regs->clk_div.div_frag = clk & 0xf;
|
||||
|
||||
critical_exit();
|
||||
return UART_OK;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user