# HG changeset patch # User Mychaela Falconia # Date 1615699618 0 # Node ID 0a21a7ffe144a9588e313605ebb091473ae05caf # Parent f6b03af63bf70763cf3b090d2233d8c53adb041e calypso: caltest front end put together diff -r f6b03af63bf7 -r 0a21a7ffe144 .hgignore --- 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$ diff -r f6b03af63bf7 -r 0a21a7ffe144 calypso/Makefile --- 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} diff -r f6b03af63bf7 -r 0a21a7ffe144 calypso/caltest.c --- /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 +#include +#include +#include +#include +#include +#include + +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); +}