3 comedi routines for voltage ranges
5 COMEDI - Linux Control and Measurement Device Interface
6 Copyright (C) 1997-8 David A. Schleef <ds@stm.lbl.gov>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <comedi_module.h>
26 #include <asm/uaccess.h>
30 comedi_lrange range_bipolar10={ 1, {BIP_RANGE(10)}};
31 comedi_lrange range_bipolar5={ 1, {BIP_RANGE(5)}};
32 comedi_lrange range_bipolar2_5={ 1, {BIP_RANGE(2.5)}};
33 comedi_lrange range_unipolar10={ 1, {UNI_RANGE(10)}};
34 comedi_lrange range_unipolar5={ 1, {UNI_RANGE(5)}};
35 comedi_lrange range_unknown={ 1, {{0,1,0}}}; /* XXX */
39 range information ioctl
42 pointer to rangeinfo structure
48 n comedi_krange structures to rangeinfo->range_ptr
50 int do_rangeinfo_ioctl(comedi_device *dev,comedi_rangeinfo *arg)
57 if(copy_from_user(&it,arg,sizeof(comedi_rangeinfo)))
60 minor=(it.range_type>>24)&0xf;
61 subd=(it.range_type>>20)&0xf;
62 chan=(it.range_type>>16)&0xff;
64 if(minor>COMEDI_NDEVICES)
66 dev=comedi_devices+minor;
67 if(!dev->attached)return -EINVAL;
68 if(subd>=dev->n_subdevices)return -EINVAL;
69 s=dev->subdevices+subd;
72 }else if(s->range_table_list){
73 if(chan>=s->n_chan)return -EINVAL;
74 lr=s->range_table_list[chan];
79 if(copy_to_user(it.range_ptr,lr->range,
80 sizeof(comedi_krange)*lr->length))
88 This function checks each element in a channel/gain list to make
89 make sure it is valid.
91 int check_chanlist(comedi_subdevice *s,int n,unsigned int *chanlist)
99 if(CR_CHAN(chanlist[i])>=s->n_chan ||
100 CR_RANGE(chanlist[i])>=s->range_table->length){
101 rt_printk("bad chanlist[%d]=0x%08x n_chan=%d range length=%d\n",
102 i,chanlist[i],s->n_chan,s->range_table->length);
105 printk("[%d]=0x%08x\n",i,chanlist[i]);
110 }else if(s->range_table_list){
112 chan=CR_CHAN(chanlist[i]);
113 if(chan>=s->n_chan ||
114 CR_RANGE(chanlist[i])>=s->range_table_list[chan]->length){
115 rt_printk("bad chanlist[%d]=0x%08x\n",i,chanlist[i]);
120 rt_printk("comedi: (bug) no range type list!\n");