mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
Fix rounding error in baudrate calculation.
This commit is contained in:
parent
e3c19714d4
commit
1ceb8ae358
@ -71,7 +71,11 @@
|
|||||||
#define UART_CLOCK_RATE 16000000 /* 16 MHz */
|
#define UART_CLOCK_RATE 16000000 /* 16 MHz */
|
||||||
#define UART_CTL_HSE_VALUE 0
|
#define UART_CTL_HSE_VALUE 0
|
||||||
#define UART_CTL_VALUE ( UART_CTL_RXE | UART_CTL_TXE | (UART_CTL_HSE_VALUE << 5) )
|
#define UART_CTL_VALUE ( UART_CTL_RXE | UART_CTL_TXE | (UART_CTL_HSE_VALUE << 5) )
|
||||||
#define BAUD2BRD(baud) ( (UART_CLOCK_RATE << (UART_CTL_HSE_VALUE + 2)) / (baud) )
|
|
||||||
|
/* DIV_ROUND() divides integers while avoiding a rounding error: */
|
||||||
|
#define DIV_ROUND(num, denom) ( ((num) + (denom) / 2) / (denom) )
|
||||||
|
|
||||||
|
#define BAUD2BRD(baud) DIV_ROUND(UART_CLOCK_RATE << (UART_CTL_HSE_VALUE + 2), (baud))
|
||||||
|
|
||||||
#define uart_set_baudrate(baud) ( \
|
#define uart_set_baudrate(baud) ( \
|
||||||
REG(UART_BASE | UART_IBRD) = BAUD2BRD(baud) >> 6, \
|
REG(UART_BASE | UART_IBRD) = BAUD2BRD(baud) >> 6, \
|
||||||
|
Loading…
Reference in New Issue
Block a user