Commit | Line | Data |
---|---|---|
9893f627 DR |
1 | # |
2 | /* | |
3 | */ | |
4 | ||
5 | /* | |
6 | * DC-11 driver | |
7 | */ | |
8 | #include "../param.h" | |
9 | #include "../conf.h" | |
10 | #include "../user.h" | |
11 | #include "../tty.h" | |
12 | #include "../proc.h" | |
13 | ||
14 | /* | |
15 | * Base address of DC-11's. Minor device i is at | |
16 | * DCADDR + 10*i. | |
17 | */ | |
18 | #define DCADDR 0174000 | |
19 | ||
20 | /* | |
21 | * Number of DC's for which table space is allocated. | |
22 | */ | |
23 | #define NDC11 14 | |
24 | ||
25 | /* | |
26 | * Control bits in device registers | |
27 | */ | |
28 | #define CDLEAD 01 | |
29 | #define CARRIER 04 | |
30 | #define SPEED1 010 | |
31 | #define STOP1 0400 | |
32 | #define RQSEND 01 | |
33 | #define PARITY 040 | |
34 | #define ERROR 0100000 | |
35 | #define CTRANS 040000 | |
36 | #define RINGIND 020000 | |
37 | ||
38 | ||
39 | struct tty dc11[NDC11]; | |
40 | ||
41 | struct dcregs { | |
42 | int dcrcsr; | |
43 | int dcrbuf; | |
44 | int dctcsr; | |
45 | int dctbuf; | |
46 | }; | |
47 | ||
48 | /* | |
49 | * Input-side speed and control bit table. | |
50 | * Each DC11 has 4 speeds which correspond to the 4 non-zero entries. | |
51 | * The table index is the same as the speed-selector | |
52 | * number for the DH11. | |
53 | * Attempts to set the speed to a zero entry are ignored. | |
54 | */ | |
55 | int dcrstab[] { | |
56 | 0, /* 0 baud */ | |
57 | 0, /* 50 baud */ | |
58 | 0, /* 75 baud */ | |
59 | 0, /* 110 baud */ | |
60 | 01101, /* 134.5 baud: 7b/ch, speed 0 */ | |
61 | 0111, /* 150 baud: 8b/ch, speed 1 */ | |
62 | 0, /* 200 baud */ | |
63 | 0121, /* 300 baud: 8b/ch, speed 2 */ | |
64 | 0, /* 600 baud */ | |
65 | 0131, /* 1200 baud */ | |
66 | 0, /* 1800 baud */ | |
67 | 0, /* 2400 baud */ | |
68 | 0, /* 4800 baud */ | |
69 | 0, /* 9600 baud */ | |
70 | 0, /* X0 */ | |
71 | 0, /* X1 */ | |
72 | }; | |
73 | ||
74 | /* | |
75 | * Transmitter speed table | |
76 | */ | |
77 | int dctstab[] { | |
78 | 0, /* 0 baud */ | |
79 | 0, /* 50 baud */ | |
80 | 0, /* 75 baud */ | |
81 | 0, /* 110 baud */ | |
82 | 0501, /* 134.5 baud: stop 1 */ | |
83 | 0511, /* 150 baud */ | |
84 | 0, /* 200 baud */ | |
85 | 0521, /* 300 baud */ | |
86 | 0, /* 600 baud */ | |
87 | 0531, /* 1200 baud */ | |
88 | 0, /* 1800 baud */ | |
89 | 0, /* 2400 baud */ | |
90 | 0, /* 4800 baud */ | |
91 | 0, /* 9600 baud */ | |
92 | 0, /* X0 */ | |
93 | 0, /* X1 */ | |
94 | }; | |
95 | ||
96 | /* | |
97 | * Open a DC11, waiting until carrier is established. | |
98 | * Default initial conditions are set up on the first open. | |
99 | * t_state's CARR_ON bit is a pure copy of the hardware | |
100 | * CARRIER bit, and is only used to regularize | |
101 | * carrier tests in general tty routines. | |
102 | */ | |
103 | dcopen(dev, flag) | |
104 | { | |
105 | register struct tty *rtp; | |
106 | register *addr; | |
107 | ||
108 | if (dev.d_minor >= NDC11) { | |
109 | u.u_error = ENXIO; | |
110 | return; | |
111 | } | |
112 | rtp = &dc11[dev.d_minor]; | |
113 | rtp->t_addr = addr = DCADDR + dev.d_minor*8; | |
114 | rtp->t_state =| WOPEN; | |
115 | addr->dcrcsr =| IENABLE|CDLEAD; | |
116 | if ((rtp->t_state&ISOPEN) == 0) { | |
117 | rtp->t_erase = CERASE; | |
118 | rtp->t_kill = CKILL; | |
119 | addr->dcrcsr = IENABLE|CDLEAD|SPEED1; | |
120 | addr->dctcsr = IENABLE|SPEED1|STOP1|RQSEND; | |
121 | rtp->t_state = ISOPEN | WOPEN; | |
122 | rtp->t_flags = ODDP|EVENP|ECHO; | |
123 | } | |
124 | if (addr->dcrcsr & CARRIER) | |
125 | rtp->t_state =| CARR_ON; | |
126 | while ((rtp->t_state & CARR_ON) == 0) | |
127 | sleep(&rtp->t_rawq, TTIPRI); | |
128 | rtp->t_state =& ~WOPEN; | |
129 | if (u.u_procp->p_ttyp == 0) { | |
130 | u.u_procp->p_ttyp = rtp; | |
131 | rtp->t_dev = dev; | |
132 | } | |
133 | } | |
134 | ||
135 | /* | |
136 | * Close a dc11 | |
137 | */ | |
138 | dcclose(dev) | |
139 | { | |
140 | register struct tty *tp; | |
141 | ||
142 | (tp = &dc11[dev.d_minor])->t_state = 0; | |
143 | if (tp->t_flags&HUPCL) | |
144 | tp->t_addr->dcrcsr =& ~CDLEAD; | |
145 | wflushtty(tp); | |
146 | } | |
147 | ||
148 | /* | |
149 | * Read a DC11 | |
150 | */ | |
151 | dcread(dev) | |
152 | { | |
153 | ttread(&dc11[dev.d_minor]); | |
154 | } | |
155 | ||
156 | /* | |
157 | * Write a DC11 | |
158 | */ | |
159 | dcwrite(dev) | |
160 | { | |
161 | ttwrite(&dc11[dev.d_minor]); | |
162 | } | |
163 | ||
164 | /* | |
165 | * DC11 transmitter interrupt. | |
166 | */ | |
167 | dcxint(dev) | |
168 | { | |
169 | register struct tty *tp; | |
170 | ||
171 | ttstart(tp = &dc11[dev.d_minor]); | |
172 | if (tp->t_outq.c_cc == 0 || tp->t_outq.c_cc == TTLOWAT) | |
173 | wakeup(&tp->t_outq); | |
174 | } | |
175 | ||
176 | /* | |
177 | * DC11 receiver interrupt. | |
178 | */ | |
179 | dcrint(dev) | |
180 | { | |
181 | register struct tty *tp; | |
182 | register int c, csr; | |
183 | ||
184 | tp = &dc11[dev.d_minor]; | |
185 | c = tp->t_addr->dcrbuf; | |
186 | /* | |
187 | * If carrier is off, and an open is not in progress, | |
188 | * knock down the CD lead to hang up the local dataset | |
189 | * and signal a hangup. | |
190 | */ | |
191 | if (((csr = tp->t_addr->dcrcsr) & CARRIER) == 0) { | |
192 | if ((tp->t_state&WOPEN) == 0) { | |
193 | tp->t_addr->dcrcsr =& ~CDLEAD; | |
194 | if (tp->t_state & CARR_ON) | |
195 | signal(tp, SIGHUP); | |
196 | flushtty(tp); | |
197 | } | |
198 | tp->t_state =& ~CARR_ON; | |
199 | return; | |
200 | } | |
201 | if (csr&ERROR || (tp->t_state&ISOPEN)==0) { | |
202 | if (tp->t_state&WOPEN && csr&CARRIER) | |
203 | tp->t_state =| CARR_ON; | |
204 | wakeup(tp); | |
205 | return; | |
206 | } | |
207 | csr =& PARITY; | |
208 | if (csr&&(tp->t_flags&ODDP) || !csr&&(tp->t_flags&EVENP)) | |
209 | ttyinput(c, tp); | |
210 | } | |
211 | ||
212 | /* | |
213 | * DC11 stty/gtty. | |
214 | * Perform general functions and set speeds. | |
215 | */ | |
216 | dcsgtty(dev, av) | |
217 | int *av; | |
218 | { | |
219 | register struct tty *tp; | |
220 | register r; | |
221 | ||
222 | tp = &dc11[dev.d_minor]; | |
223 | if (ttystty(tp, av)) | |
224 | return; | |
225 | if (r = dcrstab[tp->t_speeds.lobyte&017]) | |
226 | tp->t_addr->dcrcsr = r; | |
227 | else | |
228 | tp->t_addr->dcrcsr =& ~CDLEAD; | |
229 | if (r = dctstab[tp->t_speeds.hibyte&017]) | |
230 | tp->t_addr->dctcsr = r; | |
231 | } |