home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / sys / hp300 / stand / fhpib.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-05  |  5.0 KB  |  190 lines

  1. /*
  2.  * Copyright (c) 1982, 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms, with or without
  6.  * modification, are permitted provided that the following conditions
  7.  * are met:
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  * 2. Redistributions in binary form must reproduce the above copyright
  11.  *    notice, this list of conditions and the following disclaimer in the
  12.  *    documentation and/or other materials provided with the distribution.
  13.  * 3. All advertising materials mentioning features or use of this software
  14.  *    must display the following acknowledgement:
  15.  *    This product includes software developed by the University of
  16.  *    California, Berkeley and its contributors.
  17.  * 4. Neither the name of the University nor the names of its contributors
  18.  *    may be used to endorse or promote products derived from this software
  19.  *    without specific prior written permission.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31.  * SUCH DAMAGE.
  32.  *
  33.  *    @(#)fhpib.c    7.2 (Berkeley) 12/16/90
  34.  */
  35.  
  36. /*
  37.  * 98625A/B HPIB driver
  38.  */
  39.  
  40. #include "sys/param.h"
  41. #include "../dev/fhpibreg.h"
  42. #include "hpibvar.h"
  43.  
  44. fhpibinit(unit)
  45.     register int unit;
  46. {
  47.     register struct hpib_softc *hs = &hpib_softc[unit];
  48.     register struct fhpibdevice *hd = (struct fhpibdevice *)hs->sc_addr;
  49.  
  50.     if (hd->hpib_cid != HPIBC)
  51.         return(0);
  52.     hs->sc_type = HPIBC;
  53.     hs->sc_ba = HPIBC_BA;
  54.     fhpibreset(unit);
  55.     return(1);
  56. }
  57.  
  58. fhpibreset(unit)
  59. {
  60.     register struct hpib_softc *hs = &hpib_softc[unit];
  61.     register struct fhpibdevice *hd;
  62.  
  63.     hd = (struct fhpibdevice *)hs->sc_addr;
  64.     hd->hpib_cid = 0xFF;
  65.     DELAY(100);
  66.     hd->hpib_cmd = CT_8BIT;
  67.     hd->hpib_ar = AR_ARONC;
  68.     hd->hpib_cmd |= CT_IFC;
  69.     hd->hpib_cmd |= CT_INITFIFO;
  70.     DELAY(100);
  71.     hd->hpib_cmd &= ~CT_IFC;
  72.     hd->hpib_cmd |= CT_REN;
  73.     hd->hpib_stat = ST_ATN;
  74.     hd->hpib_data = C_DCL;
  75.     DELAY(100000);
  76. }
  77.  
  78. fhpibsend(unit, slave, sec, buf, cnt)
  79.     register char *buf;
  80.     register int cnt;
  81. {
  82.     register struct hpib_softc *hs = &hpib_softc[unit];
  83.     register struct fhpibdevice *hd;
  84.     int origcnt = cnt;
  85.  
  86.     hd = (struct fhpibdevice *)hs->sc_addr;
  87.     hd->hpib_stat = 0;
  88.     hd->hpib_imask = IM_IDLE | IM_ROOM;
  89.     fhpibwait(hd, IM_IDLE);
  90.     hd->hpib_stat = ST_ATN;
  91.     hd->hpib_data = C_UNL;
  92.     hd->hpib_data = C_TAG + hs->sc_ba;
  93.     hd->hpib_data = C_LAG + slave;
  94.     if (sec != -1)
  95.         hd->hpib_data = C_SCG + sec;
  96.     fhpibwait(hd, IM_IDLE);
  97.     hd->hpib_stat = ST_WRITE;
  98.     if (cnt) {
  99.         while (--cnt) {
  100.             hd->hpib_data = *buf++;
  101.             if (fhpibwait(hd, IM_ROOM) < 0)
  102.                 break;
  103.         }
  104.         hd->hpib_stat = ST_EOI;
  105.         hd->hpib_data = *buf;
  106.         if (fhpibwait(hd, IM_ROOM) < 0)
  107.             cnt++;
  108.         hd->hpib_stat = ST_ATN;
  109.         /* XXX: HP-UX claims bug with CS80 transparent messages */
  110.         if (sec == 0x12)
  111.             DELAY(150);
  112.         hd->hpib_data = C_UNL;
  113.         fhpibwait(hd, IM_IDLE);
  114.     }
  115.     hd->hpib_imask = 0;
  116.     return(origcnt - cnt);
  117. }
  118.  
  119. fhpibrecv(unit, slave, sec, buf, cnt)
  120.     register char *buf;
  121.     register int cnt;
  122. {
  123.     register struct hpib_softc *hs = &hpib_softc[unit];
  124.     register struct fhpibdevice *hd;
  125.     int origcnt = cnt;
  126.  
  127.     hd = (struct fhpibdevice *)hs->sc_addr;
  128.     hd->hpib_stat = 0;
  129.     hd->hpib_imask = IM_IDLE | IM_ROOM | IM_BYTE;
  130.     fhpibwait(hd, IM_IDLE);
  131.     hd->hpib_stat = ST_ATN;
  132.     hd->hpib_data = C_UNL;
  133.     hd->hpib_data = C_LAG + hs->sc_ba;
  134.     hd->hpib_data = C_TAG + slave;
  135.     if (sec != -1)
  136.         hd->hpib_data = C_SCG + sec;
  137.     fhpibwait(hd, IM_IDLE);
  138.     hd->hpib_stat = ST_READ0;
  139.     hd->hpib_data = 0;
  140.     if (cnt) {
  141.         while (--cnt >= 0) {
  142.             if (fhpibwait(hd, IM_BYTE) < 0)
  143.                 break;
  144.             *buf++ = hd->hpib_data;
  145.         }
  146.         cnt++;
  147.         fhpibwait(hd, IM_ROOM);
  148.         hd->hpib_stat = ST_ATN;
  149.         hd->hpib_data = (slave == 31) ? C_UNA : C_UNT;
  150.         fhpibwait(hd, IM_IDLE);
  151.     }
  152.     hd->hpib_imask = 0;
  153.     return(origcnt - cnt);
  154. }
  155.  
  156. fhpibppoll(unit)
  157.     register int unit;
  158. {
  159.     register struct hpib_softc *hs = &hpib_softc[unit];
  160.     register struct fhpibdevice *hd;
  161.     register int ppoll;
  162.  
  163.     hd = (struct fhpibdevice *)hs->sc_addr;
  164.     hd->hpib_stat = 0;
  165.     hd->hpib_psense = 0;
  166.     hd->hpib_pmask = 0xFF;
  167.     hd->hpib_imask = IM_PPRESP | IM_PABORT;
  168.     DELAY(25);
  169.     hd->hpib_intr = IM_PABORT;
  170.     ppoll = hd->hpib_data;
  171.     if (hd->hpib_intr & IM_PABORT)
  172.         ppoll = 0;
  173.     hd->hpib_imask = 0;
  174.     hd->hpib_pmask = 0;
  175.     hd->hpib_stat = ST_IENAB;
  176.     return(ppoll);
  177. }
  178.  
  179. fhpibwait(hd, x)
  180.     register struct fhpibdevice *hd;
  181. {
  182.     register int timo = 100000;
  183.  
  184.     while ((hd->hpib_intr & x) == 0 && --timo)
  185.         ;
  186.     if (timo == 0)
  187.         return(-1);
  188.     return(0);
  189. }
  190.