hil_gpib.c revision 1.1
1#include <sys/param.h> 2#include <sys/systm.h> 3#include <sys/callout.h> 4#include <sys/conf.h> 5#include <sys/device.h> 6 7#include <dev/gpib/gpibvar.h> 8 9#ifdef DEBUG 10int hildebug = 0; 11#define HDB_FOLLOW 0x01 12#define HDB_MMAP 0x02 13#define HDB_MASK 0x04 14#define HDB_CONFIG 0x08 15#define HDB_KEYBOARD 0x10 16#define HDB_IDMODULE 0x20 17#define HDB_EVENTS 0x80 18#define DPRINTF(mask, str) if (hildebug & (mask)) printf str 19#else 20#define DPRINTF(mask, str) /* nothing */ 21#endif 22 23struct hil_softc { 24 struct device sc_dev; 25 gpib_chipset_tag_t sc_ic; 26 gpib_handle_t sc_hdl; 27 28 int sc_address; /* GPIB address */ 29 int sc_flags; 30#define HILF_ALIVE 0x01 31#define HILF_OPEN 0x02 32#define HILF_UIO 0x04 33#define HILF_TIMO 0x08 34#define HILF_DELAY 0x10 35}; 36 37int hilmatch(struct device *, struct cfdata *, void *); 38void hilattach(struct device *, struct device *, void *); 39 40const struct cfattach hil_ca = { 41 sizeof(struct hil_softc), hilmatch, hilattach, 42}; 43 44void hilcallback(void *, int); 45void hilstart(void *); 46 47int 48hilmatch(parent, match, aux) 49 struct device *parent; 50 struct cfdata *match; 51 void *aux; 52{ 53 struct gpib_attach_args *ga = aux; 54 u_int8_t *cmd = "SE;"; 55 u_int8_t stat; 56 57 if (gpibsend(ga->ga_ic, ga->ga_address, -1, cmd, 3) != 3) 58 return (0); 59 if (gpibrecv(ga->ga_ic, ga->ga_address, -1, &stat, 1) != 1) 60 return (0); 61 printf("hilmatch: enable status byte 0x%x\n", stat); 62 return (1); 63} 64 65void 66hilattach(parent, self, aux) 67 struct device *parent, *self; 68 void *aux; 69{ 70 struct hil_softc *sc = (struct hil_softc *)self; 71 struct gpib_attach_args *ga = aux; 72 73 printf("\n"); 74 75 sc->sc_ic = ga->ga_ic; 76 sc->sc_address = ga->ga_address; 77 78 if (gpibregister(sc->sc_ic, sc->sc_address, hilcallback, sc, 79 &sc->sc_hdl)) { 80 printf("%s: can't register callback\n", sc->sc_dev.dv_xname); 81 return; 82 } 83 84 sc->sc_flags = HILF_ALIVE; 85} 86 87void 88hilcallback(v, action) 89 void *v; 90 int action; 91{ 92 struct hil_softc *sc = v; 93 94 DPRINTF(HDB_FOLLOW, ("hilcallback: v=%p, action=%d\n", v, action)); 95 96 switch (action) { 97 case GPIBCBF_START: 98 hilstart(sc); 99 case GPIBCBF_INTR: 100 /* no-op */ 101 break; 102#ifdef DEBUG 103 default: 104 DPRINTF(HDB_FOLLOW, ("hilcallback: unknown action %d\n", 105 action)); 106 break; 107#endif 108 } 109} 110 111void 112hilstart(v) 113 void *v; 114{ 115 struct hil_softc *sc = v; 116 117 DPRINTF(HDB_FOLLOW, ("hilstart(%x)\n", sc->sc_dev.dv_unit)); 118 119 sc->sc_flags &= ~HILF_DELAY; 120} 121