uart.h: Add uart_get_baud/uart_set_baud functions, change default baud rate from 74906 to 115200

This commit is contained in:
Angus Gratton 2015-10-06 17:06:56 +11:00
parent 707d0ed981
commit 3ceadfc0a6
14 changed files with 18 additions and 42 deletions

View file

@ -11,6 +11,7 @@
#include "esp/types.h"
#include "esp/uart_regs.h"
#include "esp/clocks.h"
#define UART_FIFO_MAX 127
@ -110,4 +111,17 @@ static inline void uart_flush_rxfifo(int uart_num) {
uart_clear_rxfifo(uart_num);
}
/* Set uart baud rate to the desired value */
static inline void uart_set_baud(int uart_num, int bps)
{
uint32_t divider = APB_CLK_FREQ / bps;
UART(uart_num).CLOCK_DIVIDER = divider;
}
/* Returns the current baud rate for the UART */
static inline int uart_get_baud(int uart_num)
{
return APB_CLK_FREQ / FIELD2VAL(UART_CLOCK_DIVIDER_VALUE, UART(uart_num).CLOCK_DIVIDER);
}
#endif /* _ESP_UART_H */