X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fao_serial.c;h=4155e776934ac59f196e67642aa23d462d011025;hb=91b023e7e4eeed838e0320d2ddac0f6aac39e565;hp=f2f5e69736e6540f07572d90b9ba45a163337059;hpb=a1da7e871aee75308bc05ce1b7a0dc402e4c9509;p=fw%2Faltos diff --git a/src/ao_serial.c b/src/ao_serial.c index f2f5e697..4155e776 100644 --- a/src/ao_serial.c +++ b/src/ao_serial.c @@ -60,7 +60,7 @@ ao_serial_getchar(void) __critical ao_sleep(&ao_usart1_rx_fifo); ao_fifo_remove(ao_usart1_rx_fifo, c); if (serial_echo) { - printf("%02x\n", (uint8_t) c); + printf("%02x\n", ((int) c) & 0xff); flush(); } return c; @@ -75,6 +75,13 @@ ao_serial_putchar(char c) __critical ao_serial_tx1_start(); } +static void +ao_serial_drain(void) __critical +{ + while (!ao_fifo_empty(ao_usart1_tx_fifo)) + ao_sleep(&ao_usart1_tx_fifo); +} + static void send_serial(void) { @@ -115,6 +122,9 @@ static const struct { void ao_serial_set_speed(uint8_t speed) { + ao_serial_drain(); + if (speed > AO_SERIAL_SPEED_57600) + return; U1BAUD = ao_serial_speeds[speed].baud; U1GCR = ao_serial_speeds[speed].gcr; }