annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <sys/file.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <sys/ioctl.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <asm/ioctls.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <asm/termbits.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <unistd.h>
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 int target_fd;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 open_serial_port(ttyport)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char *ttyport;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (target_fd < 0) {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 perror(ttyport);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 exit(1);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 ioctl(target_fd, TIOCEXCL);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return 0;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 set_serial_params(br)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct termios2 target_termios;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 target_termios.c_iflag = IGNBRK;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 target_termios.c_oflag = 0;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 target_termios.c_cflag = BOTHER|CLOCAL|HUPCL|CREAD|CS8|CSTOPB|PARENB;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 target_termios.c_lflag = 0;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 target_termios.c_cc[VMIN] = 1;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 target_termios.c_cc[VTIME] = 0;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 target_termios.c_ispeed = br;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 target_termios.c_ospeed = br;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 perror("TCSETSF2");
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 exit(1);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return 0;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 set_serial_nonblock(state)
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 int state;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 ioctl(target_fd, FIONBIO, &state);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 serial_card_reset()
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 {
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 int mctl_arg = TIOCM_DTR | TIOCM_RTS;
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 ioctl(target_fd, TIOCMBIS, &mctl_arg);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 usleep(20000);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 ioctl(target_fd, TCFLSH, TCIFLUSH);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 ioctl(target_fd, TIOCMBIC, &mctl_arg);
1d96f3b4f155 serial: started with fcsim-serial-atr
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }