FreeCalypso > hg > freecalypso-sw
comparison loadtools/sercomm.c @ 7:aa1f6fe16fef
loadtools building blocks started
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Tue, 30 Apr 2013 07:19:48 +0000 |
parents | |
children | fea204bc7674 |
comparison
equal
deleted
inserted
replaced
6:5eaafa83be60 | 7:aa1f6fe16fef |
---|---|
1 /* | |
2 * This module handles the establishment of serial communication | |
3 * with the target, i.e., the host-side termios stuff. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <sys/file.h> | |
8 #include <sys/ioctl.h> | |
9 #include <termios.h> | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <unistd.h> | |
13 | |
14 char *target_ttydev; | |
15 int target_fd; | |
16 struct termios target_termios; | |
17 | |
18 open_target_serial() | |
19 { | |
20 target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK); | |
21 if (target_fd < 0) { | |
22 perror(target_ttydev); | |
23 exit(1); | |
24 } | |
25 target_termios.c_iflag = IGNBRK; | |
26 target_termios.c_oflag = 0; | |
27 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; | |
28 target_termios.c_lflag = 0; | |
29 target_termios.c_cc[VMIN] = 1; | |
30 target_termios.c_cc[VTIME] = 0; | |
31 /* start at B19200, as that's what we'll need to use initially */ | |
32 cfsetispeed(&target_termios, B19200); | |
33 cfsetospeed(&target_termios, B19200); | |
34 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { | |
35 perror("initial tcsetattr on target"); | |
36 exit(1); | |
37 } | |
38 return 0; | |
39 } |