Fix buggy UART baudrate calculation in the RL78 UART driver.

This commit is contained in:
Ian Martin 2014-01-22 18:41:55 -05:00
parent 2e69d024a5
commit 00468a3f53

View file

@ -39,13 +39,12 @@
#include "uart0.h"
#define DESIRED_BAUDRATE 9600
#define FUDGE_FACTOR 4
/* Note that only 9600 and 115200 bps were tested: */
#define PRESCALE_THRESH ((9600 + 115200) / 2)
/* Note that only 9600, 38400, and 115200 bps were tested. */
#define PRESCALE_THRESH ((38400 + 115200) / 2)
#define PRS_VALUE ((DESIRED_BAUDRATE < PRESCALE_THRESH) ? 4 : 0)
#define f_MCK (f_CLK / (1 << PRS_VALUE) / FUDGE_FACTOR)
#define SDR_VALUE ((f_MCK / DESIRED_BAUDRATE) >> 1)
#define f_MCK (f_CLK / (1 << PRS_VALUE))
#define SDR_VALUE (f_MCK / DESIRED_BAUDRATE / 2 - 1)
void
uart0_init(void)