diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-06-15 15:06:10 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-06-29 13:33:58 -0400 |
commit | 292453d3060abf81e13aeb7bc7d76d3c3709da79 (patch) | |
tree | 2cec3840a26418b5d84efde4ef8230e44c18c6ac /src/avr | |
parent | 1ae78d08e9a7d356c4b8555799ee42c9244c1b7d (diff) | |
download | kutter-292453d3060abf81e13aeb7bc7d76d3c3709da79.tar.gz kutter-292453d3060abf81e13aeb7bc7d76d3c3709da79.tar.xz kutter-292453d3060abf81e13aeb7bc7d76d3c3709da79.zip |
command: Move command_task() to board specific code
Move the command_task() code from the generic code to the board
specific code. This enables more flexibility in how the board
specific code processes input.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/avr')
-rw-r--r-- | src/avr/serial.c | 18 | ||||
-rw-r--r-- | src/avr/usbserial.c | 18 |
2 files changed, 32 insertions, 4 deletions
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) |