annotate rfcal/cmu200/openport.c @ 195:db9ee7745cdd

fc-cmu200d: socket handling skeleton added
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 24 Apr 2017 01:43:02 +0000
parents 219ae678b955
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
187
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Serial port opening code for talking to CMU200
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/file.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <termios.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <unistd.h>
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 extern int target_fd;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 static struct baudrate {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *name;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 speed_t termios_code;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 } baud_rate_table[] = {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {"1200", B1200},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 {"2400", B2400},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {"4800", B4800},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 {"9600", B9600},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {"19200", B19200},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 {"38400", B38400},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {"57600", B57600},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {"115200", B115200},
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /* table search terminator */
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 {NULL, B0}
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 };
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 open_target_serial(ttydev, baudname)
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 char *ttydev, *baudname;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 struct termios target_termios;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 struct baudrate *br;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 for (br = baud_rate_table; br->name; br++)
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (!strcmp(br->name, baudname))
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 break;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (!br->name) {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fprintf(stderr, "baud rate \"%s\" unknown/unsupported\n",
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 baudname);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 target_fd = open(ttydev, O_RDWR|O_NONBLOCK);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (target_fd < 0) {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 perror(ttydev);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 target_termios.c_iflag = IGNBRK;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 target_termios.c_oflag = 0;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8|CRTSCTS;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 target_termios.c_lflag = 0;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 target_termios.c_cc[VMIN] = 1;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 target_termios.c_cc[VTIME] = 0;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 cfsetispeed(&target_termios, br->termios_code);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 cfsetospeed(&target_termios, br->termios_code);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 perror("initial tcsetattr on target");
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 exit(1);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return 0;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 set_serial_nonblock(state)
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 int state;
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 ioctl(target_fd, FIONBIO, &state);
219ae678b955 fc-serscpi utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }