diff options
author | Keith Packard <keithp@keithp.com> | 2017-04-28 00:02:54 -0700 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-04-28 00:02:54 -0700 |
commit | ac3fc7da669f58c7abd25b0ca8cc425238b84217 (patch) | |
tree | 962f7f44321614e628558ecd42021dff5b5539ca | |
parent | 7d4f7880b0934c208df65cea8b0f549f32f1c7d2 (diff) |
altos/stmf0: Compute serial baud rate registers at runtime
This allows the system clock to vary at runtime, instead of requiring
a fixed value.
Signed-off-by: Keith Packard <keithp@keithp.com>
-rw-r--r-- | src/stmf0/ao_serial_stm.c | 26 |
1 files changed, 7 insertions, 19 deletions
diff --git a/src/stmf0/ao_serial_stm.c b/src/stmf0/ao_serial_stm.c index 30b0dbd2..06fc054a 100644 --- a/src/stmf0/ao_serial_stm.c +++ b/src/stmf0/ao_serial_stm.c @@ -163,24 +163,12 @@ ao_usart_drain(struct ao_stm_usart *usart) ao_arch_release_interrupts(); } -static const struct { - uint32_t brr; -} ao_usart_speeds[] = { - [AO_SERIAL_SPEED_4800] = { - AO_PCLK / 4800 - }, - [AO_SERIAL_SPEED_9600] = { - AO_PCLK / 9600 - }, - [AO_SERIAL_SPEED_19200] = { - AO_PCLK / 19200 - }, - [AO_SERIAL_SPEED_57600] = { - AO_PCLK / 57600 - }, - [AO_SERIAL_SPEED_115200] = { - AO_PCLK / 115200 - }, +static const uint32_t ao_usart_speeds[] = { + [AO_SERIAL_SPEED_4800] = 4800, + [AO_SERIAL_SPEED_9600] = 9600, + [AO_SERIAL_SPEED_19200] = 19200, + [AO_SERIAL_SPEED_57600] = 57600, + [AO_SERIAL_SPEED_115200] = 115200, }; static void @@ -188,7 +176,7 @@ ao_usart_set_speed(struct ao_stm_usart *usart, uint8_t speed) { if (speed > AO_SERIAL_SPEED_115200) return; - usart->reg->brr = ao_usart_speeds[speed].brr; + usart->reg->brr = AO_PCLK / ao_usart_speeds[speed]; } static void |