FreeCalypso > hg > fc-sim-tools
comparison serial/serport.c @ 38:1d96f3b4f155
serial: started with fcsim-serial-atr
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 20 Mar 2021 19:19:46 +0000 |
parents | |
children | 61a8ac93764f |
comparison
equal
deleted
inserted
replaced
37:4e5586c7f275 | 38:1d96f3b4f155 |
---|---|
1 #include <sys/types.h> | |
2 #include <sys/file.h> | |
3 #include <sys/ioctl.h> | |
4 #include <asm/ioctls.h> | |
5 #include <asm/termbits.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include <unistd.h> | |
9 | |
10 int target_fd; | |
11 | |
12 open_serial_port(ttyport) | |
13 char *ttyport; | |
14 { | |
15 target_fd = open(ttyport, O_RDWR|O_NONBLOCK); | |
16 if (target_fd < 0) { | |
17 perror(ttyport); | |
18 exit(1); | |
19 } | |
20 ioctl(target_fd, TIOCEXCL); | |
21 return 0; | |
22 } | |
23 | |
24 set_serial_params(br) | |
25 { | |
26 struct termios2 target_termios; | |
27 | |
28 target_termios.c_iflag = IGNBRK; | |
29 target_termios.c_oflag = 0; | |
30 target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8|CSTOPB|PARENB; | |
31 target_termios.c_lflag = 0; | |
32 target_termios.c_cc[VMIN] = 1; | |
33 target_termios.c_cc[VTIME] = 0; | |
34 target_termios.c_ispeed = br; | |
35 target_termios.c_ospeed = br; | |
36 if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) { | |
37 perror("TCSETSF2"); | |
38 exit(1); | |
39 } | |
40 return 0; | |
41 } | |
42 | |
43 set_serial_nonblock(state) | |
44 int state; | |
45 { | |
46 ioctl(target_fd, FIONBIO, &state); | |
47 } | |
48 | |
49 serial_card_reset() | |
50 { | |
51 int mctl_arg = TIOCM_DTR | TIOCM_RTS; | |
52 | |
53 ioctl(target_fd, TIOCMBIS, &mctl_arg); | |
54 usleep(20000); | |
55 ioctl(target_fd, TCFLSH, TCIFLUSH); | |
56 ioctl(target_fd, TIOCMBIC, &mctl_arg); | |
57 } |