⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quatech_daqp_cs.c

📁 rtlinux-3.2-pre3.tar.bz2 rtlinux3.2-pre3的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/*======================================================================    Quatech DAQP PCMCIA data capture cards COMEDI client driver    Copyright (C) 2000 Brent Baccala <baccala@freesoft.org>    The DAQP interface code in this file is released into the public domain.    COMEDI - Linux Control and Measurement Device Interface    Copyright (C) 1998 David A. Schleef <ds@schleef.org>    daqp_cs.c 1.00    Documentation for the DAQP PCMCIA cards can be found on Quatech's site:                ftp://ftp.quatech.com/Manuals/daqp-208.pdf    This manual is for both the DAQP-208 and the DAQP-308.    This code presently doesn't do D/A conversion; only A/D.    Also, I've had problems getting interrupts to work reliably,    the driver currently polls the card.    Multiple DAPQ cards are handled and can be independently attached    by specifying a numeric argument to comedi_config.  Cards are    numbered sequentially from 0 in the order they are inserted/detected.======================================================================*//*Driver: quatech_daqp_cs.oDescription: Quatech DAQP PCMCIA data capture cardsAuthor: Brent Baccala <baccala@freesoft.org>Status: unkownDevices: [Quatech] DAQP-208 (daqp), DAQP-308*/#include <linux/comedidev.h>#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/cisreg.h>#include <pcmcia/ds.h>/*   All the PCMCIA modules use PCMCIA_DEBUG to control debugging.  If   you do not define PCMCIA_DEBUG at all, all the debug code will be   left out.  If you compile with PCMCIA_DEBUG=0, the debug code will   be present but disabled -- but it can then be enabled for specific   modules at load time with a 'pc_debug=#' option to insmod.*/#ifdef PCMCIA_DEBUGstatic int pc_debug = PCMCIA_DEBUG;MODULE_PARM(pc_debug, "i");#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)static char *version ="daqp_cs.c 1.00 2000/10/02 (Brent Baccala)";#else#define DEBUG(n, args...)#endif/* Maximum number of separate DAQP devices we'll allow */#define MAX_DEV         4/* I can't get my DAQP-308 to reliably generate interrupts, so I poll it *//* #define USE_INTERRUPTS *//*   A dev_link_t structure has fields for most things that are needed   to keep track of a socket, but there will usually be some device   specific information that also needs to be kept track of.  The   'priv' pointer in a dev_link_t structure can be used to point to   a device-specific private data structure, like this.   To simplify the data structure handling, we actually include the   dev_link_t structure in the device's private data structure.   A driver needs to provide a dev_node_t structure for each device   on a card.  In some cases, there is only one device per card (for   example, ethernet cards, modems).  In other cases, there may be   many actual or logical devices (SCSI adapters, memory cards with   multiple partitions).  The dev_node_t structures need to be kept   in a linked list starting at the 'dev' field of a dev_link_t   structure.  We allocate them in the card's private data structure,   because they generally shouldn't be allocated dynamically.   We also provide an index into the dev_table*/   typedef struct local_info_t {    dev_link_t		link;    dev_node_t		node;    int			stop;    int			table_index;    wait_queue_head_t	endofscan;} local_info_t;/* A list of "instances" of the device. */static local_info_t *dev_table[MAX_DEV] = { NULL, /* ... */ };/* this is COMEDI's private data structure unique to this hardware driver.   Not to be confused with PCMCIA's local_info_t (above).*/typedef struct {	int devnum;} daqp_private;#define devpriv ((daqp_private *)dev->private)/*====================================================================*//* Parameters that can be set with 'insmod' *//* The old way: bit map of interrupts to choose from *//* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */static u_int irq_mask = 0xdeb8;/* Newer, simpler way of listing specific interrupts */static int irq_list[4] = { -1 };MODULE_PARM(irq_mask, "i");MODULE_PARM(irq_list, "1-4i");/*====================================================================*//* The DAQP communicates with the system through a 16 byte I/O window. */#define DAQP_FIFO_SIZE		4096#define DAQP_FIFO		0#define DAQP_SCANLIST		1#define DAQP_CONTROL		2#define DAQP_STATUS		2#define DAQP_DIGITAL_IO		3#define DAQP_PACER_LOW		4#define DAQP_PACER_MID		5#define DAQP_PACER_HIGH		6#define DAQP_COMMAND		7#define DAQP_DA			8#define DAQP_TIMER		10#define DAQP_AUX		15#define DAQP_SCANLIST_DIFFERENTIAL	0x4000#define DAQP_SCANLIST_GAIN(x)		((x)<<12)#define DAQP_SCANLIST_CHANNEL(x)	((x)<<8)#define DAQP_SCANLIST_START		0x0080#define DAQP_SCANLIST_EXT_GAIN(x)	((x)<<4)#define DAQP_SCANLIST_EXT_CHANNEL(x)	(x)#define DAQP_CONTROL_PACER_100kHz	0xc0#define DAQP_CONTROL_PACER_1MHz		0x80#define DAQP_CONTROL_PACER_5MHz		0x40#define DAQP_CONTROL_PACER_EXTERNAL	0x00#define DAQP_CONTORL_EXPANSION		0x20#define DAQP_CONTROL_EOS_INT_ENABLE	0x10#define DAQP_CONTROL_FIFO_INT_ENABLE	0x08#define DAQP_CONTROL_TRIGGER_ONESHOT	0x00#define DAQP_CONTROL_TRIGGER_CONTINUOUS	0x04#define DAQP_CONTROL_TRIGGER_INTERNAL	0x00#define DAQP_CONTROL_TRIGGER_EXTERNAL	0x02#define DAQP_CONTROL_TRIGGER_RISING	0x00#define DAQP_CONTROL_TRIGGER_FALLING	0x01#define DAQP_STATUS_IDLE		0x80#define DAQP_STATUS_RUNNING		0x40#define DAQP_STATUS_DATA_LOST		0x20#define DAQP_STATUS_END_OF_SCAN		0x10#define DAQP_STATUS_FIFO_THRESHOLD	0x08#define DAQP_STATUS_FIFO_FULL		0x04#define DAQP_STATUS_FIFO_NEARFULL	0x02#define DAQP_STATUS_FIFO_EMPTY		0x01#define DAQP_COMMAND_ARM		0x80#define DAQP_COMMAND_RSTF		0x40#define DAQP_COMMAND_RSTQ		0x20#define DAQP_COMMAND_STOP		0x10#define DAQP_COMMAND_LATCH		0x08#define DAQP_COMMAND_100kHz		0x00#define DAQP_COMMAND_50kHz		0x02#define DAQP_COMMAND_25kHz		0x04#define DAQP_COMMAND_FIFO_DATA		0x01#define DAQP_COMMAND_FIFO_PROGRAM	0x00#define DAQP_AUX_TRIGGER_TTL		0x00#define DAQP_AUX_TRIGGER_ANALOG		0x80#define DAQP_AUX_TRIGGER_PRETRIGGER	0x40#define DAQP_AUX_TIMER_INT_ENABLE	0x20#define DAQP_AUX_TIMER_RELOAD		0x00#define DAQP_AUX_TIMER_PAUSE		0x08#define DAQP_AUX_TIMER_GO		0x10#define DAQP_AUX_TIMER_GO_EXTERNAL	0x18#define DAQP_AUX_TIMER_EXTERNAL_SRC	0x04#define DAQP_AUX_TIMER_INTERNAL_SRC	0x00#define DAQP_AUX_DA_DIRECT		0x00#define DAQP_AUX_DA_OVERFLOW		0x01#define DAQP_AUX_DA_EXTERNAL		0x02#define DAQP_AUX_DA_PACER		0x03#define DAQP_AUX_RUNNING		0x80#define DAQP_AUX_TRIGGERED		0x40#define DAQP_AUX_DA_BUFFER		0x20#define DAQP_AUX_TIMER_OVERFLOW		0x10#define DAQP_AUX_CONVERSION		0x08#define DAQP_AUX_DATA_LOST		0x04#define DAQP_AUX_FIFO_NEARFULL		0x02#define DAQP_AUX_FIFO_EMPTY		0x01static comedi_lrange range_daqp_ai = { 4, {	BIP_RANGE( 10 ),	BIP_RANGE( 5 ),	BIP_RANGE( 2.5 ),	BIP_RANGE( 1.25 )}};/*====================================================================*//* comedi interface code */static int daqp_attach(comedi_device *dev,comedi_devconfig *it);static int daqp_detach(comedi_device *dev);static comedi_driver driver_daqp={	driver_name:	"daqp",	module:		THIS_MODULE,	attach:		daqp_attach,	detach:		daqp_detach,};static void daqp_dump(comedi_device *dev){	printk("DAQP: status %02x; aux status %02x\n",	       inb(dev->iobase + DAQP_STATUS), inb(dev->iobase + DAQP_AUX));}static int daqp_ai_insn_read(comedi_device *dev,comedi_subdevice *s,	comedi_insn *insn,lsampl_t *data){	local_info_t *local;	int i;	int v;	int counter=10000;#ifdef USE_INTERRUPTS	int threshold;	int flags;	int timeout;#endif	if (!dev_table[devpriv->devnum] || dev_table[devpriv->devnum]->stop) {		return -EIO;	} else {		local = dev_table[devpriv->devnum];	}	/* Stop any running conversion */	outb(DAQP_COMMAND_STOP,	     dev->iobase+DAQP_COMMAND);	outb(0, dev->iobase+DAQP_AUX);	/* Reset scan list queue */	outb(DAQP_COMMAND_RSTQ,	     dev->iobase+DAQP_COMMAND);	/* Program one scan list entry */	v = DAQP_SCANLIST_CHANNEL(CR_CHAN(insn->chanspec))		| DAQP_SCANLIST_GAIN(CR_RANGE(insn->chanspec));	if (CR_AREF(insn->chanspec) == AREF_DIFF) {		v |= DAQP_SCANLIST_DIFFERENTIAL;	}	v |= DAQP_SCANLIST_START;	outb(v & 0xff, dev->iobase + DAQP_SCANLIST);	outb(v >> 8, dev->iobase + DAQP_SCANLIST);	/* Reset data FIFO (see page 28 of DAQP User's Manual) */	outb(DAQP_COMMAND_RSTF,	     dev->iobase + DAQP_COMMAND);#ifdef USE_INTERRUPTS	/* Set FIFO threshold */	// threshold = DAQP_FIFO_SIZE - 2*it->n_chan;	threshold = DAQP_FIFO_SIZE - 1;	outb(0, dev->iobase + DAQP_FIFO);	outb(0, dev->iobase + DAQP_FIFO);	outb(threshold & 0xff, dev->iobase + DAQP_FIFO);	outb(threshold >> 8, dev->iobase + DAQP_FIFO);#endif	/* Set trigger */	v = DAQP_CONTROL_TRIGGER_ONESHOT | DAQP_CONTROL_TRIGGER_INTERNAL	  | DAQP_CONTROL_PACER_100kHz;#ifdef USE_INTERRUPTS	v |= DAQP_CONTROL_FIFO_INT_ENABLE;#endif	outb(v, dev->iobase + DAQP_CONTROL);#ifdef USE_INTERRUPTS	save_flags(flags);	cli();#endif	/* Start conversion */	outb(DAQP_COMMAND_ARM | DAQP_COMMAND_FIFO_DATA,	     dev->iobase + DAQP_COMMAND);#ifdef USE_INTERRUPTS	timeout = sleep_on_timeout(&local->endofscan, 1*HZ);	restore_flags(flags);	printk("timeout: %d\n", timeout);#endif	i=0;	/* Wait for data in FIFO */	while (--counter	       && (inb(dev->iobase + DAQP_STATUS)		   & DAQP_STATUS_FIFO_EMPTY));	if (!counter) {		printk("DAQP FIFO never got data!\n");		daqp_dump(dev);		return -EIO;	} else {		data[i] = inb(dev->iobase + DAQP_FIFO);		data[i] |= inb(dev->iobase + DAQP_FIFO) << 8;		data[i] ^= 0x8000;	}	/* XXX wrong, but I don't know how to fix it --ds */	return 1;}static void daqp_interrupt(int irq, void * dev_id, struct pt_regs *regs){	local_info_t *local = (local_info_t *)dev_id;	if (local == NULL) {		printk(KERN_WARNING "daqp_interrupt(): irq %d for unknown device.\n",		       irq);		return;	}	wake_up(&local->endofscan);	printk("daqp_interrupt()\n");}/* daqp_attach is called via comedi_config to attach a comedi device * to a /dev/comedi*.  Note that this is different from daqp_cs_attach() * which is called by the pcmcia subsystem to attach the PCMCIA card * when it is inserted. */static int daqp_attach(comedi_device *dev, comedi_devconfig *it){	int ret;	comedi_subdevice *s;	if (it->options[0] < 0 || it->options[0] >= MAX_DEV	    || ! dev_table[it->options[0]]) {	  printk("comedi%d: No such daqp device %d\n",		 dev->minor, it->options[0]);	  return -EIO;	}	/* Probably should pull this out of PCMCIA CIS tuples */	dev->board_name = "Quatech DAQP";	dev->iobase=dev_table[it->options[0]]->link.io.BasePort1;	if((ret=alloc_private(dev,sizeof(daqp_private))) < 0)		return ret;	devpriv->devnum = it->options[0];	if((ret=alloc_subdevices(dev, 1))<0)		return ret;	printk("comedi%d: attaching daqp%d (io 0x%04x)\n",	       dev->minor, it->options[0], dev->iobase);	s=dev->subdevices+0;	s->type=COMEDI_SUBD_AI;	s->subdev_flags=SDF_READABLE|AREF_GROUND|AREF_DIFF;	s->n_chan=8;	s->maxdata=0xffff;	s->range_table=&range_daqp_ai;	s->insn_read=daqp_ai_insn_read;	return 1;}/* daqp_detach (called from comedi_comdig) does nothing. If the PCMCIA * card is removed, daqp_cs_detach() is called by the pcmcia subsystem. */static int daqp_detach(comedi_device *dev){	printk("comedi%d: detaching daqp\n",dev->minor);		return 0;}/*====================================================================    PCMCIA interface code    The rest of the code in this file is based on dummy_cs.c v1.24    from the Linux pcmcia_cs distribution v3.1.8 and is subject    to the following license agreement.    The remaining contents of this file are subject to the Mozilla Public    License Version 1.1 (the "License"); you may not use this file    except in compliance with the License. You may obtain a copy of    the License at http://www.mozilla.org/MPL/    Software distributed under the License is distributed on an "AS    IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or    implied. See the License for the specific language governing    rights and limitations under the License.    The initial developer of the original code is David A. Hinds    <dhinds@pcmcia.sourceforge.org>.  Portions created by David A. Hinds    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.    Alternatively, the contents of this file may be used under the    terms of the GNU Public License version 2 (the "GPL"), in which    case the provisions of the GPL are applicable instead of the    above.  If you wish to allow the use of your version of this file    only under the terms of the GPL and not to allow others to use    your version of this file under the MPL, indicate your decision    by deleting the provisions above and replace them with the notice    and other provisions required by the GPL.  If you do not delete    the provisions above, a recipient may use your version of this    file under either the MPL or the GPL.    ======================================================================*//*   The event() function is this driver's Card Services event handler.   It will be called by Card Services when an appropriate card status   event is received.  The config() and release() entry points are   used to configure or release a socket, in response to card   insertion and ejection events.*/static void daqp_cs_config(dev_link_t *link);static void daqp_cs_release(u_long arg);static int daqp_cs_event(event_t event, int priority,		       event_callback_args_t *args);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -