FreeCalypso > hg > fc-sim-tools
comparison calypso/caltest.c @ 6:0a21a7ffe144
calypso: caltest front end put together
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 05:26:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5:f6b03af63bf7 | 6:0a21a7ffe144 |
---|---|
1 #include <sys/types.h> | |
2 #include <sys/file.h> | |
3 #include <sys/ioctl.h> | |
4 #include <termios.h> | |
5 #include <stdio.h> | |
6 #include <stdlib.h> | |
7 #include <unistd.h> | |
8 | |
9 int target_fd; | |
10 | |
11 open_serial_port(ttyport) | |
12 char *ttyport; | |
13 { | |
14 target_fd = open(ttyport, O_RDWR|O_NONBLOCK); | |
15 if (target_fd < 0) { | |
16 perror(ttyport); | |
17 exit(1); | |
18 } | |
19 ioctl(target_fd, TIOCEXCL); | |
20 return 0; | |
21 } | |
22 | |
23 set_termios() | |
24 { | |
25 struct termios target_termios; | |
26 | |
27 target_termios.c_iflag = IGNBRK; | |
28 target_termios.c_oflag = 0; | |
29 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; | |
30 target_termios.c_lflag = 0; | |
31 target_termios.c_cc[VMIN] = 1; | |
32 target_termios.c_cc[VTIME] = 0; | |
33 cfsetispeed(&target_termios, B115200); | |
34 cfsetospeed(&target_termios, B115200); | |
35 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { | |
36 perror("tcsetattr"); | |
37 exit(1); | |
38 } | |
39 return 0; | |
40 } | |
41 | |
42 main(argc, argv) | |
43 char **argv; | |
44 { | |
45 char c_arg[16]; | |
46 | |
47 if (argc != 3) { | |
48 fprintf(stderr, "usage: %s ttyport second-prog\n", argv[0]); | |
49 exit(1); | |
50 } | |
51 open_serial_port(argv[1]); | |
52 set_termios(); | |
53 sprintf(c_arg, "-C%d", target_fd); | |
54 execl(argv[2], argv[2], c_arg, (char *) 0); | |
55 perror(argv[2]); | |
56 exit(1); | |
57 } |