diff --git a/src/avr/serial.c b/src/avr/serial.c index 3221b6f0..213b10ed 100644 --- a/src/avr/serial.c +++ b/src/avr/serial.c @@ -92,7 +92,7 @@ enable_tx_irq(void) ****************************************************************/ // Return a buffer (and length) containing any incoming messages -char * +static char * console_get_input(uint8_t *plen) { *plen = readb(&receive_pos); @@ -100,7 +100,7 @@ console_get_input(uint8_t *plen) } // Remove from the receive buffer the given number of bytes -void +static void console_pop_input(uint8_t len) { uint8_t copied = 0; @@ -124,6 +124,20 @@ console_pop_input(uint8_t len) } } +// Process any incoming commands +void +console_task(void) +{ + uint8_t buf_len, pop_count; + char *buf = console_get_input(&buf_len); + int8_t ret = command_find_block(buf, buf_len, &pop_count); + if (ret > 0) + command_dispatch(buf, pop_count); + if (ret) + console_pop_input(pop_count); +} +DECL_TASK(console_task); + // Return an output buffer that the caller may fill with transmit messages char * console_get_output(uint8_t len) diff --git a/src/avr/usbserial.c b/src/avr/usbserial.c index 3b14ea0a..78ef719e 100644 --- a/src/avr/usbserial.c +++ b/src/avr/usbserial.c @@ -22,7 +22,7 @@ usbserial_init(void) DECL_INIT(usbserial_init); // Return a buffer (and length) containing any incoming messages -char * +static char * console_get_input(uint8_t *plen) { for (;;) { @@ -38,7 +38,7 @@ console_get_input(uint8_t *plen) } // Remove from the receive buffer the given number of bytes -void +static void console_pop_input(uint8_t len) { uint8_t needcopy = receive_pos - len; @@ -47,6 +47,20 @@ console_pop_input(uint8_t len) receive_pos = needcopy; } +// Process any incoming commands +void +console_task(void) +{ + uint8_t buf_len, pop_count; + char *buf = console_get_input(&buf_len); + int8_t ret = command_find_block(buf, buf_len, &pop_count); + if (ret > 0) + command_dispatch(buf, pop_count); + if (ret) + console_pop_input(pop_count); +} +DECL_TASK(console_task); + // Return an output buffer that the caller may fill with transmit messages char * console_get_output(uint8_t len) diff --git a/src/command.c b/src/command.c index 6bc42bed..709e75c4 100644 --- a/src/command.c +++ b/src/command.c @@ -231,7 +231,7 @@ command_lookup_parser(uint8_t cmdid) enum { CF_NEED_SYNC=1<<0, CF_NEED_VALID=1<<1 }; // Find the next complete message. -static int8_t +int8_t command_find_block(char *buf, uint8_t buf_len, uint8_t *pop_count) { static uint8_t sync_state; @@ -293,7 +293,7 @@ nak: } // Dispatch all the commands found in a message block -static void +void command_dispatch(char *buf, uint8_t msglen) { char *p = &buf[MESSAGE_HEADER_SIZE]; @@ -312,17 +312,3 @@ command_dispatch(char *buf, uint8_t msglen) func(args); } } - -// Background task that reads commands from the board serial port -void -command_task(void) -{ - uint8_t buf_len, pop_count; - char *buf = console_get_input(&buf_len); - uint8_t ret = command_find_block(buf, buf_len, &pop_count); - if (ret > 0) - command_dispatch(buf, pop_count); - if (ret) - console_pop_input(pop_count); -} -DECL_TASK(command_task); diff --git a/src/command.h b/src/command.h index 5bd6faf4..f2d90ee4 100644 --- a/src/command.h +++ b/src/command.h @@ -35,6 +35,8 @@ // command.c struct command_encoder; void _sendf(const struct command_encoder *ce, ...); +int8_t command_find_block(char *buf, uint8_t buf_len, uint8_t *pop_count); +void command_dispatch(char *buf, uint8_t msglen); // out/compile_time_request.c (auto generated file) struct command_encoder { diff --git a/src/generic/misc.h b/src/generic/misc.h index 4408a34a..9847e9a9 100644 --- a/src/generic/misc.h +++ b/src/generic/misc.h @@ -4,8 +4,6 @@ #include // size_t #include // uint8_t -char *console_get_input(uint8_t *plen); -void console_pop_input(uint8_t len); char *console_get_output(uint8_t len); void console_push_output(uint8_t len); diff --git a/src/pru/main.c b/src/pru/main.c index 9a132a02..cebcaa26 100644 --- a/src/pru/main.c +++ b/src/pru/main.c @@ -100,7 +100,7 @@ DECL_INIT(timer_init); ****************************************************************/ // Return a buffer (and length) containing any incoming messages -char * +static char * console_get_input(uint8_t *plen) { uint32_t read_count = readl(&SHARED_MEM->read_count); @@ -111,12 +111,25 @@ console_get_input(uint8_t *plen) } // Remove from the receive buffer the given number of bytes -void +static void console_pop_input(uint8_t len) { writel(&SHARED_MEM->read_count, 0); } +// Process any incoming commands +void +console_task(void) +{ + uint8_t buf_len, pop_count; + char *buf = console_get_input(&buf_len); + int8_t ret = command_find_block(buf, buf_len, &pop_count); + if (ret) + command_dispatch(buf, pop_count); + console_pop_input(pop_count); +} +DECL_TASK(console_task); + // Return an output buffer that the caller may fill with transmit messages char * console_get_output(uint8_t len) diff --git a/src/sam3x8e/serial.c b/src/sam3x8e/serial.c index 652d54d4..c0653443 100644 --- a/src/sam3x8e/serial.c +++ b/src/sam3x8e/serial.c @@ -83,7 +83,7 @@ enable_tx_irq(void) ****************************************************************/ // Return a buffer (and length) containing any incoming messages -char * +static char * console_get_input(uint8_t *plen) { *plen = readl(&receive_pos); @@ -91,7 +91,7 @@ console_get_input(uint8_t *plen) } // Remove from the receive buffer the given number of bytes -void +static void console_pop_input(uint8_t len) { uint32_t copied = 0; @@ -115,6 +115,20 @@ console_pop_input(uint8_t len) } } +// Process any incoming commands +void +console_task(void) +{ + uint8_t buf_len, pop_count; + char *buf = console_get_input(&buf_len); + int8_t ret = command_find_block(buf, buf_len, &pop_count); + if (ret > 0) + command_dispatch(buf, pop_count); + if (ret) + console_pop_input(pop_count); +} +DECL_TASK(console_task); + // Return an output buffer that the caller may fill with transmit messages char * console_get_output(uint8_t len) diff --git a/src/simulator/main.c b/src/simulator/main.c index 47dd49f4..bdad1a6a 100644 --- a/src/simulator/main.c +++ b/src/simulator/main.c @@ -85,19 +85,6 @@ timer_read_time(void) * Turn stdin/stdout into serial console ****************************************************************/ -// XXX -char * -console_get_input(uint8_t *plen) -{ - *plen = 0; - return NULL; -} - -void -console_pop_input(uint8_t len) -{ -} - // Return an output buffer that the caller may fill with transmit messages char * console_get_output(uint8_t len)