X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fao_serial.c;h=dd383fca18ff141a5ffd7c0af0f923f746437eca;hp=e926b4e4fb24d656a04fbea8434e2b169440669d;hb=8cdf4fb051c22b35c251d90bc288551f7c2898bf;hpb=34f148500df427c148188c0ada20bf914a7c74ba diff --git a/src/ao_serial.c b/src/ao_serial.c index e926b4e4..dd383fca 100644 --- a/src/ao_serial.c +++ b/src/ao_serial.c @@ -21,7 +21,7 @@ volatile __xdata struct ao_fifo ao_usart1_rx_fifo; volatile __xdata struct ao_fifo ao_usart1_tx_fifo; void -ao_serial_rx1_isr(void) interrupt 3 +ao_serial_rx1_isr(void) __interrupt 3 { if (!ao_fifo_full(ao_usart1_rx_fifo)) ao_fifo_insert(ao_usart1_rx_fifo, U1DBUF); @@ -42,7 +42,7 @@ ao_serial_tx1_start(void) } void -ao_serial_tx1_isr(void) interrupt 14 +ao_serial_tx1_isr(void) __interrupt 14 { UTX1IF = 0; ao_serial_tx1_started = 0; @@ -50,6 +50,8 @@ ao_serial_tx1_isr(void) interrupt 14 ao_wakeup(&ao_usart1_tx_fifo); } +static __pdata serial_echo; + char ao_serial_getchar(void) __critical { @@ -57,6 +59,13 @@ ao_serial_getchar(void) __critical while (ao_fifo_empty(ao_usart1_rx_fifo)) ao_sleep(&ao_usart1_rx_fifo); ao_fifo_remove(ao_usart1_rx_fifo, c); + if (serial_echo) { + printf("%02x ", ((int) c) & 0xff); + if (c >= ' ') + putchar(c); + putchar('\n'); + flush(); + } return c; } @@ -70,18 +79,22 @@ ao_serial_putchar(char c) __critical } 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 +monitor_serial(void) +{ + ao_cmd_hex(); + serial_echo = ao_cmd_lex_i != 0; } __code struct ao_cmds ao_serial_cmds[] = { - { 'S', send_serial, "S Send data to serial line" }, - { 0, send_serial, NULL }, + { monitor_serial, "M \0Monitor serial data" }, + { 0, NULL }, }; static const struct { @@ -92,6 +105,10 @@ 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 @@ -101,6 +118,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; }