From owner-freebsd-questions Thu Aug 31 13:06:11 1995 Return-Path: questions-owner Received: (from majordom@localhost) by freefall.FreeBSD.org (8.6.11/8.6.6) id NAA19896 for questions-outgoing; Thu, 31 Aug 1995 13:06:11 -0700 Received: from ref.tfs.com (ref.tfs.com [140.145.254.251]) by freefall.FreeBSD.org (8.6.11/8.6.6) with ESMTP id NAA19890 ; Thu, 31 Aug 1995 13:06:10 -0700 Received: (from julian@localhost) by ref.tfs.com (8.6.11/8.6.9) id NAA00449; Thu, 31 Aug 1995 13:04:28 -0700 From: Julian Elischer Message-Id: <199508312004.NAA00449@ref.tfs.com> Subject: Re: Driver creation.; [FAQ ENTRY] To: gatliff@cel.cummins.com (William A. Gatliff) Date: Thu, 31 Aug 1995 13:04:27 -0700 (PDT) Cc: questions@freebsd.org, faq@freebsd.org In-Reply-To: <9508311806.AA01512@cel.cummins.com> from "William A. Gatliff" at Aug 31, 95 01:06:50 pm X-Mailer: ELM [version 2.4 PL24] Content-Type: text Content-Length: 3508 Sender: questions-owner@freebsd.org Precedence: bulk well the easiest way to go is to copy an existing driver that does something similar to what you want.. first you need to get your driver included in the kernel: RUN THIS SCRIPT :) -------cut here------------------ #!/bin/sh cd /sys/i386/conf cat >>files.i386 <>DOHICKY <>../isa/dohicky.c < #include #include #include #include int dohickyprobe (struct isa_device *), dohickyattach (struct isa_device *); struct isa_driver dohickydriver = {dohickyprobe, dohickyattach, "dohicky"}; struct dh_softc { struct isa_device *dev; } static struct kern_devconf kdc_dohicky[NLPT] = { { 0, 0, 0, /* filled in by dev_attach */ "dohicky", 0, { MDDT_ISA, 0, "tty" }, isa_generic_externalize, 0, 0, ISA_EXTERNALLEN, &kdc_isa0, /* parent */ 0, /* parentdata */ DC_UNCONFIGURED, /* state */ "Parallel printer adapter", DC_CLS_PARALLEL | DC_CLS_NETIF /* class */ } }; static inline void dohicky_registerdev(struct isa_device *id) { if(id->id_unit) kdc_dohicky[id->id_unit] = kdc_dohicky[0]; kdc_dohicky[id->id_unit].kdc_unit = id->id_unit; kdc_dohicky[id->id_unit].kdc_isa = id; dev_attach(&kdc_dohicky[id->id_unit]); } #define NUMPORTS 4 /* add your own test to see if it exists */ /* should return the number of ports needed */ dohickyprobe (struct isa_device *dev) { outb (dev->id_iobase, 0xff); DELAY (10000); /* 10 ms delay */ return ((inb (dev->id_iobase) & 0x0f) == 0x0f)? NUMPORTS : 0 ; #endif } /* called if the probe succeeded */ int dohickyattach (struct isa_device *dev) { int unit = dev->id_unit; if (unit > 1) {printf("bad unit for dohicky\n");return;} /*set up your sown softc structures etc.*/ dh_softc[unit].dev = dev; /* this might be supposed to occur in the probe */ dohicky_registerdev(dev); return 1; } void dhintr(int unit) { if (unit > 1) {printf("bad unit for dohicky\n");return;} return 0 } int dohickyioctl (dev_t dev, int cmd, caddr_t data, int flag, struct proc *p) { int unit = UNIT (dev); int x; switch (cmd) { case DHIOCRESET: outb(dh_softc[unit]->id_iobase,0xff); /* whatever resets it */ break; default: return ENXIO; } return 0; } /* * you also nead read,write, open, close routines * but this should get you started */ DONE cat >>../../sys/dhio.h < > I'm planning to write a driver for a do-hickey that connects > to my PC's printer port or uses an i/o card (ISA). > > Can anyone point me to some tutorial info on how to write > drivers for FreeBSD? > > Thanks! > > b.g. > >