ppi.c revision 1.13 1 1.13 scottr /* $NetBSD: ppi.c,v 1.13 1997/04/02 22:37:33 scottr Exp $ */
2 1.6 cgd
3 1.1 cgd /*
4 1.11 thorpej * Copyright (c) 1996, 1997 Jason R. Thorpe. All rights reserved.
5 1.5 mycroft * Copyright (c) 1982, 1990, 1993
6 1.5 mycroft * The Regents of the University of California. All rights reserved.
7 1.1 cgd *
8 1.1 cgd * Redistribution and use in source and binary forms, with or without
9 1.1 cgd * modification, are permitted provided that the following conditions
10 1.1 cgd * are met:
11 1.1 cgd * 1. Redistributions of source code must retain the above copyright
12 1.1 cgd * notice, this list of conditions and the following disclaimer.
13 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 cgd * notice, this list of conditions and the following disclaimer in the
15 1.1 cgd * documentation and/or other materials provided with the distribution.
16 1.1 cgd * 3. All advertising materials mentioning features or use of this software
17 1.1 cgd * must display the following acknowledgement:
18 1.1 cgd * This product includes software developed by the University of
19 1.1 cgd * California, Berkeley and its contributors.
20 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
21 1.1 cgd * may be used to endorse or promote products derived from this software
22 1.1 cgd * without specific prior written permission.
23 1.1 cgd *
24 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 cgd * SUCH DAMAGE.
35 1.1 cgd *
36 1.6 cgd * @(#)ppi.c 8.1 (Berkeley) 6/16/93
37 1.1 cgd */
38 1.1 cgd
39 1.1 cgd /*
40 1.1 cgd * Printer/Plotter HPIB interface
41 1.1 cgd */
42 1.1 cgd
43 1.3 mycroft #include <sys/param.h>
44 1.3 mycroft #include <sys/systm.h>
45 1.12 scottr #include <sys/conf.h>
46 1.12 scottr #include <sys/device.h>
47 1.3 mycroft #include <sys/errno.h>
48 1.12 scottr #include <sys/malloc.h>
49 1.12 scottr #include <sys/proc.h>
50 1.3 mycroft #include <sys/uio.h>
51 1.11 thorpej
52 1.11 thorpej #include <hp300/dev/hpibvar.h>
53 1.1 cgd
54 1.3 mycroft #include <hp300/dev/ppiioctl.h>
55 1.1 cgd
56 1.1 cgd struct ppi_softc {
57 1.11 thorpej struct device sc_dev;
58 1.1 cgd int sc_flags;
59 1.11 thorpej struct hpibqueue sc_hq; /* HP-IB job queue entry */
60 1.1 cgd struct ppiparam sc_param;
61 1.1 cgd #define sc_burst sc_param.burst
62 1.1 cgd #define sc_timo sc_param.timo
63 1.1 cgd #define sc_delay sc_param.delay
64 1.1 cgd int sc_sec;
65 1.11 thorpej int sc_slave; /* HP-IB slave address */
66 1.11 thorpej };
67 1.1 cgd
68 1.1 cgd /* sc_flags values */
69 1.1 cgd #define PPIF_ALIVE 0x01
70 1.1 cgd #define PPIF_OPEN 0x02
71 1.1 cgd #define PPIF_UIO 0x04
72 1.1 cgd #define PPIF_TIMO 0x08
73 1.1 cgd #define PPIF_DELAY 0x10
74 1.1 cgd
75 1.11 thorpej int ppimatch __P((struct device *, struct cfdata *, void *));
76 1.11 thorpej void ppiattach __P((struct device *, struct device *, void *));
77 1.11 thorpej
78 1.11 thorpej struct cfattach ppi_ca = {
79 1.11 thorpej sizeof(struct ppi_softc), ppimatch, ppiattach
80 1.11 thorpej };
81 1.11 thorpej
82 1.11 thorpej struct cfdriver ppi_cd = {
83 1.11 thorpej NULL, "ppi", DV_DULL
84 1.11 thorpej };
85 1.11 thorpej
86 1.11 thorpej void ppistart __P((void *));
87 1.11 thorpej void ppinoop __P((void *));
88 1.11 thorpej
89 1.11 thorpej void ppitimo __P((void *));
90 1.11 thorpej int ppirw __P((dev_t, struct uio *));
91 1.11 thorpej int ppihztoms __P((int));
92 1.11 thorpej int ppimstohz __P((int));
93 1.11 thorpej
94 1.11 thorpej bdev_decl(ppi);
95 1.11 thorpej cdev_decl(ppi);
96 1.11 thorpej
97 1.1 cgd #define UNIT(x) minor(x)
98 1.1 cgd
99 1.1 cgd #ifdef DEBUG
100 1.1 cgd int ppidebug = 0x80;
101 1.1 cgd #define PDB_FOLLOW 0x01
102 1.1 cgd #define PDB_IO 0x02
103 1.1 cgd #define PDB_NOCHECK 0x80
104 1.1 cgd #endif
105 1.1 cgd
106 1.7 thorpej int
107 1.11 thorpej ppimatch(parent, match, aux)
108 1.11 thorpej struct device *parent;
109 1.11 thorpej struct cfdata *match;
110 1.11 thorpej void *aux;
111 1.1 cgd {
112 1.11 thorpej struct hpibbus_attach_args *ha = aux;
113 1.11 thorpej
114 1.11 thorpej /*
115 1.11 thorpej * The printer/plotter doesn't return an ID tag.
116 1.11 thorpej * The check below prevents us from matching a CS80
117 1.11 thorpej * device by mistake.
118 1.11 thorpej */
119 1.11 thorpej if (ha->ha_id & 0x200)
120 1.11 thorpej return (0);
121 1.1 cgd
122 1.1 cgd /*
123 1.11 thorpej * To prevent matching all unused slots on the bus, we
124 1.11 thorpej * don't allow wildcarded locators.
125 1.1 cgd */
126 1.11 thorpej if (match->hpibbuscf_slave == HPIBBUS_SLAVE_UNK ||
127 1.11 thorpej match->hpibbuscf_punit == HPIBBUS_PUNIT_UNK)
128 1.7 thorpej return (0);
129 1.7 thorpej
130 1.7 thorpej return (1);
131 1.7 thorpej }
132 1.7 thorpej
133 1.7 thorpej void
134 1.11 thorpej ppiattach(parent, self, aux)
135 1.11 thorpej struct device *parent, *self;
136 1.11 thorpej void *aux;
137 1.7 thorpej {
138 1.11 thorpej struct ppi_softc *sc = (struct ppi_softc *)self;
139 1.11 thorpej struct hpibbus_attach_args *ha = aux;
140 1.7 thorpej
141 1.10 christos printf("\n");
142 1.7 thorpej
143 1.11 thorpej sc->sc_slave = ha->ha_slave;
144 1.11 thorpej
145 1.11 thorpej /* Initialize the hpib queue entry. */
146 1.11 thorpej sc->sc_hq.hq_softc = sc;
147 1.11 thorpej sc->sc_hq.hq_slave = sc->sc_slave;
148 1.11 thorpej sc->sc_hq.hq_start = ppistart;
149 1.11 thorpej sc->sc_hq.hq_go = ppinoop;
150 1.11 thorpej sc->sc_hq.hq_intr = ppinoop;
151 1.11 thorpej
152 1.1 cgd sc->sc_flags = PPIF_ALIVE;
153 1.1 cgd }
154 1.1 cgd
155 1.11 thorpej void
156 1.11 thorpej ppinoop(arg)
157 1.11 thorpej void *arg;
158 1.11 thorpej {
159 1.11 thorpej /* Noop! */
160 1.11 thorpej }
161 1.11 thorpej
162 1.11 thorpej int
163 1.11 thorpej ppiopen(dev, flags, fmt, p)
164 1.1 cgd dev_t dev;
165 1.11 thorpej int flags, fmt;
166 1.11 thorpej struct proc *p;
167 1.1 cgd {
168 1.12 scottr int unit = UNIT(dev);
169 1.11 thorpej struct ppi_softc *sc;
170 1.11 thorpej
171 1.11 thorpej if (unit >= ppi_cd.cd_ndevs ||
172 1.11 thorpej (sc = ppi_cd.cd_devs[unit]) == NULL ||
173 1.11 thorpej (sc->sc_flags & PPIF_ALIVE) == 0)
174 1.11 thorpej return (ENXIO);
175 1.1 cgd
176 1.1 cgd #ifdef DEBUG
177 1.1 cgd if (ppidebug & PDB_FOLLOW)
178 1.10 christos printf("ppiopen(%x, %x): flags %x\n",
179 1.1 cgd dev, flags, sc->sc_flags);
180 1.1 cgd #endif
181 1.1 cgd if (sc->sc_flags & PPIF_OPEN)
182 1.11 thorpej return (EBUSY);
183 1.1 cgd sc->sc_flags |= PPIF_OPEN;
184 1.1 cgd sc->sc_burst = PPI_BURST;
185 1.1 cgd sc->sc_timo = ppimstohz(PPI_TIMO);
186 1.1 cgd sc->sc_delay = ppimstohz(PPI_DELAY);
187 1.1 cgd sc->sc_sec = -1;
188 1.1 cgd return(0);
189 1.1 cgd }
190 1.1 cgd
191 1.11 thorpej int
192 1.11 thorpej ppiclose(dev, flags, fmt, p)
193 1.1 cgd dev_t dev;
194 1.11 thorpej int flags, fmt;
195 1.11 thorpej struct proc *p;
196 1.1 cgd {
197 1.12 scottr int unit = UNIT(dev);
198 1.11 thorpej struct ppi_softc *sc = ppi_cd.cd_devs[unit];
199 1.1 cgd
200 1.1 cgd #ifdef DEBUG
201 1.1 cgd if (ppidebug & PDB_FOLLOW)
202 1.10 christos printf("ppiclose(%x, %x): flags %x\n",
203 1.1 cgd dev, flags, sc->sc_flags);
204 1.1 cgd #endif
205 1.1 cgd sc->sc_flags &= ~PPIF_OPEN;
206 1.1 cgd return(0);
207 1.1 cgd }
208 1.1 cgd
209 1.11 thorpej void
210 1.11 thorpej ppistart(arg)
211 1.11 thorpej void *arg;
212 1.1 cgd {
213 1.11 thorpej struct ppi_softc *sc = arg;
214 1.11 thorpej
215 1.1 cgd #ifdef DEBUG
216 1.1 cgd if (ppidebug & PDB_FOLLOW)
217 1.13 scottr printf("ppistart(%x)\n", sc->sc_dev.dv_unit);
218 1.1 cgd #endif
219 1.11 thorpej sc->sc_flags &= ~PPIF_DELAY;
220 1.11 thorpej wakeup(sc);
221 1.1 cgd }
222 1.1 cgd
223 1.5 mycroft void
224 1.11 thorpej ppitimo(arg)
225 1.11 thorpej void *arg;
226 1.1 cgd {
227 1.11 thorpej struct ppi_softc *sc = arg;
228 1.11 thorpej
229 1.1 cgd #ifdef DEBUG
230 1.1 cgd if (ppidebug & PDB_FOLLOW)
231 1.11 thorpej printf("ppitimo(%x)\n", sc->sc_dev.dv_unit);
232 1.1 cgd #endif
233 1.11 thorpej sc->sc_flags &= ~(PPIF_UIO|PPIF_TIMO);
234 1.11 thorpej wakeup(sc);
235 1.1 cgd }
236 1.1 cgd
237 1.11 thorpej int
238 1.11 thorpej ppiread(dev, uio, flags)
239 1.1 cgd dev_t dev;
240 1.1 cgd struct uio *uio;
241 1.11 thorpej int flags;
242 1.1 cgd {
243 1.1 cgd
244 1.1 cgd #ifdef DEBUG
245 1.1 cgd if (ppidebug & PDB_FOLLOW)
246 1.13 scottr printf("ppiread(%x, %p)\n", dev, uio);
247 1.1 cgd #endif
248 1.1 cgd return (ppirw(dev, uio));
249 1.1 cgd }
250 1.1 cgd
251 1.11 thorpej int
252 1.11 thorpej ppiwrite(dev, uio, flags)
253 1.1 cgd dev_t dev;
254 1.1 cgd struct uio *uio;
255 1.11 thorpej int flags;
256 1.1 cgd {
257 1.1 cgd
258 1.1 cgd #ifdef DEBUG
259 1.1 cgd if (ppidebug & PDB_FOLLOW)
260 1.13 scottr printf("ppiwrite(%x, %p)\n", dev, uio);
261 1.1 cgd #endif
262 1.1 cgd return (ppirw(dev, uio));
263 1.1 cgd }
264 1.1 cgd
265 1.11 thorpej int
266 1.1 cgd ppirw(dev, uio)
267 1.1 cgd dev_t dev;
268 1.12 scottr struct uio *uio;
269 1.1 cgd {
270 1.1 cgd int unit = UNIT(dev);
271 1.11 thorpej struct ppi_softc *sc = ppi_cd.cd_devs[unit];
272 1.12 scottr int s, len, cnt;
273 1.12 scottr char *cp;
274 1.1 cgd int error = 0, gotdata = 0;
275 1.11 thorpej int buflen, ctlr, slave;
276 1.1 cgd char *buf;
277 1.1 cgd
278 1.1 cgd if (uio->uio_resid == 0)
279 1.1 cgd return(0);
280 1.1 cgd
281 1.11 thorpej ctlr = sc->sc_dev.dv_parent->dv_unit;
282 1.11 thorpej slave = sc->sc_slave;
283 1.11 thorpej
284 1.1 cgd #ifdef DEBUG
285 1.1 cgd if (ppidebug & (PDB_FOLLOW|PDB_IO))
286 1.13 scottr printf("ppirw(%x, %p, %c): burst %d, timo %d, resid %x\n",
287 1.1 cgd dev, uio, uio->uio_rw == UIO_READ ? 'R' : 'W',
288 1.1 cgd sc->sc_burst, sc->sc_timo, uio->uio_resid);
289 1.1 cgd #endif
290 1.5 mycroft buflen = min(sc->sc_burst, uio->uio_resid);
291 1.1 cgd buf = (char *)malloc(buflen, M_DEVBUF, M_WAITOK);
292 1.1 cgd sc->sc_flags |= PPIF_UIO;
293 1.1 cgd if (sc->sc_timo > 0) {
294 1.1 cgd sc->sc_flags |= PPIF_TIMO;
295 1.11 thorpej timeout(ppitimo, sc, sc->sc_timo);
296 1.1 cgd }
297 1.12 scottr len = cnt = 0;
298 1.1 cgd while (uio->uio_resid > 0) {
299 1.5 mycroft len = min(buflen, uio->uio_resid);
300 1.1 cgd cp = buf;
301 1.1 cgd if (uio->uio_rw == UIO_WRITE) {
302 1.1 cgd error = uiomove(cp, len, uio);
303 1.1 cgd if (error)
304 1.1 cgd break;
305 1.1 cgd }
306 1.1 cgd again:
307 1.1 cgd s = splbio();
308 1.11 thorpej if ((sc->sc_flags & PPIF_UIO) &&
309 1.11 thorpej hpibreq(sc->sc_dev.dv_parent, &sc->sc_hq) == 0)
310 1.1 cgd sleep(sc, PRIBIO+1);
311 1.1 cgd /*
312 1.1 cgd * Check if we timed out during sleep or uiomove
313 1.1 cgd */
314 1.1 cgd (void) splsoftclock();
315 1.1 cgd if ((sc->sc_flags & PPIF_UIO) == 0) {
316 1.1 cgd #ifdef DEBUG
317 1.1 cgd if (ppidebug & PDB_IO)
318 1.10 christos printf("ppirw: uiomove/sleep timo, flags %x\n",
319 1.1 cgd sc->sc_flags);
320 1.1 cgd #endif
321 1.1 cgd if (sc->sc_flags & PPIF_TIMO) {
322 1.11 thorpej untimeout(ppitimo, sc);
323 1.1 cgd sc->sc_flags &= ~PPIF_TIMO;
324 1.1 cgd }
325 1.1 cgd splx(s);
326 1.1 cgd break;
327 1.1 cgd }
328 1.1 cgd splx(s);
329 1.1 cgd /*
330 1.1 cgd * Perform the operation
331 1.1 cgd */
332 1.1 cgd if (uio->uio_rw == UIO_WRITE)
333 1.11 thorpej cnt = hpibsend(ctlr, slave, sc->sc_sec, cp, len);
334 1.1 cgd else
335 1.11 thorpej cnt = hpibrecv(ctlr, slave, sc->sc_sec, cp, len);
336 1.1 cgd s = splbio();
337 1.11 thorpej hpibfree(sc->sc_dev.dv_parent, &sc->sc_hq);
338 1.1 cgd #ifdef DEBUG
339 1.1 cgd if (ppidebug & PDB_IO)
340 1.13 scottr printf("ppirw: %s(%d, %d, %x, %p, %d) -> %d\n",
341 1.1 cgd uio->uio_rw == UIO_READ ? "recv" : "send",
342 1.11 thorpej ctlr, slave, sc->sc_sec, cp, len, cnt);
343 1.1 cgd #endif
344 1.1 cgd splx(s);
345 1.1 cgd if (uio->uio_rw == UIO_READ) {
346 1.1 cgd if (cnt) {
347 1.1 cgd error = uiomove(cp, cnt, uio);
348 1.1 cgd if (error)
349 1.1 cgd break;
350 1.1 cgd gotdata++;
351 1.1 cgd }
352 1.1 cgd /*
353 1.1 cgd * Didn't get anything this time, but did in the past.
354 1.1 cgd * Consider us done.
355 1.1 cgd */
356 1.1 cgd else if (gotdata)
357 1.1 cgd break;
358 1.1 cgd }
359 1.1 cgd s = splsoftclock();
360 1.1 cgd /*
361 1.1 cgd * Operation timeout (or non-blocking), quit now.
362 1.1 cgd */
363 1.1 cgd if ((sc->sc_flags & PPIF_UIO) == 0) {
364 1.1 cgd #ifdef DEBUG
365 1.1 cgd if (ppidebug & PDB_IO)
366 1.10 christos printf("ppirw: timeout/done\n");
367 1.1 cgd #endif
368 1.1 cgd splx(s);
369 1.1 cgd break;
370 1.1 cgd }
371 1.1 cgd /*
372 1.1 cgd * Implement inter-read delay
373 1.1 cgd */
374 1.1 cgd if (sc->sc_delay > 0) {
375 1.1 cgd sc->sc_flags |= PPIF_DELAY;
376 1.11 thorpej timeout(ppistart, sc, sc->sc_delay);
377 1.12 scottr error = tsleep(sc, (PCATCH|PZERO) + 1, "hpib", 0);
378 1.1 cgd if (error) {
379 1.1 cgd splx(s);
380 1.1 cgd break;
381 1.1 cgd }
382 1.1 cgd }
383 1.1 cgd splx(s);
384 1.1 cgd /*
385 1.1 cgd * Must not call uiomove again til we've used all data
386 1.1 cgd * that we already grabbed.
387 1.1 cgd */
388 1.1 cgd if (uio->uio_rw == UIO_WRITE && cnt != len) {
389 1.1 cgd cp += cnt;
390 1.1 cgd len -= cnt;
391 1.1 cgd cnt = 0;
392 1.1 cgd goto again;
393 1.1 cgd }
394 1.1 cgd }
395 1.1 cgd s = splsoftclock();
396 1.1 cgd if (sc->sc_flags & PPIF_TIMO) {
397 1.11 thorpej untimeout(ppitimo, sc);
398 1.1 cgd sc->sc_flags &= ~PPIF_TIMO;
399 1.1 cgd }
400 1.1 cgd if (sc->sc_flags & PPIF_DELAY) {
401 1.11 thorpej untimeout(ppistart, sc);
402 1.1 cgd sc->sc_flags &= ~PPIF_DELAY;
403 1.1 cgd }
404 1.1 cgd splx(s);
405 1.1 cgd /*
406 1.1 cgd * Adjust for those chars that we uiomove'ed but never wrote
407 1.1 cgd */
408 1.1 cgd if (uio->uio_rw == UIO_WRITE && cnt != len) {
409 1.1 cgd uio->uio_resid += (len - cnt);
410 1.1 cgd #ifdef DEBUG
411 1.1 cgd if (ppidebug & PDB_IO)
412 1.10 christos printf("ppirw: short write, adjust by %d\n",
413 1.1 cgd len-cnt);
414 1.1 cgd #endif
415 1.1 cgd }
416 1.1 cgd free(buf, M_DEVBUF);
417 1.1 cgd #ifdef DEBUG
418 1.1 cgd if (ppidebug & (PDB_FOLLOW|PDB_IO))
419 1.10 christos printf("ppirw: return %d, resid %d\n", error, uio->uio_resid);
420 1.1 cgd #endif
421 1.1 cgd return (error);
422 1.1 cgd }
423 1.1 cgd
424 1.11 thorpej int
425 1.3 mycroft ppiioctl(dev, cmd, data, flag, p)
426 1.1 cgd dev_t dev;
427 1.11 thorpej u_long cmd;
428 1.1 cgd caddr_t data;
429 1.1 cgd int flag;
430 1.3 mycroft struct proc *p;
431 1.1 cgd {
432 1.11 thorpej struct ppi_softc *sc = ppi_cd.cd_devs[UNIT(dev)];
433 1.1 cgd struct ppiparam *pp, *upp;
434 1.1 cgd int error = 0;
435 1.1 cgd
436 1.1 cgd switch (cmd) {
437 1.1 cgd case PPIIOCGPARAM:
438 1.1 cgd pp = &sc->sc_param;
439 1.1 cgd upp = (struct ppiparam *)data;
440 1.1 cgd upp->burst = pp->burst;
441 1.1 cgd upp->timo = ppihztoms(pp->timo);
442 1.1 cgd upp->delay = ppihztoms(pp->delay);
443 1.1 cgd break;
444 1.1 cgd case PPIIOCSPARAM:
445 1.1 cgd pp = &sc->sc_param;
446 1.1 cgd upp = (struct ppiparam *)data;
447 1.1 cgd if (upp->burst < PPI_BURST_MIN || upp->burst > PPI_BURST_MAX ||
448 1.1 cgd upp->delay < PPI_DELAY_MIN || upp->delay > PPI_DELAY_MAX)
449 1.1 cgd return(EINVAL);
450 1.1 cgd pp->burst = upp->burst;
451 1.1 cgd pp->timo = ppimstohz(upp->timo);
452 1.1 cgd pp->delay = ppimstohz(upp->delay);
453 1.1 cgd break;
454 1.1 cgd case PPIIOCSSEC:
455 1.1 cgd sc->sc_sec = *(int *)data;
456 1.1 cgd break;
457 1.1 cgd default:
458 1.1 cgd return(EINVAL);
459 1.1 cgd }
460 1.1 cgd return (error);
461 1.1 cgd }
462 1.1 cgd
463 1.11 thorpej int
464 1.1 cgd ppihztoms(h)
465 1.1 cgd int h;
466 1.1 cgd {
467 1.1 cgd extern int hz;
468 1.12 scottr int m = h;
469 1.1 cgd
470 1.1 cgd if (m > 0)
471 1.1 cgd m = m * 1000 / hz;
472 1.1 cgd return(m);
473 1.1 cgd }
474 1.1 cgd
475 1.11 thorpej int
476 1.1 cgd ppimstohz(m)
477 1.1 cgd int m;
478 1.1 cgd {
479 1.1 cgd extern int hz;
480 1.12 scottr int h = m;
481 1.1 cgd
482 1.1 cgd if (h > 0) {
483 1.1 cgd h = h * hz / 1000;
484 1.1 cgd if (h == 0)
485 1.1 cgd h = 1000 / hz;
486 1.1 cgd }
487 1.1 cgd return(h);
488 1.1 cgd }
489