summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--linux/.clangd0
-rwxr-xr-xlinux/mainbin0 -> 16784 bytes
-rw-r--r--linux/main.c132
-rw-r--r--ppc/.clangd (renamed from .clangd)0
-rw-r--r--ppc/Makefile (renamed from Makefile)0
-rw-r--r--ppc/fire-pit/test.c (renamed from fire-pit/test.c)0
-rw-r--r--ppc/fire-pit/test.h (renamed from fire-pit/test.h)0
-rw-r--r--ppc/source/macros.h (renamed from source/macros.h)0
-rw-r--r--ppc/source/state.h (renamed from source/state.h)0
-rw-r--r--ppc/source/states/menu.c (renamed from source/states/menu.c)0
-rw-r--r--ppc/source/template.c (renamed from source/template.c)0
-rw-r--r--ppc/source/term.h (renamed from source/term.h)0
-rw-r--r--ppc/source/test-impl.inc.h (renamed from source/test-impl.inc.h)0
-rw-r--r--ppc/source/test.c (renamed from source/test.c)0
-rw-r--r--ppc/source/test.h (renamed from source/test.h)0
-rw-r--r--ppc/source/tests/basic.c (renamed from source/tests/basic.c)0
-rw-r--r--ppc/source/tests/led.c (renamed from source/tests/led.c)0
17 files changed, 132 insertions, 0 deletions
diff --git a/linux/.clangd b/linux/.clangd
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/linux/.clangd
diff --git a/linux/main b/linux/main
new file mode 100755
index 0000000..e84e0b9
--- /dev/null
+++ b/linux/main
Binary files differ
diff --git a/linux/main.c b/linux/main.c
new file mode 100644
index 0000000..bd208f2
--- /dev/null
+++ b/linux/main.c
@@ -0,0 +1,132 @@
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <poll.h>
+
+#ifdef DEBUG_MESSAGE
+#define DEBUG(_s, ...) fprintf(stderr, _s, ## __VA_ARGS__)
+#else
+#define DEBUG(_s, ...)
+#endif
+
+#define elt0(_exp) ((_exp) < 0)
+#define check(_x, _cond, ...) do { if (_cond(_x)) { fatal_error(__VA_ARGS__); } } while (0)
+#define fatal_error(...) do { fprintf(stderr, __VA_ARGS__); exit(1); } while (0)
+
+#define GECKO_BAUD B115200
+
+static int setup_term(const char *name) {
+ int fd;
+ int flags;
+ struct termios tio;
+
+#define O(_ex, _m) check(_ex, elt0, "error " _m " %s: %s\n", name, strerror(errno))
+
+ O(fd = openat(AT_FDCWD, name, O_RDWR | O_NOCTTY), "opening");
+ O(tcgetattr(fd, &tio), "getting tio attrs for");
+ O(cfsetispeed(&tio, GECKO_BAUD), "setting ispeed of");
+ O(cfsetospeed(&tio, GECKO_BAUD), "setting ospeed of");
+
+ tio.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL | IXON);
+ tio.c_oflag &= ~OPOST;
+ tio.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
+ tio.c_cflag &= ~(CSIZE | PARENB);
+ tio.c_cflag |= CS8;
+
+ O(tcsetattr(fd, TCSANOW, &tio), "setting tio attrs for");
+
+ O(flags = fcntl(fd, F_GETFL), "getting stream status for");
+ flags |= O_NONBLOCK;
+ O(fcntl(fd, F_SETFL, flags), "setting stream status for");
+
+#undef O
+
+ return fd;
+}
+
+static void handle_command(const char *cmd) {
+
+}
+
+int main(int argc, char **argv) {
+ struct termios tio;
+ int tfd;
+ unsigned char buf[1024];
+ char cmdbuf[1024];
+ struct pollfd fds[2];
+ int infd;
+ int flags;
+ int can_write = 0;
+ size_t partialcmd_sz = 0;
+
+ int test_mode = 0;
+
+ if (argc != 2) {
+ fprintf(stderr, "Usage: %s <term>\n", argv[0]);
+ return 1;
+ }
+
+ tfd = setup_term(argv[1]);
+
+ check(infd = dup(STDIN_FILENO), elt0, "error duplicating stdin: %s\n", strerror(errno));
+ check(flags = fcntl(infd, F_GETFL), elt0, "error getting stream status for stdin: %s\n", strerror(errno));
+ flags |= O_NONBLOCK;
+ check(fcntl(infd, F_SETFL, flags), elt0, "setting stream status for stdin: %s\n", strerror(errno));
+
+ fds[0].fd = tfd;
+ fds[0].events = POLLIN | POLLOUT;
+
+ fds[1].fd = STDIN_FILENO;
+ fds[1].events = POLLIN;
+
+ while (1) {
+ int nready;
+ check(nready = poll(fds, 2, -1), elt0, "poll()ing: %s\n", strerror(errno));
+
+ if (nready == 0) continue;
+
+ for (nfds_t i = 0; i < 2; ++i) {
+ if (fds[i].revents & (POLLERR | POLLHUP)) {
+ fatal_error("stream error or hangup condition on %d\n", fds[i].fd);
+ }
+
+ if (fds[i].revents & POLLIN) {
+ ssize_t nread;
+ while ((nread = read(fds[i].fd, buf, 1024)) > 0) {
+ if (fds[i].fd == infd) {
+ /* command */
+ for (ssize_t cidx = 0; cidx < nread; ++i) {
+ /* TODO: split command by lines */
+ }
+ } else {
+ /* gecko */
+
+ }
+ check(write(STDOUT_FILENO, buf, nread), elt0, "write(%d) failed: %s\n", STDOUT_FILENO, strerror(errno));
+ }
+
+ if (nread == 0 && fds[i].fd == tfd) {
+ fatal_error("EOF reached on terminal.\n");
+ }
+
+ if (nread < 0 && errno != EAGAIN) {
+ fatal_error("io error on fd %d: %s\n", fds[i].fd, strerror(errno));
+ }
+ }
+
+ if (fds[i].revents & POLLOUT) {
+ fds[i].events &= ~POLLOUT;
+ can_write = 1;
+ }
+ }
+ }
+
+ close(tfd);
+ close(infd);
+
+ return 0;
+}
diff --git a/.clangd b/ppc/.clangd
index ed00e13..ed00e13 100644
--- a/.clangd
+++ b/ppc/.clangd
diff --git a/Makefile b/ppc/Makefile
index f896f14..f896f14 100644
--- a/Makefile
+++ b/ppc/Makefile
diff --git a/fire-pit/test.c b/ppc/fire-pit/test.c
index 822db4f..822db4f 100644
--- a/fire-pit/test.c
+++ b/ppc/fire-pit/test.c
diff --git a/fire-pit/test.h b/ppc/fire-pit/test.h
index c907530..c907530 100644
--- a/fire-pit/test.h
+++ b/ppc/fire-pit/test.h
diff --git a/source/macros.h b/ppc/source/macros.h
index 9a9db83..9a9db83 100644
--- a/source/macros.h
+++ b/ppc/source/macros.h
diff --git a/source/state.h b/ppc/source/state.h
index 2f70527..2f70527 100644
--- a/source/state.h
+++ b/ppc/source/state.h
diff --git a/source/states/menu.c b/ppc/source/states/menu.c
index ea5134b..ea5134b 100644
--- a/source/states/menu.c
+++ b/ppc/source/states/menu.c
diff --git a/source/template.c b/ppc/source/template.c
index 8665774..8665774 100644
--- a/source/template.c
+++ b/ppc/source/template.c
diff --git a/source/term.h b/ppc/source/term.h
index cc65615..cc65615 100644
--- a/source/term.h
+++ b/ppc/source/term.h
diff --git a/source/test-impl.inc.h b/ppc/source/test-impl.inc.h
index 8e1559f..8e1559f 100644
--- a/source/test-impl.inc.h
+++ b/ppc/source/test-impl.inc.h
diff --git a/source/test.c b/ppc/source/test.c
index c59deaf..c59deaf 100644
--- a/source/test.c
+++ b/ppc/source/test.c
diff --git a/source/test.h b/ppc/source/test.h
index 81a107a..81a107a 100644
--- a/source/test.h
+++ b/ppc/source/test.h
diff --git a/source/tests/basic.c b/ppc/source/tests/basic.c
index 4f34ba4..4f34ba4 100644
--- a/source/tests/basic.c
+++ b/ppc/source/tests/basic.c
diff --git a/source/tests/led.c b/ppc/source/tests/led.c
index 82913ae..82913ae 100644
--- a/source/tests/led.c
+++ b/ppc/source/tests/led.c