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

@ -16,8 +16,8 @@
#include "common_macros.h"
#include "xtensa_ops.h"
#include "esp/rom.h"
#include "esp/uart.h"
#include "esp/iomux_regs.h"
#include "esp/uart_regs.h"
#include "esp/spi_regs.h"
#include "esp/dport_regs.h"
#include "esp/wdev_regs.h"
@ -30,7 +30,6 @@
void user_init(void);
#define UART_DIVISOR 1068 // 74906 bps (yeah, I don't understand it either)
#define BOOT_INFO_SIZE 28
//TODO: phy_info should probably be a struct (no idea about its organization, though)
#define PHY_INFO_SIZE 128
@ -293,8 +292,8 @@ static void init_networking(uint8_t *phy_info, uint8_t *mac_addr) {
printf("FATAL: sdk_register_chipv6_phy failed");
halt();
}
sdk_uart_div_modify(0, UART_DIVISOR);
sdk_uart_div_modify(1, UART_DIVISOR);
uart_set_baud(0, 115200);
uart_set_baud(1, 115200);
sdk_phy_disable_agc();
sdk_ieee80211_phy_init(sdk_g_ic.s.phy_mode);
sdk_lmacInit();

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 */