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

📄 cb_das16_cs.c

📁 rtlinux-3.2-pre3.tar.bz2 rtlinux3.2-pre3的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	}else{		/* external trigger */		/* should be level/edge, hi/lo specification here */		/* should specify multiple external triggers */		if(cmd->scan_begin_arg>9){			cmd->scan_begin_arg=9;			err++;		}	}	if(cmd->convert_src==TRIG_TIMER){		if(cmd->convert_arg<MAX_SPEED){			cmd->convert_arg=MAX_SPEED;			err++;		}		if(cmd->convert_arg>MIN_SPEED){			cmd->convert_arg=MIN_SPEED;			err++;		}	}else{		/* external trigger */		/* see above */		if(cmd->convert_arg>9){			cmd->convert_arg=9;			err++;		}	}	if(cmd->scan_end_arg!=cmd->chanlist_len){		cmd->scan_end_arg=cmd->chanlist_len;		err++;	}	if(cmd->stop_src==TRIG_COUNT){		if(cmd->stop_arg>0x00ffffff){			cmd->stop_arg=0x00ffffff;			err++;		}	}else{		/* TRIG_NONE */		if(cmd->stop_arg!=0){			cmd->stop_arg=0;			err++;		}	}	if(err)return 3;	/* step 4: fix up any arguments */	if(cmd->scan_begin_src==TRIG_TIMER){		unsigned int div1, div2;		tmp=cmd->scan_begin_arg;		i8253_cascade_ns_to_timer(100, &div1, &div2, 			&cmd->scan_begin_arg, cmd->flags&TRIG_ROUND_MASK);		if(tmp!=cmd->scan_begin_arg)err++;	}	if(cmd->convert_src==TRIG_TIMER){		unsigned int div1, div2;		tmp=cmd->convert_arg;		i8253_cascade_ns_to_timer(100, &div1, &div2, 			&cmd->scan_begin_arg, cmd->flags&TRIG_ROUND_MASK);		if(tmp!=cmd->convert_arg)err++;		if(cmd->scan_begin_src==TRIG_TIMER &&		  cmd->scan_begin_arg<cmd->convert_arg*cmd->scan_end_arg){			cmd->scan_begin_arg=cmd->convert_arg*cmd->scan_end_arg;			err++;		}	}	if(err)return 4;	return 0;}static int das16cs_ao_winsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){	int i;	int chan = CR_CHAN(insn->chanspec);	unsigned short status1;	unsigned short d;	int bit;	for(i=0;i<insn->n;i++){		devpriv->ao_readback[chan] = data[i];		d = data[i];		//devpriv->status1 |= 0x0009;		outw(devpriv->status1, dev->iobase + 4);		comedi_udelay(1);		status1 = devpriv->status1;		//if(chan)status1 &= ~0x0008;		//else status1 &= ~0x0001;		if(chan)status1 |= 0x0008;		else status1 |= 0x0001;		printk("0x%04x\n",status1);		outw(status1, dev->iobase + 4);		comedi_udelay(1);		for(bit=15;bit>=0;bit--){			int b = (d>>bit)&1;			printk("0x%04x\n",status1 | b | 0x0000);			outw(status1 | b | 0x0000, dev->iobase + 4);			comedi_udelay(1);			printk("0x%04x\n",status1 | b | 0x0004);			outw(status1 | b | 0x0004, dev->iobase + 4);			comedi_udelay(1);		}		outw(devpriv->status1, dev->iobase + 4);	}	return i;}/* AO subdevices should have a read insn as well as a write insn. * Usually this means copying a value stored in devpriv. */static int das16cs_ao_rinsn(comedi_device *dev,comedi_subdevice *s,comedi_insn *insn,lsampl_t *data){	int i;	int chan = CR_CHAN(insn->chanspec);	for(i=0;i<insn->n;i++)		data[i] = devpriv->ao_readback[chan];	return i;}/* DIO devices are slightly special.  Although it is possible to * implement the insn_read/insn_write interface, it is much more * useful to applications if you implement the insn_bits interface. * This allows packed reading/writing of the DIO channels.  The * comedi core can convert between insn_bits and insn_read/write */static int das16cs_dio_insn_bits(comedi_device *dev,comedi_subdevice *s,	comedi_insn *insn,lsampl_t *data){	if(insn->n!=2)return -EINVAL;	if(data[0]){		s->state &= ~data[0];		s->state |= data[0]&data[1];		outw(s->state,dev->iobase + 16);	}	/* on return, data[1] contains the value of the digital	 * input and output lines. */	data[1]=inw(dev->iobase + 16);	return 2;}static int das16cs_dio_insn_config(comedi_device *dev,comedi_subdevice *s,	comedi_insn *insn,lsampl_t *data){	int chan=CR_CHAN(insn->chanspec);	int bits;	if(insn->n!=1)return -EINVAL;	if(chan<4)bits=0x0f;	else bits=0xf0;	if(data[0]==COMEDI_OUTPUT){		s->io_bits |= bits;	}else{		s->io_bits &= bits;	}	devpriv->status2 &= ~0x00c0;	devpriv->status2 |= (s->io_bits&0xf0)?0x0080:0;	devpriv->status2 |= (s->io_bits&0x0f)?0x0040:0;	outw(devpriv->status2,dev->iobase + 6);	return 1;}static int das16cs_timer_insn_read(comedi_device *dev,comedi_subdevice *s,	comedi_insn *insn,lsampl_t *data){	return -EINVAL;}static int das16cs_timer_insn_config(comedi_device *dev,comedi_subdevice *s,	comedi_insn *insn,lsampl_t *data){	return -EINVAL;}/* PCMCIA stuff *//*======================================================================    The following pcmcia code for the pcm-das08 is adapted from the    dummy_cs.c driver of the Linux PCMCIA Card Services package.    The initial developer of the original code is David A. Hinds    <dahinds@users.sourceforge.net>.  Portions created by David A. Hinds    are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.======================================================================*//*   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.*/#if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)#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 ="cb_das16_cs.c pcmcia code (David Schleef), modified from dummy_cs.c 1.31 2001/08/24 12:13:13 (David Hinds)";#else#define DEBUG(n, args...)#endif/*====================================================================*//* 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 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.  They are invoked from the das08_pcmcia   event handler.*/static void das16cs_pcmcia_config(dev_link_t *link);static void das16cs_pcmcia_release(u_long arg);static int das16cs_pcmcia_event(event_t event, int priority,		       event_callback_args_t *args);/*   The attach() and detach() entry points are used to create and destroy   "instances" of the driver, where each instance represents everything   needed to manage one actual PCMCIA card.*/static dev_link_t *das16cs_pcmcia_attach(void);static void das16cs_pcmcia_detach(dev_link_t *);/*   You'll also need to prototype all the functions that will actually   be used to talk to your device.  See 'memory_cs' for a good example   of a fully self-sufficient driver; the other drivers rely more or   less on other parts of the kernel.*//*   The dev_info variable is the "key" that is used to match up this   device driver with appropriate cards, through the card configuration   database.*/static dev_info_t dev_info = "cb_das16_cs";/*   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.   In this case, we also provide a flag to indicate if a device is   "stopped" due to a power management event, or card ejection.  The   device IO routines can use a flag like this to throttle IO to a   card that is not ready to accept it.   The bus_operations pointer is used on platforms for which we need   to use special socket-specific versions of normal IO primitives   (inb, outb, readb, writeb, etc) for card IO.*/typedef struct local_info_t {    dev_link_t		link;    dev_node_t		node;    int			stop;    struct bus_operations *bus;} local_info_t;/*====================================================================*/static void cs_error(client_handle_t handle, int func, int ret){    error_info_t err = { func, ret };    CardServices(ReportError, handle, &err);}/*======================================================================    das16cs_pcmcia_attach() creates an "instance" of the driver, allocating    local data structures for one device.  The device is registered    with Card Services.    The dev_link structure is initialized, but we don't actually    configure the card at this point -- we wait until we receive a    card insertion event.======================================================================*/static dev_link_t *das16cs_pcmcia_attach(void){    local_info_t *local;    dev_link_t *link;    client_reg_t client_reg;    int ret, i;    DEBUG(0, "das16cs_pcmcia_attach()\n");    /* Allocate space for private device-specific data */    local = kmalloc(sizeof(local_info_t), GFP_KERNEL);    if (!local) return NULL;    memset(local, 0, sizeof(local_info_t));    link = &local->link; link->priv = local;    /* Initialize the dev_link_t structure */    link->release.function = &das16cs_pcmcia_release;    link->release.data = (u_long)link;    /* Interrupt setup */    link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;    link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;    if (irq_list[0] == -1)	link->irq.IRQInfo2 = irq_mask;    else	for (i = 0; i < 4; i++)	    link->irq.IRQInfo2 |= 1 << irq_list[i];    link->irq.Handler = NULL;    /*      General socket configuration defaults can go here.  In this      client, we assume very little, and rely on the CIS for almost      everything.  In most clients, many details (i.e., number, sizes,      and attributes of IO windows) are fixed by the nature of the      device, and can be hard-wired here.    */    link->conf.Attributes = 0;    link->conf.Vcc = 50;    link->conf.IntType = INT_MEMORY_AND_IO;    /* Register with Card Services */    link->next = dev_list;    dev_list = link;    client_reg.dev_info = &dev_info;    client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;    client_reg.EventMask =	CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |	CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |	CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;    client_reg.event_handler = &das16cs_pcmcia_event;    client_reg.Version = 0x0210;    client_reg.event_callback_args.client_data = link;    ret = CardServices(RegisterClient, &link->handle, &client_reg);    if (ret != CS_SUCCESS) {	cs_error(link->handle, RegisterClient, ret);	das16cs_pcmcia_detach(link);	return NULL;    }

⌨️ 快捷键说明

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