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