FreeCalypso > hg > freecalypso-reveng
annotate fluid-mnf/serial.c @ 342:6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 13 Mar 2020 05:39:37 +0000 |
parents | 9cecc930d78f |
children | 917e05f03ad2 |
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> |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 #include <assert.h> |
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 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 /****************************************************************************** |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
40 * Linux Driver |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 ******************************************************************************/ |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
43 static int target_fd; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
44 static struct termios2 target_termios; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
45 |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
46 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
|
47 |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
48 static void fill_termios(int bps) |
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 int termios_baud_code; |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
52 switch (bps) { |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
53 case 9600: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
54 termios_baud_code = B9600; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
55 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
56 case 19200: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
57 termios_baud_code = B19200; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
58 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
59 case 38400: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
60 termios_baud_code = B38400; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
61 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
62 case 57600: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
63 termios_baud_code = B57600; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
64 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
65 case 115200: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
66 termios_baud_code = B115200; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
67 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
68 case 230400: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
69 termios_baud_code = B230400; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
70 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
71 case 460800: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
72 termios_baud_code = B460800; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
73 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
74 case 921600: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
75 termios_baud_code = B921600; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
76 break; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
77 default: |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
78 termios_baud_code = BOTHER; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
79 } |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
80 target_termios.c_iflag = IGNBRK; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
81 target_termios.c_oflag = 0; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
82 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
|
83 target_termios.c_lflag = 0; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
84 target_termios.c_cc[VMIN] = 1; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
85 target_termios.c_cc[VTIME] = 0; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
86 target_termios.c_ispeed = bps; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
87 target_termios.c_ospeed = bps; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
88 } |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 int serial_init(int uart, int bps, char *flowcontrol) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
92 char ttyport[32]; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
93 static int zero = 0; |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
95 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
|
96 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
|
97 if (target_fd < 0) |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
98 return E_OS + E_UART_INIT; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
99 ioctl(target_fd, TIOCEXCL); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
100 fill_termios(bps); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
101 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
|
102 return E_OS + E_UART_INIT; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
103 ioctl(target_fd, FIONBIO, &zero); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
105 if (arg_uart_level_convert) { |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
106 /* |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
107 * Powering TI's serial level converter |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
108 * with DTR = +12V and RTS = -12V |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
109 */ |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
110 serial_dtr(1); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
111 serial_rts(0); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
112 } |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
114 serial_reset(); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
115 return 0; |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 int serial_is_baudrate(int bps) |
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 i; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 const struct rate_s { |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 int bps; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 int baudrate; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 } rates[] = { |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 { 9600, 9600 }, { 9, 9600 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 { 14400, 14400 }, { 14, 14400 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 { 19200, 19200 }, { 19, 19200 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 { 38400, 38400 }, { 38, 38400 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 { 57600, 57600 }, { 57, 57600 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 { 115200, 115200 }, { 115, 115200 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 { 203125, 203125 }, { 203, 203125 }, // 13MHz clock |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 { 230400, 230400 }, { 230, 230400 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 { 406250, 406250 }, { 406, 406250 }, // 13MHz clock |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 { 460800, 460800 }, { 460, 460800 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 { 812500, 812500 }, { 812, 812500 }, // 13MHz clock |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 { 921600, 921600 }, { 921, 921600 }, |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 { 0, 0 } // terminator |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 }; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 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
|
141 if (rates[i].bps == bps) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 break; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 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
|
145 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 return 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 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 int serial_baudrate_set(int bps) |
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 bps = serial_is_baudrate(bps); |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 if (bps == 0) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 return E_OS + E_UART_PARAM; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
155 fill_termios(bps); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
156 if (ioctl(target_fd, TCSETSF2, &target_termios) < 0) |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return E_OS + E_UART_PARAM; |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 return bps; |
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 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 int serial_baudrate_get(void) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
164 return target_termios.c_ospeed; |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 void serial_exit(void) |
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 serial_reset(); |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
170 close(target_fd); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 // Clear buffers and transactions. |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 void serial_reset(void) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
176 ioctl(target_fd, TCFLSH, TCIOFLUSH); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 // 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
|
180 int serial_transfer_time(int size) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 { |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 return 1000 * 10 * size / serial_baudrate_get(); |
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 |
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 * Send |
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 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 int serial_send(char *buf, int size) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
192 int cc; |
311
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 cc = write(target_fd, buf, size); |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
195 if (cc < 0) |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
196 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
|
197 return cc; |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 |
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 * Receive |
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 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 void serial_recv_reset(void) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
207 ioctl(target_fd, TCFLSH, TCIFLUSH); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
210 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
|
211 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
212 /* to be filled */ |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 /****************************************************************************** |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 * Control of Delta cable special outputs |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 ******************************************************************************/ |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 void serial_rts(char state) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
222 int rts_arg = TIOCM_RTS; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
223 |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 if (state) |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
225 ioctl(target_fd, TIOCMBIS, &rts_arg); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 else |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
227 ioctl(target_fd, TIOCMBIC, &rts_arg); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 } |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 void serial_dtr(char state) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 { |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
232 int dtr_arg = TIOCM_DTR; |
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
233 |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 if (state) |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
235 ioctl(target_fd, TIOCMBIS, &dtr_arg); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 else |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
237 ioctl(target_fd, TIOCMBIC, &dtr_arg); |
311
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 void serial_break(char state) |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 { |
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 if (state) |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
243 ioctl(target_fd, TIOCSBRK); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 else |
342
6ff231195905
fluid-mnf/serial.[ch]: beginning of Linux port
Mychaela Falconia <falcon@freecalypso.org>
parents:
311
diff
changeset
|
245 ioctl(target_fd, TIOCCBRK); |
311
9cecc930d78f
fluid-mnf: original source from TI,
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 } |