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

📄 das08.c

📁 rtlinux-3.2-pre3.tar.bz2 rtlinux3.2-pre3的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*    comedi/drivers/das.c    DAS08 driver    COMEDI - Linux Control and Measurement Device Interface    Copyright (C) 2000 David A. Schleef <ds@schleef.org>    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.******************************************************************//*Driver: das08.oDescription: DAS-08 compatible boardsAuthor: Warren Jasper, ds, Frank HessDevices: [ComputerBoards] DAS08 (das08), DAS08-PGM (das08-pgm),  DAS08-PGH (das08-pgh), DAS08-PGL (das08-pgl), DAS08-AOH (das08-aoh),  DAS08-AOL (das08-aol), DAS08-AOM (das08-aom), DAS08/JR-AO (das08/jr-ao),  DAS08/JR-16-AO (das08jr-16-ao), PCI-DAS08 (pci-das08), PCM-DAS08 (pcm-das08),  PC104-DAS08 (pc104-das08), DAS08/JR/16 (das08jr/16)Status: worksThis is a rewrite of the das08 and das08jr drivers.Options (for ISA cards):        [0] - base io addressOptions (for pci-das08):        [0] - bus  (optional)        [1] = slot (optional)Use the name 'pci-das08' for the pci-das08, NOT 'das08'.Options (for pcm-das08):        NONEThe das08 driver doesn't support asynchronous commands, sincethe cheap das08 hardware doesn't really support them (except forpcm-das08).  Thecomedi_rt_timer driver can be used to emulate commands for thisdriver.*/#include <linux/comedidev.h>#include <linux/delay.h>#include <linux/pci.h>#include "8255.h"// pcmcia includes#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)#include <pcmcia/version.h>#include <pcmcia/cs_types.h>#include <pcmcia/cs.h>#include <pcmcia/cistpl.h>#include <pcmcia/ds.h>#endif	// CONFIG_PCMCIA#define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307#define PCI_DEVICE_ID_PCIDAS08 0x29#define PCIDAS08_SIZE 0x54// pci configuration registers#define INTCSR               0x4c#define   INTR1_ENABLE         0x1#define   INTR1_HIGH_POLARITY  0x2#define   PCI_INTR_ENABLE      0x40#define   INTR1_EDGE_TRIG      0x100	// requires high polarity#define CNTRL                0x50#define   CNTRL_DIR            0x2#define   CNTRL_INTR           0x4/*    cio-das08.pdf  "das08"  0	a/d bits 0-3		start 8 bit  1	a/d bits 4-11		start 12 bit  2	eoc, ip1-3, irq, mux	op1-4, inte, mux  3	unused			unused  4567	8254  89ab	8255  requires hard-wiring for async ai*/#define DAS08_LSB		0#define DAS08_MSB		1#define DAS08_TRIG_12BIT	1#define DAS08_STATUS		2#define   DAS08_EOC			(1<<7)#define   DAS08_IRQ			(1<<3)#define   DAS08_IP(x)			(((x)>>4)&0x7)#define DAS08_CONTROL		2#define   DAS08_MUX_MASK	0x7#define   DAS08_MUX(x)		((x) & DAS08_MUX_MASK)#define   DAS08_INTE			(1<<3)#define   DAS08_DO_MASK		0xf0#define   DAS08_OP(x)		(((x) << 4) & DAS08_DO_MASK)/*    cio-das08jr.pdf  "das08/jr-ao"  0	a/d bits 0-3		unused  1	a/d bits 4-11		start 12 bit  2	eoc, mux		mux  3	di			do  4	unused			ao0_lsb  5	unused			ao0_msb  6	unused			ao1_lsb  7	unused			ao1_msb*/#define DAS08JR_DIO		3#define DAS08JR_AO_LSB(x)	((x)?6:4)#define DAS08JR_AO_MSB(x)	((x)?7:5)/*    cio-das08_aox.pdf  "das08-aoh"  "das08-aol"  "das08-aom"  0	a/d bits 0-3		start 8 bit  1	a/d bits 4-11		start 12 bit  2	eoc, ip1-3, irq, mux	op1-4, inte, mux  3	mux, gain status	gain control  4567	8254  8	unused			ao0_lsb  9	unused			ao0_msb  a	unused			ao1_lsb  b	unused			ao1_msb  89ab  cdef	8255*/#define DAS08AO_GAIN_CONTROL	3#define DAS08AO_GAIN_STATUS	3#define DAS08AO_AO_LSB(x)	((x)?0xa:8)#define DAS08AO_AO_MSB(x)	((x)?0xb:9)#define DAS08AO_AO_UPDATE	8/* gainlist same as _pgx_ below */static int das08_ai_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);static int das08_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);static int das08_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);static int das08jr_di_rbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);static int das08jr_do_wbits(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);static int das08jr_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);static int das08ao_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data);#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)/*   A linked list of "instances" of the das08_pcmcia device.  Each actual   PCMCIA card corresponds to one device instance, and is described   by one dev_link_t structure (defined in ds.h).   You may not want to use a linked list for this -- for example, the   memory card driver uses an array of dev_link_t pointers, where minor   device numbers are used to derive the corresponding array index.*/static dev_link_t *dev_list = NULL;#endifstatic comedi_lrange range_das08_pgl = { 9, {	BIP_RANGE(10),	BIP_RANGE(5),	BIP_RANGE(2.5),	BIP_RANGE(1.25),	BIP_RANGE(0.625),	UNI_RANGE(10),	UNI_RANGE(5),	UNI_RANGE(2.5),	UNI_RANGE(1.25)}};static comedi_lrange range_das08_pgh = { 12, {	BIP_RANGE(10),	BIP_RANGE(5),	BIP_RANGE(1),	BIP_RANGE(0.5),	BIP_RANGE(0.1),	BIP_RANGE(0.05),	BIP_RANGE(0.01),	BIP_RANGE(0.005),	UNI_RANGE(10),	UNI_RANGE(1),	UNI_RANGE(0.1),	UNI_RANGE(0.01),}};static comedi_lrange range_das08_pgm = { 9, {	BIP_RANGE(10),	BIP_RANGE(5),	BIP_RANGE(0.5),	BIP_RANGE(0.05),	BIP_RANGE(0.01),	UNI_RANGE(10),	UNI_RANGE(1),	UNI_RANGE(0.1),	UNI_RANGE(0.01)}};/*    cio-das08jr.pdf  "das08/jr-ao"  0	a/d bits 0-3		unused  1	a/d bits 4-11		start 12 bit  2	eoc, mux		mux  3	di			do  4	unused			ao0_lsb  5	unused			ao0_msb  6	unused			ao1_lsb  7	unused			ao1_msb*/enum das08_lrange {das08_pg_none, das08_bipolar5, das08_pgh, das08_pgl, das08_pgm};static comedi_lrange *das08_ai_lranges[]={	&range_unknown,	&range_bipolar5,	&range_das08_pgh,	&range_das08_pgl,	&range_das08_pgm,};static int das08_pgh_gainlist[] = { 8, 0, 10, 2, 12, 4, 14, 6, 1, 3, 5, 7 };static int das08_pgl_gainlist[] = { 8, 0, 2, 4, 6, 1, 3, 5, 7 };static int das08_pgm_gainlist[] = { 8, 0, 10, 12, 14, 9, 11, 13, 15 };static int *das08_gainlists[] = {	NULL,	NULL,	das08_pgh_gainlist,	das08_pgl_gainlist,	das08_pgm_gainlist,};enum das08_bustype {isa, pci, pcmcia, pc104};// different ways ai data is encoded in first two registersenum das08_ai_encoding {das08_encode12, das08_encode16, das08_pcm_encode12};typedef struct das08_board_struct{	char		*name;	unsigned int	id;	// id for pci/pcmcia boards	enum das08_bustype	bustype;	void		*ai;	unsigned int	ai_nbits;	enum das08_lrange	ai_pg;	enum das08_ai_encoding	ai_encoding;	void		*ao;	unsigned int	ao_nbits;	void		*di;	void		*do_;	unsigned int	do_nchan;	unsigned int	i8255_offset;	unsigned int	i8254_offset;	unsigned int	iosize;	// number of ioports used} das08_board;static struct das08_board_struct das08_boards[]={	{	name:		"das08",		// cio-das08.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pg_none,	ai_encoding:	das08_encode12,	ao:		NULL,	ao_nbits:	12,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	8,	i8254_offset:	4,	iosize:	16, // unchecked	},	{	name:		"das08-pgm",		// cio-das08pgx.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pgm,	ai_encoding:	das08_encode12,	ao:		NULL,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"das08-pgh",		// cio-das08pgx.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pgh,	ai_encoding:	das08_encode12,	ao:		NULL,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"das08-pgl",		// cio-das08pgx.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pgl,	ai_encoding:	das08_encode12,	ao:		NULL,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"das08-aoh",		// cio-das08_aox.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pgh,	ai_encoding:	das08_encode12,	ao:		das08ao_ao_winsn,	// 8	ao_nbits:	12,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0x0c,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"das08-aol",		// cio-das08_aox.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pgl,	ai_encoding:	das08_encode12,	ao:		das08ao_ao_winsn,	// 8	ao_nbits:	12,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0x0c,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"das08-aom",		// cio-das08_aox.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pgm,	ai_encoding:	das08_encode12,	ao:		das08ao_ao_winsn,	// 8	ao_nbits:	12,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0x0c,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"das08/jr-ao",		// cio-das08-jr-ao.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pg_none,	ai_encoding:	das08_encode12,	ao:		das08jr_ao_winsn,	ao_nbits:	12,	di:		das08jr_di_rbits,	do_:		das08jr_do_wbits,	do_nchan:	8,	i8255_offset:	0,	i8254_offset:	0,	iosize:	16, // unchecked	},	{	name:		"das08jr-16-ao",	// cio-das08jr-16-ao.pdf	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	16,	ai_pg:		das08_pg_none,	ai_encoding:	das08_encode12,	ao:		das08jr_ao_winsn,	ao_nbits:	16,	di:		das08jr_di_rbits,	do_:		das08jr_do_wbits,	do_nchan:	8,	i8255_offset:	0,	i8254_offset:	0x04,	iosize:	16, // unchecked	},	{	name:		"pci-das08",	id:	PCI_DEVICE_ID_PCIDAS08,	bustype:	pci,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_bipolar5,	ai_encoding:	das08_encode12,	ao:		NULL,	ao_nbits:	0,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0,	i8254_offset:	4,	iosize:	8,	},#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)	{	name:		"pcm-das08",	id:	0x0,	// XXX	bustype:	pcmcia,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_bipolar5,	ai_encoding:	das08_pcm_encode12,	ao:		NULL,	ao_nbits:	0,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	3,	i8255_offset:	0,	i8254_offset:	0,	iosize:	16, // unchecked	},#endif // CONFIG_PCMCIA	{	name:		"pc104-das08",	bustype:	pc104,	ai:		das08_ai_rinsn,	ai_nbits:	12,	ai_pg:		das08_pg_none,	ai_encoding:	das08_encode12,	ao:		NULL,	ao_nbits:	0,	di:		das08_di_rbits,	do_:		das08_do_wbits,	do_nchan:	4,	i8255_offset:	0,	i8254_offset:	4,	iosize:	16, // unchecked	},#if 0	{	name:		"das08/f",	},	{	name:		"das08jr",	},#endif	{	name:		"das08jr/16",	bustype:	isa,	ai:		das08_ai_rinsn,	ai_nbits:	16,	ai_pg:		das08_pg_none,	ai_encoding:	das08_encode16,	ao:		NULL,	ao_nbits:	0,	di:		das08jr_di_rbits,	do_:		das08jr_do_wbits,	do_nchan:	8,	i8255_offset:	0,	i8254_offset:	0,	iosize:	16, // unchecked	},#if 0

⌨️ 快捷键说明

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