FreeCalypso > hg > freecalypso-sw
annotate loadtools/sercomm.c @ 48:38664e0b7c32
fc-sertool renamed to fc-iram
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sun, 23 Jun 2013 01:13:03 +0000 |
parents | fea204bc7674 |
children | 54392d1ea474 |
rev | line source |
---|---|
7
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 /* |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 * This module handles the establishment of serial communication |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 * with the target, i.e., the host-side termios stuff. |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 */ |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 #include <sys/types.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
7 #include <sys/file.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 #include <sys/ioctl.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 #include <termios.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 #include <stdio.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
11 #include <stdlib.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
12 #include <unistd.h> |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
13 |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
14 char *target_ttydev; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
15 int target_fd; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
16 struct termios target_termios; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
17 |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
18 open_target_serial() |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
19 { |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
20 target_fd = open(target_ttydev, O_RDWR|O_NONBLOCK); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
21 if (target_fd < 0) { |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
22 perror(target_ttydev); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
23 exit(1); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
24 } |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
25 target_termios.c_iflag = IGNBRK; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
26 target_termios.c_oflag = 0; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 target_termios.c_cflag = CLOCAL|HUPCL|CREAD|CS8; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 target_termios.c_lflag = 0; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
29 target_termios.c_cc[VMIN] = 1; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 target_termios.c_cc[VTIME] = 0; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
31 /* start at B19200, as that's what we'll need to use initially */ |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 cfsetispeed(&target_termios, B19200); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 cfsetospeed(&target_termios, B19200); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 perror("initial tcsetattr on target"); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
36 exit(1); |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 } |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 return 0; |
aa1f6fe16fef
loadtools building blocks started
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
39 } |
9
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
40 |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
41 switch_baud_rate(code) |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
42 { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
43 cfsetispeed(&target_termios, code); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
44 cfsetospeed(&target_termios, code); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
45 if (tcsetattr(target_fd, TCSAFLUSH, &target_termios) < 0) { |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
46 perror("tcsetattr to switch baud rate"); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
47 exit(1); |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
48 } |
fea204bc7674
fc-sertool compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
7
diff
changeset
|
49 } |