projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add ao_alarm
[fw/altos]
/
src
/
ao_serial.c
diff --git
a/src/ao_serial.c
b/src/ao_serial.c
index e926b4e4fb24d656a04fbea8434e2b169440669d..1e3ea3e39b2cd26852d30b18f5a8c5c095070f18 100644
(file)
--- a/
src/ao_serial.c
+++ b/
src/ao_serial.c
@@
-50,6
+50,8
@@
ao_serial_tx1_isr(void) interrupt 14
ao_wakeup(&ao_usart1_tx_fifo);
}
ao_wakeup(&ao_usart1_tx_fifo);
}
+static __pdata serial_echo;
+
char
ao_serial_getchar(void) __critical
{
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);
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;
}
return c;
}
@@
-69,6
+78,13
@@
ao_serial_putchar(char c) __critical
ao_serial_tx1_start();
}
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)
{
static void
send_serial(void)
{
@@
-79,8
+95,24
@@
send_serial(void)
}
}
}
}
+static void
+monitor_serial(void)
+{
+ ao_cmd_hex();
+ serial_echo = ao_cmd_lex_i != 0;
+}
+
+static void
+serial_baud(void)
+{
+ ao_cmd_hex();
+ ao_serial_set_speed(ao_cmd_lex_i);
+}
+
__code struct ao_cmds ao_serial_cmds[] = {
{ 'S', send_serial, "S <data> Send data to serial line" },
__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" },
+ { 'B', serial_baud, "B <0 = 4800, 1 = 57600> Set serial baud rate" },
{ 0, send_serial, NULL },
};
{ 0, send_serial, NULL },
};
@@
-92,6
+124,10
@@
static const struct {
/* .baud = */ 163,
/* .gcr = */ (7 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
},
/* .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
/* [AO_SERIAL_SPEED_57600] = */ {
/* .baud = */ 59,
/* .gcr = */ (11 << UxGCR_BAUD_E_SHIFT) | UxGCR_ORDER_LSB
@@
-101,6
+137,9
@@
static const struct {
void
ao_serial_set_speed(uint8_t speed)
{
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;
}
U1BAUD = ao_serial_speeds[speed].baud;
U1GCR = ao_serial_speeds[speed].gcr;
}