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 ", ((int) c) & 0xff);
+ if (c >= ' ')
+ putchar(c);
+ putchar('\n');
flush();
}
return c;
}
static void
-send_serial(void)
+ao_serial_drain(void) __critical
{
- ao_cmd_white();
- while (ao_cmd_lex_c != '\n') {
- ao_serial_putchar(ao_cmd_lex_c);
- ao_cmd_lex();
- }
+ while (!ao_fifo_empty(ao_usart1_tx_fifo))
+ ao_sleep(&ao_usart1_tx_fifo);
}
static void
}
__code struct ao_cmds ao_serial_cmds[] = {
- { 'S', send_serial, "S <data> Send data to serial line" },
{ 'M', monitor_serial, "M <enable> Monitor serial data" },
- { 0, send_serial, NULL },
+ { 0, monitor_serial, NULL },
};
static const struct {
/* .baud = */ 163,
/* .gcr = */ (7 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
},
+ /* [AO_SERIAL_SPEED_9600] = */ {
+ /* .baud = */ 163,
+ /* .gcr = */ (8 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
+ },
/* [AO_SERIAL_SPEED_57600] = */ {
/* .baud = */ 59,
/* .gcr = */ (11 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
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;
}