changeset 6:0a21a7ffe144

calypso: caltest front end put together
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 05:26:58 +0000
parents f6b03af63bf7
children b25d4dfe5798
files .hgignore calypso/Makefile calypso/caltest.c
diffstat 3 files changed, 62 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Mar 14 05:15:49 2021 +0000
+++ b/.hgignore	Sun Mar 14 05:26:58 2021 +0000
@@ -2,6 +2,7 @@
 
 \.[oa]$
 
+^calypso/caltest$
 ^calypso/fcsim-calypso-be$
 
 ^pcsc/fc-pcsc-atr$
--- a/calypso/Makefile	Sun Mar 14 05:15:49 2021 +0000
+++ b/calypso/Makefile	Sun Mar 14 05:26:58 2021 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	fcsim-calypso-be
+PROGS=	fcsim-calypso-be caltest
 
 INSTALL_PREFIX=	/opt/freecalypso
 
@@ -13,6 +13,9 @@
 fcsim-calypso-be:	${MAIN_OBJS}
 	${CC} ${CFLAGS} -o $@ ${MAIN_OBJS}
 
+caltest:	caltest.c
+	${CC} ${CFLAGS} -o $@ $@.c
+
 install:
 	mkdir -p ${INSTBIN}
 	install -c fcsim-calypso-be ${INSTBIN}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/calypso/caltest.c	Sun Mar 14 05:26:58 2021 +0000
@@ -0,0 +1,57 @@
+#include <sys/types.h>
+#include <sys/file.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int target_fd;
+
+open_serial_port(ttyport)
+	char *ttyport;
+{
+	target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
+	if (target_fd < 0) {
+		perror(ttyport);
+		exit(1);
+	}
+	ioctl(target_fd, TIOCEXCL);
+	return 0;
+}
+
+set_termios()
+{
+	struct termios target_termios;
+
+	target_termios.c_iflag = IGNBRK;
+	target_termios.c_oflag = 0;
+	target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8;
+	target_termios.c_lflag = 0;
+	target_termios.c_cc[VMIN] = 1;
+	target_termios.c_cc[VTIME] = 0;
+	cfsetispeed(&target_termios, B115200);
+	cfsetospeed(&target_termios, B115200);
+	if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
+		perror("tcsetattr");
+		exit(1);
+	}
+	return 0;
+}
+
+main(argc, argv)
+	char **argv;
+{
+	char c_arg[16];
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s ttyport second-prog\n", argv[0]);
+		exit(1);
+	}
+	open_serial_port(argv[1]);
+	set_termios();
+	sprintf(c_arg, "-C%d", target_fd);
+	execl(argv[2], argv[2], c_arg, (char *) 0);
+	perror(argv[2]);
+	exit(1);
+}