annotate fluid-mnf/serial.c @ 347:21d38dce4d15

fluid-mnf: removed silly wait for RETURN from no-arguments display
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 13 Mar 2020 06:27:15 +0000
parents 2bd27d940023
children 37b5f94de802
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /******************************************************************************
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * FLUID (Flash Loader Utility Independent of Device)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 *
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * Copyright Texas Instruments, 2001.
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * Mads Meisner-Jensen, mmj@ti.com.
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 *
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * Serial/UART driver
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 *
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 * $Id: serial.c 1.23 Fri, 18 Oct 2002 08:53:12 +0200 mmj $
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 *
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
11 * This serial interface handling architecture has been majorly redesigned
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
12 * by Mychaela N. Falconia for the present fluid-mnf Linux port.
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
13 *
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
14 * Because FLUID supports Calypso high baud rates of 203125, 406250 and 812500
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
15 * bps, as well as D-Sample XXO (eXternal Xtal Oscillator) baud rates of
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
16 * 230400, 460800 and 912600 bps, the present fluid-mnf port had to be made
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
17 * quite Linux-specific, using the same raw ioctl approach as is used in
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
18 * freecalypso-tools/libserial-linux.
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
19 *
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 ******************************************************************************/
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #include "fluid.h"
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 #include "serial.h"
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 #include "trace.h"
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
26 #include <sys/types.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
27 #include <sys/file.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
28 #include <sys/time.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
29 #include <sys/ioctl.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
30 #include <asm/ioctls.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
31 #include <asm/termbits.h>
344
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
32 #include <sys/errno.h>
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 #include <stdio.h>
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
34 #include <stdlib.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
35 #include <string.h>
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
36 #include <unistd.h>
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
344
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
38 extern int errno;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
39
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /******************************************************************************
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
42 * Linux Driver
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 ******************************************************************************/
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
45 static int target_fd;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
46 static struct termios2 target_termios;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
47
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
48 static const char port_name_prefix[] = "/dev/ttyUSB";
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
49
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
50 static void fill_termios(int bps)
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
51 {
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
52 int termios_baud_code;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
54 switch (bps) {
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
55 case 9600:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
56 termios_baud_code = B9600;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
57 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
58 case 19200:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
59 termios_baud_code = B19200;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
60 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
61 case 38400:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
62 termios_baud_code = B38400;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
63 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
64 case 57600:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
65 termios_baud_code = B57600;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
66 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
67 case 115200:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
68 termios_baud_code = B115200;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
69 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
70 case 230400:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
71 termios_baud_code = B230400;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
72 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
73 case 460800:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
74 termios_baud_code = B460800;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
75 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
76 case 921600:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
77 termios_baud_code = B921600;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
78 break;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
79 default:
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
80 termios_baud_code = BOTHER;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
81 }
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
82 target_termios.c_iflag = IGNBRK;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
83 target_termios.c_oflag = 0;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
84 target_termios.c_cflag = termios_baud_code | CLOCAL|HUPCL|CREAD|CS8;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
85 target_termios.c_lflag = 0;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
86 target_termios.c_cc[VMIN] = 1;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
87 target_termios.c_cc[VTIME] = 0;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
88 target_termios.c_ispeed = bps;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
89 target_termios.c_ospeed = bps;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
90 }
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 int serial_init(int uart, int bps, char *flowcontrol)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
94 char ttyport[32];
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
95 static int zero = 0;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
97 sprintf(ttyport, "%s%d", port_name_prefix, uart);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
98 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
99 if (target_fd < 0)
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
100 return E_OS + E_UART_INIT;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
101 ioctl(target_fd, TIOCEXCL);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
102 fill_termios(bps);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
103 if (ioctl(target_fd, TCSETSF2, &target_termios) < 0)
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
104 return E_OS + E_UART_INIT;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
105 ioctl(target_fd, FIONBIO, &zero);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
107 if (arg_uart_level_convert) {
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
108 /*
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
109 * Powering TI's serial level converter
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
110 * with DTR = +12V and RTS = -12V
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
111 */
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
112 serial_dtr(1);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
113 serial_rts(0);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
114 }
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
116 serial_reset();
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
117 return 0;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 int serial_is_baudrate(int bps)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 int i;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 const struct rate_s {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 int bps;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 int baudrate;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 } rates[] = {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 { 9600, 9600 }, { 9, 9600 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 { 14400, 14400 }, { 14, 14400 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 { 19200, 19200 }, { 19, 19200 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 { 38400, 38400 }, { 38, 38400 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 { 57600, 57600 }, { 57, 57600 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 { 115200, 115200 }, { 115, 115200 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 { 203125, 203125 }, { 203, 203125 }, // 13MHz clock
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 { 230400, 230400 }, { 230, 230400 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 { 406250, 406250 }, { 406, 406250 }, // 13MHz clock
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 { 460800, 460800 }, { 460, 460800 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 { 812500, 812500 }, { 812, 812500 }, // 13MHz clock
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 { 921600, 921600 }, { 921, 921600 },
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 { 0, 0 } // terminator
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 };
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 for (i = 0; i < sizeof(rates) / sizeof(struct rate_s) - 1; i++)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (rates[i].bps == bps)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 break;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 tr(TrTargetDrv, "serial_is_baudrate(%d) %d\n", bps, rates[i].baudrate);
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 return rates[i].baudrate;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 int serial_baudrate_set(int bps)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 bps = serial_is_baudrate(bps);
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 if (bps == 0)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 return E_OS + E_UART_PARAM;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
157 fill_termios(bps);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
158 if (ioctl(target_fd, TCSETSF2, &target_termios) < 0)
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 return E_OS + E_UART_PARAM;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 return bps;
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 int serial_baudrate_get(void)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
166 return target_termios.c_ospeed;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 void serial_exit(void)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 serial_reset();
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
172 close(target_fd);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 // Clear buffers and transactions.
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 void serial_reset(void)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
178 ioctl(target_fd, TCFLSH, TCIOFLUSH);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 // Return the number of milli-seconds it takes to transfer <n> bytes.
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 int serial_transfer_time(int size)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 return 1000 * 10 * size / serial_baudrate_get();
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 /***************************************
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 * Send
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 ***************************************/
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 int serial_send(char *buf, int size)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
194 int cc;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
196 cc = write(target_fd, buf, size);
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
197 if (cc < 0)
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
198 cc = E_OS + E_UART_DRV_SEND;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
199 return cc;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 /***************************************
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 * Receive
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 ***************************************/
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 void serial_recv_reset(void)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
209 ioctl(target_fd, TCFLSH, TCIFLUSH);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
212 int serial_recv(char *buf, int size, int timeout)
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 {
344
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
214 fd_set fds;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
215 struct timeval tv;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
216 int cc;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
217
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
218 for (;;) {
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
219 FD_ZERO(&fds);
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
220 FD_SET(target_fd, &fds);
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
221 tv.tv_sec = timeout / 1000;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
222 tv.tv_usec = (timeout % 1000) * 1000;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
223 cc = select(target_fd+1, &fds, NULL, NULL, &tv);
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
224 if (cc < 0) {
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
225 if (errno == EINTR)
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
226 continue;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
227 return E_OS + E_UART_DRV_RECV;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
228 }
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
229 break;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
230 }
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
231 if (cc == 0)
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
232 return cc;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
233 cc = read(target_fd, buf, size);
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
234 if (cc <= 0)
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
235 cc = E_OS + E_UART_DRV_RECV;
2bd27d940023 fluid-mnf/serial.c: serial_recv() implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 343
diff changeset
236 return cc;
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 /******************************************************************************
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 * Control of Delta cable special outputs
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 ******************************************************************************/
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 void serial_rts(char state)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
246 int rts_arg = TIOCM_RTS;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
247
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 if (state)
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
249 ioctl(target_fd, TIOCMBIS, &rts_arg);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 else
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
251 ioctl(target_fd, TIOCMBIC, &rts_arg);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 void serial_dtr(char state)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 {
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
256 int dtr_arg = TIOCM_DTR;
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
257
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 if (state)
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
259 ioctl(target_fd, TIOCMBIS, &dtr_arg);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 else
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
261 ioctl(target_fd, TIOCMBIC, &dtr_arg);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 }
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 void serial_break(char state)
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 {
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 if (state)
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
267 ioctl(target_fd, TIOCSBRK);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 else
342
6ff231195905 fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents: 311
diff changeset
269 ioctl(target_fd, TIOCCBRK);
311
9cecc930d78f fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 }