par.c revision 1.2 1 1.1 mw /*
2 1.1 mw * Copyright (c) 1982, 1990 The Regents of the University of California.
3 1.1 mw * All rights reserved.
4 1.1 mw *
5 1.1 mw * Redistribution and use in source and binary forms, with or without
6 1.1 mw * modification, are permitted provided that the following conditions
7 1.1 mw * are met:
8 1.1 mw * 1. Redistributions of source code must retain the above copyright
9 1.1 mw * notice, this list of conditions and the following disclaimer.
10 1.1 mw * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 mw * notice, this list of conditions and the following disclaimer in the
12 1.1 mw * documentation and/or other materials provided with the distribution.
13 1.1 mw * 3. All advertising materials mentioning features or use of this software
14 1.1 mw * must display the following acknowledgement:
15 1.1 mw * This product includes software developed by the University of
16 1.1 mw * California, Berkeley and its contributors.
17 1.1 mw * 4. Neither the name of the University nor the names of its contributors
18 1.1 mw * may be used to endorse or promote products derived from this software
19 1.1 mw * without specific prior written permission.
20 1.1 mw *
21 1.1 mw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 mw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 mw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 mw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 mw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 mw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 mw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 mw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 mw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 mw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 mw * SUCH DAMAGE.
32 1.1 mw *
33 1.1 mw * from: @(#)ppi.c 7.3 (Berkeley) 12/16/90
34 1.1 mw * $Id: par.c,v 1.2 1993/10/30 23:41:28 mw Exp $
35 1.1 mw */
36 1.1 mw
37 1.1 mw /*
38 1.1 mw * parallel port interface
39 1.1 mw */
40 1.1 mw
41 1.2 mw #include "par.h"
42 1.1 mw #if NPAR > 0
43 1.1 mw
44 1.1 mw #include "sys/param.h"
45 1.1 mw #include "sys/errno.h"
46 1.1 mw #include "sys/uio.h"
47 1.1 mw #include "sys/malloc.h"
48 1.2 mw #include "sys/file.h"
49 1.2 mw #include "sys/systm.h"
50 1.1 mw
51 1.1 mw #include "device.h"
52 1.1 mw #include "parioctl.h"
53 1.2 mw #include "../amiga/cia.h"
54 1.1 mw
55 1.2 mw int parattach(), parstart(), partimo();
56 1.2 mw void parintr();
57 1.1 mw struct driver pardriver = {
58 1.1 mw parattach, "par", parstart,
59 1.1 mw };
60 1.1 mw
61 1.1 mw struct par_softc {
62 1.1 mw int sc_flags;
63 1.1 mw struct amiga_device *sc_ad;
64 1.1 mw struct parparam sc_param;
65 1.1 mw #define sc_burst sc_param.burst
66 1.1 mw #define sc_timo sc_param.timo
67 1.1 mw #define sc_delay sc_param.delay
68 1.2 mw } par_softc[NPAR];
69 1.1 mw
70 1.1 mw /* sc_flags values */
71 1.1 mw #define PARF_ALIVE 0x01
72 1.1 mw #define PARF_OPEN 0x02
73 1.1 mw #define PARF_UIO 0x04
74 1.1 mw #define PARF_TIMO 0x08
75 1.1 mw #define PARF_DELAY 0x10
76 1.1 mw #define PARF_OREAD 0x40
77 1.1 mw #define PARF_OWRITE 0x80
78 1.1 mw
79 1.1 mw #define UNIT(x) minor(x)
80 1.1 mw
81 1.1 mw #ifdef DEBUG
82 1.2 mw int pardebug = 0;
83 1.1 mw #define PDB_FOLLOW 0x01
84 1.1 mw #define PDB_IO 0x02
85 1.2 mw #define PDB_INTERRUPT 0x04
86 1.1 mw #define PDB_NOCHECK 0x80
87 1.1 mw #endif
88 1.1 mw
89 1.1 mw parattach(ad)
90 1.1 mw register struct amiga_device *ad;
91 1.1 mw {
92 1.1 mw register struct par_softc *sc = &par_softc[ad->amiga_unit];
93 1.1 mw
94 1.1 mw #ifdef DEBUG
95 1.1 mw if ((pardebug & PDB_NOCHECK) == 0)
96 1.1 mw #endif
97 1.1 mw sc->sc_flags = PARF_ALIVE;
98 1.1 mw sc->sc_ad = ad;
99 1.1 mw return(1);
100 1.1 mw }
101 1.1 mw
102 1.1 mw paropen(dev, flags)
103 1.1 mw dev_t dev;
104 1.1 mw {
105 1.1 mw register int unit = UNIT(dev);
106 1.1 mw register struct par_softc *sc = &par_softc[unit];
107 1.1 mw
108 1.1 mw if (unit >= NPAR || (sc->sc_flags & PARF_ALIVE) == 0)
109 1.1 mw return(ENXIO);
110 1.1 mw #ifdef DEBUG
111 1.1 mw if (pardebug & PDB_FOLLOW)
112 1.2 mw {
113 1.2 mw printf("paropen(%x, %x): flags %x, ",
114 1.2 mw dev, flags, sc->sc_flags);
115 1.2 mw printf ("port = $%x\n",
116 1.2 mw ((ciab.pra ^ CIAB_PRA_SEL)
117 1.2 mw & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
118 1.2 mw }
119 1.1 mw #endif
120 1.1 mw if (sc->sc_flags & PARF_OPEN)
121 1.1 mw return(EBUSY);
122 1.1 mw /* can either read or write, but not both */
123 1.1 mw if ((flags & (FREAD|FWRITE)) == (FREAD|FWRITE))
124 1.1 mw return EINVAL;
125 1.1 mw
126 1.1 mw sc->sc_flags |= PARF_OPEN;
127 1.1 mw if (flags & FREAD)
128 1.1 mw sc->sc_flags |= PARF_OREAD;
129 1.1 mw else
130 1.1 mw sc->sc_flags |= PARF_OWRITE;
131 1.1 mw sc->sc_burst = PAR_BURST;
132 1.1 mw sc->sc_timo = parmstohz(PAR_TIMO);
133 1.1 mw sc->sc_delay = parmstohz(PAR_DELAY);
134 1.1 mw /* enable interrupts for CIAA-FLG */
135 1.1 mw ciaa.icr = CIA_ICR_IR_SC | CIA_ICR_FLG;
136 1.1 mw return(0);
137 1.1 mw }
138 1.1 mw
139 1.1 mw parclose(dev, flags)
140 1.1 mw dev_t dev;
141 1.1 mw {
142 1.1 mw register int unit = UNIT(dev);
143 1.1 mw register struct par_softc *sc = &par_softc[unit];
144 1.1 mw
145 1.1 mw #ifdef DEBUG
146 1.1 mw if (pardebug & PDB_FOLLOW)
147 1.1 mw printf("parclose(%x, %x): flags %x\n",
148 1.1 mw dev, flags, sc->sc_flags);
149 1.1 mw #endif
150 1.1 mw sc->sc_flags &= ~(PARF_OPEN|PARF_OREAD|PARF_OWRITE);
151 1.1 mw /* don't allow interrupts for CIAA-FLG any longer */
152 1.1 mw ciaa.icr = CIA_ICR_FLG;
153 1.1 mw return(0);
154 1.1 mw }
155 1.1 mw
156 1.1 mw parstart(unit)
157 1.1 mw int unit;
158 1.1 mw {
159 1.1 mw #ifdef DEBUG
160 1.1 mw if (pardebug & PDB_FOLLOW)
161 1.1 mw printf("parstart(%x)\n", unit);
162 1.1 mw #endif
163 1.1 mw par_softc[unit].sc_flags &= ~PARF_DELAY;
164 1.1 mw wakeup(&par_softc[unit]);
165 1.1 mw }
166 1.1 mw
167 1.1 mw partimo(unit)
168 1.1 mw int unit;
169 1.1 mw {
170 1.1 mw #ifdef DEBUG
171 1.1 mw if (pardebug & PDB_FOLLOW)
172 1.1 mw printf("partimo(%x)\n", unit);
173 1.1 mw #endif
174 1.1 mw par_softc[unit].sc_flags &= ~(PARF_UIO|PARF_TIMO);
175 1.1 mw wakeup(&par_softc[unit]);
176 1.1 mw }
177 1.1 mw
178 1.1 mw parread(dev, uio)
179 1.1 mw dev_t dev;
180 1.1 mw struct uio *uio;
181 1.1 mw {
182 1.1 mw
183 1.1 mw #ifdef DEBUG
184 1.1 mw if (pardebug & PDB_FOLLOW)
185 1.1 mw printf("parread(%x, %x)\n", dev, uio);
186 1.1 mw #endif
187 1.1 mw return (parrw(dev, uio));
188 1.1 mw }
189 1.1 mw
190 1.1 mw parwrite(dev, uio)
191 1.1 mw dev_t dev;
192 1.1 mw struct uio *uio;
193 1.1 mw {
194 1.1 mw
195 1.1 mw #ifdef DEBUG
196 1.1 mw if (pardebug & PDB_FOLLOW)
197 1.1 mw printf("parwrite(%x, %x)\n", dev, uio);
198 1.1 mw #endif
199 1.1 mw return (parrw(dev, uio));
200 1.1 mw }
201 1.1 mw
202 1.1 mw parrw(dev, uio)
203 1.1 mw dev_t dev;
204 1.1 mw register struct uio *uio;
205 1.1 mw {
206 1.1 mw int unit = UNIT(dev);
207 1.1 mw register struct par_softc *sc = &par_softc[unit];
208 1.1 mw register int s, len, cnt;
209 1.1 mw register char *cp;
210 1.1 mw int error = 0, gotdata = 0;
211 1.1 mw int buflen;
212 1.1 mw char *buf;
213 1.1 mw
214 1.2 mw if (!!(sc->sc_flags & PARF_OREAD) ^ (uio->uio_rw == UIO_READ))
215 1.1 mw return EINVAL;
216 1.1 mw
217 1.1 mw if (uio->uio_resid == 0)
218 1.1 mw return(0);
219 1.1 mw
220 1.1 mw #ifdef DEBUG
221 1.1 mw if (pardebug & (PDB_FOLLOW|PDB_IO))
222 1.1 mw printf("parrw(%x, %x, %c): burst %d, timo %d, resid %x\n",
223 1.1 mw dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W',
224 1.1 mw sc->sc_burst, sc->sc_timo, uio->uio_resid);
225 1.1 mw #endif
226 1.1 mw buflen = MIN(sc->sc_burst, uio->uio_resid);
227 1.1 mw buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK);
228 1.1 mw sc->sc_flags |= PARF_UIO;
229 1.2 mw if (sc->sc_timo > 0)
230 1.2 mw {
231 1.2 mw sc->sc_flags |= PARF_TIMO;
232 1.2 mw timeout(partimo, unit, sc->sc_timo);
233 1.1 mw }
234 1.2 mw while (uio->uio_resid > 0)
235 1.2 mw {
236 1.2 mw len = MIN(buflen, uio->uio_resid);
237 1.2 mw cp = buf;
238 1.2 mw if (uio->uio_rw == UIO_WRITE)
239 1.2 mw {
240 1.2 mw error = uiomove(cp, len, uio);
241 1.2 mw if (error)
242 1.2 mw break;
243 1.2 mw }
244 1.2 mw again:
245 1.2 mw s = splbio();
246 1.2 mw #if 0
247 1.2 mw if ((sc->sc_flags & PARF_UIO) && hpibreq(&sc->sc_dq) == 0)
248 1.2 mw sleep(sc, PRIBIO+1);
249 1.2 mw #endif
250 1.2 mw /*
251 1.2 mw * Check if we timed out during sleep or uiomove
252 1.2 mw */
253 1.2 mw (void) splsoftclock();
254 1.2 mw if ((sc->sc_flags & PARF_UIO) == 0)
255 1.2 mw {
256 1.2 mw #ifdef DEBUG
257 1.2 mw if (pardebug & PDB_IO)
258 1.2 mw printf("parrw: uiomove/sleep timo, flags %x\n",
259 1.2 mw sc->sc_flags);
260 1.2 mw #endif
261 1.2 mw if (sc->sc_flags & PARF_TIMO)
262 1.2 mw {
263 1.2 mw untimeout(partimo, unit);
264 1.2 mw sc->sc_flags &= ~PARF_TIMO;
265 1.2 mw }
266 1.2 mw splx(s);
267 1.2 mw break;
268 1.2 mw }
269 1.2 mw splx(s);
270 1.2 mw /*
271 1.2 mw * Perform the operation
272 1.2 mw */
273 1.2 mw if (uio->uio_rw == UIO_WRITE)
274 1.2 mw cnt = parsend (cp, len);
275 1.2 mw else
276 1.2 mw cnt = parreceive (cp, len);
277 1.2 mw
278 1.2 mw if (cnt < 0)
279 1.2 mw {
280 1.2 mw error = -cnt;
281 1.2 mw break;
282 1.2 mw }
283 1.2 mw
284 1.2 mw s = splbio();
285 1.1 mw #if 0
286 1.2 mw hpibfree(&sc->sc_dq);
287 1.1 mw #endif
288 1.1 mw #ifdef DEBUG
289 1.1 mw if (pardebug & PDB_IO)
290 1.2 mw printf("parrw: %s(%x, %d) -> %d\n",
291 1.2 mw uio->uio_rw == UIO_READ ? "recv" : "send", cp, len, cnt);
292 1.1 mw #endif
293 1.1 mw splx(s);
294 1.2 mw if (uio->uio_rw == UIO_READ)
295 1.2 mw {
296 1.2 mw if (cnt)
297 1.2 mw {
298 1.2 mw error = uiomove(cp, cnt, uio);
299 1.2 mw if (error)
300 1.2 mw break;
301 1.2 mw gotdata++;
302 1.2 mw }
303 1.2 mw /*
304 1.2 mw * Didn't get anything this time, but did in the past.
305 1.2 mw * Consider us done.
306 1.2 mw */
307 1.2 mw else if (gotdata)
308 1.2 mw break;
309 1.2 mw }
310 1.2 mw s = splsoftclock();
311 1.1 mw /*
312 1.2 mw * Operation timeout (or non-blocking), quit now.
313 1.1 mw */
314 1.2 mw if ((sc->sc_flags & PARF_UIO) == 0)
315 1.2 mw {
316 1.1 mw #ifdef DEBUG
317 1.2 mw if (pardebug & PDB_IO)
318 1.2 mw printf("parrw: timeout/done\n");
319 1.1 mw #endif
320 1.2 mw splx(s);
321 1.2 mw break;
322 1.2 mw }
323 1.2 mw /*
324 1.2 mw * Implement inter-read delay
325 1.2 mw */
326 1.2 mw if (sc->sc_delay > 0)
327 1.2 mw {
328 1.2 mw sc->sc_flags |= PARF_DELAY;
329 1.2 mw timeout(parstart, unit, sc->sc_delay);
330 1.2 mw error = tsleep(sc, PCATCH|PZERO-1, "par-cdelay", 0);
331 1.2 mw if (error)
332 1.2 mw {
333 1.2 mw splx(s);
334 1.2 mw break;
335 1.2 mw }
336 1.2 mw }
337 1.1 mw splx(s);
338 1.2 mw /*
339 1.2 mw * Must not call uiomove again til we've used all data
340 1.2 mw * that we already grabbed.
341 1.2 mw */
342 1.2 mw if (uio->uio_rw == UIO_WRITE && cnt != len)
343 1.2 mw {
344 1.2 mw cp += cnt;
345 1.2 mw len -= cnt;
346 1.2 mw cnt = 0;
347 1.2 mw goto again;
348 1.2 mw }
349 1.1 mw }
350 1.2 mw s = splsoftclock();
351 1.2 mw if (sc->sc_flags & PARF_TIMO)
352 1.2 mw {
353 1.2 mw untimeout(partimo, unit);
354 1.2 mw sc->sc_flags &= ~PARF_TIMO;
355 1.1 mw }
356 1.2 mw if (sc->sc_flags & PARF_DELAY)
357 1.2 mw {
358 1.2 mw untimeout(parstart, unit);
359 1.2 mw sc->sc_flags &= ~PARF_DELAY;
360 1.1 mw }
361 1.1 mw splx(s);
362 1.1 mw /*
363 1.1 mw * Adjust for those chars that we uiomove'ed but never wrote
364 1.1 mw */
365 1.2 mw if (uio->uio_rw == UIO_WRITE && cnt != len)
366 1.2 mw {
367 1.2 mw uio->uio_resid += (len - cnt);
368 1.1 mw #ifdef DEBUG
369 1.2 mw if (pardebug & PDB_IO)
370 1.2 mw printf("parrw: short write, adjust by %d\n",
371 1.2 mw len-cnt);
372 1.1 mw #endif
373 1.2 mw }
374 1.1 mw free(buf, M_DEVBUF);
375 1.1 mw #ifdef DEBUG
376 1.1 mw if (pardebug & (PDB_FOLLOW|PDB_IO))
377 1.1 mw printf("parrw: return %d, resid %d\n", error, uio->uio_resid);
378 1.1 mw #endif
379 1.1 mw return (error);
380 1.1 mw }
381 1.1 mw
382 1.2 mw int
383 1.1 mw parioctl(dev, cmd, data, flag)
384 1.2 mw dev_t dev;
385 1.2 mw int cmd;
386 1.2 mw caddr_t data;
387 1.2 mw int flag;
388 1.1 mw {
389 1.1 mw struct par_softc *sc = &par_softc[UNIT(dev)];
390 1.1 mw struct parparam *pp, *upp;
391 1.1 mw int error = 0;
392 1.1 mw
393 1.2 mw switch (cmd)
394 1.2 mw {
395 1.2 mw case PARIOCGPARAM:
396 1.2 mw pp = &sc->sc_param;
397 1.2 mw upp = (struct parparam *)data;
398 1.2 mw upp->burst = pp->burst;
399 1.2 mw upp->timo = parhztoms(pp->timo);
400 1.2 mw upp->delay = parhztoms(pp->delay);
401 1.2 mw break;
402 1.2 mw
403 1.2 mw case PARIOCSPARAM:
404 1.2 mw pp = &sc->sc_param;
405 1.2 mw upp = (struct parparam *)data;
406 1.2 mw if (upp->burst < PAR_BURST_MIN || upp->burst > PAR_BURST_MAX ||
407 1.2 mw upp->delay < PAR_DELAY_MIN || upp->delay > PAR_DELAY_MAX)
408 1.2 mw return(EINVAL);
409 1.2 mw pp->burst = upp->burst;
410 1.2 mw pp->timo = parmstohz(upp->timo);
411 1.2 mw pp->delay = parmstohz(upp->delay);
412 1.2 mw break;
413 1.2 mw
414 1.2 mw default:
415 1.1 mw return(EINVAL);
416 1.2 mw }
417 1.1 mw return (error);
418 1.1 mw }
419 1.1 mw
420 1.2 mw int
421 1.1 mw parhztoms(h)
422 1.2 mw int h;
423 1.1 mw {
424 1.1 mw extern int hz;
425 1.1 mw register int m = h;
426 1.1 mw
427 1.1 mw if (m > 0)
428 1.1 mw m = m * 1000 / hz;
429 1.1 mw return(m);
430 1.1 mw }
431 1.1 mw
432 1.2 mw int
433 1.1 mw parmstohz(m)
434 1.2 mw int m;
435 1.1 mw {
436 1.1 mw extern int hz;
437 1.1 mw register int h = m;
438 1.1 mw
439 1.1 mw if (h > 0) {
440 1.1 mw h = h * hz / 1000;
441 1.1 mw if (h == 0)
442 1.1 mw h = 1000 / hz;
443 1.1 mw }
444 1.1 mw return(h);
445 1.1 mw }
446 1.1 mw
447 1.2 mw /* stuff below here if for interrupt driven output of data thru
448 1.2 mw the parallel port. */
449 1.2 mw
450 1.2 mw int partimeout_pending;
451 1.2 mw int parsend_pending;
452 1.2 mw
453 1.1 mw void
454 1.1 mw parintr (mask)
455 1.1 mw int mask;
456 1.1 mw {
457 1.2 mw int s = splclock();
458 1.2 mw #ifdef DEBUG
459 1.2 mw if (pardebug & PDB_INTERRUPT)
460 1.2 mw printf ("parintr %s\n", mask ? "FLG" : "tout");
461 1.2 mw #endif
462 1.2 mw /* if invoked from timeout handler, mask will be 0, if from
463 1.2 mw interrupt, it will contain the cia-icr mask, which is != 0 */
464 1.2 mw if (mask)
465 1.2 mw {
466 1.2 mw if (partimeout_pending)
467 1.2 mw untimeout ((timeout_t) parintr, 0);
468 1.2 mw if (parsend_pending)
469 1.2 mw parsend_pending = 0;
470 1.2 mw }
471 1.2 mw
472 1.2 mw /* either way, there won't be a timeout pending any longer */
473 1.2 mw partimeout_pending = 0;
474 1.2 mw
475 1.1 mw wakeup (parintr);
476 1.2 mw splx (s);
477 1.2 mw }
478 1.2 mw
479 1.2 mw int
480 1.2 mw parsendch (ch)
481 1.2 mw u_char ch;
482 1.2 mw {
483 1.2 mw int error = 0;
484 1.2 mw int s;
485 1.2 mw
486 1.2 mw /* if either offline, busy or out of paper, wait for that
487 1.2 mw condition to clear */
488 1.2 mw s = splclock();
489 1.2 mw while (!error
490 1.2 mw && (parsend_pending
491 1.2 mw || ((ciab.pra ^ CIAB_PRA_SEL)
492 1.2 mw & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT))))
493 1.2 mw {
494 1.2 mw extern int hz;
495 1.2 mw
496 1.2 mw #ifdef DEBUG
497 1.2 mw if (pardebug & PDB_INTERRUPT)
498 1.2 mw printf ("parsendch, port = $%x\n",
499 1.2 mw ((ciab.pra ^ CIAB_PRA_SEL)
500 1.2 mw & (CIAB_PRA_SEL|CIAB_PRA_BUSY|CIAB_PRA_POUT)));
501 1.2 mw #endif
502 1.2 mw /* wait a second, and try again */
503 1.2 mw timeout ((timeout_t) parintr, 0, hz);
504 1.2 mw partimeout_pending = 1;
505 1.2 mw /* this is essentially a flipflop to have us wait for the
506 1.2 mw first character being transmitted when trying to transmit
507 1.2 mw the second, etc. */
508 1.2 mw parsend_pending = 0;
509 1.2 mw /* it's quite important that a parallel putc can be
510 1.2 mw interrupted, given the possibility to lock a printer
511 1.2 mw in an offline condition.. */
512 1.2 mw if (error = tsleep (parintr, PCATCH|PZERO-1, "parsendch", 0))
513 1.2 mw {
514 1.2 mw #ifdef DEBUG
515 1.2 mw if (pardebug & PDB_INTERRUPT)
516 1.2 mw printf ("parsendch interrupted, error = %d\n", error);
517 1.2 mw #endif
518 1.2 mw if (partimeout_pending)
519 1.2 mw untimeout ((timeout_t) parintr, 0);
520 1.2 mw
521 1.2 mw partimeout_pending = 0;
522 1.2 mw }
523 1.2 mw }
524 1.2 mw
525 1.2 mw if (! error)
526 1.2 mw {
527 1.2 mw #ifdef DEBUG
528 1.2 mw if (pardebug & PDB_INTERRUPT)
529 1.2 mw printf ("#%d", ch);
530 1.2 mw #endif
531 1.2 mw ciaa.prb = ch;
532 1.2 mw parsend_pending = 1;
533 1.2 mw }
534 1.2 mw
535 1.2 mw splx (s);
536 1.2 mw
537 1.2 mw return error;
538 1.1 mw }
539 1.1 mw
540 1.2 mw
541 1.1 mw int
542 1.1 mw parsend (buf, len)
543 1.1 mw u_char *buf;
544 1.1 mw int len;
545 1.1 mw {
546 1.2 mw int err, orig_len = len;
547 1.2 mw
548 1.1 mw /* make sure I/O lines are setup right for output */
549 1.1 mw
550 1.1 mw /* control lines set to input */
551 1.1 mw ciab.ddra &= ~(CIAB_PRA_SEL|CIAB_PRA_POUT|CIAB_PRA_BUSY);
552 1.1 mw /* data lines to output */
553 1.1 mw ciaa.ddrb = 0xff;
554 1.1 mw
555 1.2 mw for (; len; len--, buf++)
556 1.2 mw if (err = parsendch (*buf))
557 1.2 mw return err < 0 ? -EINTR : -err;
558 1.2 mw
559 1.2 mw /* either all or nothing.. */
560 1.2 mw return orig_len;
561 1.1 mw }
562 1.1 mw
563 1.1 mw
564 1.1 mw
565 1.2 mw int
566 1.2 mw parreceive (buf, len)
567 1.2 mw u_char *buf;
568 1.2 mw int len;
569 1.2 mw {
570 1.2 mw /* oh deary me, something's gotta be left to be implemented
571 1.2 mw later... */
572 1.2 mw return 0;
573 1.2 mw }
574 1.1 mw
575 1.1 mw
576 1.1 mw #endif
577