aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-06-15 15:06:10 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-06-29 13:33:58 -0400
commit292453d3060abf81e13aeb7bc7d76d3c3709da79 (patch)
tree2cec3840a26418b5d84efde4ef8230e44c18c6ac /src
parent1ae78d08e9a7d356c4b8555799ee42c9244c1b7d (diff)
downloadkutter-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')
-rw-r--r--src/avr/serial.c18
-rw-r--r--src/avr/usbserial.c18
-rw-r--r--src/command.c18
-rw-r--r--src/command.h2
-rw-r--r--src/generic/misc.h2
-rw-r--r--src/pru/main.c17
-rw-r--r--src/sam3x8e/serial.c18
-rw-r--r--src/simulator/main.c13
8 files changed, 67 insertions, 39 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)
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 <stddef.h> // size_t
#include <stdint.h> // 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)